/** * Event details controller. * * @param integer $id Event id * @param Request $request Incoming request * @param Application $app Silex application */ public function eventAction($id, Request $request, Application $app) { $event = $app['dao.event']->find($id); $types = $app['dao.type']->findAll(); $commentFormView = null; $ticketFormView = null; $user = $app['user']; if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) { // A user is fully authenticated : he can add comments and commands $ticket = new Ticket(); $ticket->setEvent($event); $ticketForm = $app['form.factory']->create(new TicketType(), $ticket); $ticketForm->handleRequest($request); if ($ticketForm->isSubmitted() && $ticketForm->isValid()) { $app['dao.ticket']->save($ticket, $user); $app['session']->getFlashBag()->add('success', 'Your command was succesfully added.'); } $ticketFormView = $ticketForm->createView(); $comment = new Commentary(); $comment->setEvent($event); $comment->setUser($user); $commentForm = $app['form.factory']->create(new CommentType(), $comment); $commentForm->handleRequest($request); if ($commentForm->isSubmitted() && $commentForm->isValid()) { $app['dao.commentary']->save($comment); $app['session']->getFlashBag()->add('success', 'Your comment was succesfully added.'); } $commentFormView = $commentForm->createView(); } $comments = $app['dao.commentary']->findAllByEvent($id); return $app['twig']->render('event.html.twig', array('event' => $event, 'comments' => $comments, 'types' => $types, 'commentForm' => $commentFormView, 'ticketForm' => $ticketFormView)); }
/** * Saves a comment into the database. * * @param \MicroCMS\Domain\Comment $comment The comment to save */ public function save(Commentary $comment) { $commentData = array('rate_commentary' => '0', 'text_commentary' => $comment->getText(), 'num_event' => $comment->getEvent()->getNum(), 'num_user' => $comment->getUser()->getNum()); if ($comment->getNum()) { // The comment has already been saved : update it $this->getDb()->update('commentary', $commentData, array('num_commentary' => $comment->getNum())); } else { // The comment has never been saved : insert it $this->getDb()->insert('commentary', $commentData); // Get the id of the newly created comment and set it on the entity. $id = $this->getDb()->lastInsertId(); $comment->setNum($id); } }