選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

57 行
1.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  7. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  8. use Lc\CaracoleBundle\Resolver\SectionResolver;
  9. use Lc\SovBundle\Repository\AbstractRepository as SovAbstractRepository;
  10. trait RepositoryTrait
  11. {
  12. protected $merchantResolver;
  13. protected $sectionResolver;
  14. public function __construct(
  15. ManagerRegistry $managerRegistry,
  16. SectionResolver $sectionResolver,
  17. MerchantResolver $merchantResolver
  18. ) {
  19. parent::__construct($managerRegistry);
  20. $this->merchantResolver = $merchantResolver;
  21. $this->sectionResolver = $sectionResolver;
  22. }
  23. protected function setCriteria(array $criteria) :array
  24. {
  25. $criteria = parent::setCriteria($criteria);
  26. $className = $this->getClassMetadata()->getName();
  27. $entity = new $className;
  28. if ($entity instanceof FilterMerchantInterface) {
  29. if (!isset($criteria['merchant'])) {
  30. $criteria['merchant'] = $this->merchantResolver->getCurrent();
  31. }
  32. if ($criteria['merchant'] === false) {
  33. unset($criteria['merchant']);
  34. }
  35. }
  36. if ($entity instanceof FilterSectionInterface) {
  37. if (!isset($criteria['section'])) {
  38. $criteria['section'] = $this->sectionResolver->getCurrent();
  39. }
  40. if ($criteria['section'] === false) {
  41. unset($criteria['section']);
  42. }
  43. }
  44. return $criteria;
  45. }
  46. }