No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

138 líneas
3.3KB

  1. <?php
  2. namespace Lc\SovBundle\Repository;
  3. use Lc\SovBundle\Doctrine\EntityInterface;
  4. use Lc\SovBundle\Model\Site\PageInterface;
  5. abstract class AbstractStore implements StoreInterface
  6. {
  7. public function createDefaultQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface
  8. {
  9. $query = $this->createQuery($query);
  10. $query->resetRelationsJoin();
  11. $this->filtersDefault($query);
  12. $this->relationsDefault($query);
  13. $this->orderByDefault($query);
  14. return $query;
  15. }
  16. public function createQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface
  17. {
  18. if (is_null($query)) {
  19. $query = $this->query->create();
  20. }
  21. return $query;
  22. }
  23. /*
  24. public function orderByDefault(RepositoryQueryInterface $query)
  25. {
  26. return $query;
  27. }
  28. public function filtersDefault(RepositoryQueryInterface $query)
  29. {
  30. $query->filterIsOnlineAndOffline();
  31. return $query;
  32. }
  33. public function relationsDefault($query)
  34. {
  35. return $query;
  36. }
  37. */
  38. public function getRepositoryQuery()
  39. {
  40. return $this->query;
  41. }
  42. public function getOneById(int $id)
  43. {
  44. $query = $this->query->create();
  45. $query->filterById($id);
  46. return $query->findOne();
  47. }
  48. public function getOneBySlug(string $slug, bool $isOnline = true, $query = null)
  49. {
  50. $query = $this->createDefaultQuery($query);
  51. $query->filterBySlug($slug);
  52. if ($isOnline) {
  53. $query->filterIsOnline();
  54. }
  55. return $query->findOne();
  56. }
  57. public function getOneByDevAlias(string $devAlias, $query = null)
  58. {
  59. $query = $this->createDefaultQuery($query);
  60. $query->filterByDevAlias($devAlias);
  61. return $query->findOne();
  62. }
  63. public function getOneOnlineByDevAlias(string $devAlias, $query = null)
  64. {
  65. $query = $this->createDefaultQuery($query);
  66. $query
  67. ->filterByDevAlias($devAlias)
  68. ->filterIsOnline();
  69. return $query->findOne();
  70. }
  71. public function getOneByOldUrl(string $oldUrl, $query = null)
  72. {
  73. $query = $this->createDefaultQuery($query);
  74. $query
  75. ->filterByOldUrl($oldUrl)
  76. ->filterIsOnline();
  77. return $query->findOne();
  78. }
  79. public function get($query = null)
  80. {
  81. $query = $this->createDefaultQuery($query);
  82. return $query->find();
  83. }
  84. public function getAll($query = null)
  85. {
  86. $query = $this->createQuery($query);
  87. $query->filterIsOnlineAndOffline();
  88. return $query->find();
  89. }
  90. public function getOnline($query = null)
  91. {
  92. $query = $this->createDefaultQuery($query);
  93. $query->filterIsOnline();
  94. return $query->find();
  95. }
  96. public function getOnlineAndOffline($query = null)
  97. {
  98. $query = $this->createDefaultQuery($query);
  99. $query->filterIsOnlineAndOffline();
  100. return $query->find();
  101. }
  102. public function getParent(bool $isOnline = true, $query = null)
  103. {
  104. $query = $this->createDefaultQuery($query);
  105. if ($isOnline) {
  106. $query->filterIsOnline();
  107. }
  108. $query->filterIsParent();
  109. return $query->find();
  110. }
  111. }