<?php
namespace App\Controller;
use App\Entity\Services;
use App\Entity\Settings;
use App\Entity\SubServices;
use App\Service\Api;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class ServicesController extends AbstractController
{
/**
* @Route("/services/{Text}/{IDSN}", name="service_details")
*/
public function serviceDetails(string $Text, string $IDSN, Api $apiService)
{
$data['services'] = $apiService->getAllServices();
$data['current_service'] = null;
$data["icons"] = $apiService->getServicesIcons();
// Get the current service
foreach ($data['services'] as $key => $service) {
if ($service['IDSN'] == $IDSN) {
$data['current_service'] = $service;
}
}
// If no service found then render error
if (!$data['current_service']) {
return $this->render('errors/notFoundService.html.twig', $data);
}
// Get service groups names
foreach ($data['current_service']['subs'] as $key => $value) {
$data['groups'][$value['GroupName']][] = $value;
}
return $this->render('services/index.html.twig', $data);
}
/**
* @Route("/services/{Service}/{SubService}/{IDSN}/{IDGService}", name="sub_service_details")
*/
public function subServiceDetails(string $Service, string $SubService, string $IDSN, string $IDGService, Api $apiService)
{
$data['services'] = $apiService->getAllServices();
$data['current_service'] = null;
$data['current_sub_service'] = null;
$data["icons"] = $apiService->getServicesIcons();
// Get the current service
foreach ($data['services'] as $key => $service) {
if ($service['IDSN'] == $IDSN) {
$data['current_service'] = $service;
}
}
// Check if the current service does not exists
if (!$data['current_service']) {
return $this->render('errors/notFoundService.html.twig', $data);
}
// Get the current sub service
foreach ($data['current_service']['subs'] as $key => $subservice) {
if ($subservice['IDGService'] == $IDGService) {
$data['current_sub_service'] = $subservice;
}
}
// Check if the current sub service does not exists
if (!$data['current_sub_service']) {
return $this->render('errors/notFoundService.html.twig', $data);
}
return $this->render('services/details.html.twig', $data);
}
}