src/Controller/DefaultController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpClient\HttpClient;
  7. class DefaultController extends AbstractController
  8. {
  9.     public function admin(Request $request): Response
  10.     {
  11.         return $this->redirectToRoute('sonata_admin_dashboard');
  12.     }
  13.     public function index($slasecret nullRequest $request): Response
  14.     {
  15.         $user $this->getUser();
  16.         if($user) {
  17.             $isLoggedIn true;
  18.         } else {
  19.             $isLoggedIn false;
  20.         }
  21.         $valid null;
  22.         $CHEQContracts null;
  23.         $others null;
  24.         $changes = [];
  25.         if(!$slasecret && $isLoggedIn) {
  26.             $slasecret $request->request->get('sla_botname'null);
  27.         } else {
  28.             $slasecret "sla:".$slasecret;
  29.         }
  30.         if($slasecret) {
  31.             $slaChanges = [];
  32.             $em $this->getDoctrine()->getManager();
  33.             $projectRepo $em->getRepository("App\Entity\Project");
  34.             if(strpos($slasecret"sla:") !== false) {
  35.                 $project $projectRepo->findOneBy(array("slasecret" => str_replace("sla:"""$slasecret)));
  36.             } else {
  37.                 $project $projectRepo->findOneBy(array("botname" => $slasecret));
  38.             }
  39.             if($project) {
  40.                 
  41.                 /*SLAs*/
  42.                 $slas $project->getSlaChanges();
  43.                 if(!empty($slas)) {
  44.                     foreach($slas as $sla) {
  45.                         $slaChanges["changes"][$sla->getDate()->format("Y-m-d H:i:s")] = [
  46.                             "name" => $sla->getCurrentSLA()->getName(),
  47.                             "value" => $sla->getCurrentSLA()->getValue(),
  48.                             "id" => $sla->getId(),
  49.                             "security" => $sla->getSecurity(),
  50.                         ];
  51.                     }
  52.                 }
  53.                 krsort($slaChanges["changes"]);
  54.                 $changes $slaChanges["changes"];
  55.                 $valid 1;
  56.                 
  57.                 /*CHEQContracts*/
  58.                 foreach($project->getCHEQContracts() AS $CHEQContract) {
  59.                     if(!$CHEQContract->getFiles()->isEmpty()) {
  60.                         foreach($CHEQContract->getFiles() AS $file) {
  61.                             $CHEQContracts[$CHEQContract->getCreated()->format("Y-m-d H:i:s")][$file->getName()."-".$file->getCreated()->getTimestamp()] = [
  62.                                 "fileName" => $file->getName(),
  63.                                 "fileDescription" => $file->getDescription(),
  64.                                 "fileCreated" => $file->getCreated()->format("Y-m-d H:i:s"),
  65.                                 "fileId" => $file->getId(),
  66.                                 "fileSecurity" => $file->getSecurity(),
  67.                             ];
  68.                         }
  69.                         krsort($CHEQContracts[$CHEQContract->getCreated()->format("Y-m-d H:i:s")]);
  70.                     }
  71.                 }
  72.                 
  73.                 /*Other files*/
  74.                 if(!empty($project->getFiles())) {
  75.                     foreach($project->getFiles() AS $file) {
  76.                         if($file->getCHEQContract()) {
  77.                             continue;
  78.                         }
  79.                         $extension = \explode("."$file->getFilePath()); 
  80.                         switch (\end($extension)) {
  81.                             case "png":
  82.                             case "jpg":
  83.                             case "jpeg":
  84.                             case "gif":
  85.                                 $fileType "image";
  86.                                 break;
  87.                             case "pdf":
  88.                                 $fileType "pdf";
  89.                                 break;
  90.                             default:
  91.                                 $fileType "other";
  92.                         }
  93.                         $others[] = [
  94.                             "fileName" => $file->getName(),
  95.                             "fileDescription" => $file->getDescription(),
  96.                             "fileCreated" => $file->getCreated()->format("Y-m-d H:i:s"),
  97.                             "fileId" => $file->getId(),
  98.                             "fileSecurity" => $file->getSecurity(),
  99.                             "fileType" => $fileType,
  100.                         ];
  101.                     }
  102.                     if(!empty($others)) {
  103.                         krsort($others);
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.         return $this->render("index.html.twig", [
  109.                 "valid" => $valid,
  110.                 "botname" => $slasecret,
  111.                 "changes" => $changes,
  112.                 "isLoggedIn" => $isLoggedIn,
  113.                 "CHEQContracts" => $CHEQContracts,
  114.                 "others" => $others,
  115.             ]);
  116.     }
  117. }