Есть ли способ оптимизировать отображение пользователей?Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Есть ли способ оптимизировать отображение пользователей?

Сообщение Anonymous »

Я создал метод для вызова этого метода getUserIdsByAllBranches(), и результатом будет массив. Если массив не пуст, я буду выполнять другой процесс. Но у меня возникла проблема с сопоставлением или получением всех пользователей со всеми ветвями.

Вот код:

Код: Выделить всё

/**
* Get all User Ids of Branch Permission User
* By All Branches
* @param Array
* @return Array
*/
public function getUserIdsByAllBranches($override = [])
{
if (count($override) !== 0) {
foreach($override as $property => $value) {
${$property} = $value;
}
} else {
$branchLength = App::make(BranchRepository::class)->get()->count();
}

$userIdsWithAllBranches = [];
$userIds = $this->getUserIds();

foreach($userIds as $userId) {
$identical = true;

$userBranchIds = array_values($this->get()
->where('user_id', $userId)
->pluck(['branch_id'])
->unique()
->toArray());

if(count($userBranchIds) === $branchLength) {
$initialPermissions = [];

foreach($userBranchIds as $index => $userBranchId) {
if(!$identical) {
continue;
}

$branchUserPermissions = $this->get()
->where('user_id', $userId)
->where('branch_id', $userBranchId)
->sortBy('permission_id')
->pluck(['permission_id']);

if($index === 0) {
$initialPermissions = $branchUserPermissions;
} else {
if($initialPermissions != $branchUserPermissions) {
$identical = false;
}
}
}
} else {
$identical = false;
}
if($identical) {
array_push($userIdsWithAllBranches, $userId);
}
}
return $userIdsWithAllBranches;
}

/**
* Get all User Ids of Branch Permission User
*
* @return Array
*/
public function getUserIds()
{
return array_values($this->get()
->sortBy('user_id')
->pluck(['user_id'])
->unique()
->toArray());
}
Этот метод getUserIds() будет возвращать все идентификаторы пользователей для таблицы пользователей с разрешениями на ветку.

Таблица пользователей с разрешениями на ветку:
  • branch_id
  • permission_id
  • user_id


Подробнее здесь: https://stackoverflow.com/questions/586 ... g-of-users
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»