Selaa lähdekoodia

Filtre section & merchant

feature/ticket
Fab 3 vuotta sitten
vanhempi
commit
2cd3efe64e
11 muutettua tiedostoa jossa 321 lisäystä ja 3 poistoa
  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 Näytä tiedosto

@@ -0,0 +1,67 @@
<?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 Näytä tiedosto

@@ -6,7 +6,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\Admin\AbstractCrudController;
use Lc\CaracoleBundle\Controller\Admin\AbstractCrudController;

abstract class TaxRateCrudController extends AbstractCrudController
{

+ 1
- 1
Controller/User/GroupUserCrudController.php Näytä tiedosto

@@ -3,7 +3,6 @@
namespace Lc\CaracoleBundle\Controller\User;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
@@ -12,6 +11,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Controller\Admin\AbstractCrudController;

abstract class GroupUserCrudController extends AbstractCrudController
{

+ 8
- 0
Doctrine/Extension/FilterSectionInterface.php Näytä tiedosto

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

namespace Lc\CaracoleBundle\Doctrine\Extension ;

interface FilterSectionInterface
{

}

+ 73
- 0
EventSubscriber/CreateEntityEventSubscriber.php Näytä tiedosto

@@ -0,0 +1,73 @@
<?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 Näytä tiedosto

@@ -10,6 +10,7 @@ use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Site\PageInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;

/**
@@ -23,6 +24,8 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
*/
protected $merchant;



/**
* @ORM\Column(type="string", length=32)
*/
@@ -49,6 +52,11 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
*/
protected $productCategories;

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

public function __construct()
{
$this->productFamilies = new ArrayCollection();
@@ -173,4 +181,35 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant

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 Näytä tiedosto

@@ -4,13 +4,15 @@ namespace Lc\CaracoleBundle\Model\Site;

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

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

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


public function __toString()
{
return $this->getTitle();
@@ -51,4 +59,17 @@ abstract class PageModel extends AbstractFullEntity implements FilterMerchantInt

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 Näytä tiedosto

@@ -8,6 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;

/**
* @ORM\MappedSuperclass()
@@ -27,6 +28,11 @@ abstract class UserMerchantModel implements FilterMerchantInterface
*/
protected $merchant;

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

/**
* @ORM\Column(type="float", nullable=true)
*/
@@ -76,6 +82,18 @@ abstract class UserMerchantModel implements FilterMerchantInterface
return $this;
}

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

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

return $this;
}

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

+ 55
- 0
Repository/AbstractRepository.php Näytä tiedosto

@@ -0,0 +1,55 @@
<?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 Näytä tiedosto

@@ -0,0 +1,19 @@
<?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 Näytä tiedosto

@@ -0,0 +1,18 @@
<?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…
Peruuta
Tallenna