src/Application/Service/ElasticSearch/ElasticSearchService.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Application\Service\ElasticSearch;
  3. use App\Application\Service\Cache\CacheAdapterService;
  4. use App\Application\Service\Session\SessionService;
  5. use App\ViewManager\Landing\ViewService;
  6. use Psr\Cache\InvalidArgumentException;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. class ElasticSearchService
  9. {
  10.     public const CACHE_NUM_PRODUCTS_FROM_ELASTICSEARCH 'NumProductsFromElasticSearch_';
  11.     public const ORDER_RANDOM_VALUE 6;
  12.     private RequestStack $requestStack;
  13.     private CacheAdapterService $cacheAdapterService;
  14.     private SessionService $sessionService;
  15.     public function __construct(
  16.         RequestStack $requestStack,
  17.         CacheAdapterService $cacheAdapterService,
  18.         SessionService $sessionService
  19.     ) {
  20.         $this->requestStack $requestStack;
  21.         $this->cacheAdapterService $cacheAdapterService;
  22.         $this->sessionService $sessionService;
  23.     }
  24.     public function getResultsElasticSearch(string $lang, ?int $init, ?int $limitint $ajax, array $filters, ?bool $wholesaler)
  25.     {
  26.         return \Tools::getResultsElasticSearch($lang$init$limit$ajax$filters$wholesaler);
  27.     }
  28.     /**
  29.      * @return mixed
  30.      *
  31.      * @throws InvalidArgumentException
  32.      */
  33.     public function getNumTotalProductsIndexedByElastic()
  34.     {
  35.         $langId $this->sessionService->getLocaleId();
  36.         if ($data $this->cacheAdapterService->existCache(self::CACHE_NUM_PRODUCTS_FROM_ELASTICSEARCH.$langId)) {
  37.             return $data;
  38.         }
  39.         $limitProducts ViewService::MAX_CATEGORY_PRODUCTS;
  40.         $lang $this->sessionService->getLocale();
  41.         $filters $this->requestStack->getSession()->get('filters');
  42.         $filters = ($filters ?: ['order' => [6]]);
  43.         $ajax $this->requestStack->getSession()->get('ajax') ?? 0;
  44.         $wholesaler $this->requestStack->getSession()->get('is_wholesaler');
  45.         $result =  $this->getResultsElasticSearch(
  46.             $lang,
  47.             0,
  48.             $limitProducts,
  49.             $ajax,
  50.             $filters,
  51.             $wholesaler
  52.         );
  53.         return $this->cacheAdapterService->getCache(self::CACHE_NUM_PRODUCTS_FROM_ELASTICSEARCH.$langId$result);
  54.     }
  55.     public function getFilterValues(?array $filters): ?array
  56.     {
  57.         $filtered = [];
  58.         if (!empty($filters)) {
  59.             foreach ($filters as $item) {
  60.                 $filtered[] = $item;
  61.             }
  62.         }
  63.         return $filtered;
  64.     }
  65. }