|
|
@@ -36,6 +36,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; |
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; |
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; |
|
|
|
use Lc\CaracoleBundle\Model\Section\SectionInterface; |
|
|
|
use Lc\SovBundle\Component\EntityComponent; |
|
|
|
use Lc\SovBundle\Definition\ActionDefinition; |
|
|
|
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; |
|
|
@@ -82,7 +83,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { |
|
|
|
$responseParameters->set('fields', $this->configureFields('index')); |
|
|
|
|
|
|
|
if(isset($this->filtersForm)) { |
|
|
|
if (isset($this->filtersForm)) { |
|
|
|
$responseParameters->set('filters_form', $this->filtersForm); |
|
|
|
} |
|
|
|
} |
|
|
@@ -138,10 +139,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
if ($action->getName() == ActionDefinition::WRITE_TO_USER) { |
|
|
|
$entity = $context->getEntity()->getInstance(); |
|
|
|
if ($entity !== null) { |
|
|
|
if(method_exists($entity, 'getUser')){ |
|
|
|
$url = $this->generateEaUrl(UserA) ->setController($context->getCrud()->getControllerFqcn()) |
|
|
|
->set('entityId', $entity->getParent()->getId()) |
|
|
|
->generateUrl(); |
|
|
|
if (method_exists($entity, 'getUser')) { |
|
|
|
$url = $this->generateEaUrl(UserA)->setController($context->getCrud()->getControllerFqcn()) |
|
|
|
->set('entityId', $entity->getParent()->getId()) |
|
|
|
->generateUrl(); |
|
|
|
$action->setLinkUrl($url); |
|
|
|
} |
|
|
|
} else { |
|
|
@@ -152,16 +153,17 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected function getRequestCrudAction() :string{ |
|
|
|
protected function getRequestCrudAction(): string |
|
|
|
{ |
|
|
|
return $this->getRequestStack()->getCurrentRequest()->get('crudAction'); |
|
|
|
} |
|
|
|
|
|
|
|
public function configureCrud(Crud $crud): Crud |
|
|
|
{ |
|
|
|
$crud = parent::configureCrud($crud); |
|
|
|
if($this->getRequestCrudAction() === ActionDefinition::SORT) { |
|
|
|
if ($this->getRequestCrudAction() === ActionDefinition::SORT) { |
|
|
|
$crud->setPaginatorPageSize(9999); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
$this->setMaxResults($crud); |
|
|
|
} |
|
|
|
|
|
|
@@ -169,7 +171,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
|
|
|
|
if ($this->isInstanceOf(SortableInterface::class)) { |
|
|
|
$crud->setDefaultSort(['position' => 'ASC']); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
$crud->setDefaultSort(['id' => 'DESC']); |
|
|
|
} |
|
|
|
|
|
|
@@ -321,14 +323,15 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
} |
|
|
|
|
|
|
|
public function duplicate( |
|
|
|
AdminContext $context, |
|
|
|
EntityComponent $entityComponent, |
|
|
|
TranslatorAdmin $translatorAdmin, |
|
|
|
AdminContext $context, |
|
|
|
EntityComponent $entityComponent, |
|
|
|
TranslatorAdmin $translatorAdmin, |
|
|
|
EntityManagerInterface $em |
|
|
|
) { |
|
|
|
) |
|
|
|
{ |
|
|
|
if (!$this->isGranted( |
|
|
|
Permission::EA_EXECUTE_ACTION, |
|
|
|
['action' =>ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()] |
|
|
|
['action' => ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()] |
|
|
|
)) { |
|
|
|
throw new ForbiddenActionException($context); |
|
|
|
} |
|
|
@@ -351,19 +354,22 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
return $this->redirect($url); |
|
|
|
} |
|
|
|
|
|
|
|
public function isRepositoryQueryFiltered():bool{ |
|
|
|
if(($this->filtersForm && $this->filtersForm->isSubmitted()) || $this->isRepositoryQueryFiltered){ |
|
|
|
public function isRepositoryQueryFiltered(): bool |
|
|
|
{ |
|
|
|
if (($this->filtersForm && $this->filtersForm->isSubmitted()) || $this->isRepositoryQueryFiltered) { |
|
|
|
return true; |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function createIndexRepositoryQuery( |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
FilterCollection $filters |
|
|
|
): RepositoryQueryInterface { |
|
|
|
): RepositoryQueryInterface |
|
|
|
{ |
|
|
|
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery( |
|
|
|
$this->getRepositoryQuery(), |
|
|
|
$searchDto, |
|
|
@@ -404,34 +410,38 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
|
|
|
|
|
|
|
|
public function createSortRepositoryQuery( |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
FilterCollection $filters |
|
|
|
): RepositoryQueryInterface { |
|
|
|
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto,$entityDto, $fields, $filters); |
|
|
|
if($this->isInstanceOf(StatusInterface::class)) { |
|
|
|
$repositoryQuery->filterIsOnline(); |
|
|
|
} |
|
|
|
$repositoryQuery->orderBy('position', 'asc'); |
|
|
|
return $repositoryQuery; |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
FilterCollection $filters |
|
|
|
): RepositoryQueryInterface |
|
|
|
{ |
|
|
|
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); |
|
|
|
if ($this->isInstanceOf(StatusInterface::class)) { |
|
|
|
$repositoryQuery->filterIsOnline(); |
|
|
|
} |
|
|
|
$repositoryQuery->orderBy('position', 'asc'); |
|
|
|
return $repositoryQuery; |
|
|
|
} |
|
|
|
|
|
|
|
public function createIndexQueryBuilder( |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
FilterCollection $filters |
|
|
|
): QueryBuilder { |
|
|
|
): QueryBuilder |
|
|
|
{ |
|
|
|
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); |
|
|
|
return $repositoryQuery->getQueryBuilder(); |
|
|
|
} |
|
|
|
|
|
|
|
public function createSortQueryBuilder( |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
SearchDto $searchDto, |
|
|
|
EntityDto $entityDto, |
|
|
|
FieldCollection $fields, |
|
|
|
FilterCollection $filters |
|
|
|
): QueryBuilder { |
|
|
|
): QueryBuilder |
|
|
|
{ |
|
|
|
$repositoryQuery = $this->createSortRepositoryQuery($searchDto, $entityDto, $fields, $filters); |
|
|
|
return $repositoryQuery->getQueryBuilder(); |
|
|
|
} |
|
|
@@ -473,10 +483,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
|
|
|
|
public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void |
|
|
|
{ |
|
|
|
if($this->isInstanceOf(StatusInterface::class)){ |
|
|
|
if ($this->isInstanceOf(StatusInterface::class)) { |
|
|
|
$entityInstance->setStatus(-1); |
|
|
|
$entityManager->update($entityInstance); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
$entityManager->delete($entityInstance); |
|
|
|
} |
|
|
|
$entityManager->flush(); |
|
|
@@ -774,12 +784,18 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
|
|
|
|
public function autocompleteFilter(AdminContext $context): JsonResponse |
|
|
|
{ |
|
|
|
$queryBuilder = $this->createIndexQueryBuilder( |
|
|
|
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery( |
|
|
|
$this->getRepositoryQuery(), |
|
|
|
$context->getSearch(), |
|
|
|
$context->getEntity(), |
|
|
|
FieldCollection::new([]), |
|
|
|
FilterCollection::new() |
|
|
|
); |
|
|
|
|
|
|
|
if ($this->isInstanceOf(StatusInterface::class)) { |
|
|
|
$repositoryQuery->filterIsOnlineAndOffline(); |
|
|
|
} |
|
|
|
|
|
|
|
$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT); |
|
|
|
|
|
|
|
/** @var CrudControllerInterface $controller */ |
|
|
@@ -794,20 +810,16 @@ abstract class AbstractAdminController extends EaAbstractCrudController |
|
|
|
)->getByProperty($autocompleteContext['propertyName']); |
|
|
|
|
|
|
|
$filterManager = $this->get(FilterManager::class); |
|
|
|
|
|
|
|
$filterManager->applyFilter($queryBuilder, $field, $context->getRequest()->query->get('q')); |
|
|
|
if ($filterManager->isRelationField($field->getProperty())) { |
|
|
|
$queryBuilder->select($autocompleteContext['propertyName']); |
|
|
|
} else { |
|
|
|
$queryBuilder->select('entity.' . $autocompleteContext['propertyName']); |
|
|
|
} |
|
|
|
$filteredValue = ['value' => $context->getRequest()->query->get('q')]; |
|
|
|
$filterManager->applyFilter($repositoryQuery, $field, $filteredValue); |
|
|
|
$repositoryQuery->select('.' . $autocompleteContext['propertyName']); |
|
|
|
//dump($repositoryQuery->getQueryBuilder()->getQuery()->getDQL()); |
|
|
|
|
|
|
|
$responses = array(); |
|
|
|
foreach ($queryBuilder->getQuery()->getArrayResult() as $result) { |
|
|
|
foreach ($repositoryQuery->find() as $result) { |
|
|
|
$responses[] = array_values($result)[0]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse::fromJsonString(json_encode($responses)); |
|
|
|
} |
|
|
|
|