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.

72 rindas
3.3KB

  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  5. use Symfony\Component\Validator\Constraints\DateTime;
  6. /**
  7. * @method ReductionCatalogInterface|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method ReductionCatalogInterface|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method ReductionCatalogInterface[] findAll()
  10. * @method ReductionCatalogInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class ReductionCatalogRepository extends BaseRepository implements DefaultRepositoryInterface
  13. {
  14. public function getInterfaceClass()
  15. {
  16. return ReductionCatalogInterface::class;
  17. }
  18. public function getReductionCatalogByProductFamily($productFamily, $user)
  19. {
  20. $query = $this->findByMerchantQuery();
  21. $query->andWhere('e.status = 1');
  22. $query->andWhere(':user MEMBER OF e.users OR e.users is empty');
  23. $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty');
  24. $query->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty');
  25. $query->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty');
  26. $query->andWhere(':supplier MEMBER OF e.suppliers OR e.suppliers is empty');
  27. $query->setParameter('user', $user);
  28. $query->setParameter('groupUser', $user->getGroupUsers());
  29. $query->setParameter('productFamily', $productFamily);
  30. $query->setParameter('productCategory', $productFamily->getProductCategories());
  31. $query->setParameter('supplier', $productFamily->getSupplier());
  32. return $query->getQuery()->getResult();
  33. }
  34. public function getReductionCatalogByProductFamilyConditions($productFamilyIds, $user)
  35. {
  36. $query = $this->findByMerchantQuery();
  37. $query->andWhere('e.status = 1');
  38. $query->andWhere('e.permanent = 1 OR (e.dateStart <= :now AND e.dateEnd >= :now)');
  39. if($user){
  40. $query->andWhere(':user MEMBER OF e.users OR e.users is empty');
  41. $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty');
  42. $query->setParameter('user', $user);
  43. $query->setParameter('groupUser', $user->getGroupUsers());
  44. }
  45. $query->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty');
  46. $query->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty');
  47. $query->andWhere(':supplier MEMBER OF e.suppliers OR e.suppliers is empty');
  48. $query->setParameter('productFamily', $productFamilyIds['ids']);
  49. $query->setParameter('productCategory', $productFamilyIds['categories']);
  50. $query->setParameter('supplier', $productFamilyIds['suppliers']);
  51. $query->setParameter(':now', new \DateTime());
  52. return $query->getQuery()->getResult();
  53. }
  54. }