refactor to separated entities, init abstractions

This commit is contained in:
yggverse 2024-07-03 02:34:14 +03:00
parent 08c9fe76e5
commit 90acc3ac2d
47 changed files with 1927 additions and 2069 deletions

View file

@ -64,8 +64,8 @@ class Database
return (int) $this->_database->lastInsertId();
}
public function getHistory(
string $search = '',
public function findHistory(
string $value = '',
int $start = 0,
int $limit = 1000
): array
@ -73,7 +73,7 @@ class Database
$query = $this->_database->prepare(
sprintf(
'SELECT * FROM `history`
WHERE `url` LIKE :search OR `title` LIKE :search
WHERE `url` LIKE :value OR `title` LIKE :value
ORDER BY `id` DESC
LIMIT %d,%d',
$start,
@ -83,9 +83,9 @@ class Database
$query->execute(
[
':search' => sprintf(
':value' => sprintf(
'%%%s%%',
$search
$value
)
]
);
@ -122,4 +122,35 @@ class Database
return $query->rowCount();
}
public function refreshHistory(
string $url,
?string $title = null
): void
{
// Find same records match URL
$query = $this->_database->prepare(
'SELECT * FROM `history` WHERE `url` LIKE :url'
);
$query->execute(
[
':url' => $url
]
);
// Drop previous records
foreach ($query->fetchAll() as $record)
{
$this->deleteHistory(
$record->id
);
}
// Add new record
$this->addHistory(
$url,
$title
);
}
}