src/Controller/OfficeController.php line 51

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Entity\LocationInterface;
  5. use App\Repository\JobRepositoryInterface;
  6. use App\Repository\LocationRepositoryInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class OfficeController extends AbstractController
  11. {
  12.     private LocationRepositoryInterface $locationRepository;
  13.     private JobRepositoryInterface $jobRepository;
  14.     public function __construct(LocationRepositoryInterface $locationRepositoryJobRepositoryInterface $jobRepository)
  15.     {
  16.         $this->locationRepository $locationRepository;
  17.         $this->jobRepository $jobRepository;
  18.     }
  19.     /**
  20.      * @Route("/our-locations", name="office_index")
  21.      */
  22.     public function index(): Response
  23.     {
  24.         $locations $this
  25.             ->locationRepository
  26.             ->findAll();
  27.         $jobs $this
  28.             ->jobRepository
  29.             ->createActiveQueryBuilder()
  30.             ->setMaxResults(3)
  31.             ->getQuery()
  32.             ->getResult();
  33.         return $this->render('page/office/index/index.html.twig', [
  34.             'locations' => $locations,
  35.             'jobs' => $jobs
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/location/{location}", name="office_show")
  40.      */
  41.     public function show(LocationInterface $location): Response
  42.     {
  43.         $jobs $this
  44.             ->jobRepository
  45.             ->findActiveByLocation($location);
  46.         return $this->render('page/office/show/show.html.twig', [
  47.             'location' => $location,
  48.             'jobs' => $jobs
  49.         ]);
  50.     }
  51. }