This commit is contained in:
2026-02-04 23:31:53 +01:00
commit cd59ccd99b
2401 changed files with 56808 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace MintyPHP\Repository;
use MintyPHP\DB;
class UserRoleRepository
{
public static function listRoleIdsByUserId(int $userId): array
{
$rows = DB::select('select role_id from user_roles where user_id = ?', (string) $userId);
if (!is_array($rows)) {
return [];
}
$ids = [];
foreach ($rows as $row) {
$data = $row['user_roles'] ?? $row;
if (is_array($data) && isset($data['role_id'])) {
$ids[] = (int) $data['role_id'];
}
}
return array_values(array_unique($ids));
}
public static function replaceForUser(int $userId, array $roleIds): bool
{
DB::delete('delete from user_roles where user_id = ?', (string) $userId);
if (!$roleIds) {
return true;
}
foreach ($roleIds as $roleId) {
DB::insert(
'insert into user_roles (user_id, role_id, created) values (?,?,NOW())',
(string) $userId,
(string) $roleId
);
}
return true;
}
}