src/Controller/EvolutionController.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Entity\CustomerInformation;
  5. use App\Entity\Evolution;
  6. use App\Form\EvolutionType;
  7. use App\Repository\CustomerInformationRepository;
  8. use App\Repository\EvolutionRepository;
  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 EvolutionController extends AbstractController
  15. {
  16.     #[Route('/evolution'name'app_form_evolution_new'methods: ['GET''POST'])]
  17.     public function evolution(
  18.         Request $request,
  19.         EvolutionRepository $supportRepository,
  20.         CustomerInformationRepository $customerInformationRepository,
  21.         Deck $deck,
  22.     ): Response {
  23.         $support = new Evolution();
  24.         $customerInformation = new CustomerInformation();
  25.         $support->setCustomerInformation($customerInformation);
  26.         $form $this->createForm(EvolutionType::class, $support);
  27.         $form->handleRequest($request);
  28.         if ($form->isSubmitted() && $form->isValid()) {
  29.             $customerInformationRepository->add($customerInformation);
  30.             $supportRepository->add($support);
  31.             $titre $support->getCustomerInformation()?->getName() ?? 'Pas de Titre';
  32.             $date $support->getCreated_at()->format('Y-m-d H:i:s');
  33.             $plain 'plain';
  34.             $description $this->renderView('evolution/description.md.twig', [
  35.                 'support' => $support,
  36.             ]);
  37.             // On crée le nouveau ticket dans Formulaire Evolution du NextCloud
  38.             $card $deck->createCard(
  39.                 $titre,
  40.                 $description,
  41.                 $date,
  42.                 $plain,
  43.                 Deck::STACK_EVOLUTION
  44.             );
  45.             // On récupère la liste des labels
  46.             $labels $deck->getLabels();
  47.             // On assigne un label au nouveau ticket
  48.             $labelId null;
  49.             foreach ($labels as $label) {
  50.                 if ($label['title'] === $support->getCustomerInformation()?->getCompany()) {
  51.                     $labelId $label['id'];
  52.                 }
  53.             }
  54.             if (null !== $labelId) {
  55.                 $deck->assignLabel($card['id'], $labelId);
  56.             } else {
  57.                 $color str_pad(dechex(mt_rand(00xFFFFFF)), 6'0'\STR_PAD_LEFT);
  58.                 $label $deck->createLabel($support->getCustomerInformation()?->getCompany(), $color);
  59.                 $deck->assignLabel($card['id'], $label['id']);
  60.             }
  61.             $this->addFlash('success''Votre demande d’évolution a été créée avec succès.');
  62.             return $this->redirectToRoute('app_form_index');
  63.         }
  64.         return $this->render('front/form/evolution.html.twig', [
  65.             'form' => $form->createView(),
  66.         ]);
  67.     }
  68. }