src/Controller/SupportController.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Entity\CustomerInformation;
  5. use App\Entity\Support;
  6. use App\Form\SupportType;
  7. use App\Repository\CustomerInformationRepository;
  8. use App\Repository\SupportRepository;
  9. use App\Service\Deck;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class SupportController extends AbstractController
  15. {
  16.     #[Route('/support'name'app_form_support_new'methods: ['GET''POST'])]
  17.     public function support(
  18.         Request $request,
  19.         SupportRepository $supportRepository,
  20.         CustomerInformationRepository $customerInformationRepository,
  21.         Deck $deck,
  22.     ): Response {
  23.         $support = new Support();
  24.         $customerInformation = new CustomerInformation();
  25.         $support->setCustomerInformation($customerInformation);
  26.         $form $this->createForm(SupportType::class, $support);
  27.         $form->handleRequest($request);
  28.         if ($form->isSubmitted() && $form->isValid()) {
  29.             $customerInformationRepository->add($customerInformation);
  30.             $supportRepository->add($support);
  31.             // On définit l'urgence de la demande
  32.             $stackId Deck::STACK_CLASSIQUE// Classique
  33.             if ($support->getIsBlocking()) {
  34.                 $stackId Deck::STACK_URGENT// Urgent
  35.                 if ($support->getBlockingDeadline()) {
  36.                     $interval $support->getCreated_at()->diff($support->getBlockingDeadline());
  37.                     if (=== $interval->invert && $interval->d) {
  38.                         $stackId Deck::STACK_PRIORITAIRE// Prioritaire
  39.                     }
  40.                 }
  41.             }
  42.             // On récupère la liste des labels
  43.             $labels $deck->getLabels();
  44.             $titre $support->getCustomerInformation()?->getName() ?? 'Pas de Titre';
  45.             $date $support->getCreated_at()->format('Y-m-d H:i:s');
  46.             $plain 'plain';
  47.             $description $this->renderView('support/description.md.twig', [
  48.                 'support' => $support,
  49.             ]);
  50.             // On crée le nouveau ticket dans Formulaire Support du NextCloud
  51.             $card $deck->createCard(
  52.                 $titre,
  53.                 $description,
  54.                 $date,
  55.                 $plain,
  56.                 $stackId
  57.             );
  58.             // On assigne un label au nouveau ticket
  59.             $labelId null;
  60.             $labelUrgent null;
  61.             $labelPrioritaire null;
  62.             foreach ($labels as $label) {
  63.                 if ($label['title'] === $support->getCustomerInformation()?->getCompany()) {
  64.                     $labelId $label['id'];
  65.                 }
  66.                 if ('Urgent' === $label['title']) {
  67.                     $labelUrgent $label;
  68.                 }
  69.                 if ('Prioritaire' === $label['title']) {
  70.                     $labelPrioritaire $label;
  71.                 }
  72.             }
  73.             if (null !== $labelId) {
  74.                 $deck->assignLabel($card['id'], $labelId$stackId);
  75.             } else {
  76.                 $color str_pad(dechex(mt_rand(00xFFFFFF)), 6'0'\STR_PAD_LEFT);
  77.                 $label $deck->createLabel($support->getCustomerInformation()?->getCompany(), $color);
  78.                 $deck->assignLabel($card['id'], $label['id']);
  79.             }
  80.             // Si la demande est urgente / prioritaire
  81.             if ($support->getIsBlocking()) {
  82.                 if (118 === $stackId) {
  83.                     $deck->assignLabel($card['id'], $labelUrgent['id']);
  84.                 } elseif (121 === $stackId) {
  85.                     $deck->assignLabel($card['id'], $labelPrioritaire['id']);
  86.                 }
  87.             }
  88.             $this->addFlash('success''Votre demande de support a été créée avec succès.');
  89.             return $this->redirectToRoute('app_form_index');
  90.         }
  91.         return $this->render('front/form/support.html.twig', [
  92.             'form' => $form->createView(),
  93.         ]);
  94.     }
  95. }