model
This commit is contained in:
@@ -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'=> 'Статус'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user