Przeglądaj źródła

Duplication sur section et merchant

develop
Fab 3 lat temu
rodzic
commit
e55967919a
13 zmienionych plików z 442 dodań i 282 usunięć
  1. +25
    -26
      Component/EntityComponent.php
  2. +280
    -233
      Controller/AbstractAdminController.php
  3. +21
    -13
      Doctrine/EntityManager.php
  4. +15
    -0
      Doctrine/Extension/ClearIdTrait.php
  5. +1
    -1
      Doctrine/Extension/SluggableTrait.php
  6. +28
    -0
      Event/EntityComponentEvent.php
  7. +52
    -0
      EventSubscriber/SluggablePropertyEventSubscriber.php
  8. +1
    -1
      EventSubscriber/SortablePropertyEventSubscriber.php
  9. +6
    -4
      Repository/AbstractRepository.php
  10. +7
    -1
      Resources/assets/app/adminlte/main/init.js
  11. +1
    -1
      Resources/assets/functions/widgets.js
  12. +3
    -0
      Resources/translations/admin.fr.yaml
  13. +2
    -2
      Translation/TranslatorAdmin.php

+ 25
- 26
Component/EntityComponent.php Wyświetl plik

@@ -3,56 +3,55 @@
namespace Lc\SovBundle\Component;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
use Lc\SovBundle\Event\EntityComponentEvent;
use Lc\SovBundle\Model\File\FileInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class EntityComponent
{
protected EntityManagerInterface $entityManager;
protected ParameterBagInterface $parameterBag;
protected EventDispatcherInterface $eventDispatcher;

public function __construct(
EntityManagerInterface $entityManager,
ParameterBagInterface $parameterBag
ParameterBagInterface $parameterBag,
EventDispatcherInterface $eventDispatcher
) {
$this->entityManager = $entityManager;
$this->parameterBag = $parameterBag;
$this->eventDispatcher = $eventDispatcher;
}

public function duplicateEntity($entity, $flush = true)
public function duplicateEntity($entity)
{
$newEntity = clone $entity;
$classMetadata = $this->entityManager->getClassMetadata(get_class($newEntity));

foreach ($classMetadata->getAssociationMappings() as $associationMapping){
if(in_array(FileInterface::class, class_implements($associationMapping['targetEntity']))){
$methodGet = 'get'.ucfirst($associationMapping['fieldName']);
$methodSet = 'set'.ucfirst($associationMapping['fieldName']);
if(method_exists($newEntity, $methodGet) && method_exists($newEntity, $methodSet)){
if(!is_null($newEntity->$methodGet())){
$newFile = clone $newEntity->$methodGet();
$newEntity->$methodSet($newFile);
}
}
}

if ($newEntity instanceof FileInterface) {
$newEntity = $this->duplicateImage($newEntity);
}

if ($newEntity instanceof ProductFamilyInterface) {
//TODO dispatch event duplicate
/* if ($newEntity instanceof ProductFamilyInterface) {
// @TODO : à adapter
//$newEntity = $this->productFamilyUtils->processBeforePersistProductFamily($newEntity, false, true);
}
*/
$this->entityManager->create($newEntity);

if (method_exists($newEntity, 'getAddress') && is_object($newEntity->getAddress())) {
$address = $newEntity->getAddress();
$newAddress = $this->duplicateEntity($address);
$newEntity->setAddress($newAddress);
$this->entityManager->persist($newAddress);
}

if ($newEntity instanceof SluggableInterface) {
$this->entityManager->persist($newEntity);
if ($flush) {
$this->entityManager->flush();
}
$newEntity->setSlug(null);
}
$this->entityManager->persist($newEntity);
if ($flush) {
$this->entityManager->flush();
}

$this->eventDispatcher->dispatch(new EntityComponentEvent($newEntity), EntityComponentEvent::DUPLICATE_EVENT);

return $newEntity;
}

+ 280
- 233
Controller/AbstractAdminController.php Wyświetl plik

@@ -35,6 +35,8 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
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\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
@@ -63,14 +65,14 @@ abstract class AbstractAdminController extends EaAbstractCrudController
public static function getSubscribedServices()
{
return array_merge(
parent::getSubscribedServices(),
[
'session' => SessionInterface::class,
'request' => RequestStack::class,
'em' => EntityManagerInterface::class,
'translator_admin' => TranslatorAdmin::class,
'filter_manager' => FilterManager::class,
]
parent::getSubscribedServices(),
[
'session' => SessionInterface::class,
'request' => RequestStack::class,
'em' => EntityManagerInterface::class,
'translator_admin' => TranslatorAdmin::class,
'filter_manager' => FilterManager::class,
]
);
}

@@ -113,9 +115,9 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if ($entity !== null) {
if ($entity->getParent() !== null) {
$url = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->set('entityId', $entity->getParent()->getId())
->generateUrl();
->setController($context->getCrud()->getControllerFqcn())
->set('entityId', $entity->getParent()->getId())
->generateUrl();
$action->setLinkUrl($url);
}
} else {
@@ -127,10 +129,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$entityId = $context->getRequest()->get('entityId');
if ($entityId != null) {
$url = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->setAction($action->getName())
->set('entityId', $entityId)
->generateUrl();
->setController($context->getCrud()->getControllerFqcn())
->setAction($action->getName())
->set('entityId', $entityId)
->generateUrl();
$action->setLinkUrl($url);
}
}
@@ -155,14 +157,14 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
$entityClass = $this->getEntityFqcn();
$paramListMaxResults = 'listMaxResults';
$paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
$paramSessionListMaxResults = $entityClass.'-'.$paramListMaxResults;
$requestListMaxResults = $this->get('request')->getCurrentRequest()->get($paramListMaxResults);

if ($requestListMaxResults) {
$this->get('session')->set($paramSessionListMaxResults, $requestListMaxResults);
}
$maxResults = $this->get('session')->get($paramSessionListMaxResults) ? $this->get('session')->get(
$paramSessionListMaxResults
$paramSessionListMaxResults
) : 30;

$crud->setPaginatorPageSize($maxResults);
@@ -172,17 +174,17 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($this->isInstanceOf(SeoInterface::class)) {
return [
FormField::addPanel('seo')->setTemplateName('crud/field/generic'),
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
FormField::addPanel('seo')->setTemplateName('crud/field/generic'),
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
)->hideOnIndex(),
];
} else {
return null;
@@ -193,8 +195,8 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($this->isInstanceOf(DevAliasInterface::class)) {
return [
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
];
} else {
return null;
@@ -216,9 +218,9 @@ abstract class AbstractAdminController extends EaAbstractCrudController

$fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
$filters = $this->get(FilterFactory::class)->create(
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
);
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);
@@ -227,16 +229,16 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->get(EntityFactory::class)->processFieldsForAll($entities, $fields);

$sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults()))
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
)
)
)
->getForm();
->getForm();

$entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn());
$repository = $entityManager->getRepository($this->getEntityFqcn());
@@ -263,26 +265,26 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::INDEX)
->generateUrl();
->setAction(Action::INDEX)
->generateUrl();
$this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array());

return $this->redirect($url);
}

$responseParameters = $this->configureResponseParameters(
KeyValueStore::new(
[
'pageName' => Crud::PAGE_INDEX,
'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
'entities' => $entities,
'paginator' => $paginator,
'global_actions' => array(),
'batch_actions' => array(),
'filters' => $filters,
'sortable_form' => $sortableForm,
]
)
KeyValueStore::new(
[
'pageName' => Crud::PAGE_INDEX,
'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
'entities' => $entities,
'paginator' => $paginator,
'global_actions' => array(),
'batch_actions' => array(),
'filters' => $filters,
'sortable_form' => $sortableForm,
]
)
);
$responseParameters->set('fields', $this->configureFields('index'));
$event = new AfterCrudActionEvent($context, $responseParameters);
@@ -294,17 +296,46 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $responseParameters;
}

public function duplicate(AdminContext $context, EntityComponent $entityComponent, TranslatorAdmin $translatorAdmin, EntityManagerInterface $em)
{

if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => "duplicate", 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}

if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context);
}

$newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance());
$em->create($newEntity);
$em->flush();

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();

$this->addFlash('success', $translatorAdmin->transFlashMessage('duplicate'), array());

return $this->redirect($url);
}


public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {
$queryBuilder = parent::createIndexQueryBuilder(
$searchDto,
$entityDto,
$fields,
$filters
$searchDto,
$entityDto,
$fields,
$filters
);

//TOdo utiliser les repositoryQuery ?
@@ -318,14 +349,14 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

$this->filtersForm = $this->createForm(
FiltersFormType::class,
null,
array(
'fields' => $fields,
'entity_dto' => $entityDto,
'entity_class' => $this->getEntityFqcn(),
'entity_name' => $entityDto->getName(),
)
FiltersFormType::class,
null,
array(
'fields' => $fields,
'entity_dto' => $entityDto,
'entity_class' => $this->getEntityFqcn(),
'entity_name' => $entityDto->getName(),
)
);

$filterManager = $this->get('filter_manager');
@@ -341,10 +372,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

public function createSortQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {
$queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);

@@ -373,7 +404,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$context = $this->get(AdminContextProvider::class)->getContext();

return $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
$this->get('em')->getEntityName($interface)
$this->get('em')->getEntityName($interface)
);
}

@@ -406,69 +437,85 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $actions;
}

public function getDuplicateAction(): Action
{
$duplicateAction = Action::new(
'duplicate',
$this->get('translator_admin')->transAction('duplicate'),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicate')
->setLabel($this->get('translator_admin')->transAction('duplicate'))
->setCssClass('in-dropdown text-info action-confirm');

return $duplicateAction;
}

public function buildIndexActions(Actions $actions): void
{
$actions->add(Crud::PAGE_INDEX, $this->getDuplicateAction());

$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::NEW,
[
'icon' => 'plus',
'label' => $this->get('translator_admin')->transAction('create'),
'add_class' => 'btn-sm',
]
$actions,
Crud::PAGE_INDEX,
Action::NEW,
[
'icon' => 'plus',
'label' => $this->get('translator_admin')->transAction('create'),
'add_class' => 'btn-sm',
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('edit'),
),
]
$actions,
Crud::PAGE_INDEX,
Action::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('edit'),
),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('detail'),
),
]
$actions,
Crud::PAGE_INDEX,
Action::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('detail'),
),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
'label' => $this->get('translator_admin')->transAction('delete'),
]
$actions,
Crud::PAGE_INDEX,
Action::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
'label' => $this->get('translator_admin')->transAction('delete'),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->get('translator_admin')->transAction('delete'),
]
$actions,
Crud::PAGE_INDEX,
Action::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->get('translator_admin')->transAction('delete'),
]
);
}

@@ -480,47 +527,47 @@ abstract class AbstractAdminController extends EaAbstractCrudController


$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
);


$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_continue'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_continue'),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->get('translator_admin')->transAction('delete'),
]
$actions,
Crud::PAGE_EDIT,
Action::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->get('translator_admin')->transAction('delete'),
]
);
}

@@ -533,35 +580,35 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$actions->add(Crud::PAGE_NEW, Action::INDEX);

$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
);

$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_add_another'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_add_another'),
]
);
}

@@ -569,13 +616,13 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($this->isInstanceOf(TranslatableInterface::class)) {
$actions->update(
Crud::PAGE_INDEX,
Action::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
Crud::PAGE_INDEX,
Action::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');

return $action;
}
return $action;
}
);
}
}
@@ -584,9 +631,9 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($this->isInstanceOf(SortableInterface::class)) {
$sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort')
->linkToCrudAction('sort')
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();
->linkToCrudAction('sort')
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();

$actions->add(Crud::PAGE_INDEX, $sortAction);
}
@@ -597,24 +644,24 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($this->isInstanceOf(TreeInterface::class)) {
$indexChildAction = Action::new(
'index_children',
$this->get('translator_admin')->transAction('index_children'),
'fa fa-list'
'index_children',
$this->get('translator_admin')->transAction('index_children'),
'fa fa-list'
)
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');

$backParentAction = Action::new(
'index_parent',
$this->get('translator_admin')->transAction('index_parent'),
'fa fa-chevron-left'
'index_parent',
$this->get('translator_admin')->transAction('index_parent'),
'fa fa-chevron-left'
)
->linkToCrudAction(Action::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();
->linkToCrudAction(Action::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();

$actions->add(Crud::PAGE_INDEX, $backParentAction);
$actions->add(Crud::PAGE_INDEX, $indexChildAction);
@@ -625,35 +672,35 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) {
$actions->update(
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}

if (isset($button['class'])) {
$action->setCssClass($button['class']);
}
if (isset($button['class'])) {
$action->setCssClass($button['class']);
}

if (isset($button['icon'])) {
$action->setIcon('fa fa-' . $button['icon']);
}
if (isset($button['icon'])) {
$action->setIcon('fa fa-'.$button['icon']);
}

if (isset($button['label'])) {
$action->setLabel($button['label']);
}
if (isset($button['label'])) {
$action->setLabel($button['label']);
}

if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}
if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}

if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
}
if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
}

return $action;
}
return $action;
}
);
}
}
@@ -661,22 +708,22 @@ abstract class AbstractAdminController extends EaAbstractCrudController
public function autocompleteFilter(AdminContext $context): JsonResponse
{
$queryBuilder = $this->createIndexQueryBuilder(
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
);
$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);

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

$filterManager = $this->get('filter_manager');
@@ -685,7 +732,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if ($filterManager->isRelationField($field->getProperty())) {
$queryBuilder->select($autocompleteContext['propertyName']);
} else {
$queryBuilder->select('entity.' . $autocompleteContext['propertyName']);
$queryBuilder->select('entity.'.$autocompleteContext['propertyName']);
}

$responses = array();

+ 21
- 13
Doctrine/EntityManager.php Wyświetl plik

@@ -43,31 +43,39 @@ class EntityManager extends EntityManagerDecorator
return new $entityName;
}

public function create(EntityInterface $entity): self
public function create(EntityInterface $entity, bool $dispatchEvent = true): self
{
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_CREATE_EVENT);
if($dispatchEvent) {
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_CREATE_EVENT);
}
$this->persist($entity);
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::POST_CREATE_EVENT);

if($dispatchEvent) {
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::POST_CREATE_EVENT);
}
return $this;
}

public function update(EntityInterface $entity): self
public function update(EntityInterface $entity, bool $dispatchEvent = true): self
{
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_UPDATE_EVENT);
if($dispatchEvent){
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_UPDATE_EVENT);
}
$this->persist($entity);
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::POST_UPDATE_EVENT);

if($dispatchEvent) {
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::POST_UPDATE_EVENT);
}
return $this;
}

public function delete(EntityInterface $entity): self
public function delete(EntityInterface $entity, bool $dispatchEvent = true): self
{
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_DELETE_EVENT);

if($dispatchEvent) {
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_DELETE_EVENT);
}
$this->remove($entity);
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::POST_DELETE_EVENT);

if($dispatchEvent) {
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::POST_DELETE_EVENT);
}
return $this;
}


+ 15
- 0
Doctrine/Extension/ClearIdTrait.php Wyświetl plik

@@ -0,0 +1,15 @@
<?php

namespace Lc\SovBundle\Doctrine\Extension;

trait ClearIdTrait
{

public function clearId($id): self
{
$this->id = $id;

return $this;
}

}

+ 1
- 1
Doctrine/Extension/SluggableTrait.php Wyświetl plik

@@ -9,7 +9,7 @@ trait SluggableTrait
{
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Slug(fields={"title"})
* @Gedmo\Slug(fields={"title"}, unique=true)
*/
protected $slug;


+ 28
- 0
Event/EntityComponentEvent.php Wyświetl plik

@@ -0,0 +1,28 @@
<?php

namespace Lc\SovBundle\Event;

use Lc\SovBundle\Doctrine\EntityInterface;
use Symfony\Contracts\EventDispatcher\Event;

/**
* class EntityEvent.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class EntityComponentEvent extends Event
{
const DUPLICATE_EVENT = 'entity_component_event.duplicate';

protected EntityInterface $entity;

public function __construct(EntityInterface $entity)
{
$this->entity = $entity;
}

public function getEntity(): EntityInterface
{
return $this->entity;
}
}

+ 52
- 0
EventSubscriber/SluggablePropertyEventSubscriber.php Wyświetl plik

@@ -0,0 +1,52 @@
<?php

namespace Lc\SovBundle\EventSubscriber;

use Doctrine\ORM\EntityManagerInterface;

use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Event\EntityComponentEvent;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class SluggablePropertyEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $adminUrlGenerator;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}

public static function getSubscribedEvents()
{
return [
EntityComponentEvent::DUPLICATE_EVENT => ['setSluggablePropertyDuplicateEvent'],
EntityManagerEvent::POST_UPDATE_EVENT => ['setSluggablePropertyUpdateEvent'],
];
}

public function setSluggablePropertyDuplicateEvent(EntityComponentEvent $event)
{
$entity = $event->getEntity();
if ($entity instanceof SluggableInterface) {
$entity->clearId(null);
$entity->setSlug(null);
}
}

public function setSluggablePropertyUpdateEvent(EntityManagerEvent $event)
{
$entity = $event->getEntity();
if ($entity instanceof SluggableInterface) {
$entity->setSlug(null);
}
}

}

EventSubscriber/CommonPropertyEventSubscriber.php → EventSubscriber/SortablePropertyEventSubscriber.php Wyświetl plik

@@ -12,7 +12,7 @@ use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CommonPropertyEventSubscriber implements EventSubscriberInterface
class SortablePropertyEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $adminUrlGenerator;

+ 6
- 4
Repository/AbstractRepository.php Wyświetl plik

@@ -75,15 +75,17 @@ abstract class AbstractRepository extends ServiceEntityRepository implements Ser
return $query;
}

public function findSimilarSlug($merchant)
public function findBySimilarSlug($slug)
{
$qb = $this->createQueryBuilder('entity')
->select('entity.id, COUNT(entity.slug) as niche')
->select('COUNT(entity.slug) as totalSimilar')
->andWhere('entity.status>=0')
->andWhere('entity.slug LIKE :slug')
->setParameter('slug', $slug)
->groupBy('entity.slug')
->having('COUNT(entity.slug) >1');
->having('COUNT(entity.slug) >=1');

return $qb->getQuery()->getResult();
return $qb->getQuery()->getOneOrNullResult();
}

public function findAll()

+ 7
- 1
Resources/assets/app/adminlte/main/init.js Wyświetl plik

@@ -4,7 +4,11 @@ window.addEventListener('load', (event) => {
SovNotification.init();

SovWidgets.setDateRange();
SovWidgets.setAutoCompleteField();

SovTools.log('ncihe');
$('.btn-confirm-js, .action-confirm').click(function () {
return confirm('Êtes-vous sûr de vouloir réaliser cette action ?');
});

/* Tooltip */
$('[data-toggle="tooltip"]').tooltip();
@@ -77,5 +81,7 @@ window.addEventListener('load', (event) => {
}
}

SovWidgets.setAutoCompleteField();


});

+ 1
- 1
Resources/assets/functions/widgets.js Wyświetl plik

@@ -97,7 +97,7 @@ export class SovWidgets {
autocompleteFields.each(function () {
var $this = $(this),
url = $this.data('lc-autocomplete-url');
SovTools.log($this);
$this.autoComplete({
noResultsText: 'Aucun résultat n\'a été trouvé.',
resolverSettings: {

+ 3
- 0
Resources/translations/admin.fr.yaml Wyświetl plik

@@ -32,6 +32,8 @@ action:
change: Changer
detail: Voir
send: Envoyer
duplicate: Dupliquer
cancel: Annuler
index_children: Afficher les enfants
index_parent: Retour au parent
back_index: Retour à la liste
@@ -44,6 +46,7 @@ flash_message:
update: Le contenu "%name%" a été mis à jour avec succès.
delete: Le contenu "%name%" a été supprimé avec succès.
sort: Position modifiée
duplicate: Le document a bien été dupliqué

entity:
User:

+ 2
- 2
Translation/TranslatorAdmin.php Wyświetl plik

@@ -26,9 +26,9 @@ class TranslatorAdmin
return $this->trans('menu.' . $menu);
}

public function transFlashMessage($name)
public function transFlashMessage($name, $params = [])
{
return $this->trans('flash_message.' . $name);
return $this->trans('flash_message.' . $name, $params);
}

public function transField($fieldName, $entityClass): string

Ładowanie…
Anuluj
Zapisz