/** * @param AbstractRoleSubject[] $subjects * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace * @param \Claroline\CoreBundle\Entity\Role[] $roles * * @throws Exception\LastManagerDeleteException */ public function checkWorkspaceRoleEditionIsValid(array $subjects, Workspace $workspace, array $roles) { $managerRole = $this->getManagerRole($workspace); $groupsManagers = $this->groupRepo->findByRoles(array($managerRole)); $usersManagers = $this->userRepo->findByRoles(array($managerRole)); $removedGroupsManager = 0; $removedUsersManager = 0; foreach ($subjects as $subject) { if ($subject->hasRole($managerRole->getName()) && in_array($managerRole, $roles)) { $subject instanceof \Claroline\CoreBundle\Entity\Group ? $removedGroupsManager++ : $removedUsersManager++; } } if ($removedGroupsManager >= count($groupsManagers) && $removedUsersManager >= count($usersManagers)) { throw new LastManagerDeleteException("You can't remove every managers"); } }
/** * @param \Claroline\CoreBundle\Entity\Role[] $roles * @param int $page * @param int $max * @param string $orderedBy * @param null $order * * @return \PagerFanta\PagerFanta */ public function getGroupsByRoles(array $roles, $page = 1, $max = 50, $orderedBy = 'id', $order = null) { $query = $this->groupRepo->findByRoles($roles, true, $orderedBy, $order); return $this->pagerFactory->createPager($query, $page, $max); }