em = $em; $this->process = $process; $this->storage = $storage; } /** * @param TicketItemInterface $ticketItem * @param int $from * @param int $to * @param CustomUserInterface $user * @param int $action * @return TicketLogInterveningInterface|null */ public function create(TicketItemInterface $ticketItem, int $from, int $to = null, CustomUserInterface $user,int $action){ $log = new TicketLogIntervening(); $log->setDefault($ticketItem, $from, $to, $user,$action); if(!$this->quickUpdate($log)) return null; return $log; } public function formatLogToDisplay(TicketLogInterveningInterface $log){ $lang = 'fr'; $return = array(); $user = $this->storage->getToken()->getUser(); $return['timelog'] = $log->getTimelog(); // TODO: update content of case //génération de la phrase de log en fonction de l'action réalisée switch ($log->getAction()){ case TimeLogAction::STATUS_TICKET : $return['content'] = $this->display_log_CREATE_TICKET($lang, $log->getUser()); break; case TimeLogAction::STATUS_TICKET_CLOSED : $return['content'] = $this->display_log_CHANGE_STATUS($lang, $log->getUser(), $log->getNewStatus()); break; case TimeLogAction::CHANGE_INTERVENING : if($user->hasRole('ROLE_EURO') || $user->hasRole('ROLE_SUPPORT_ADMIN')) { $return['content'] = $this->display_log_CHANGE_INTERVENANT($lang, $log->getUser(), $log->getNewIntervenant()); } else return null; break; case TimeLogAction::DELETE_INTERVENING : if($user->hasRole('ROLE_EURO') || $user->hasRole('ROLE_SUPPORT_ADMIN')) { $return['content'] = $this->display_log_DELETE_INTERVENANT($lang, $log->getUser(), $log->getNewIntervenant()); } else return null; break; case TimeLogAction::STATUS_TICKET_RESOLVED : $return['content'] = $this->display_log_MARK_RESOLVED($lang, $log->getUser(), $log->getTicket()); break; case TimeLogAction::ADD_MESSAGE : $return['content'] = $this->display_log_ADD_MESSAGE($lang, $log->getUser(), $log->getMessage()); break; case TimeLogAction::DELETE_MESSAGE : if($user->hasRole('ROLE_EURO') || $user->hasRole('ROLE_SUPPORT_ADMIN')) { $return['content'] = $this->display_log_DELETE_MESSAGE($lang, $log->getUser(), $log->getMessage()); } else return null; break; } return $return; } private function display_log_CREATE_TICKET(string $lang, CustomUserInterface $user){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à créer ce ticket"; break; } } private function display_log_CHANGE_STATUS(string $lang, CustomUserInterface $user, int $status){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à changer le statut du ticket en : ".$status; break; } } private function display_log_CHANGE_INTERVENANT(string $lang, CustomUserInterface $user, TicketIntervenant $intervenant){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à nommé ".$intervenant->getUser()->getFirstname()." ".$intervenant->getUser()->getLastname()." en tant que nouvel intervenant du ticket"; break; } } private function display_log_DELETE_INTERVENANT(string $lang, CustomUserInterface $user, TicketIntervenant $intervenant){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à supprimé ".$intervenant->getUser()->getFirstname()." ".$intervenant->getUser()->getLastname()." en tant qu'intervenant du ticket"; break; } } private function display_log_ADD_MESSAGE(string $lang, CustomUserInterface $user, TicketMessage $message){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à écrit un message"; break; } } private function display_log_DELETE_MESSAGE(string $lang, CustomUserInterface $user, TicketMessage $message){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à supprimé un message"; break; } } private function display_log_MARK_RESOLVED(string $lang, CustomUserInterface $user, TicketItem $ticketItem){ switch($lang){ case 'fr' : return $user->getFirstname()." ".$user->getLastname()." à marqué le ticket comme résolu"; break; } } /** * @param TicketLogInterveningInterface $element * @return bool */ public function update(TicketLogInterveningInterface $element) { return $this->quickUpdate($element); } /** * @param TicketLogInterveningInterface $element * @return bool */ public function quickUpdate(TicketLogInterveningInterface $element) { if (!$this->em->contains($element)) { try { $this->em->persist($element); } catch (ORMException $e) { return false; } } try { $this->em->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } /** * @param TicketLogInterveningInterface $element * @return boolean */ public function delete(TicketLogInterveningInterface $element) { try { $this->em->remove($element); } catch (ORMException $e) { return false; } try { $this->em->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } }