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.

52 lines
1.5KB

  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. return $this->query;
  17. }
  18. public function createDefaultQuery(): RepositoryQueryInterface
  19. {
  20. $this->createQuery();
  21. $defaultOptions = $this->getDefaultOptionsSearch();
  22. // with
  23. if (is_array($defaultOptions['with']) && count($defaultOptions['with'])) {
  24. $this->query->with($defaultOptions['with']);
  25. }
  26. // join with
  27. if (is_array($defaultOptions['join_with']) && count($defaultOptions['join_with'])) {
  28. $this->query->joinWith($defaultOptions['join_with']);
  29. }
  30. // id producer contexte
  31. if(isset($defaultOptions['attribute_id_producer']) && $defaultOptions['attribute_id_producer']) {
  32. $this->query->andWhere([$defaultOptions['attribute_id_producer'] => $this->getProducerContextId()]);
  33. }
  34. // order by
  35. if(isset($defaultOptions['orderby']) && $defaultOptions['orderby']) {
  36. $this->query->orderBy($defaultOptions['orderby']);
  37. }
  38. return $this->query;
  39. }
  40. }