Просмотр исходного кода

Optmisiation chargement page

packProduct
Fabien Normand 2 лет назад
Родитель
Сommit
537041fde1
2 измененных файлов: 65 добавлений и 1 удалений
  1. +64
    -0
      Controller/AbstractAdminController.php
  2. +1
    -1
      Resolver/OpeningResolver.php

+ 64
- 0
Controller/AbstractAdminController.php Просмотреть файл

@@ -2,9 +2,73 @@

namespace Lc\CaracoleBundle\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Factory\ControllerFactory;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Controller\AbstractAdminController as SovAbstractAdminController;
use Lc\SovBundle\Definition\ActionDefinition;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Repository\EntityRepository;
use Symfony\Component\HttpFoundation\JsonResponse;

abstract class AbstractAdminController extends SovAbstractAdminController
{
use AdminControllerTrait;

public function autocompleteFilter(AdminContext $context): JsonResponse
{
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery(
$this->getRepositoryQuery(),
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
);

if ($this->isInstanceOf(StatusInterface::class)) {
$repositoryQuery->filterIsOnlineAndOffline();
}
if ($this->isInstanceOf(FilterSectionInterface::class)) {
$repositoryQuery->filterBySection($this->getSectionCurrent());
}

if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$repositoryQuery->filterByMerchant($this->getMerchantCurrent());
}

$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);

/** @var CrudControllerInterface $controller */
$controller = $this->get(ControllerFactory::class)->getCrudControllerInstance(
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
ActionDefinition::INDEX,
$context->getRequest()
);
/** @var FieldDto $field */
$field = FieldCollection::new(
$controller->configureFields($autocompleteContext['originatingPage'])
)->getByProperty($autocompleteContext['propertyName']);

$filterManager = $this->get(FilterManager::class);
$filteredValue = ['value' => $context->getRequest()->query->get('q')];
$filterManager->applyFilter($repositoryQuery, $field, $filteredValue);
$repositoryQuery->select('.' . $autocompleteContext['propertyName']);
//dump($repositoryQuery->getQueryBuilder()->getQuery()->getDQL());

$responses = array();
foreach ($repositoryQuery->find() as $result) {
$responses[] = array_values($result)[0];
}

return JsonResponse::fromJsonString(json_encode($responses));
}
}

+ 1
- 1
Resolver/OpeningResolver.php Просмотреть файл

@@ -306,7 +306,7 @@ class OpeningResolver

$dateOpeningNextSale = $this->getFormatedDateOpeningNextSale($section);
if ($dateOpeningNextSale && strlen($dateOpeningNextSale) > 0) {
return 'Réouverture aux commandes le <u>'.$dateOpeningNextSale.'</u>' ;
return 'Réouverture aux commandes le <span class="underline">'.$dateOpeningNextSale.'</span>' ;
}

return null;

Загрузка…
Отмена
Сохранить