Fix LESS import error and refactor project structure
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user