Fix LESS import error and refactor project structure

This commit is contained in:
kirill.khorkov
2026-01-03 18:59:56 +03:00
parent 1bb0fc02e6
commit 4a8d4f8c3f
201 changed files with 891 additions and 14311 deletions

View File

@@ -2,9 +2,6 @@
namespace App\Core;
/**
* Model - базовый класс модели
*/
abstract class Model
{
protected Database $db;
@@ -16,18 +13,12 @@ abstract class Model
$this->db = Database::getInstance();
}
/**
* Найти запись по первичному ключу
*/
public function find(int $id): ?array
{
$sql = "SELECT * FROM {$this->table} WHERE {$this->primaryKey} = ?";
return $this->db->queryOne($sql, [$id]);
}
/**
* Получить все записи
*/
public function all(?string $orderBy = null): array
{
$sql = "SELECT * FROM {$this->table}";
@@ -37,9 +28,6 @@ abstract class Model
return $this->db->query($sql);
}
/**
* Найти записи по условию
*/
public function where(array $conditions, ?string $orderBy = null): array
{
$where = [];
@@ -59,9 +47,6 @@ abstract class Model
return $this->db->query($sql, $params);
}
/**
* Найти одну запись по условию
*/
public function findWhere(array $conditions): ?array
{
$where = [];
@@ -76,9 +61,6 @@ abstract class Model
return $this->db->queryOne($sql, $params);
}
/**
* Создать новую запись
*/
public function create(array $data): ?int
{
$columns = array_keys($data);
@@ -98,9 +80,6 @@ abstract class Model
return (int) $stmt->fetchColumn();
}
/**
* Обновить запись
*/
public function update(int $id, array $data): bool
{
$set = [];
@@ -122,18 +101,12 @@ abstract class Model
return $this->db->execute($sql, $params);
}
/**
* Удалить запись
*/
public function delete(int $id): bool
{
$sql = "DELETE FROM {$this->table} WHERE {$this->primaryKey} = ?";
return $this->db->execute($sql, [$id]);
}
/**
* Подсчитать количество записей
*/
public function count(array $conditions = []): int
{
$sql = "SELECT COUNT(*) FROM {$this->table}";
@@ -153,28 +126,18 @@ abstract class Model
return (int) $stmt->fetchColumn();
}
/**
* Выполнить произвольный SQL запрос
*/
protected function query(string $sql, array $params = []): array
{
return $this->db->query($sql, $params);
}
/**
* Выполнить произвольный SQL запрос и получить одну запись
*/
protected function queryOne(string $sql, array $params = []): ?array
{
return $this->db->queryOne($sql, $params);
}
/**
* Выполнить произвольный SQL запрос (INSERT/UPDATE/DELETE)
*/
protected function execute(string $sql, array $params = []): bool
{
return $this->db->execute($sql, $params);
}
}