'staff_1', 'requestData' => [ 'userIdList' => [ 'validation' => DataValidator::validUsersId(), 'error' => ERRORS::INVALID_LIST ], 'userId' => [ 'validation' => DataValidator::dataStoreId('user'), 'error' => ERRORS::INVALID_USER ] ] ]; } public function handler() { $userIdList = $this->getUserIdListCleared(); $superUser = User::getDataStore(Controller::request('userId')); if(!$superUser->supervisedrelation) { $superUser->supervisedrelation = new Supervisedrelation(); } $superUser->supervisedrelation->sharedUserList->clear(); foreach($userIdList as $userId) { $user = User::getDataStore($userId); $superUser->supervisedrelation->sharedUserList->add($user); } $superUser->supervisedrelation->store(); $superUser->store(); Response::respondSuccess(); } public function getUserIdListCleared(){ $clearedList = array_unique(json_decode(Controller::request('userIdList'))); $superUser = User::getDataStore(Controller::request('userId')); foreach ($clearedList as $item) { if($item == $superUser->id) throw new Exception(ERRORS::SUPERVISOR_CAN_NOT_SUPERVISE_HIMSELF); } return $clearedList; } }