Make limited backoffice employees regular employees
This commit is contained in:
@@ -1077,9 +1077,65 @@ class users_o extends db
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $users
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function markLimitedBackofficeManagedUsers(array $users): array
|
||||
{
|
||||
$userIds = [];
|
||||
foreach ($users as $user) {
|
||||
$userId = (int)($user['id'] ?? 0);
|
||||
if ($userId > 0) {
|
||||
$userIds[$userId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($userIds === []) {
|
||||
return $users;
|
||||
}
|
||||
|
||||
global $db;
|
||||
$rows = $db->fetch_all($db->query(
|
||||
'SELECT `user_id` FROM `limited_backoffice_employees` WHERE `user_id` IN (' .
|
||||
implode(',', array_map('intval', array_keys($userIds))) .
|
||||
')'
|
||||
));
|
||||
|
||||
$managedUserIds = [];
|
||||
foreach ($rows as $row) {
|
||||
$managedUserIds[(int)$row['user_id']] = true;
|
||||
}
|
||||
|
||||
foreach ($users as $key => $user) {
|
||||
$users[$key]['limited_backoffice_managed'] = isset($managedUserIds[(int)($user['id'] ?? 0)]);
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function isLimitedBackofficeManagedUser(int $userId): bool
|
||||
{
|
||||
if ($userId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $db;
|
||||
$result = $db->query(
|
||||
'SELECT `user_id` FROM `limited_backoffice_employees` WHERE `user_id` = ' . (int)$userId . ' LIMIT 1'
|
||||
);
|
||||
|
||||
return $result !== false && $result->num_rows > 0;
|
||||
}
|
||||
|
||||
public function parseCustomerNumbers(array $listObjectsWithPaginationIfSet): array
|
||||
{
|
||||
foreach ( $listObjectsWithPaginationIfSet as $key => $value ) {
|
||||
if ((bool)($value['limited_backoffice_managed'] ?? false) || (int)($value['customer_number'] ?? -1) === 0) {
|
||||
$listObjectsWithPaginationIfSet[$key]['customer_name'] = $value['display_name'] ?? null;
|
||||
continue;
|
||||
}
|
||||
|
||||
$listObjectsWithPaginationIfSet[$key]['customer_name'] = $this->getCustomerNameById($value['id']);
|
||||
}
|
||||
return $listObjectsWithPaginationIfSet;
|
||||
|
||||
Reference in New Issue
Block a user