chg: [inboxes:filtering] Populate username with eligible users in filtering modal

refacto/CRUDComponent
Sami Mokaddem 2023-12-13 14:31:55 +01:00
parent cadb56eb07
commit eefe6b22cc
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 13 additions and 1 deletions

View File

@ -16,7 +16,7 @@ use Cake\Http\Exception\ForbiddenException;
class InboxController extends AppController
{
public $filterFields = ['scope', 'action', 'Inbox.created', 'severity', 'title', 'origin', 'message', 'Users.id', 'Users.username',];
public $filterFields = ['scope', 'action', 'Inbox.created', 'severity', 'title', 'origin', 'message', 'Users.id', ['name' => 'Users.username', 'multiple' => true, 'options' => 'getAllUsername', 'select2' => true],];
public $quickFilterFields = ['scope', 'action', ['title' => true], ['message' => true], 'origin'];
public $containFields = ['Users'];

View File

@ -2,6 +2,7 @@
namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\Utility\Hash;
use Cake\Database\Schema\TableSchemaInterface;
use Cake\Database\Type;
use Cake\ORM\Table;
@ -72,6 +73,17 @@ class InboxTable extends AppTable
return $rules;
}
public function getAllUsername($currentUser): array
{
$this->Users = \Cake\ORM\TableRegistry::getTableLocator()->get('Users');
$conditions = [];
if (empty($currentUser['role']['perm_admin'])) {
$conditions['organisation_id IN'] = [$currentUser['organisation_id']];
}
$users = $this->Users->find()->where($conditions)->all()->extract('username')->toList();
return Hash::combine($users, '{n}', '{n}');
}
public function checkUserBelongsToBroodOwnerOrg($user, $entryData) {
$this->Broods = \Cake\ORM\TableRegistry::getTableLocator()->get('Broods');
$this->Individuals = \Cake\ORM\TableRegistry::getTableLocator()->get('Individuals');