Exemplo n.º 1
0
 /**
  * @Route("/{id}-{slug}/open", requirements = {"id" = "\d+"}, name="bugs_admin_open")
  * @Template()
  */
 public function openAction($id, $slug)
 {
     if (!$this->getUserLayer()->isUser() || !$this->getUser()->hasPermission('bugs.admin')) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     /** @var $bug Issue */
     $bug = $em->createQueryBuilder()->select('i, u, a')->from('EtuModuleBugsBundle:Issue', 'i')->leftJoin('i.user', 'u')->leftJoin('i.assignee', 'a')->where('i.id = :id')->setParameter('id', $id)->setMaxResults(1)->getQuery()->getOneOrNullResult();
     if (!$bug) {
         throw $this->createNotFoundException('Issue #' . $id . ' not found');
     }
     if (StringManipulationExtension::slugify($bug->getTitle()) != $slug) {
         throw $this->createNotFoundException('Invalid slug');
     }
     $bug->open();
     $em->persist($bug);
     $comment = new Comment();
     $comment->setIsStateUpdate(true);
     $comment->setIssue($bug);
     $comment->setUser($this->getUser());
     $comment->setBody($this->get('translator')->trans('bugs.bugs_admin.open.message', array('%adminName%' => $this->getUser()->getFullName())));
     $em->persist($comment);
     $em->flush();
     $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'bugs.bugs_admin.open.success'));
     return $this->redirect($this->generateUrl('bugs_view', array('id' => $bug->getId(), 'slug' => StringManipulationExtension::slugify($bug->getTitle()))));
 }