Browse Source

Filtre section & merchant

feature/ticket
Fab 3 years ago
parent
commit
2cd3efe64e
11 changed files with 321 additions and 3 deletions
  1. +67
    -0
      Controller/Admin/AbstractCrudController.php
  2. +1
    -1
      Controller/Common/TaxRateCrudController.php
  3. +1
    -1
      Controller/User/GroupUserCrudController.php
  4. +8
    -0
      Doctrine/Extension/FilterSectionInterface.php
  5. +73
    -0
      EventSubscriber/CreateEntityEventSubscriber.php
  6. +39
    -0
      Model/Section/SectionModel.php
  7. +22
    -1
      Model/Site/PageModel.php
  8. +18
    -0
      Model/User/UserMerchantModel.php
  9. +55
    -0
      Repository/AbstractRepository.php
  10. +19
    -0
      Resolver/MerchantResolver.php
  11. +18
    -0
      Resolver/SectionResolver.php

+ 67
- 0
Controller/Admin/AbstractCrudController.php View File

<?php

namespace Lc\CaracoleBundle\Controller\Admin;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;

use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Controller\Admin\AbstractCrudController as SovAbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

abstract class AbstractCrudController extends SovAbstractCrudController
{
protected $session;
protected $request;
protected $merchantResolver;
protected $sectionResolver;

public function __construct(SessionInterface $session, RequestStack $request, EntityManager $em, SectionResolver $sectionResolver, MerchantResolver $merchantResolver)
{
parent::__construct($session, $request, $em);
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;

}

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


if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$queryBuilder->andWhere('entity.merchant = :merchant');
$queryBuilder->setParameter('merchant', $this->merchantResolver->getCurrent());
}

if ($this->isInstanceOf(FilterSectionInterface::class)) {
$queryBuilder->andWhere('entity.section = :section');
$queryBuilder->setParameter('section', $this->merchantResolver->getCurrent());
}
return $queryBuilder;
}



}


+ 1
- 1
Controller/Common/TaxRateCrudController.php View File

use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\Admin\AbstractCrudController;
use Lc\CaracoleBundle\Controller\Admin\AbstractCrudController;


abstract class TaxRateCrudController extends AbstractCrudController abstract class TaxRateCrudController extends AbstractCrudController
{ {

+ 1
- 1
Controller/User/GroupUserCrudController.php View File

namespace Lc\CaracoleBundle\Controller\User; namespace Lc\CaracoleBundle\Controller\User;


use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField; use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Controller\Admin\AbstractCrudController;


abstract class GroupUserCrudController extends AbstractCrudController abstract class GroupUserCrudController extends AbstractCrudController
{ {

+ 8
- 0
Doctrine/Extension/FilterSectionInterface.php View File

<?php

namespace Lc\CaracoleBundle\Doctrine\Extension ;

interface FilterSectionInterface
{

}

+ 73
- 0
EventSubscriber/CreateEntityEventSubscriber.php View File

<?php

namespace Lc\CaracoleBundle\EventSubscriber;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CreateEntityEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $merchantResolver;
protected $sectionResolver;

public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionResolver $sectionResolver)
{
$this->em = $entityManager;
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;

}

public static function getSubscribedEvents()
{
return [
EntityManagerEvent::CREATE_EVENT => ['createEntity'],
];
}

public function createEntity(EntityManagerEvent $event)
{
$entity = $event->getEntity();
$entityRepository = $this->em->getRepository(get_class($entity));

if ($entity instanceof FilterSectionInterface) {
$this->setSectionProperty($entity, $entityRepository);
}

if ($entity instanceof FilterMerchantInterface) {
$this->setMerchantProperty($entity, $entityRepository);
}

if ($entity instanceof FilterMultipleMerchantsInterface) {
$this->setMultipleMerchantProperty($entity, $entityRepository);
}


}

private function setSectionProperty($entity)
{
$entity->setSection($this->sectionResolver->getCurrent());
}

private function setMerchantProperty($entity)
{
$entity->setMerchant($this->merchantResolver->getCurrent());
}

private function setMultipleMerchantProperty($entity)
{
if ($entity->getMerchants()->isEmpty()) {
$entity->addMerchant($this->merchantResolver->getCurrent());
}
}


}

+ 39
- 0
Model/Section/SectionModel.php View File

use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Site\PageInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;


/** /**
*/ */
protected $merchant; protected $merchant;




/** /**
* @ORM\Column(type="string", length=32) * @ORM\Column(type="string", length=32)
*/ */
*/ */
protected $productCategories; protected $productCategories;


/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Site\PageInterface", mappedBy="section")
*/
protected $pages;

public function __construct() public function __construct()
{ {
$this->productFamilies = new ArrayCollection(); $this->productFamilies = new ArrayCollection();


return $this; return $this;
} }


/**
* @return Collection|PageInterface[]
*/
public function getPages(): Collection
{
return $this->pages;
}

public function addPage(PageInterface $page): self
{
if (!$this->pages->contains($page)) {
$this->pages[] = $page;
$page->setSection($this);
}

return $this;
}

public function removePage(PageInterface $page): self
{
if ($this->pages->removeElement($page)) {
// set the owning side to null (unless already changed)
if ($page->getSection() === $this) {
$page->setSection(null);
}
}

return $this;
}
} }

+ 22
- 1
Model/Site/PageModel.php View File



use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;


/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class PageModel extends AbstractFullEntity implements FilterMerchantInterface
abstract class PageModel extends AbstractFullEntity implements FilterMerchantInterface, FilterSectionInterface
{ {
/** /**
* @ORM\Column(type="text", nullable=true) * @ORM\Column(type="text", nullable=true)
*/ */
protected $merchant; protected $merchant;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="pages")
*/
protected $section;


public function __toString() public function __toString()
{ {
return $this->getTitle(); return $this->getTitle();


return $this; return $this;
} }

public function getSection(): ?SectionInterface
{
return $this->section;
}

public function setSection(?SectionInterface $section): self
{
$this->section = $section;

return $this;
}

} }

+ 18
- 0
Model/User/UserMerchantModel.php View File

use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;


/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
protected $merchant; protected $merchant;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
*/
protected $currentAdminSection;

/** /**
* @ORM\Column(type="float", nullable=true) * @ORM\Column(type="float", nullable=true)
*/ */
return $this; return $this;
} }


public function getCurrentAdminSection(): ?SectionInterface
{
return $this->currentAdminSection;
}

public function setCurrentAdminSection(?SectionInterface $currentAdminSection): self
{
$this->currentAdminSection = $currentAdminSection;

return $this;
}

public function getCredit(): ?float public function getCredit(): ?float
{ {
return $this->credit; return $this->credit;

+ 55
- 0
Repository/AbstractRepository.php View File

<?php

namespace Lc\CaracoleBundle\Repository;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Repository\AbstractRepository as SovAbstractRepository;

abstract class AbstractRepository extends SovAbstractRepository
{
protected $merchantResolver;
protected $sectionResolver;

public function __construct(
EntityManagerInterface $entityManager,
SectionResolver $sectionResolver,
MerchantResolver $merchantResolver
) {
parent::__construct($entityManager);
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
}


protected function setCriteria(array $criteria) :array
{
$criteria = parent::setCriteria($criteria);

$className = $this->getClassMetadata()->getName();
$entity = new $className;

if ($entity instanceof FilterMerchantInterface) {
if (!isset($criteria['merchant'])) {
$criteria['merchant'] = $this->merchantResolver->getCurrent();
}
if ($criteria['merchant'] === false) {
unset($criteria['merchant']);
}
}

if ($entity instanceof FilterSectionInterface) {
if (!isset($criteria['section'])) {
$criteria['section'] = $this->sectionResolver->getCurrent();
}
if ($criteria['section'] === false) {
unset($criteria['section']);
}
}
return $criteria;
}

}

+ 19
- 0
Resolver/MerchantResolver.php View File

<?php
/**
* @author La clic ! <contact@laclic.fr>
*/


namespace Lc\CaracoleBundle\Resolver;


use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;

class MerchantResolver
{
public function getCurrent(): MerchantInterface
{
//return ;
}

}

+ 18
- 0
Resolver/SectionResolver.php View File

<?php
/**
* @author La clic ! <contact@laclic.fr>
*/


namespace Lc\CaracoleBundle\Resolver;

use Lc\CaracoleBundle\Model\Section\SectionInterface;

class SectionResolver
{
public function getCurrent(): SectionInterface
{
//return ;
}

}

Loading…
Cancel
Save