/** * 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']); } } }
/** * Saves a user into the database. * * @param \MicroCMS\Domain\User $user The user to save */ public function save(User $user) { $userData = array('login_user' => $user->getLogin(), 'name_user' => $user->getName(), 'surname_user' => $user->getSurname(), 'salt_user' => $user->getSalt(), 'password_user' => $user->getPassword(), 'role_user' => $user->getRole()); if ($user->getNum()) { // The user has already been saved : update it $this->getDb()->update('user', $userData, array('num_user' => $user->getNum())); } else { // The user has never been saved : insert it $this->getDb()->insert('user', $userData); // Get the id of the newly created user and set it on the entity. $id = $this->getDb()->lastInsertId(); $user->setNum($id); //Insertion of an order linked to the user $this->getDb()->insert('order_gd', array('num_user' => $user->getNum())); } }