Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
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.

83 lines
2.0 KiB

3 years ago
  1. <?php
  2. namespace App\Repositories;
  3. use App\Repositories\RepositoryAbstract;
  4. /**
  5. * request pages items from directus
  6. *
  7. * @author Björn Hase, Tentakelfabrik
  8. * @license http://opensource.org/licenses/MIT The MIT License
  9. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
  10. *
  11. */
  12. class PostRepository extends RepositoryAbstract
  13. {
  14. /** endpoint */
  15. protected $endpoint = 'posts';
  16. /**
  17. *
  18. */
  19. public function find($limit = 20)
  20. {
  21. return $this->queryBuilder
  22. ->fields([
  23. 'title',
  24. 'slug',
  25. 'lead',
  26. 'content',
  27. 'view',
  28. 'date_created',
  29. 'published_at',
  30. 'media_teaser.id',
  31. 'media_teaser.description'
  32. ])
  33. ->aliases('template', 'view')
  34. ->filter([
  35. 'status' => 'published',
  36. 'published_at' => [
  37. '_nnull' => 'true'
  38. ]
  39. ])
  40. ->sort(['published_at'])
  41. ->find();
  42. }
  43. /**
  44. * find single page with a slug,
  45. * page must be published
  46. *
  47. * @param string $slug
  48. * @return array
  49. */
  50. public function findOneBySlug($slug)
  51. {
  52. return $this->queryBuilder
  53. ->fields([
  54. 'title',
  55. 'slug',
  56. 'lead',
  57. 'content',
  58. 'view',
  59. 'meta',
  60. 'date_created',
  61. 'published_at',
  62. 'media_teaser.id',
  63. 'media_teaser.description',
  64. 'media_hero.id',
  65. 'media_hero.description',
  66. ])
  67. ->aliases('template', 'view')
  68. ->filter([
  69. 'status' => 'published',
  70. 'published_at' => [
  71. '_nnull' => 'true'
  72. ],
  73. 'slug' => $slug
  74. ])
  75. ->findOne();
  76. }
  77. }