src/Controller/Api/FiltersController.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: adria
  5.  * Date: 1/5/2019
  6.  * Time: 11:15 AM
  7.  */
  8. namespace App\Controller\Api;
  9. use App\Controller\Response;
  10. use App\Entity\Categories;
  11. use App\Entity\Countries;
  12. use App\Entity\FilterCategories;
  13. use App\Entity\Filters;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class FiltersController extends AbstractController
  18. {
  19.     use Response;
  20.     /**
  21.      * @Route("/api/filters", name="api_filters", methods={"GET"})
  22.      */
  23.     public function listAction(EntityManagerInterface $em)
  24.     {
  25.         $categories $em->getRepository(Categories::class)->findAllActive();
  26.         $filterCategories $em->getRepository(FilterCategories::class)->findAllActive();
  27.         foreach ($filterCategories as &$category) {
  28.             $category['filters'] = $em->getRepository(Filters::class)->findAllByCategory($category['id']);
  29.         }
  30.         return $this->jsonResponse([
  31.             'categories' => $categories,
  32.             'filters'    => $filterCategories,
  33.         ]);
  34.     }
  35.     /**
  36.      * @Route("/api/countries", name="api_countries", methods={"GET"})
  37.      */
  38.     public function countriesAction(EntityManagerInterface $em)
  39.     {
  40.         $countries $em->getRepository(Countries::class)->findBy([], ['countryName' => 'ASC']);
  41.         return $this->json([
  42.             'status' => 'ok',
  43.             'data'   => $countries,
  44.         ], 200, [], ['groups' => ["countries"]]);
  45.     }
  46. }