diff --git a/src/Controller/InboxController.php b/src/Controller/InboxController.php index 77fac8f..ddbe8ad 100644 --- a/src/Controller/InboxController.php +++ b/src/Controller/InboxController.php @@ -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']; diff --git a/src/Model/Table/InboxTable.php b/src/Model/Table/InboxTable.php index a7626e7..4a90910 100644 --- a/src/Model/Table/InboxTable.php +++ b/src/Model/Table/InboxTable.php @@ -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');