Deprecated: Symfony\Component\Translation\t(): Implicitly marking parameter $domain as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/translation/Resources/functions.php on line 18

Deprecated: Symfony\Component\Dotenv\Dotenv::loadEnv(): Implicitly marking parameter $envKey as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/dotenv/Dotenv.php on line 110

Deprecated: Symfony\Component\Runtime\GenericRuntime::getResolver(): Implicitly marking parameter $reflector as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/runtime/GenericRuntime.php on line 89

Deprecated: Symfony\Component\Runtime\RuntimeInterface::getResolver(): Implicitly marking parameter $reflector as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/runtime/RuntimeInterface.php on line 26

Deprecated: Symfony\Component\Console\Input\ArgvInput::__construct(): Implicitly marking parameter $argv as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/ArgvInput.php on line 46

Deprecated: Symfony\Component\Console\Input\ArgvInput::__construct(): Implicitly marking parameter $definition as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/ArgvInput.php on line 46

Deprecated: Symfony\Component\Console\Input\Input::__construct(): Implicitly marking parameter $definition as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/Input.php on line 36

Deprecated: Constant E_STRICT is deprecated in /var/www/html/t/taurushr/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /var/www/html/t/taurushr/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

src/Controller/ServiceController.php line 145

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Service;
  4. use App\Form\ServiceType;
  5. use App\Entity\ServiceCategory;
  6. use App\Annotation\CmsAdminDash;
  7. use App\Annotation\CmsComponent;
  8. use App\Service\ServiceController as BaseServiceController;
  9. use App\Repository\ServiceRepository;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. #[Route('/takeflight/service')]
  16. class ServiceController extends AbstractController
  17. {
  18.     public function __construct(private readonly BaseServiceController $serviceController) {}
  19.     /**
  20.      * Simple Parent Route for admin side-bar.
  21.      *
  22.      * @CmsAdminDash("Manage Services", active=true, role="ROLE_CMS_ACCESS", routeName="control_service_index", icon="fa fa-cogs", dontLink=true, menuPosition=10)
  23.      */
  24.     #[Route(path'/index'name'control_service_index'methods: ['GET'])]
  25.     public function contentIndex()
  26.     {
  27.         return false;
  28.     }
  29.     /**
  30.      * @CmsAdminDash("Services", active=true, routeName="app_service_index",icon="glyphicon glyphicon-picture", menuPosition=30, parentRouteName="control_service_index")
  31.      */
  32.     #[Route('/'name'app_service_index'methods: ['GET'])]
  33.     public function index(ServiceRepository $serviceRepository): Response
  34.     {
  35.         return $this->render('service/index.html.twig', [
  36.             'services' => $serviceRepository->findBy(['deleted' => false]),
  37.         ]);
  38.     }
  39.     #[Route('/new'name'app_service_new'methods: ['GET''POST'])]
  40.     public function new(Request $request): Response
  41.     {
  42.         $service = new Service();
  43.         $form $this->createForm(ServiceType::class, $service);
  44.         $form->handleRequest($request);
  45.         if ($form->isSubmitted() && $form->isValid()) {
  46.             // REQUIRED IF USING UPLOAD FILE TRAIT
  47.             // $service->uploadFile();
  48.             $entityManager $this->getDoctrine()->getManager();
  49.             $entityManager->persist($service);
  50.             $entityManager->flush();
  51.             return $this->redirectToRoute('app_service_index', [], Response::HTTP_SEE_OTHER);
  52.         }
  53.         return $this->render('service/new.html.twig', [
  54.             'service' => $service,
  55.             'form' => $form->createView(),
  56.         ]);
  57.     }
  58.     #[Route('/{id}'name'app_service_show'methods: ['GET'])]
  59.     public function show(Service $service): Response
  60.     {
  61.         return $this->render('service/show.html.twig', [
  62.             'service' => $service,
  63.         ]);
  64.     }
  65.     #[Route('/{id}/edit'name'app_service_edit'methods: ['GET''POST'])]
  66.     public function edit(Request $requestService $service): Response
  67.     {
  68.         $form $this->createForm(ServiceType::class, $service);
  69.         $form->handleRequest($request);
  70.         if ($form->isSubmitted() && $form->isValid()) {
  71.             // REQUIRED IF USING UPLOAD FILE TRAIT
  72.             // $service->uploadFile();
  73.             $this->getDoctrine()->getManager()->flush();
  74.             return $this->redirectToRoute('app_service_index', [], Response::HTTP_SEE_OTHER);
  75.         }
  76.         return $this->render('service/edit.html.twig', [
  77.             'service' => $service,
  78.             'form' => $form->createView(),
  79.         ]);
  80.     }
  81.     #[Route('/{id}'name'app_service_delete'methods: ['POST'])]
  82.     public function delete(Request $requestService $service): Response
  83.     {
  84.         if ($this->isCsrfTokenValid('delete'.$service->getId(), $request->request->get('_token'))) {
  85.             $entityManager $this->getDoctrine()->getManager();
  86.             $service->setActive(false);
  87.             $service->setDeleted(true);
  88.             $entityManager->persist($service);
  89.             $entityManager->flush();
  90.             $this->addFlash('success''Success - Service deleted');
  91.         }
  92.         return $this->redirectToRoute('app_service_index', [], Response::HTTP_SEE_OTHER);
  93.     }
  94.     /**
  95.      * @CmsComponent("Service Categories", active=true, routeName="embed_service_categories")
  96.      */
  97.     #[Route(path'/test-service-categories'name'embed_service_categories')]
  98.     public function embedServiceCategories(EntityManagerInterface $emRequest $request): Response
  99.     {
  100.         $categories $em->getRepository(ServiceCategory::class)->findAllWithServices();
  101.         return $this->render('@theme/service/index.html.twig', [
  102.             'categories' => $categories,
  103.         ]);
  104.     }
  105.     /**
  106.      * @CmsComponent("Service Category", slug="{service_category_slug}", slugEntity="ServiceCategory", active=true, routeName="embed_service_category")
  107.      */
  108.     #[Route(path'/test-service-categories/{service_category_slug}'name'embed_service_category')]
  109.     public function embedServiceCategory1(EntityManagerInterface $emRequest $requestmixed $service_category_slug)
  110.     {
  111.         $serviceCategory $em->getRepository(ServiceCategory::class)->findOneWithServices($service_category_slug);
  112.         if (!$serviceCategory) {
  113.             return new Response('Not Found');
  114.         }
  115.         $employerServices $serviceCategory->getServices()->filter(function($service) {
  116.             return $service->getEmployerOrEmployee() === 'Employer';
  117.         });
  118.         $employeeServices $serviceCategory->getServices()->filter(function($service) {
  119.             return $service->getEmployerOrEmployee() === 'Employee';
  120.         });
  121.         return $this->render('@theme/service/category1.html.twig', [
  122.             'category' => $serviceCategory,
  123.             'employerServices' => $employerServices,
  124.             'employeeServices' => $employeeServices,
  125.         ]);
  126.     }
  127.     /**
  128.      * @CmsComponent("Service", slug="{service_slug}", slugEntity="Service", active=true, routeName="embed_service")
  129.      */
  130.     #[Route(path'/test-service-categories/category/{service_slug}'name'embed_service')]
  131.     public function embedService(EntityManagerInterface $emRequest $requestmixed $service_slug)
  132.     {
  133.         if ($this->isGranted('ROLE_ADMIN')) {
  134.             $service $em->getRepository(Service::class)->findOneWithCategory($service_slugfalse);
  135.         } else {
  136.             $service $em->getRepository(Service::class)->findOneWithCategory($service_slug);
  137.         }
  138.         if (!$service) {
  139.             return $this->serviceController->componentRedirect('/service-not-found');
  140.         }
  141.         return $this->render('@theme/service/service.html.twig', [
  142.             'service' => $service,
  143.         ]);
  144.     }
  145. }