/**
  * Get user permission
  *
  * @param Group $group
  * @return GroupUserPermission|NULL
  */
 public function getUserPermission(Group $group)
 {
     static $permissions = array();
     if (array_key_exists($group->getRole(), $permissions)) {
         return $permissions[$group->getRole()];
     }
     if (($user = $this->tokenStorage->getToken()->getUser()) instanceof User) {
         foreach ($user->getGroupPermissions() as $permission) {
             if ($permission->getGroup()->isEqualTo($group)) {
                 return $permissions[$group->getRole()] = $permission;
             }
         }
     }
     return null;
 }
 /**
  * (non-PHPdoc)
  *
  * @see \Symfony\Component\Form\AbstractType::buildForm()
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add("groupUserPermission", "entity", array("class" => "ADHUserBundle:GroupUserPermission", "choices" => $this->group->getUserPermissions(), "choice_label" => "user", "required" => true));
     $builder->add("confirm", "checkbox", array("required" => true));
     $builder->add("remove", "submit", array());
 }
Exemple #3
0
 /**
  * Add member to group
  * 
  * @Security("is_fully_authenticated()")
  * @GroupSecurity("group_is('leavable') and user_can('remove member')", group="group")
  * 
  * @Route("/remove/{group}", name="adh_user_group_member_remove")
  * @Method({"GET", "POST"})
  * 
  * @ParamConverter("group", options={"mapping": {"group": "role"}})
  *
  * @param Request $request
  * @param Group $group
  */
 public function removeAction(Request $request, Group $group)
 {
     $searchGroupUserPermission = new SearchGroupUserPermission();
     $form = $this->createForm(new SearchGroupUserPermissionType($group), $searchGroupUserPermission);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid() && $searchGroupUserPermission->isConfirmed()) {
         $entityManager = $this->getDoctrine()->getManager();
         $entityManager->remove($searchGroupUserPermission->getGroupUserPermission());
         $entityManager->flush();
         return $this->redirectToRoute("adh_user_group_member_list", array("group" => $group->getShortRole(), "size" => $request->isXmlHttpRequest() ? 4 : 24));
     }
     return $this->render("ADHUserBundle:Group/Member:remove.html.twig", array("form" => $form->createView(), "group" => $group));
 }