/**
  * @param Portfolio $portfolio
  * @param User      $user
  *
  * @return bool
  */
 public function visibleToUser(Portfolio $portfolio, User $user)
 {
     $visibility = $portfolio->getVisibility();
     $isVisible = false;
     if ($portfolio->getUser() === $user) {
         $isVisible = true;
     } else {
         if (Portfolio::VISIBILITY_EVERYBODY === $visibility || Portfolio::VISIBILITY_PLATFORM_USER === $visibility) {
             $isVisible = true;
         } elseif (Portfolio::VISIBILITY_USER === $visibility) {
             $portfolioUsers = $portfolio->getPortfolioUsers();
             foreach ($portfolioUsers as $portfolioUser) {
                 if ($user === $portfolioUser->getUser()) {
                     $isVisible = true;
                     break;
                 }
             }
             if (!$isVisible) {
                 $portfolioGroups = $portfolio->getPortfolioGroups();
                 $userGroups = $user->getGroups();
                 foreach ($portfolioGroups as $portfolioGroup) {
                     foreach ($userGroups as $userGroup) {
                         if ($userGroup === $portfolioGroup->getGroup()) {
                             $isVisible = true;
                             break;
                         }
                     }
                 }
             }
             if (!$isVisible) {
                 $portfolioTeams = $portfolio->getPortfolioTeams();
                 /** @var \Claroline\TeamBundle\Entity\Team[] $userTeams */
                 $userTeams = $this->teamManager->getTeamsByUser($user);
                 foreach ($portfolioTeams as $portfolioTeam) {
                     foreach ($userTeams as $userTeam) {
                         if ($userTeam === $portfolioTeam->getTeam()) {
                             $isVisible = true;
                             break;
                         }
                     }
                 }
             }
         }
     }
     return $isVisible;
 }
Example #2
0
 private function generateGroupRestrictions(User $user)
 {
     $restrictions = [];
     if (!$user->hasRole('ROLE_ADMIN')) {
         $restrictions = $user->getGroups()->toArray();
     }
     return $restrictions;
 }
Example #3
0
 public function removeUser(User $user)
 {
     $user->getGroups()->removeElement($this);
 }
 /**
  * Get list of groups a user belongs to.
  *
  * @param User $user
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  *
  * @Route(
  *     "/group/current_user",
  *     name = "innova_path_criteria_user_groups"
  * )
  * @Method("GET")
  * @ParamConverter("user", converter="current_user", options={"allowAnonymous"=true})
  */
 public function listUserGroupsAction(User $user = null)
 {
     $data = [];
     if ($user) {
         // Retrieve Groups of the User
         $groups = $user->getGroups();
         // data needs to be explicitly set because Group does not extends Serializable
         foreach ($groups as $group) {
             $data[$group->getId()] = $group->getName();
         }
     }
     return new JsonResponse($data);
 }