src/Controller/ServicesController.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Services;
  4. use App\Entity\Settings;
  5. use App\Entity\SubServices;
  6. use App\Service\Api;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class ServicesController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/services/{Text}/{IDSN}", name="service_details")
  15.      */
  16.     public function serviceDetails(string $Textstring $IDSNApi $apiService
  17.     {
  18.         $data['services'] = $apiService->getAllServices();
  19.         $data['current_service'] = null;
  20.         $data["icons"] = $apiService->getServicesIcons();
  21.         
  22.         // Get the current service
  23.         foreach ($data['services'] as $key => $service) {
  24.             if ($service['IDSN'] == $IDSN) {
  25.                 $data['current_service'] = $service;
  26.             }
  27.         }
  28.         // If no service found then render error
  29.         if (!$data['current_service']) {
  30.             return $this->render('errors/notFoundService.html.twig'$data);
  31.         }
  32.         // Get service groups names
  33.         foreach ($data['current_service']['subs'] as $key => $value) {
  34.             $data['groups'][$value['GroupName']][] = $value;
  35.         }
  36.         return $this->render('services/index.html.twig'$data);
  37.     }
  38.     /**
  39.      * @Route("/services/{Service}/{SubService}/{IDSN}/{IDGService}", name="sub_service_details")
  40.      */
  41.     public function subServiceDetails(string $Servicestring $SubServicestring $IDSNstring $IDGServiceApi $apiService
  42.     {
  43.         $data['services'] = $apiService->getAllServices();
  44.         $data['current_service'] = null;
  45.         $data['current_sub_service'] = null;
  46.         $data["icons"] = $apiService->getServicesIcons();
  47.         
  48.         // Get the current service
  49.         foreach ($data['services'] as $key => $service) {
  50.             if ($service['IDSN'] == $IDSN) {
  51.                 $data['current_service'] = $service;
  52.             }
  53.         }
  54.         // Check if the current service does not exists 
  55.         if (!$data['current_service']) {
  56.             return $this->render('errors/notFoundService.html.twig'$data);
  57.         }
  58.         // Get the current sub service
  59.         foreach ($data['current_service']['subs'] as $key => $subservice) {
  60.             if ($subservice['IDGService'] == $IDGService) {
  61.                 $data['current_sub_service'] = $subservice;
  62.             }
  63.         }
  64.         // Check if the current sub service does not exists 
  65.         if (!$data['current_sub_service']) {
  66.             return $this->render('errors/notFoundService.html.twig'$data);
  67.         }
  68.         
  69.         return $this->render('services/details.html.twig'$data);
  70.     }
  71. }