forked from fa/breadcrumb-the-shire
instances added god may help
This commit is contained in:
@@ -6,7 +6,7 @@ use MintyPHP\DB;
|
||||
|
||||
class UserDepartmentRepository
|
||||
{
|
||||
public static function listDepartmentIdsByUserId(int $userId): array
|
||||
public function listDepartmentIdsByUserId(int $userId): array
|
||||
{
|
||||
$rows = DB::select('select department_id from user_departments where user_id = ?', (string) $userId);
|
||||
if (!is_array($rows)) {
|
||||
@@ -22,7 +22,7 @@ class UserDepartmentRepository
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
|
||||
public static function replaceForUser(int $userId, array $departmentIds): bool
|
||||
public function replaceForUser(int $userId, array $departmentIds): bool
|
||||
{
|
||||
DB::delete('delete from user_departments where user_id = ?', (string) $userId);
|
||||
if (!$departmentIds) {
|
||||
@@ -40,7 +40,7 @@ class UserDepartmentRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function removeInvalidForDepartment(int $departmentId): int
|
||||
public function removeInvalidForDepartment(int $departmentId): int
|
||||
{
|
||||
$query = 'delete ud from user_departments ud ' .
|
||||
'where ud.department_id = ? and not exists (' .
|
||||
@@ -52,17 +52,17 @@ class UserDepartmentRepository
|
||||
return $result !== false ? (int) $result : 0;
|
||||
}
|
||||
|
||||
public static function countUsersByDepartmentIds(array $departmentIds): array
|
||||
public function countUsersByDepartmentIds(array $departmentIds): array
|
||||
{
|
||||
return self::countByDepartmentIds($departmentIds, false);
|
||||
return $this->countByDepartmentIds($departmentIds, false);
|
||||
}
|
||||
|
||||
public static function countActiveUsersByDepartmentIds(array $departmentIds): array
|
||||
public function countActiveUsersByDepartmentIds(array $departmentIds): array
|
||||
{
|
||||
return self::countByDepartmentIds($departmentIds, true);
|
||||
return $this->countByDepartmentIds($departmentIds, true);
|
||||
}
|
||||
|
||||
private static function countByDepartmentIds(array $departmentIds, bool $activeOnly): array
|
||||
private function countByDepartmentIds(array $departmentIds, bool $activeOnly): array
|
||||
{
|
||||
$departmentIds = array_values(array_unique(array_map('intval', $departmentIds)));
|
||||
$departmentIds = array_values(array_filter($departmentIds, static fn ($id) => $id > 0));
|
||||
@@ -85,17 +85,17 @@ class UserDepartmentRepository
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$departmentId = self::extractIntField($row, 'department_id');
|
||||
$departmentId = $this->extractIntField($row, 'department_id');
|
||||
if ($departmentId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result[$departmentId] = self::extractIntField($row, 'user_count');
|
||||
$result[$departmentId] = $this->extractIntField($row, 'user_count');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function extractIntField(array $row, string $field): int
|
||||
private function extractIntField(array $row, string $field): int
|
||||
{
|
||||
foreach ($row as $value) {
|
||||
if (!is_array($value)) {
|
||||
|
||||
Reference in New Issue
Block a user