Exemplo n.º 1
0
 public function mainpotAction()
 {
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('EUMainBundle:Pot');
     $mainPot = $rep->find(1);
     $user = $this->getUser();
     $participation = new Participation();
     $participation->setUser($user);
     $participation->setPot($mainPot);
     $participation->setAcceptedAt(new \DateTime());
     $em->persist($participation);
     $em->flush();
     return $this->redirectToRoute('pots_list');
 }
Exemplo n.º 2
0
 public function inviteAction($id, $iduser)
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('EUMainBundle:Pot');
     $pot = $rep->find($id);
     $rep = $em->getRepository('ApplicationSonataUserBundle:User');
     $user = $rep->find($iduser);
     $response = new ResponseHelper($this);
     if ($pot && $user) {
         $rep = $em->getRepository('EUMainBundle:Participation');
         $participations = $rep->findBy(array('pot' => $pot, 'user' => $user));
         if (sizeof($participations) > 0) {
             $response->setStatusCode(Response::HTTP_NO_CONTENT);
         } elseif ($pot->getManager() !== $this->getUser()) {
             $response->setStatusCode(Response::HTTP_LOCKED);
         } else {
             $participation = new Participation();
             $participation->setUser($user);
             $participation->setPot($pot);
             $em->persist($participation);
             $em->flush();
             $response->setStatusCode(Response::HTTP_CREATED);
         }
     } else {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
         $response->setMessage('There is no pot or no user with this ID in the database');
         $response->setMessageType('warning');
         $response->addMessageButton('default', $request->headers->get('referer') == '' ? $this->generateUrl('eu_main_homepage') : $request->headers->get('referer'), 'Back');
         $response->addMessageButton('warning', $this->generateUrl('eu_main_homepage'), 'Home');
     }
     return $response->renderResponse();
 }