/**
  *
  * @Route("branches/{branchId}/jury/{juryId}/add-user")
  * @Method({"GET"})
  */
 public function addUsersAction($juryId, $branchId)
 {
     $template = $this->get('template');
     $request = $this->getRequest();
     $type = new DirectorJuryUserType();
     $user = new Entity\User();
     $form = $this->createForm($type, $user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $jury = $this->getManager()->getRepository('Entity\\Jury')->find($juryId);
         $factory = $this->get('security.encoder_factory');
         $encoder = $factory->getEncoder($user);
         $pass = $encoder->encodePassword($user->getPassword(), $user->getSalt());
         $user->setPassword($pass);
         $user->setStatus(STUDENT);
         $user->setChatcallUserId(0);
         $user->setChatcallDate(null);
         $user->setCurriculumItems(null);
         $user->setChatcallText(' ');
         $user->setActive(true);
         $em = $this->getManager();
         $em->persist($user);
         $user->getUserId();
         $role = current($user->getRoles());
         $juryMember = new Entity\JuryMembers();
         $juryMember->setJury($jury);
         $juryMember->setRole($role);
         $juryMember->setUser($user);
         $em->persist($juryMember);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', "User saved");
         //return $this->redirect($url);
     }
     $template->assign('form', $form->createView());
     $template->assign('juryId', $juryId);
     $template->assign('branchId', $branchId);
     $response = $template->render_template($this->getTemplatePath() . 'add_user.tpl');
     return new Response($response, 200, array());
 }
 /**
  * @Route("/{id}/add-members", requirements={"id" = "\d+"})
  * @Method({"GET"})
  */
 public function addMembersAction(Application $app, $id)
 {
     $extraJS = array('<link href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/style.css" rel="stylesheet" type="text/css" />', '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript"></script>');
     $app['extraJS'] = $extraJS;
     $juryUserType = new JuryMembersType();
     $juryMember = new Entity\JuryMembers();
     $juryMember->setJuryId($id);
     $form = $this->createForm($juryUserType, $juryMember);
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         if ($form->isValid()) {
             /** @var Entity\JuryMembers $item */
             $item = $form->getData();
             $userIdList = $item->getUserId();
             $userId = $userIdList[0];
             $user = $this->getManager()->getRepository('Entity\\User')->find($userId);
             if (!$user) {
                 throw new \Exception('Unable to found User');
             }
             $jury = $this->getRepository()->find($id);
             if (!$jury) {
                 throw new \Exception('Unable to found Jury');
             }
             $juryMember->setUser($user);
             $juryMember->setJury($jury);
             $em = $this->getManager();
             $em->persist($juryMember);
             $em->flush();
             $this->get('session')->getFlashBag()->add('success', "Saved");
             $url = $this->get('url_generator')->generate('jury.controller:readAction', array('id' => $id));
             return $this->redirect($url);
         }
     }
     $template = $this->get('template');
     $template->assign('jury_id', $id);
     $template->assign('form', $form->createView());
     $response = $template->render_template($this->getTemplatePath() . 'add_members.tpl');
     return new Response($response, 200, array());
 }