/**
  * @Route("/create", name="rnc_admin_news_create")
  * @Template()
  * @Secure(roles="ROLE_ADMIN")
  */
 public function createAction()
 {
     $request = $this->get('request');
     $isAdmin = $this->get('security.context')->isGranted('ROLE_ADMIN');
     $user = $this->get('security.context')->getToken()->getUser();
     $news = new News(array('fr' => null, 'en' => null));
     if ($isAdmin) {
         $news->setPublished(true);
     } else {
         $news->setPublished(false);
     }
     $news->setAuthor($user);
     $form = $this->createForm(new NewsType(), $news);
     $formHandler = new NewsHandler($form, $request, $this->get('doctrine')->getEntityManager());
     if ($formHandler->process()) {
         $this->get('session')->setFlash('success', 'flash.news.create');
         return $this->redirect($this->generateUrl('rnc_news_show', array('slug' => $news->getContent($this->get('request')->getLocale())->getSlug())));
     }
     return $this->render('RNCAdminBundle:News:create.html.twig', array('form' => $form->createView()));
 }
예제 #2
0
 public function onSuccess(News $news)
 {
     $news->setNbUpdates($news->getNbUpdates() + 1);
     $this->em->persist($news);
     $this->em->flush();
 }