/** * testConstruct * * @return void */ public function testConstruct() { $result = new Result(); $result->__construct(null, Result::CODE_SUCCESS, ['Test Message']); }
/** * fetchByParentRoleId * * @param mixed $parentRoleId the parent id * * @return Result */ public function fetchByParentRoleId($parentRoleId) { $roles = $this->getEntityManager()->getRepository($this->getEntityClass())->findBy(['parentRoleId' => $parentRoleId]); $result = new Result($roles); if (empty($roles)) { $result->setMessage('No roles found,'); } return $result; }
/** * delete * * @param User $user user * @param array $roles roles * * @return Result */ public function delete(User $user, $roles = []) { $failed = []; $result = new Result($failed, Result::CODE_SUCCESS); foreach ($roles as $key => $roleId) { $removeResult = $this->remove($user, $roleId); if (!$removeResult->isSuccess()) { $failed[] = $roleId; $result->setCode(Result::CODE_FAIL); $result->setMessage("Failed to remove role {$roleId} with error: " . $removeResult->getMessage()); $result->setData($failed); } else { $result->setMessage("Removed role {$roleId}"); } } return $result; }