You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserPointSaleRepository.php 1.6KB

1 vuosi sitten
1 vuosi sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace domain\PointSale\UserPointSale;
  3. use domain\Distribution\Distribution\Distribution;
  4. use domain\PointSale\PointSale\PointSale;
  5. use domain\PointSale\PointSale\PointSaleSolver;
  6. use domain\User\User\User;
  7. use domain\_\AbstractRepository;
  8. class UserPointSaleRepository extends AbstractRepository
  9. {
  10. protected UserPointSaleRepositoryQuery $query;
  11. protected PointSaleSolver $pointSaleSolver;
  12. public function loadDependencies(): void
  13. {
  14. $this->loadQuery(UserPointSaleRepositoryQuery::class);
  15. $this->pointSaleSolver = $this->loadService(PointSaleSolver::class);
  16. }
  17. public function getDefaultOptionsSearch(): array
  18. {
  19. return [
  20. self::WITH => [],
  21. self::JOIN_WITH => [],
  22. self::ORDER_BY => '',
  23. self::ATTRIBUTE_ID_PRODUCER => 'point_sale.id_producer'
  24. ] ;
  25. }
  26. public function findUserPointSalesByUser(User $user, Distribution $distribution = null): array
  27. {
  28. $userPointSalesArray = $this->createDefaultQuery()
  29. ->joinPointSale()
  30. ->filterByUser($user)
  31. ->find();
  32. if($distribution) {
  33. $userPointSalesArray = $this->pointSaleSolver->filterUserPointSalesByDistribution($userPointSalesArray, $distribution);
  34. }
  35. return $userPointSalesArray;
  36. }
  37. public function findOneUserPointSale(User $user = null, PointSale $pointSale = null)
  38. {
  39. if(!$user || !$pointSale) {
  40. return null;
  41. }
  42. return $this->createDefaultQuery()
  43. ->joinPointSale()
  44. ->filterByUser($user)
  45. ->filterByPointSale($pointSale)
  46. ->findOne();
  47. }
  48. }