instances added god may help

This commit is contained in:
2026-02-23 12:58:19 +01:00
parent 25370a1a55
commit 99db252f60
290 changed files with 9858 additions and 4914 deletions

View File

@@ -7,7 +7,7 @@ use MintyPHP\Repository\Support\RepoQuery;
class RoleRepository
{
private static function unwrap(?array $row): ?array
private function unwrap(?array $row): ?array
{
if (!$row) {
return null;
@@ -15,7 +15,7 @@ class RoleRepository
return $row['roles'] ?? null;
}
private static function unwrapList($rows): array
private function unwrapList($rows): array
{
if (!is_array($rows)) {
return [];
@@ -30,23 +30,23 @@ class RoleRepository
return $list;
}
public static function list(): array
public function list(): array
{
$rows = DB::select(
'select id, uuid, description, code, active, created_by, modified_by, created, modified from roles order by id desc'
);
return self::unwrapList($rows);
return $this->unwrapList($rows);
}
public static function listActive(): array
public function listActive(): array
{
$rows = DB::select(
'select id, uuid, description, code, active, created_by, modified_by, created, modified from roles where active = 1 order by description asc'
);
return self::unwrapList($rows);
return $this->unwrapList($rows);
}
public static function listByIds(array $roleIds): array
public function listByIds(array $roleIds): array
{
$roleIds = array_values(array_unique(array_map('intval', $roleIds)));
$roleIds = array_values(array_filter($roleIds, static fn ($id) => $id > 0));
@@ -59,10 +59,10 @@ class RoleRepository
'select id, uuid, description, code, active, created_by, modified_by, created, modified from roles where id in (' . $placeholders . ')',
...array_map('strval', $roleIds)
);
return self::unwrapList($rows);
return $this->unwrapList($rows);
}
public static function listIds(): array
public function listIds(): array
{
$rows = DB::select('select id from roles');
if (!is_array($rows)) {
@@ -78,7 +78,7 @@ class RoleRepository
return array_values(array_unique($ids));
}
public static function listActiveIds(): array
public function listActiveIds(): array
{
$rows = DB::select('select id from roles where active = 1');
if (!is_array($rows)) {
@@ -94,7 +94,7 @@ class RoleRepository
return array_values(array_unique($ids));
}
public static function listPaged(array $options): array
public function listPaged(array $options): array
{
$search = trim((string) ($options['search'] ?? ''));
$allowedOrder = ['id', 'uuid', 'description', 'code', 'active', 'created', 'modified'];
@@ -123,29 +123,29 @@ class RoleRepository
return [
'total' => $total,
'rows' => self::unwrapList($rows),
'rows' => $this->unwrapList($rows),
];
}
public static function find(int $id): ?array
public function find(int $id): ?array
{
$row = DB::selectOne(
'select id, uuid, description, code, active, created_by, modified_by, created, modified from roles where id = ? limit 1',
(string) $id
);
return self::unwrap($row);
return $this->unwrap($row);
}
public static function findByUuid(string $uuid): ?array
public function findByUuid(string $uuid): ?array
{
$row = DB::selectOne(
'select id, uuid, description, code, active, created_by, modified_by, created, modified from roles where uuid = ? limit 1',
$uuid
);
return self::unwrap($row);
return $this->unwrap($row);
}
public static function existsByCode(string $code, int $excludeId = 0): bool
public function existsByCode(string $code, int $excludeId = 0): bool
{
$code = trim($code);
if ($code === '') {
@@ -159,7 +159,7 @@ class RoleRepository
return $count ? ((int) $count > 0) : false;
}
public static function create(array $data)
public function create(array $data)
{
return DB::insert(
'insert into roles (uuid, description, code, active, created_by, created) values (?,?,?,?,?,NOW())',
@@ -171,7 +171,7 @@ class RoleRepository
);
}
public static function update(int $id, array $data): bool
public function update(int $id, array $data): bool
{
$fields = [
'description' => $data['description'],
@@ -195,7 +195,7 @@ class RoleRepository
return $result !== false;
}
public static function delete(int $id): bool
public function delete(int $id): bool
{
$result = DB::delete('delete from roles where id = ?', (string) $id);
return $result !== false;