model
This commit is contained in:
parent
e28dfe172d
commit
b9425ee8cf
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
.idea
|
||||
vendor
|
19
info.php
19
info.php
@ -1,25 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace src;
|
||||
|
||||
use src\debug\Debug;
|
||||
use src\dto\InformationDTO;
|
||||
use src\file_db_driver\FileDatabaseDriver;
|
||||
use src\models\UserModel;
|
||||
|
||||
require_once "vendor/autoload.php";
|
||||
|
||||
ini_set("display_errors", true);
|
||||
error_reporting(-1);
|
||||
|
||||
//$fileName = "Information.txt";
|
||||
//$fileModeOpen = "a";
|
||||
|
||||
$fullInformation = new InformationDTO();
|
||||
$fullInformation->load($_REQUEST);
|
||||
|
||||
$string = $fullInformation->toString();
|
||||
|
||||
$obj = new FileDatabaseDriver();
|
||||
$obj->connect(__DIR__ . "/Information.txt");
|
||||
//$obj->updateServiceInfo($string);
|
||||
$obj->save($string);
|
||||
$obj->close();
|
||||
$user = new UserModel();
|
||||
$user->load($_REQUEST);
|
||||
$user->save();
|
||||
|
||||
require "views/search.php";
|
21
search.php
21
search.php
@ -5,31 +5,20 @@ use src\Processing;
|
||||
|
||||
require_once "vendor/autoload.php";
|
||||
|
||||
$rep = new \src\file_db_driver\FileDatabaseDriver();
|
||||
$rep->connect(__DIR__ . "/Information.txt");
|
||||
ini_set("display_errors", true);
|
||||
error_reporting(-1);
|
||||
|
||||
$columnKeys = $rep->getHeadKeys();
|
||||
//$columnValues = $rep->getHeadValues();
|
||||
$columnValues = ['id','Фамилия','Имя','Отчество','Дата рождения','Пол','Код страны','Номер телефона','Email','Статус'];
|
||||
$user = new \src\models\UserModel();
|
||||
|
||||
$columns = array_combine($columnKeys, $columnValues);
|
||||
|
||||
//$res = $rep->find([$_REQUEST['key'] => $_REQUEST['result_search']])->limit(7)->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();
|
||||
$infArr = $json->createJsonArray($columns, $infArr, "form1");
|
||||
$infArr = $json->createJsonArray($user->labels(), $res, "form1");
|
||||
|
||||
$table = new \Itguild\Tables\ListJsonTable($infArr);
|
||||
$table->create();
|
||||
|
@ -18,6 +18,8 @@ class Processing
|
||||
"meta" => [
|
||||
"title" => $title,
|
||||
"columns" => $columns,
|
||||
"perPage" => 10,
|
||||
"currentPage" => 1,
|
||||
"params" =>
|
||||
[
|
||||
"class" => "table table-bordered",
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace src\dto;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
class BaseDTO
|
||||
{
|
||||
public int $id;
|
||||
|
@ -24,6 +24,8 @@ class InformationDTO extends BaseDTO
|
||||
public string $countryCode;
|
||||
public string $phoneNumber;
|
||||
public string $email;
|
||||
public int $status = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@ -35,7 +37,7 @@ class InformationDTO extends BaseDTO
|
||||
public function fillable(): array
|
||||
{
|
||||
// return [
|
||||
// 'surname', 'name', 'patronymic', 'dateOfBirth', 'gender', 'countryCode', 'phoneNumber', 'email'
|
||||
// 'surname', 'name', 'patronymic', 'dateOfBirth', 'gender', 'countryCode', 'phoneNumber', 'email', 'status'
|
||||
// ];
|
||||
return [
|
||||
$this->surname, $this->name, $this->patronymic, $this->dateOfBirth, $this->gender, $this->countryCode, $this->phoneNumber, $this->email, "\n"
|
||||
|
@ -76,7 +76,7 @@ class FileDatabaseDriver
|
||||
// return $this->headValues;
|
||||
// }
|
||||
|
||||
public function find(array $query): self
|
||||
public function find(array $query = []): self
|
||||
{
|
||||
foreach ($query as $key => $value) {
|
||||
$this->query[$key] = $value;
|
||||
@ -110,7 +110,7 @@ class FileDatabaseDriver
|
||||
$flag = false;
|
||||
foreach ($this->query as $key => $value) {
|
||||
foreach ($this->query[$key] as $k => $v) {
|
||||
if (strlen($this->searchInStr($v, $item, $key)) > 0) {
|
||||
if ($this->searchInStr($v, $item, $key)) {
|
||||
$flag = true;
|
||||
break;
|
||||
} else {
|
||||
@ -128,11 +128,11 @@ class FileDatabaseDriver
|
||||
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 (preg_match("/" . $strForSearch . "/", $item[$column])) {
|
||||
return $item[$column];
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,6 +142,7 @@ class FileDatabaseDriver
|
||||
public function all(): array
|
||||
{
|
||||
$this->resArr = $this->search();
|
||||
$this->close();
|
||||
return $this->resArr;
|
||||
}
|
||||
|
||||
@ -181,7 +182,9 @@ class FileDatabaseDriver
|
||||
$fileArr[0] = $serviceStr;
|
||||
file_put_contents($this->filePath, $fileArr);
|
||||
|
||||
$str = $this->serviceInfo['last_id'] . ';' . $string;
|
||||
$str = $this->serviceInfo['last_id'] . ';' . $string . "\n";
|
||||
fwrite($this->file, $str);
|
||||
|
||||
$this->close();
|
||||
}
|
||||
}
|
@ -2,13 +2,15 @@
|
||||
|
||||
namespace src\models;
|
||||
|
||||
use src\debug\Debug;
|
||||
use src\file_db_driver\FileDatabaseDriver;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
class BaseModel
|
||||
{
|
||||
protected FileDatabaseDriver $fdd;
|
||||
|
||||
public int $id;
|
||||
// public int $id;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -24,6 +26,15 @@ class BaseModel
|
||||
return [];
|
||||
}
|
||||
|
||||
public function load(array $array): void
|
||||
{
|
||||
if (is_array($array)) {
|
||||
foreach ($array as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -32,9 +43,36 @@ class BaseModel
|
||||
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
37
src/models/UserModel.php
Normal 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'=> 'Статус'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
3;Билай;Станислав;Романович;2002-03-11;Мужчина;+7;9493761924;stasbilay02@yandex.ru;0
|
||||
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
|
||||
18;Зайцева;Анжела;Игоревна;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
|
Loading…
Reference in New Issue
Block a user