コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
 /**
  * Saves a ticekt into the database.
  *
  * @param \MicroCMS\Domain\Ticket $ticket The ticket to save
  * @param \MicroCMS\Domain\User $user The user linked to the ticket
  */
 public function save(Ticket $ticket, User $user)
 {
     $ticketData = array('num_ticket' => $ticket->getNum(), 'num_event' => $ticket->getEvent()->getNum(), 'numPlace_ticket' => $ticket->getNumPlace());
     if ($ticket->getNum()) {
         // The ticket has already been saved : update it
         $this->getDb()->update('ticket', $ticketData, array('num_ticket' => $ticket->getNum()));
     } else {
         // The ticket has never been saved : insert it
         $this->getDb()->insert('ticket', $ticketData);
         // Get the id of the newly created user and set it on the entity.
         $id = $this->getDb()->lastInsertId();
         $ticket->setNum($id);
         $sql = "select num_order from order_gd where num_user = ?";
         $row = $this->getDb()->fetchAssoc($sql, array($user->getNum()));
         if ($row) {
             $this->getDb()->insert('ticketsbyorder', array('num_ticket' => $ticket->getNum(), 'num_order' => $row['num_order']));
         } else {
             throw new \Exception("No order matching id " . $row['num_order']);
         }
     }
 }