Ejemplo n.º 1
0
 /**
  * @Route("/", name="answer")
  * @Method({"GET", "POST"})
  */
 public function indexAction(Request $request)
 {
     /**
      * get all questionnaires for the user
      * then list them
      */
     $em = $this->getDoctrine()->getManager();
     $inviteForm = $this->createFormBuilder()->add('id', 'text', array('label' => 'Team id'))->add('save', 'submit', array('label' => 'Submit'))->getForm();
     $inviteForm->handleRequest($request);
     if ($inviteForm->isSubmitted() && $inviteForm->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $team = $em->getRepository('AppBundle:Team')->find($inviteForm["id"]->getData());
         if (!$team) {
             $this->get('session')->getFlashBag()->add('danger', 'No team found!');
             return $this->redirectToRoute('answer');
         }
         $membership = new TeamMember();
         $membership->setUser($this->getUser());
         $membership->setTeam($team);
         $membership->setRole("user");
         $em->persist($membership);
         $this->getUser()->addTeam($membership);
         $team->addMember($membership);
         $em->flush();
         $this->get('session')->getFlashBag()->add('notice', 'Joined new team succesfully!');
     }
     $userTeams = $this->getUser()->getTeams();
     $questionnaires = array();
     foreach ($userTeams as $membership) {
         foreach ($membership->getTeam()->getProjects() as $project) {
             if ($project->getQuestionnaire() != null) {
                 foreach ($project->getQuestionnaire() as $q) {
                     if (!in_array($q, $questionnaires)) {
                         $questionnaires[] = $q;
                     }
                 }
             }
         }
     }
     return $this->render('Questionnaire/Answer/answer.html.twig', array('questionnaires' => $questionnaires, 'inviteForm' => $inviteForm->createView()));
 }
Ejemplo n.º 2
0
 /**
  * Displays a form to edit an existing team entity.
  *
  * @Route("team/{id}/edit", requirements={"id" = "\d+"}, name="team_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Team $team, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $teamForm = $this->get("form.factory")->createNamedBuilder("teamForm", "form", $team)->add('teamName', 'text', array('label' => 'Team Name'))->add('country', 'choice', array('choices' => array('FIN' => 'Finland', 'EST' => 'Estonia', 'NOR' => 'Norway', 'RU' => 'Russia', 'SWE' => 'Sweden'), 'required' => true))->getForm();
     $teamMembers = $team->getMembers();
     $users = array();
     foreach ($teamMembers as $teamMember) {
         $users[] = $teamMember->getUser();
     }
     $allUsers = $this->getDoctrine()->getRepository('AppBundle:User')->findAll();
     $choiceArray = array_diff($allUsers, $users);
     $memberForm = $this->get("form.factory")->createNamedBuilder("memberForm")->add('user', 'entity', array('class' => 'AppBundle:User', 'property' => 'username', 'choices' => $choiceArray))->add('save', 'submit', array('label' => 'Add Member', 'attr' => array('class' => 'btn btn-primary')))->getForm();
     if ('POST' === $request->getMethod()) {
         if ($request->request->has('memberForm')) {
             $memberForm->handleRequest($request);
             $newMember = new TeamMember();
             $newUser = $memberForm['user']->getData();
             $newMember->setUser($newUser);
             $newMember->setTeam($team);
             $newMember->setRole("user");
             $newUser->addTeam($newMember);
             $team->addMember($newMember);
             $em->persist($newMember);
             $em->flush();
             $this->get('session')->getFlashBag()->add('notice', 'New member was added succesfully!');
         }
         if ($request->request->has('teamForm')) {
             $teamForm->handleRequest($request);
             $em->flush();
             $this->get('session')->getFlashBag()->add('notice', 'Your changes were saved!');
         }
     }
     return $this->render('admin/team/team_edit.html.twig', array('team' => $team, 'teamForm' => $teamForm->createView(), 'memberForm' => $memberForm->createView()));
 }