add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks - Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists - Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services - Add Microsoft OIDC SSO, API token management, and user lifecycle features - Add swagger-ui vendor integration and OpenAPI spec - Add production Docker setup and bin/ scripts - Update composer dependencies, config, templates, and frontend assets throughout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -45,10 +45,69 @@ class UserDepartmentRepository
|
||||
$query = 'delete ud from user_departments ud ' .
|
||||
'where ud.department_id = ? and not exists (' .
|
||||
'select 1 from user_tenants ut ' .
|
||||
'join tenant_departments td on td.tenant_id = ut.tenant_id ' .
|
||||
'where ut.user_id = ud.user_id and td.department_id = ud.department_id' .
|
||||
'join departments d on d.id = ud.department_id ' .
|
||||
'where ut.user_id = ud.user_id and ut.tenant_id = d.tenant_id' .
|
||||
')';
|
||||
$result = DB::delete($query, (string) $departmentId);
|
||||
return $result !== false ? (int) $result : 0;
|
||||
}
|
||||
|
||||
public static function countUsersByDepartmentIds(array $departmentIds): array
|
||||
{
|
||||
return self::countByDepartmentIds($departmentIds, false);
|
||||
}
|
||||
|
||||
public static function countActiveUsersByDepartmentIds(array $departmentIds): array
|
||||
{
|
||||
return self::countByDepartmentIds($departmentIds, true);
|
||||
}
|
||||
|
||||
private static 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));
|
||||
if (!$departmentIds) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($departmentIds), '?'));
|
||||
$joinUsersSql = $activeOnly ? ' join users u on u.id = ud.user_id and u.active = 1' : '';
|
||||
$rows = DB::select(
|
||||
'select ud.department_id, count(distinct ud.user_id) as user_count from user_departments ud' .
|
||||
$joinUsersSql .
|
||||
' where ud.department_id in (' . $placeholders . ') group by ud.department_id',
|
||||
...array_map('strval', $departmentIds)
|
||||
);
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$departmentId = self::extractIntField($row, 'department_id');
|
||||
if ($departmentId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result[$departmentId] = self::extractIntField($row, 'user_count');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function extractIntField(array $row, string $field): int
|
||||
{
|
||||
foreach ($row as $value) {
|
||||
if (!is_array($value)) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($field, $value)) {
|
||||
return (int) $value[$field];
|
||||
}
|
||||
}
|
||||
if (array_key_exists($field, $row)) {
|
||||
return (int) $row[$field];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user