public function tacosAction($id, Request $request, Application $app)
 {
     $tacos = $app['dao.tacos']->find($id);
     $comments = $app['dao.comment']->findAllByTacos($id);
     $commentFormView = null;
     if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) {
         $comment = new Comment();
         $comment->setTacos($tacos);
         $user = $app['user'];
         $comment->setAuthor($user);
         $commentForm = $app['form.factory']->create(new CommentType(), $comment);
         $commentForm->handleRequest($request);
         if ($commentForm->isSubmitted() && $commentForm->isValid()) {
             $app['dao.comment']->save($comment);
             $app['session']->getFlashBag()->add('success', 'Votre commentaire a été ajouté avec succès !');
         }
         $commentFormView = $commentForm->createView();
     }
     return $app['twig']->render('tacos.html.twig', array('tacos' => $tacos, 'comments' => $comments, 'commentForm' => $commentFormView));
 }
Ejemplo n.º 2
0
 public function save(Comment $comment)
 {
     $commentData = array('tacos_id' => $comment->getTacos()->getId(), 'usr_id' => $comment->getAuthor()->getId(), 'com_content' => $comment->getContent());
     if ($comment->getId()) {
         $this->getDb()->update('t_comment', $commentData, array('com_id' => $comment->getId()));
     } else {
         $this->getDb()->insert('t_comment', $commentData);
         $id = $this->getDb()->lastInsertId();
         $comment->setId($id);
     }
 }