Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AbstractRepository.php 1.7KB

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