This commit is contained in:
Kavalar 2024-06-26 12:42:42 +03:00
parent e28dfe172d
commit b9425ee8cf
10 changed files with 107 additions and 38 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea .idea
vendor

View File

@ -1,25 +1,20 @@
<?php <?php
namespace src;
use src\debug\Debug; use src\debug\Debug;
use src\dto\InformationDTO; use src\dto\InformationDTO;
use src\file_db_driver\FileDatabaseDriver; use src\file_db_driver\FileDatabaseDriver;
use src\models\UserModel;
require_once "vendor/autoload.php"; require_once "vendor/autoload.php";
ini_set("display_errors", true);
error_reporting(-1);
//$fileName = "Information.txt"; //$fileName = "Information.txt";
//$fileModeOpen = "a"; //$fileModeOpen = "a";
$fullInformation = new InformationDTO(); $user = new UserModel();
$fullInformation->load($_REQUEST); $user->load($_REQUEST);
$user->save();
$string = $fullInformation->toString();
$obj = new FileDatabaseDriver();
$obj->connect(__DIR__ . "/Information.txt");
//$obj->updateServiceInfo($string);
$obj->save($string);
$obj->close();
require "views/search.php"; require "views/search.php";

View File

@ -5,31 +5,20 @@ use src\Processing;
require_once "vendor/autoload.php"; require_once "vendor/autoload.php";
$rep = new \src\file_db_driver\FileDatabaseDriver(); ini_set("display_errors", true);
$rep->connect(__DIR__ . "/Information.txt"); error_reporting(-1);
$columnKeys = $rep->getHeadKeys(); $user = new \src\models\UserModel();
//$columnValues = $rep->getHeadValues();
$columnValues = ['id','Фамилия','Имя','Отчество','Дата рождения','Пол','Код страны','Номер телефона','Email','Статус'];
$columns = array_combine($columnKeys, $columnValues);
//$res = $rep->find([$_REQUEST['key'] => $_REQUEST['result_search']])->limit(7)->all(); //$res = $rep->find([$_REQUEST['key'] => $_REQUEST['result_search']])->limit(7)->all();
//$res = $rep->find($_REQUEST)->limit(10)->all(); //$res = $rep->find($_REQUEST)->limit(10)->all();
$res = $rep->find(['name' => ['Станислав', 'Анастасия', 'Анжела'], 'status' => ['0']])->limit(10)->all(); $res = $user->find(['name' => ['Анжела']])->limit(10)->all();
$rep->close();
$infArr = [];
foreach ($res as $key){
$inf = new InformationDTO();
$inf->load($key);
$infArr[] = $inf;
}
$json = new Processing(); $json = new Processing();
$infArr = $json->createJsonArray($columns, $infArr, "form1"); $infArr = $json->createJsonArray($user->labels(), $res, "form1");
$table = new \Itguild\Tables\ListJsonTable($infArr); $table = new \Itguild\Tables\ListJsonTable($infArr);
$table->create(); $table->create();

View File

@ -18,6 +18,8 @@ class Processing
"meta" => [ "meta" => [
"title" => $title, "title" => $title,
"columns" => $columns, "columns" => $columns,
"perPage" => 10,
"currentPage" => 1,
"params" => "params" =>
[ [
"class" => "table table-bordered", "class" => "table table-bordered",

View File

@ -2,6 +2,7 @@
namespace src\dto; namespace src\dto;
#[\AllowDynamicProperties]
class BaseDTO class BaseDTO
{ {
public int $id; public int $id;

View File

@ -24,6 +24,8 @@ class InformationDTO extends BaseDTO
public string $countryCode; public string $countryCode;
public string $phoneNumber; public string $phoneNumber;
public string $email; public string $email;
public int $status = 0;
public function __construct() public function __construct()
{ {
@ -35,7 +37,7 @@ class InformationDTO extends BaseDTO
public function fillable(): array public function fillable(): array
{ {
// return [ // return [
// 'surname', 'name', 'patronymic', 'dateOfBirth', 'gender', 'countryCode', 'phoneNumber', 'email' // 'surname', 'name', 'patronymic', 'dateOfBirth', 'gender', 'countryCode', 'phoneNumber', 'email', 'status'
// ]; // ];
return [ return [
$this->surname, $this->name, $this->patronymic, $this->dateOfBirth, $this->gender, $this->countryCode, $this->phoneNumber, $this->email, "\n" $this->surname, $this->name, $this->patronymic, $this->dateOfBirth, $this->gender, $this->countryCode, $this->phoneNumber, $this->email, "\n"

View File

@ -76,7 +76,7 @@ class FileDatabaseDriver
// return $this->headValues; // return $this->headValues;
// } // }
public function find(array $query): self public function find(array $query = []): self
{ {
foreach ($query as $key => $value) { foreach ($query as $key => $value) {
$this->query[$key] = $value; $this->query[$key] = $value;
@ -110,7 +110,7 @@ class FileDatabaseDriver
$flag = false; $flag = false;
foreach ($this->query as $key => $value) { foreach ($this->query as $key => $value) {
foreach ($this->query[$key] as $k => $v) { foreach ($this->query[$key] as $k => $v) {
if (strlen($this->searchInStr($v, $item, $key)) > 0) { if ($this->searchInStr($v, $item, $key)) {
$flag = true; $flag = true;
break; break;
} else { } else {
@ -128,11 +128,11 @@ class FileDatabaseDriver
return $resArr; return $resArr;
} }
protected function searchInStr(string $strForSearch, array $item, string $column): ?string protected function searchInStr(string $strForSearch, array $item, string $column): ?array
{ {
if (isset($item[$column])) { if (isset($item[$column])) {
if (preg_match("/" . $strForSearch . "/", $item[$column])) { if (preg_match("/" . $strForSearch . "/", $item[$column])) {
return $item[$column]; return $item;
} }
} }
@ -142,6 +142,7 @@ class FileDatabaseDriver
public function all(): array public function all(): array
{ {
$this->resArr = $this->search(); $this->resArr = $this->search();
$this->close();
return $this->resArr; return $this->resArr;
} }
@ -181,7 +182,9 @@ class FileDatabaseDriver
$fileArr[0] = $serviceStr; $fileArr[0] = $serviceStr;
file_put_contents($this->filePath, $fileArr); file_put_contents($this->filePath, $fileArr);
$str = $this->serviceInfo['last_id'] . ';' . $string; $str = $this->serviceInfo['last_id'] . ';' . $string . "\n";
fwrite($this->file, $str); fwrite($this->file, $str);
$this->close();
} }
} }

View File

@ -2,13 +2,15 @@
namespace src\models; namespace src\models;
use src\debug\Debug;
use src\file_db_driver\FileDatabaseDriver; use src\file_db_driver\FileDatabaseDriver;
#[\AllowDynamicProperties]
class BaseModel class BaseModel
{ {
protected FileDatabaseDriver $fdd; protected FileDatabaseDriver $fdd;
public int $id; // public int $id;
public function __construct() public function __construct()
{ {
@ -24,6 +26,15 @@ class BaseModel
return []; return [];
} }
public function load(array $array): void
{
if (is_array($array)) {
foreach ($array as $key => $value) {
$this->{$key} = $value;
}
}
}
/** /**
* @return string * @return string
*/ */
@ -32,9 +43,36 @@ class BaseModel
return ""; return "";
} }
public function save() public function labels(): array
{ {
return [];
}
public function save(): void
{
$this->fdd->save($this->toString());
}
public function find(array $request = []): FileDatabaseDriver
{
return $this->fdd->find($request);
}
public function toString(): string
{
$str = '';
$lastItems = array_key_last($this->fdd->getHeadKeys());
foreach ($this->fdd->getHeadKeys() as $key => $value) {
if (isset($this->{$value})) {
if ($key === $lastItems) {
$str .= $this->{$value};
} else {
$str .= $this->{$value} . ";";
}
}
}
return $str;
} }
} }

37
src/models/UserModel.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace src\models;
class UserModel extends BaseModel
{
public int $status = 1;
public function file(): string
{
return "user.txt";
}
public function fillable(): array
{
return [
'surname', 'name', 'patronymic', 'dateOfBirth', 'gender', 'countryCode', 'phoneNumber', 'email', 'status'
];
}
public function labels(): array
{
return [
'surname' => 'Фамилия',
'name' => 'Имя',
'patronymic' => 'Отчество',
'dateOfBirth' => 'Дата рождения',
'gender' => 'Пол',
'countryCode' => 'Код страны',
'phoneNumber' => 'Номер телефона',
'email' => 'Email',
'status'=> 'Статус'
];
}
}

View File

@ -1,4 +1,4 @@
autoincrement=id;last_id=24;table_name=user_info autoincrement=id;last_id=36;table_name=user
id;surname;name;patronymic;dateOfBirth;gender;countryCode;phoneNumber;email;status id;surname;name;patronymic;dateOfBirth;gender;countryCode;phoneNumber;email;status
3;Билай;Станислав;Романович;2002-03-11;Мужчина;+7;9493761924;stasbilay02@yandex.ru;0 3;Билай;Станислав;Романович;2002-03-11;Мужчина;+7;9493761924;stasbilay02@yandex.ru;0
4;Иванова;Мария;Сергеевна;2002-04-05;Женщина;+38;2222222222;sdguhnlnoih@gmail.com;1 4;Иванова;Мария;Сергеевна;2002-04-05;Женщина;+38;2222222222;sdguhnlnoih@gmail.com;1
@ -17,4 +17,5 @@ id;surname;name;patronymic;dateOfBirth;gender;countryCode;phoneNumber;email;stat
17;Зайцева;Анжела;Игоревна;7777-07-07;Женщина;+7;4444444444;aksjfhfka@mail.ru;0 17;Зайцева;Анжела;Игоревна;7777-07-07;Женщина;+7;4444444444;aksjfhfka@mail.ru;0
18;Зайцева;Анжела;Игоревна;7777-07-07;Женщина;+7;4444444444;aksjfhfka@mail.ru;1 18;Зайцева;Анжела;Игоревна;7777-07-07;Женщина;+7;4444444444;aksjfhfka@mail.ru;1
19;Зайцева;Анжела;Игоревна;7777-07-07;Женщина;+7;4444444444;aksjfhfka@mail.ru;1 19;Зайцева;Анжела;Игоревна;7777-07-07;Женщина;+7;4444444444;aksjfhfka@mail.ru;1
24;ddd;Кирилл;ddd;2024-06-25;Мужчина;+7;9281234567;apuc06@mail.ru; 24;ddd;Кирилл;dfdf;2024-06-25;Мужчина;+7;9281234567;apuc06@mail.ru;1
36;ddd4;Кирилл;ddd4;2024-06-25;Мужчина;+7;9281234567;apuc06@mail.ru;1