/** * Set ticket * * @param \Hackzilla\Bundle\TicketBundle\Entity\Ticket $ticket * * @return $this */ public function setTicket(Ticket $ticket = null) { $this->ticket = $ticket; if (\is_null($this->getUserObject())) { $user = $this->getUser(); } else { $user = $this->getUserObject(); } // if null, then new ticket if (\is_null($ticket->getUserCreated())) { $ticket->setUserCreated($user); } $ticket->setLastUser($user); $ticket->setLastMessage($this->getCreatedAt()); $ticket->setPriority($this->getPriority()); // if ticket not closed, then it'll be set to null if (\is_null($this->getStatus())) { $this->setStatus($ticket->getStatus()); } else { $ticket->setStatus($this->getStatus()); } return $this; }
/** * Deletes a Ticket entity. * * @param Request $request * @param Ticket $ticket * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function deleteAction(Request $request, Ticket $ticket) { $userManager = $this->get('hackzilla_ticket.user_manager'); $user = $userManager->getCurrentUser(); if (!\is_object($user) || !$userManager->hasRole($user, TicketRole::Admin)) { throw new \Symfony\Component\HttpKernel\Exception\HttpException(403); } $form = $this->createDeleteForm($ticket->getId()); $form->submit($request); if ($form->isValid()) { if (!$ticket) { throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY')); } $ticketManager = $this->get('hackzilla_ticket.ticket_manager'); $ticketManager->deleteTicket($ticket); $event = new TicketEvent($ticket); $this->get('event_dispatcher')->dispatch(TicketEvents::TICKET_DELETE, $event); } return $this->redirect($this->generateUrl('hackzilla_ticket')); }