ver.0.4
This commit is contained in:
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
//namespace src;
|
||||
//
|
||||
//class Forms
|
||||
//{
|
||||
// public string $infoForm;
|
||||
// public string $forSearchForm;
|
||||
//
|
||||
// public function __construct()
|
||||
// {
|
||||
// $this->infoForm = '
|
||||
// <form action="../info.php" target="_blank" method="post">
|
||||
// Фамилия:<br>
|
||||
// <input type = "text" name = "surname" required size="50" autofocus placeholder="Фамилия"> <br> <br>
|
||||
//
|
||||
// Имя:<br>
|
||||
// <input type = "text" name = "name" required size="50" placeholder="Имя"> <br> <br>
|
||||
//
|
||||
// Отчество (если есть):<br>
|
||||
// <input type = "text" name = "patronymic" size="50" placeholder="Отчество"> <br> <br>
|
||||
//
|
||||
// Дата Рождения: <br>
|
||||
// <input type="date" name="dateOfBirth" required> <br> <br>
|
||||
//
|
||||
// Ваш пол: <br>
|
||||
// <input type="radio" name="gender" value="Мужчина" checked> Мужчина
|
||||
// <input type="radio" name="gender" value="Женжина"> Женжина<br> <br>
|
||||
//
|
||||
// Номер телефона (Например 1234567890): <br>
|
||||
// <select name="countryCode">
|
||||
// <option value="+7" >Russia +7</option>
|
||||
// <option value="+38">Ukraine +38</option>
|
||||
// </select>
|
||||
// <input type="tel" name="phoneNumber" pattern="[0-9]{10}" maxlength="10" required placeholder="1234567890"> <br> <br>
|
||||
//
|
||||
// Email адрес: <br>
|
||||
// <input type="Email" name="email" required> <br><br>
|
||||
//
|
||||
// <input type = "submit" value="Подтвердить">
|
||||
// <input type="reset">
|
||||
// </form>';
|
||||
//
|
||||
// $this->forSearchForm = '
|
||||
// <form action="../search.php" target="_blank" method="post">
|
||||
// <input type="search" placeholder="Поиск" name="result_search"> <br> <br>
|
||||
// Среди чего найти? <br>
|
||||
// <select name="key">
|
||||
// <option value="surname">Фамилия</option>
|
||||
// <option value="name">Имя</option>
|
||||
// <option value="patronymic">Отчество</option>
|
||||
// <option value="dateOfBirth">Дата рождения</option>
|
||||
// <option value="gender">Пол</option>
|
||||
// <option value="countryCode">Код страны</option>
|
||||
// <option value="phoneNumber">Номер телефона</option>
|
||||
// <option value="email">Email</option>
|
||||
// </select> <br><br>
|
||||
// <input type="submit" value="Поиск">
|
||||
// </form>';
|
||||
// }
|
||||
//
|
||||
// public function getInfoForm(): string
|
||||
// {
|
||||
// return $this->infoForm;
|
||||
// }
|
||||
//
|
||||
// public function getForSearchForm(): string
|
||||
// {
|
||||
// return $this->forSearchForm;
|
||||
// }
|
||||
//}
|
@ -11,11 +11,9 @@ class FileDatabaseDriver
|
||||
public $file;
|
||||
public array $headKeys = [];
|
||||
public array $headValues = [];
|
||||
|
||||
private array $resArr = [];
|
||||
private array $query = [];
|
||||
private int $limitInt = 10;
|
||||
|
||||
public array $serviceInfo = [];
|
||||
|
||||
public function connect(string $filePath): bool
|
||||
@ -26,7 +24,7 @@ class FileDatabaseDriver
|
||||
if ($this->file) {
|
||||
$this->getServiceInfo();
|
||||
$this->setHeadKeys();
|
||||
$this->setHeadValues();
|
||||
// $this->setHeadValues();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -62,31 +60,26 @@ class FileDatabaseDriver
|
||||
return $this->headKeys;
|
||||
}
|
||||
|
||||
public function setHeadValues(): void
|
||||
{
|
||||
$headArr = explode(';', fgets($this->file));
|
||||
foreach ($headArr as $item){
|
||||
$item = str_replace("\n", "", $item);
|
||||
$item = str_replace("\r", "", $item);
|
||||
$this->headValues[] = $item;
|
||||
}
|
||||
// $this->head = explode(';', fgets($this->file));
|
||||
}
|
||||
|
||||
public function getHeadValues(): array
|
||||
{
|
||||
return $this->headValues;
|
||||
}
|
||||
// public function setHeadValues(): void
|
||||
// {
|
||||
// $headArr = explode(';', fgets($this->file));
|
||||
// foreach ($headArr as $item){
|
||||
// $item = str_replace("\n", "", $item);
|
||||
// $item = str_replace("\r", "", $item);
|
||||
// $this->headValues[] = $item;
|
||||
// }
|
||||
//// $this->head = explode(';', fgets($this->file));
|
||||
// }
|
||||
//
|
||||
// public function getHeadValues(): array
|
||||
// {
|
||||
// return $this->headValues;
|
||||
// }
|
||||
|
||||
public function find(array $query): self
|
||||
{
|
||||
$j = 0;
|
||||
foreach ($query as $key => $value) {
|
||||
if(strlen($value) > 0) {
|
||||
$this->query['column'][$j] = $key;
|
||||
$this->query['value'][$j] = $value;
|
||||
$j++;
|
||||
}
|
||||
$this->query[$key] = $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@ -103,33 +96,35 @@ class FileDatabaseDriver
|
||||
$resArr = [];
|
||||
$i = 1;
|
||||
while (!feof($this->file)) {
|
||||
if ($i > $this->limitInt){
|
||||
if ($i > $this->limitInt) {
|
||||
break;
|
||||
}
|
||||
$str = fgets($this->file);
|
||||
if (!empty($str)){
|
||||
if (!empty($str)) {
|
||||
$str = str_replace("\n", "", $str);
|
||||
$str = str_replace("\r", "", $str);
|
||||
|
||||
$item = explode(";", $str);
|
||||
$item = array_combine($this->headKeys, $item);
|
||||
|
||||
$cnt = count($this->query['column']);
|
||||
for ($j = 0; $j < $cnt; $j++) {
|
||||
if (strlen($this->searchInStr($this->query['value'][$j], $item, $this->query['column'][$j])) > 0) {
|
||||
$flag = true;
|
||||
} else {
|
||||
$flag = false;
|
||||
break;
|
||||
$flag = false;
|
||||
foreach ($this->query as $key => $value) {
|
||||
foreach ($this->query[$key] as $k => $v) {
|
||||
if (strlen($this->searchInStr($v, $item, $key)) > 0) {
|
||||
$flag = true;
|
||||
break;
|
||||
} else {
|
||||
$flag = false;
|
||||
}
|
||||
}
|
||||
if(!$flag) break;
|
||||
}
|
||||
if ($flag){
|
||||
if ($flag) {
|
||||
$resArr[] = $item;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resArr;
|
||||
}
|
||||
|
||||
@ -155,10 +150,38 @@ class FileDatabaseDriver
|
||||
fclose($this->file);
|
||||
}
|
||||
|
||||
// public function updateServiceInfo(string $string): void
|
||||
// {
|
||||
// $id = $this->serviceInfo['last_id'];
|
||||
// $this->serviceInfo['last_id'] = ++$id;
|
||||
// foreach ($this->serviceInfo as $key => $value) {
|
||||
// $arr[] = $key . '=' . $value;
|
||||
// }
|
||||
// $fileArr = file($this->filePath);
|
||||
// if (isset($arr)) {
|
||||
// $serviceStr = implode(';', $arr) . "\n";
|
||||
// }
|
||||
// $fileArr[0] = $serviceStr;
|
||||
// file_put_contents($this->filePath, $fileArr);
|
||||
//
|
||||
// $str = $id . ';' . $string;
|
||||
// $this->save($str);
|
||||
// }
|
||||
|
||||
public function save(string $string): void
|
||||
{
|
||||
// $file = fopen($fileName, "a");
|
||||
fwrite($this->file, $string);
|
||||
// fclose($file);
|
||||
$this->serviceInfo['last_id']++;
|
||||
foreach ($this->serviceInfo as $key => $value) {
|
||||
$arr[] = $key . '=' . $value;
|
||||
}
|
||||
$fileArr = file($this->filePath);
|
||||
if (isset($arr)) {
|
||||
$serviceStr = implode(';', $arr) . "\n";
|
||||
}
|
||||
$fileArr[0] = $serviceStr;
|
||||
file_put_contents($this->filePath, $fileArr);
|
||||
|
||||
$str = $this->serviceInfo['last_id'] . ';' . $string;
|
||||
fwrite($this->file, $str);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user