<?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; | |||||
} | |||||
} | |||||
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 | ||||
{ | { |
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 | ||||
{ | { |
<?php | |||||
namespace Lc\CaracoleBundle\Doctrine\Extension ; | |||||
interface FilterSectionInterface | |||||
{ | |||||
} |
<?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()); | |||||
} | |||||
} | |||||
} |
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; | |||||
} | |||||
} | } |
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; | |||||
} | |||||
} | } |
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; |
<?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; | |||||
} | |||||
} |
<?php | |||||
/** | |||||
* @author La clic ! <contact@laclic.fr> | |||||
*/ | |||||
namespace Lc\CaracoleBundle\Resolver; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
class MerchantResolver | |||||
{ | |||||
public function getCurrent(): MerchantInterface | |||||
{ | |||||
//return ; | |||||
} | |||||
} |
<?php | |||||
/** | |||||
* @author La clic ! <contact@laclic.fr> | |||||
*/ | |||||
namespace Lc\CaracoleBundle\Resolver; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
class SectionResolver | |||||
{ | |||||
public function getCurrent(): SectionInterface | |||||
{ | |||||
//return ; | |||||
} | |||||
} |