'user', 'requestData' => [ 'supervisedUsers' => [ 'validation' => DataValidator::oneOf(DataValidator::validUsersId(),DataValidator::nullType()), 'error' => ERRORS:: INVALID_SUPERVISED_USERS ], 'page' => [ 'validation' => DataValidator::oneOf(DataValidator::numeric()->positive(),DataValidator::nullType()), 'error' => ERRORS::INVALID_PAGE ] ] ]; } private $authors; private $page; private $showOwnTickets; private $supervisedUserList; public function handler() { if(Controller::isStaffLogged()) throw new RequestException(ERRORS::NO_PERMISSION); $this->page = Controller::request('page') ? Controller::request('page') : 1; $this->showOwnTickets = (bool)Controller::request('showOwnTickets'); $this->supervisedUserList = Controller::request('supervisedUsers')? json_decode(Controller::request('supervisedUsers')) : []; $this->authors = $this->createAuthorsArray(); if(!$this->canUserHandleSupervisedUsers()){ throw new Exception(ERRORS::INVALID_SUPERVISED_USERS); } $searchController = new SearchController(true); Controller::setDataRequester(function ($key) { switch ($key) { case 'authors': return json_encode($this->authors); case 'page' : return $this->page*1; case 'supervisor': return 1; } return null; }); if(empty($this->authors)) { Response::respondSuccess([]); } else { $searchController->handler(); } } public function canUserHandleSupervisedUsers() { $user = Controller::getLoggedUser(); if(!$user->supervisedrelation && $this->supervisedUserList) return false; if(!empty($this->supervisedUserList)){ foreach($this->supervisedUserList as $supevisedUser) { if(!$user->supervisedrelation->sharedUserList->includesId($supevisedUser) && $supevisedUser != $user->id){ return false; } } } return true; } public function createAuthorsArray(){ $user = Controller::getLoggedUser(); $authors = []; if(!empty($this->supervisedUserList)){ foreach(array_unique($this->supervisedUserList) as $supervised){ array_push($authors, ['id' => $supervised, 'isStaff' => 0]); } }; if(!in_array( $user->id, $this->supervisedUserList) && $this->showOwnTickets){ array_push($authors, ['id' => $user->id*1, 'isStaff' => 0]); } return $authors; } }