private function checkTicketEditionAccess(User $user, Ticket $ticket)
 {
     $interventions = $ticket->getInterventions();
     if ($user->getId() !== $ticket->getUser()->getId() || count($interventions) > 0 || $ticket->getLevel() !== 0) {
         throw new AccessDeniedException();
     }
 }
 public function sendTicketMail(User $user, Ticket $ticket, $type = '', Comment $comment = null)
 {
     $contactMail = null;
     $receivers = [];
     $extra = [];
     switch ($type) {
         case 'new_ticket':
             $contactIds = $this->getConfigurationContactsOption();
             $contactMail = $ticket->getContactMail();
             if (count($contactIds) > 0) {
                 $receivers = $this->userManager->getUsersByIds($contactIds);
                 $subject = '[' . $this->translator->trans('new_ticket', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle();
                 $content = $ticket->getDescription() . '<br><br>' . $this->translator->trans('mail', [], 'platform') . ' : ' . $ticket->getContactMail() . '<br>' . $this->translator->trans('phone', [], 'platform') . ' : ' . $ticket->getContactPhone() . '<br><br>';
             }
             break;
         case 'ticket_edition':
             $contactIds = $this->getConfigurationContactsOption();
             $contactMail = $ticket->getContactMail();
             if (count($contactIds) > 0) {
                 $receivers = $this->userManager->getUsersByIds($contactIds);
                 $subject = '[' . $this->translator->trans('ticket_edition', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle();
                 $content = $ticket->getDescription() . '<br><br>' . $this->translator->trans('mail', [], 'platform') . ' : ' . $ticket->getContactMail() . '<br>' . $this->translator->trans('phone', [], 'platform') . ' : ' . $ticket->getContactPhone() . '<br><br>';
             }
             break;
         case 'ticket_deletion':
             $contactIds = $this->getConfigurationContactsOption();
             if (count($contactIds) > 0) {
                 $receivers = $this->userManager->getUsersByIds($contactIds);
                 $subject = '[' . $this->translator->trans('ticket_deletion', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle();
                 $content = $this->translator->trans('ticket_deletion', [], 'support') . '<br><br>';
             }
             break;
         case 'new_admin_comment':
             $extra['to'] = [$ticket->getContactMail()];
             if (!is_null($comment)) {
                 $subject = '[' . $this->translator->trans('new_comment', [], 'support') . '][' . $this->translator->trans('ticket', [], 'support') . ' #' . $ticket->getNum() . '] ' . $ticket->getTitle();
                 $content = $comment->getContent() . '<br><br>';
             }
             break;
         case 'new_comment':
             $contactIds = $this->getConfigurationContactsOption();
             $contactMail = $ticket->getContactMail();
             if (count($contactIds) > 0 && !is_null($comment)) {
                 $receivers = $this->userManager->getUsersByIds($contactIds);
                 $subject = '[' . $this->translator->trans('new_comment', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle();
                 $content = $comment->getContent() . '<br><br>' . $this->translator->trans('mail', [], 'platform') . ' : ' . $ticket->getContactMail() . '<br>' . $this->translator->trans('phone', [], 'platform') . ' : ' . $ticket->getContactPhone() . '<br><br>';
             }
             break;
         default:
             break;
     }
     if (count($receivers) > 0 || count($extra) > 0) {
         $this->mailManager->send($subject, $content, $receivers, null, $extra, false, $contactMail);
     }
 }
 /**
  * @EXT\Route(
  *     "/admin/ticket/{ticket}/management/info",
  *     name="formalibre_admin_ticket_management_info",
  *     options={"expose"=true}
  * )
  * @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
  * @EXT\Template()
  */
 public function adminTicketManagementInfoAction(User $authenticatedUser, Ticket $ticket)
 {
     $interventions = $ticket->getInterventions();
     $lastIntervention = null;
     $nbInterventions = count($interventions);
     $totalTime = 0;
     if ($nbInterventions > 0) {
         $lastIntervention = $interventions[$nbInterventions - 1];
         foreach ($interventions as $intervention) {
             $duration = $intervention->getDuration();
             if (!is_null($duration)) {
                 $totalTime += $duration;
             }
         }
     }
     $unfinishedInterventions = $this->supportManager->getUnfinishedInterventionByTicket($ticket);
     $hasOngoingIntervention = false;
     $ongoingIntervention = null;
     $otherUnfinishedInterventions = array();
     foreach ($unfinishedInterventions as $unfinishedIntervention) {
         if ($unfinishedIntervention->getUser() === $authenticatedUser) {
             $hasOngoingIntervention = true;
             $ongoingIntervention = $unfinishedIntervention;
         } else {
             $otherUnfinishedInterventions[] = $unfinishedIntervention;
         }
     }
     $withCredits = $this->supportManager->getConfigurationCreditOption();
     if ($withCredits) {
         $datasEvent = new GenericDatasEvent($ticket->getUser());
         $this->eventDispatcher->dispatch('formalibre_request_nb_remaining_credits', $datasEvent);
         $response = $datasEvent->getResponse();
         $nbCredits = is_null($response) ? 666 : $response;
     } else {
         $nbCredits = 666;
     }
     $nbHours = (int) ($totalTime / 60);
     $nbMinutes = $nbHours === 0 ? $totalTime : $totalTime % ($nbHours * 60);
     $totalCredits = 5 * $nbHours + ceil($nbMinutes / 15);
     return array('ticket' => $ticket, 'currentUser' => $authenticatedUser, 'unfinishedInterventions' => $otherUnfinishedInterventions, 'hasOngoingIntervention' => $hasOngoingIntervention, 'ongoingIntervention' => $ongoingIntervention, 'lastIntervention' => $lastIntervention, 'nbCredits' => $nbCredits, 'totalCredits' => $totalCredits, 'availableCredits' => $nbCredits, 'totalTime' => $totalTime, 'withCredits' => $withCredits);
 }