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(); } }
/** * @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); }