<?php
/**
* Created by PhpStorm.
* User: adria
* Date: 1/5/2019
* Time: 11:15 AM
*/
namespace App\Controller\Api;
use App\Controller\Response;
use App\Entity\Categories;
use App\Entity\Countries;
use App\Entity\FilterCategories;
use App\Entity\Filters;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class FiltersController extends AbstractController
{
use Response;
/**
* @Route("/api/filters", name="api_filters", methods={"GET"})
*/
public function listAction(EntityManagerInterface $em)
{
$categories = $em->getRepository(Categories::class)->findAllActive();
$filterCategories = $em->getRepository(FilterCategories::class)->findAllActive();
foreach ($filterCategories as &$category) {
$category['filters'] = $em->getRepository(Filters::class)->findAllByCategory($category['id']);
}
return $this->jsonResponse([
'categories' => $categories,
'filters' => $filterCategories,
]);
}
/**
* @Route("/api/countries", name="api_countries", methods={"GET"})
*/
public function countriesAction(EntityManagerInterface $em)
{
$countries = $em->getRepository(Countries::class)->findBy([], ['countryName' => 'ASC']);
return $this->json([
'status' => 'ok',
'data' => $countries,
], 200, [], ['groups' => ["countries"]]);
}
}