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.

AbstractRepository.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace common\logic;
  3. abstract class AbstractRepository extends AbstractService implements RepositoryInterface
  4. {
  5. const WITH = 'with';
  6. const JOIN_WITH = 'join_with';
  7. const ORDER_BY = 'orderby';
  8. const ATTRIBUTE_ID_PRODUCER = 'attribute_id_producer';
  9. public function loadQuery(string $serviceClass)
  10. {
  11. $this->query = $this->loadService($serviceClass);
  12. }
  13. public function createQuery()
  14. {
  15. $this->query->createQuery();
  16. $this->defaultWith();
  17. $this->defaultJoinWith();
  18. return $this->query;
  19. }
  20. public function createDefaultQuery(): RepositoryQueryInterface
  21. {
  22. $this->createQuery();
  23. $this->defaultWith();
  24. $this->defaultJoinWith();
  25. $this->defaultFilterProducerContext();
  26. $this->defaultOrderBy();
  27. return $this->query;
  28. }
  29. public function defaultWith(): void
  30. {
  31. $defaultOptions = $this->getDefaultOptionsSearch();
  32. if (is_array($defaultOptions['with']) && count($defaultOptions['with'])) {
  33. $this->query->with($defaultOptions['with']);
  34. }
  35. }
  36. public function defaultJoinWith(): void
  37. {
  38. $defaultOptions = $this->getDefaultOptionsSearch();
  39. if (is_array($defaultOptions['join_with']) && count($defaultOptions['join_with'])) {
  40. $this->query->joinWith($defaultOptions['join_with']);
  41. }
  42. }
  43. public function defaultFilterProducerContext(): void
  44. {
  45. $defaultOptions = $this->getDefaultOptionsSearch();
  46. if(isset($defaultOptions['attribute_id_producer']) && $defaultOptions['attribute_id_producer']) {
  47. $this->query->andWhere([$defaultOptions['attribute_id_producer'] => $this->getProducerContextId()]);
  48. }
  49. }
  50. public function defaultOrderBy(): void
  51. {
  52. $defaultOptions = $this->getDefaultOptionsSearch();
  53. if(isset($defaultOptions['orderby']) && $defaultOptions['orderby']) {
  54. $this->query->orderBy($defaultOptions['orderby']);
  55. }
  56. }
  57. }