instances added god may help
This commit is contained in:
@@ -6,7 +6,7 @@ use MintyPHP\DB;
|
||||
|
||||
class UserTenantRepository
|
||||
{
|
||||
public static function listTenantIdsByUserId(int $userId): array
|
||||
public function listTenantIdsByUserId(int $userId): array
|
||||
{
|
||||
$rows = DB::select('select tenant_id from user_tenants where user_id = ?', (string) $userId);
|
||||
if (!is_array($rows)) {
|
||||
@@ -22,7 +22,7 @@ class UserTenantRepository
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
|
||||
public static function replaceForUser(int $userId, array $tenantIds): bool
|
||||
public function replaceForUser(int $userId, array $tenantIds): bool
|
||||
{
|
||||
DB::delete('delete from user_tenants where user_id = ?', (string) $userId);
|
||||
if (!$tenantIds) {
|
||||
@@ -40,17 +40,17 @@ class UserTenantRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function countUsersByTenantIds(array $tenantIds): array
|
||||
public function countUsersByTenantIds(array $tenantIds): array
|
||||
{
|
||||
return self::countByTenantIds($tenantIds, false);
|
||||
return $this->countByTenantIds($tenantIds, false);
|
||||
}
|
||||
|
||||
public static function countActiveUsersByTenantIds(array $tenantIds): array
|
||||
public function countActiveUsersByTenantIds(array $tenantIds): array
|
||||
{
|
||||
return self::countByTenantIds($tenantIds, true);
|
||||
return $this->countByTenantIds($tenantIds, true);
|
||||
}
|
||||
|
||||
private static function countByTenantIds(array $tenantIds, bool $activeOnly): array
|
||||
private function countByTenantIds(array $tenantIds, bool $activeOnly): array
|
||||
{
|
||||
$tenantIds = array_values(array_unique(array_map('intval', $tenantIds)));
|
||||
$tenantIds = array_values(array_filter($tenantIds, static fn ($id) => $id > 0));
|
||||
@@ -74,17 +74,17 @@ class UserTenantRepository
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$tenantId = self::extractIntField($row, 'tenant_id');
|
||||
$tenantId = $this->extractIntField($row, 'tenant_id');
|
||||
if ($tenantId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result[$tenantId] = self::extractIntField($row, 'user_count');
|
||||
$result[$tenantId] = $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