Пример #1
0
 /**
  * Creates a new Tache entity.
  *
  * @Route("/create/{gid}", name="tache_create")
  *
  *
  */
 public function createAction($gid)
 {
     if (false === $this->get('security.context')->isGranted('ROLE_USER')) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getEntityManager();
     $config = $this->get('config.extension');
     $entity = new Tache();
     $entity->setStatut(0);
     $request = $this->getRequest();
     $admin = $this->get('security.context')->isGranted('ROLE_HUMAIN');
     $user = $this->get('security.context')->getToken()->getUser();
     if ($gid != "") {
         $groupe = $em->getRepository('AssoMakerPHPMBundle:GroupeTache')->find($gid);
         if (!$groupe) {
             throw $this->createNotFoundException('Pas de groupe correspondant.');
         }
         $entity->setGroupeTache($groupe);
         $entity->setLieu($groupe->getLieu());
         $entity->setResponsable($groupe->getResponsable());
         $entity->setStatut(0);
         $entity->setNom('Tâche sans nom');
         $entity->setPermisNecessaire(0);
     }
     $em->persist($entity);
     $em->flush();
     return $this->redirect($this->generateUrl('tache_edit', array('id' => $entity->getId())));
 }
Пример #2
0
 /**
  * Edits an existing GroupeTache entity.
  *
  * @Route("/{id}/update", name="groupetache_update")
  * @Method("post")
  * @Template("AssoMakerPHPMBundle:GroupeTache:edit.html.twig")
  */
 public function updateAction($id)
 {
     if (false === $this->get('security.context')->isGranted('ROLE_USER')) {
         throw new AccessDeniedException();
     }
     $admin = $this->get('security.context')->isGranted('ROLE_HUMAIN');
     $em = $this->getDoctrine()->getEntityManager();
     $request = $this->getRequest();
     $config = $this->get('config.extension');
     $param = $request->request->all();
     $entity = $em->getRepository('AssoMakerPHPMBundle:GroupeTache')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find GroupeTache entity.');
     }
     $editForm = $this->createForm(new GroupeTacheType($admin, $config), $entity);
     $request = $this->getRequest();
     $editForm->handleRequest($request);
     if ($editForm->isValid()) {
         if ($param['action'] == 'delete' && $entity->isDeletable()) {
             $entity->setStatut(-1);
         }
         if ($param['action'] == 'restore') {
             $entity->setStatut(0);
         }
         $em->persist($entity);
         $em->flush();
         if ($param['action'] == 'add_tache') {
             $tache = new Tache();
             $tache->setGroupeTache($entity);
             $tache->setNom("Tâche sans nom");
             $tache->setStatut(0);
             $tache->setResponsable($entity->getResponsable());
             $tache->setPermisNecessaire(-1);
             $tache->setLieu($entity->getLieu());
             $em->persist($tache);
             $em->flush();
             return $this->redirect($this->generateUrl('tache_edit', array('id' => $tache->getId())));
         }
         return $this->redirect($this->generateUrl('groupetache_edit', array('id' => $id)));
     }
     return array('entity' => $entity, 'form' => $editForm->createView());
 }