Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/SovBundle into develop

develop
Guillaume 3 years ago
parent
commit
d2fa872d3a
26 changed files with 798 additions and 408 deletions
  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. +20
    -10
      Repository/AbstractRepositoryQuery.php
  11. +62
    -32
      Repository/Reminder/ReminderRepositoryQuery.php
  12. +104
    -70
      Repository/Reminder/ReminderStore.php
  13. +3
    -0
      Repository/Site/NewsRepositoryQuery.php
  14. +32
    -0
      Repository/Site/NewsStore.php
  15. +7
    -0
      Repository/Site/PageRepositoryQuery.php
  16. +12
    -0
      Repository/Site/PageStore.php
  17. +16
    -3
      Repository/Ticket/TicketRepositoryQuery.php
  18. +34
    -2
      Repository/Ticket/TicketStore.php
  19. +6
    -5
      Repository/User/UserRepository.php
  20. +23
    -0
      Repository/User/UserRepositoryQuery.php
  21. +34
    -1
      Repository/User/UserStore.php
  22. +9
    -3
      Resources/assets/app/adminlte/main/init.js
  23. +1
    -1
      Resources/assets/functions/prices.js
  24. +1
    -1
      Resources/assets/functions/widgets.js
  25. +3
    -0
      Resources/translations/admin.fr.yaml
  26. +2
    -2
      Translation/TranslatorAdmin.php

+ 25
- 26
Component/EntityComponent.php View File

namespace Lc\SovBundle\Component; namespace Lc\SovBundle\Component;


use Doctrine\ORM\EntityManagerInterface; 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 Lc\SovBundle\Model\File\FileInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;


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


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


public function duplicateEntity($entity, $flush = true)
public function duplicateEntity($entity)
{ {
$newEntity = clone $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 // @TODO : à adapter
//$newEntity = $this->productFamilyUtils->processBeforePersistProductFamily($newEntity, false, true); //$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; return $newEntity;
} }

+ 280
- 233
Controller/AbstractAdminController.php View File

use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; 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\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface; use Lc\SovBundle\Doctrine\Extension\SeoInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface; use Lc\SovBundle\Doctrine\Extension\SortableInterface;
public static function getSubscribedServices() public static function getSubscribedServices()
{ {
return array_merge( 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,
]
); );
} }


if ($entity !== null) { if ($entity !== null) {
if ($entity->getParent() !== null) { if ($entity->getParent() !== null) {
$url = $adminUrlGenerator $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); $action->setLinkUrl($url);
} }
} else { } else {
$entityId = $context->getRequest()->get('entityId'); $entityId = $context->getRequest()->get('entityId');
if ($entityId != null) { if ($entityId != null) {
$url = $adminUrlGenerator $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); $action->setLinkUrl($url);
} }
} }
{ {
$entityClass = $this->getEntityFqcn(); $entityClass = $this->getEntityFqcn();
$paramListMaxResults = 'listMaxResults'; $paramListMaxResults = 'listMaxResults';
$paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
$paramSessionListMaxResults = $entityClass.'-'.$paramListMaxResults;
$requestListMaxResults = $this->get('request')->getCurrentRequest()->get($paramListMaxResults); $requestListMaxResults = $this->get('request')->getCurrentRequest()->get($paramListMaxResults);


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


$crud->setPaginatorPageSize($maxResults); $crud->setPaginatorPageSize($maxResults);
{ {
if ($this->isInstanceOf(SeoInterface::class)) { if ($this->isInstanceOf(SeoInterface::class)) {
return [ 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(), )->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 { } else {
return null; return null;
{ {
if ($this->isInstanceOf(DevAliasInterface::class)) { if ($this->isInstanceOf(DevAliasInterface::class)) {
return [ return [
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
]; ];
} else { } else {
return null; return null;


$fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX)); $fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
$filters = $this->get(FilterFactory::class)->create( $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); $queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->get(PaginatorFactory::class)->create($queryBuilder); $paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);
$this->get(EntityFactory::class)->processFieldsForAll($entities, $fields); $this->get(EntityFactory::class)->processFieldsForAll($entities, $fields);


$sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults())) $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()); $entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn());
$repository = $entityManager->getRepository($this->getEntityFqcn()); $repository = $entityManager->getRepository($this->getEntityFqcn());
} }


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


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


$responseParameters = $this->configureResponseParameters( $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')); $responseParameters->set('fields', $this->configureFields('index'));
$event = new AfterCrudActionEvent($context, $responseParameters); $event = new AfterCrudActionEvent($context, $responseParameters);
return $responseParameters; 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( public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder { ): QueryBuilder {
$queryBuilder = parent::createIndexQueryBuilder( $queryBuilder = parent::createIndexQueryBuilder(
$searchDto,
$entityDto,
$fields,
$filters
$searchDto,
$entityDto,
$fields,
$filters
); );


//TOdo utiliser les repositoryQuery ? //TOdo utiliser les repositoryQuery ?
} }


$this->filtersForm = $this->createForm( $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'); $filterManager = $this->get('filter_manager');
} }


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


$context = $this->get(AdminContextProvider::class)->getContext(); $context = $this->get(AdminContextProvider::class)->getContext();


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


return $actions; 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 public function buildIndexActions(Actions $actions): void
{ {
$actions->add(Crud::PAGE_INDEX, $this->getDuplicateAction());

$this->actionUpdate( $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( $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( $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( $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( $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'),
]
); );
} }






$this->actionUpdate( $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( $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( $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( $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'),
]
); );
} }


$actions->add(Crud::PAGE_NEW, Action::INDEX); $actions->add(Crud::PAGE_NEW, Action::INDEX);


$this->actionUpdate( $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( $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( $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'),
]
); );
} }


{ {
if ($this->isInstanceOf(TranslatableInterface::class)) { if ($this->isInstanceOf(TranslatableInterface::class)) {
$actions->update( $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;
}
); );
} }
} }
{ {
if ($this->isInstanceOf(SortableInterface::class)) { if ($this->isInstanceOf(SortableInterface::class)) {
$sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort') $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); $actions->add(Crud::PAGE_INDEX, $sortAction);
} }
{ {
if ($this->isInstanceOf(TreeInterface::class)) { if ($this->isInstanceOf(TreeInterface::class)) {
$indexChildAction = Action::new( $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( $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, $backParentAction);
$actions->add(Crud::PAGE_INDEX, $indexChildAction); $actions->add(Crud::PAGE_INDEX, $indexChildAction);
{ {
if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) { if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) {
$actions->update( $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;
}
); );
} }
} }
public function autocompleteFilter(AdminContext $context): JsonResponse public function autocompleteFilter(AdminContext $context): JsonResponse
{ {
$queryBuilder = $this->createIndexQueryBuilder( $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); $autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);


/** @var CrudControllerInterface $controller */ /** @var CrudControllerInterface $controller */
$controller = $this->get(ControllerFactory::class)->getCrudControllerInstance( $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 */ /** @var FieldDto $field */
$field = FieldCollection::new( $field = FieldCollection::new(
$controller->configureFields($autocompleteContext['originatingPage'])
$controller->configureFields($autocompleteContext['originatingPage'])
)->getByProperty($autocompleteContext['propertyName']); )->getByProperty($autocompleteContext['propertyName']);


$filterManager = $this->get('filter_manager'); $filterManager = $this->get('filter_manager');
if ($filterManager->isRelationField($field->getProperty())) { if ($filterManager->isRelationField($field->getProperty())) {
$queryBuilder->select($autocompleteContext['propertyName']); $queryBuilder->select($autocompleteContext['propertyName']);
} else { } else {
$queryBuilder->select('entity.' . $autocompleteContext['propertyName']);
$queryBuilder->select('entity.'.$autocompleteContext['propertyName']);
} }


$responses = array(); $responses = array();

+ 21
- 13
Doctrine/EntityManager.php View File

return new $entityName; 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->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; 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->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; 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->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; return $this;
} }



+ 15
- 0
Doctrine/Extension/ClearIdTrait.php View File

<?php

namespace Lc\SovBundle\Doctrine\Extension;

trait ClearIdTrait
{

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

return $this;
}

}

+ 1
- 1
Doctrine/Extension/SluggableTrait.php View File

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



+ 28
- 0
Event/EntityComponentEvent.php View File

<?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 View File

<?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 View File

use Lc\SovBundle\Repository\AbstractRepositoryInterface; use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;


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

+ 6
- 4
Repository/AbstractRepository.php View File

return $query; return $query;
} }


public function findSimilarSlug($merchant)
public function findBySimilarSlug($slug)
{ {
$qb = $this->createQueryBuilder('entity') $qb = $this->createQueryBuilder('entity')
->select('entity.id, COUNT(entity.slug) as niche')
->select('COUNT(entity.slug) as totalSimilar')
->andWhere('entity.status>=0') ->andWhere('entity.status>=0')
->andWhere('entity.slug LIKE :slug')
->setParameter('slug', $slug)
->groupBy('entity.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() public function findAll()

+ 20
- 10
Repository/AbstractRepositoryQuery.php View File

return $this; return $this;
} }


public function count(): string
{
return $this->query->getQuery()
->getSingleScalarResult();
}

public function findOne() public function findOne()
{ {
return $this->query->getQuery() return $this->query->getQuery()
->setMaxResults(1) ->setMaxResults(1)
->getOneOrNullResult()
;
->getOneOrNullResult();
} }


public function find() :array
public function find(): array
{ {
return $this->query->getQuery()->getResult(); return $this->query->getQuery()->getResult();
} }


public function limit(int $maxResults)
{
return $this->query->setMaxResults($maxResults);
}

public function paginate(int $page = 1, int $limit = 20) public function paginate(int $page = 1, int $limit = 20)
{ {
return $this->paginator->paginate($this->query->getQuery(), $page, $limit); return $this->paginator->paginate($this->query->getQuery(), $page, $limit);


foreach ($words as $k => $v) { foreach ($words as $k => $v) {
if (isset($v[0]) && '.' === $v[0]) { if (isset($v[0]) && '.' === $v[0]) {
$words[$k] = $this->id.$v;
$words[$k] = $this->id . $v;
} }
} }


return $data; return $data;
} }


public function orderBy($field, $sort){
if(substr($field,0,1)=== '.'){
return $this->addOrderBy($field, $sort) ;
}else{
return $this->addOrderBy('.'.$field, $sort) ;
public function orderBy(string $field, string $sort = 'ASC'): self
{
if (substr($field, 0, 1) === '.') {
return $this->addOrderBy($field, $sort);
} else {
return $this->addOrderBy('.' . $field, $sort);
} }
} }

} }



+ 62
- 32
Repository/Reminder/ReminderRepositoryQuery.php View File

namespace Lc\SovBundle\Repository\Reminder; namespace Lc\SovBundle\Repository\Reminder;


use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery; use Lc\SovBundle\Repository\AbstractRepositoryQuery;


class ReminderRepositoryQuery extends AbstractRepositoryQuery implements ReminderRepositoryQueryInterface class ReminderRepositoryQuery extends AbstractRepositoryQuery implements ReminderRepositoryQueryInterface
{ {
protected $isJoinUser = false;

public function __construct(ReminderRepository $repository, PaginatorInterface $paginator) public function __construct(ReminderRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


public function filterDone($done = false)
public function filterByDone($done = false): self
{ {
return $this return $this
->andWhere('.done = :done')
->setParameter(':done', $done);
->andWhere('.done = :done')
->setParameter(':done', $done);
} }


public function filterUser($user)
public function joinUser(): self
{ {
if (!$this->isJoinUser) {
$this->isJoinUser = true;

return $this
->leftJoin('.users', 'u');
}
return $this;
}

public function filterByUser(UserInterface $user): self
{
$this->joinUser();
return $this return $this
->leftJoin('.users', 'u')
->having('COUNT(u.id) = 0')
->orHaving(':user MEMBER OF .users')
->setParameter(':user', $user)
->groupBy('.id');
->having('COUNT(u.id) = 0')
->orHaving(':user MEMBER OF .users')
->setParameter(':user', $user);
} }


public function filterCrudAction($crudAction)
public function filterByCrudAction(?string $crudAction= null): self
{ {
if(is_null($crudAction)) {
if (is_null($crudAction)) {
return $this return $this
->andWhere('.crudControllerFqcn IS NULL');
}
else {
->andWhere('.crudControllerFqcn IS NULL');
} else {
return $this return $this
->andWhere('.crudAction = :crudAction')
->setParameter(':crudAction', $crudAction);
->andWhere('.crudAction = :crudAction')
->setParameter(':crudAction', $crudAction);
} }
} }


public function filterCrudControllerFqcn($crudControllerFqcn)
public function filterByCrudControllerFqcn(?string $crudControllerFqcn= null): self
{ {
if(is_null($crudControllerFqcn)) {
if (is_null($crudControllerFqcn)) {
return $this return $this
->andWhere('.crudControllerFqcn IS NULL');
}
else {
->andWhere('.crudControllerFqcn IS NULL');
} else {
return $this return $this
->andWhere('.crudControllerFqcn = :crudControllerFqcn')
->setParameter(':crudControllerFqcn', $crudControllerFqcn);
->andWhere('.crudControllerFqcn = :crudControllerFqcn')
->setParameter(':crudControllerFqcn', $crudControllerFqcn);
} }
} }


public function filterEntityId($entityId)
public function filterByEntityId(?int $entityId=null): self
{ {
if(is_null($entityId)) {
if (is_null($entityId)) {
return $this return $this
->andWhere('.entityId IS NULL');
}
else {
->andWhere('.entityId IS NULL');
} else {
return $this return $this
->andWhere('.entityId = :entityId')
->setParameter(':entityId', $entityId);
->andWhere('.entityId = :entityId')
->setParameter(':entityId', $entityId);
} }
} }


public function orderDefault()
public function filterIsNotDone(): self
{ {
return $this return $this
->orderBy('.dateReminder', 'ASC');
->andWhere('.done = 0');
} }


public function filterLikeCrudAction(string $crudAction): self
{
return $this
->andWhere('.crudAction LIKE :crudAction')
->setParameter('crudAction', $crudAction);
}

public function filterLikeCrudControllerFqcn(string $crudControllerFqcn): self
{
return $this
->andWhere('.crudControllerFqcn LIKE :crudControllerFqcn')
->setParameter('crudControllerFqcn', $crudControllerFqcn);
}

public function filterLikeEntityId(int $entityId): self
{
return $this
->andWhere('.entityId LIKE :id')
->setParameter('entityId', $entityId);
}
} }

+ 104
- 70
Repository/Reminder/ReminderStore.php View File



namespace Lc\SovBundle\Repository\Reminder; namespace Lc\SovBundle\Repository\Reminder;


use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;


class ReminderStore extends AbstractStore implements ReminderStoreInterface class ReminderStore extends AbstractStore implements ReminderStoreInterface
$query = $this->query->create(); $query = $this->query->create();
} }


$query->filterDone();
$query->filterByDone();


if (array_key_exists('user', $params)) { if (array_key_exists('user', $params)) {
$query->filterUser($params['user']);
$query
->filterByUser($params['user'])
->groupBy('.id');
} }


if (array_key_exists('crudAction', $params)) { if (array_key_exists('crudAction', $params)) {
$query->filterCrudAction($params['crudAction']);
$query->filterByCrudAction($params['crudAction']);
} }


if (array_key_exists('crudControllerFqcn', $params)) { if (array_key_exists('crudControllerFqcn', $params)) {
$query->filterCrudControllerFqcn($params['crudControllerFqcn']);
$query->filterByCrudControllerFqcn($params['crudControllerFqcn']);
} }


if (array_key_exists('entityId', $params)) { if (array_key_exists('entityId', $params)) {
$query->filterEntityId($params['entityId']);
$query->filterByEntityId($params['entityId']);
} }


$query->orderDefault();
$query->orderBy('.dateReminder');


return $query->find(); return $query->find();
} }


/*

public function getRemindersByUser($user)
{
$reminderRepo = $this->em->getRepository(ReminderInterface::class);


$reminders = $reminderRepo->findByUser($user);

$entitiesRepo = array();
$entitiesConfig = array();
if (count($reminders) > 0) {
foreach ($reminders as $reminder) {
if ($reminder->getEntityName()) {
if (!isset($entitiesConfig[$reminder->getEntityName()])) {
$entitiesConfig[$reminder->getEntityName()] = $this->configManager->getEntityConfig($reminder->getEntityName());
}
if ($reminder->getEntityAction() == 'edit' || $reminder->getEntityAction() == 'show') {
if (!isset($entitiesRepo[$reminder->getEntityName()])) {
$entitiesRepo[$reminder->getEntityName()] = $this->em->getRepository($entitiesConfig[$reminder->getEntityName()]['class']);
}

if ($reminder->getEntityId()) {
$reminder->relatedPage = $entitiesRepo[$reminder->getEntityName()]->find($reminder->getEntityId())->__toString();
}
} else {
$reminder->relatedPage = 'Liste de ' . $entitiesConfig[$reminder->getEntityName()]['label'];
}
}
}
}
return $reminders;
// findByUser
public function getByUser(UserInterface $user, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
} }


*/
$query = $this->query->create();


/*
public function findByUser($user)
{
$qb = $this->createQueryBuilder('e')
->leftJoin('e.users', 'u')
->having('COUNT(u.id) = 0')
->orHaving(':user MEMBER OF e.users')
->andWhere('e.done = 0')
->setParameter('user', $user)
->orderBy('e.dateReminder', 'ASC')
->groupBy('e.id');

return $qb->getQuery()->getResult();
$query
->filterByUser($user)
->filterIsNotDone()
->orderBy('.dateReminder')
->groupBy('.id');

return $query->find();
} }


public function findByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId = null)
{
$qb = $this->createQueryBuilder('e');
$qb->leftJoin('e.users', 'u');
$qb->having('COUNT(u.id) = 0');
$qb->orHaving(':user MEMBER OF e.users');
$qb->andWhere('e.done = 0');
$qb->andWhere('e.crudAction LIKE :crudAction');
$qb->andWhere('e.crudControllerFqcn LIKE :entity');
$qb->setParameter('crudAction', $crudAction);
$qb->setParameter('crudControllerFqcn', $crudControllerFqcn);
$qb->setParameter('user', $user);
// findByEasyAdminConfigAndUser
public function getByEasyAdminConfigAndUser(
string $crudAction,
string $crudControllerFqcn,
UserInterface $user,
int $entityId = null,
$query = null
): array {
if (is_null($query)) {
$query = $this->query->create();
}

$query
->filterByUser($user)
->filterLikeCrudAction($crudAction)
->filterLikeCrudControllerFqcn($crudControllerFqcn)
->filterIsNotDone();

if ($entityId) { if ($entityId) {
$qb->andWhere('e.entityId LIKE :id');
$qb->setParameter('entityId', $entityId);
$query
->filterLikeEntityId($entityId);
} }
$qb->orderBy('e.dateReminder', 'ASC');
$qb->groupBy('e.id');
$query
->orderBy('.dateReminder')
->groupBy('.id');

return $query->find();
}


return $qb->getQuery()->getResult();
}*/
// public function findByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId = null)
// {
// $qb = $this->createQueryBuilder('e');
// $qb->leftJoin('e.users', 'u');
// $qb->having('COUNT(u.id) = 0');
// $qb->orHaving(':user MEMBER OF e.users');
// $qb->andWhere('e.done = 0');
// $qb->andWhere('e.crudAction LIKE :crudAction');
// $qb->andWhere('e.crudControllerFqcn LIKE :entity');
// $qb->setParameter('crudAction', $crudAction);
// $qb->setParameter('crudControllerFqcn', $crudControllerFqcn);
// $qb->setParameter('user', $user);
// if ($entityId) {
// $qb->andWhere('e.entityId LIKE :id');
// $qb->setParameter('entityId', $entityId);
// }
// $qb->orderBy('e.dateReminder', 'ASC');
// $qb->groupBy('e.id');
//
// return $qb->getQuery()->getResult();
// }
} }
/*

public function getRemindersByUser($user)
{
$reminderRepo = $this->em->getRepository(ReminderInterface::class);


$reminders = $reminderRepo->findByUser($user);

$entitiesRepo = array();
$entitiesConfig = array();
if (count($reminders) > 0) {
foreach ($reminders as $reminder) {
if ($reminder->getEntityName()) {
if (!isset($entitiesConfig[$reminder->getEntityName()])) {
$entitiesConfig[$reminder->getEntityName()] = $this->configManager->getEntityConfig($reminder->getEntityName());
}
if ($reminder->getEntityAction() == 'edit' || $reminder->getEntityAction() == 'show') {
if (!isset($entitiesRepo[$reminder->getEntityName()])) {
$entitiesRepo[$reminder->getEntityName()] = $this->em->getRepository($entitiesConfig[$reminder->getEntityName()]['class']);
}

if ($reminder->getEntityId()) {
$reminder->relatedPage = $entitiesRepo[$reminder->getEntityName()]->find($reminder->getEntityId())->__toString();
}
} else {
$reminder->relatedPage = 'Liste de ' . $entitiesConfig[$reminder->getEntityName()]['label'];
}
}
}
}
return $reminders;
}

*/

+ 3
- 0
Repository/Site/NewsRepositoryQuery.php View File

namespace Lc\SovBundle\Repository\Site; namespace Lc\SovBundle\Repository\Site;


use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery; use Lc\SovBundle\Repository\AbstractRepositoryQuery;


class NewsRepositoryQuery extends AbstractRepositoryQuery implements NewsRepositoryQueryInterface class NewsRepositoryQuery extends AbstractRepositoryQuery implements NewsRepositoryQueryInterface
{ {
use StatusRepositoryQueryTrait;

public function __construct(NewsRepository $repository, PaginatorInterface $paginator) public function __construct(NewsRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);

+ 32
- 0
Repository/Site/NewsStore.php View File

{ {
$this->query = $query; $this->query = $query;
} }

//findLatests
public function getLatests(int $maxResults = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}
$query
->filterIsOnline()
->orderBy('.date', 'DESC');

if ($maxResults) {
$query
->limit($maxResults);
}

return $query->find();
}

public function findLatests($maxResults = 0)
{
$result = $this->findByMerchantQuery()
->orderBy('e.date', 'DESC');

$result->andWhere('e.status = 1');

if ($maxResults) {
$result->setMaxResults($maxResults);
}

return $result->getQuery()->getResult();
}
} }

+ 7
- 0
Repository/Site/PageRepositoryQuery.php View File

{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

public function filterBySlug(string $slug)
{
return $this
->andWhere('.slug = :slug')
->setParameter('slug', $slug);
}
} }

+ 12
- 0
Repository/Site/PageStore.php View File



namespace Lc\SovBundle\Repository\Site; namespace Lc\SovBundle\Repository\Site;


use Lc\SovBundle\Model\Site\PageInterface;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;


class PageStore extends AbstractStore implements PageStoreInterface class PageStore extends AbstractStore implements PageStoreInterface
{ {
$this->query = $query; $this->query = $query;
} }

//findPageBySlug
public function getBySlug(string $slug): ?PageInterface
{
$query = $this->query->create();

$query
->filterBySlug($slug);

return $query->findOne();
}
} }

+ 16
- 3
Repository/Ticket/TicketRepositoryQuery.php View File

parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


public function filterByUser(UserInterface $user)
public function filterByUser(UserInterface $user): self
{ {
return $this return $this
->andWhere('.user = :user')
->setParameter('user', $user);
->andWhere('.user = :user')
->setParameter('user', $user);
}

public function filterByStatus($statusArray): self
{
return $this
->andWhere('.status IN (:status)')
->setParameter('status', $statusArray);
}

public function selectCount(): self
{
return $this
->select('count(r.id) as count');
} }
} }

+ 34
- 2
Repository/Ticket/TicketStore.php View File



namespace Lc\SovBundle\Repository\Ticket; namespace Lc\SovBundle\Repository\Ticket;


use App\Entity\Ticket\Ticket;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;


class TicketStore extends AbstractStore implements TicketStoreInterface class TicketStore extends AbstractStore implements TicketStoreInterface
} }


// getTicketsByUser // getTicketsByUser
public function getByUser($user)
public function getByUser($user, $query = null): array
{ {
$query = $this->query->create();
if (is_null($query)) {
$query = $this->query->create();
}


$query->filterByUser($user); $query->filterByUser($user);


return $query->find(); return $query->find();
} }

// findAllOpen
public function getAllOpen(int $limit = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

$query
->filterByStatus(Ticket::TICKET_STATUS_OPEN)
->limit($limit)
->orderBy('r.id', 'DESC');

return $query->find();
}

//countAllOpen
public function countAllOpen($query = null): string
{
if (is_null($query)) {
$query = $this->query->create();
}
$query
->selectCount()
->filterByStatus(Ticket::TICKET_STATUS_OPEN);

return $query->count();
}
} }

+ 6
- 5
Repository/User/UserRepository.php View File

$this->_em->flush(); $this->_em->flush();
} }


public function findByRole($role) {
public function findByRole($role)
{
return $this->createQueryBuilder('u') return $this->createQueryBuilder('u')
->andWhere('u.roles LIKE :role')
->setParameter('role', '%'.$role.'%')
->getQuery()
->getResult();
->andWhere('u.roles LIKE :role')
->setParameter('role', '%' . $role . '%')
->getQuery()
->getResult();
} }
} }

+ 23
- 0
Repository/User/UserRepositoryQuery.php View File



namespace Lc\SovBundle\Repository\User; namespace Lc\SovBundle\Repository\User;


use App\Entity\Merchant\Merchant;
use App\Entity\Newsletter\Newsletter;
use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery; use Lc\SovBundle\Repository\AbstractRepositoryQuery;


{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

public function filterByNewsletter(Newsletter $newsletter): self
{
return $this
->andWhere(':newsletter MEMBER OF .newsletters')
->setParameter('newsletter', $newsletter->getId());
}

public function filterLikeRole(string $role): self
{
return $this
->andWhere('.roles LIKE :roles')
->setParameter('roles', '%"' . $role . '"%');
}

public function filterLikeTicketTypeNotification(string $ticketType): self
{
return $this
->andWhere('.ticketTypesNotification LIKE :ticketType')
->setParameter('ticketType', '%"' . $ticketType . '"%');
}
} }

+ 34
- 1
Repository/User/UserStore.php View File



namespace Lc\SovBundle\Repository\User; namespace Lc\SovBundle\Repository\User;


use Lc\SovBundle\Model\User\UserInterface;
use App\Entity\Newsletter\Newsletter;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;


class UserStore extends AbstractStore implements UserStoreInterface class UserStore extends AbstractStore implements UserStoreInterface
{ {
$this->query = $query; $this->query = $query;
} }

//findAllByNewsletter
public function getByNewsletter(Newsletter $newsletter, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

$query
->filterByNewsletter($newsletter);

return $query->find();
}

//findByRole
public function getByRole(string $role): array
{
$query = $this->query->create();
$query
->filterLikeRole($role);

return $query->find();
}

//findByTicketTypesNotification
public function getByTicketTypesNotification(string $ticketType): array
{
$query = $this->query->create();
$query
->filterLikeTicketTypeNotification($ticketType);

return $query->find();
}
} }

+ 9
- 3
Resources/assets/app/adminlte/main/init.js View File

SovNotification.init(); SovNotification.init();


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

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


/* Tooltip */ /* Tooltip */
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();


/* Select2 */ /* Select2 */
if ($('.select2, select.form-control').length) {
if ($('.form-select, .select2, select.form-control').length) {


$('form .form-widget>select.form-control, .select2').each(function (i, elm) {

$('form .form-widget>select.form-control, .select2, .form-select').each(function (i, elm) {
if (!$(this).hasClass('disable-select2')) { if (!$(this).hasClass('disable-select2')) {
SovWidgets.setSelect2($(elm)); SovWidgets.setSelect2($(elm));
} }
} }
} }


SovWidgets.setAutoCompleteField();



}); });

+ 1
- 1
Resources/assets/functions/prices.js View File



static applyReductionPercent(price, percentage) static applyReductionPercent(price, percentage)
{ {
return applyPercent(price, -percentage);
return this.applyPercent(price, -percentage);
} }


static applyReductionAmount(price, amount) static applyReductionAmount(price, amount)

+ 1
- 1
Resources/assets/functions/widgets.js View File

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

+ 3
- 0
Resources/translations/admin.fr.yaml View File

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


entity: entity:
User: User:

+ 2
- 2
Translation/TranslatorAdmin.php View File

return $this->trans('menu.' . $menu); 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 public function transField($fieldName, $entityClass): string

Loading…
Cancel
Save