TYPO3 CMS  TYPO3_8-7
PostRepository.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
27 {
29 
36  public function findAllByBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog)
37  {
38  $query = $this->createQuery();
39  return $query
40  ->matching(
41  $query->equals('blog', $blog)
42  )
43  ->execute();
44  }
45 
53  public function findByTagAndBlog($tag, \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog)
54  {
55  $query = $this->createQuery();
56  return $query
57  ->matching(
58  $query->logicalAnd(
59  $query->equals('blog', $blog),
60  $query->equals('tags.name', $tag)
61  )
62  )
63  ->execute();
64  }
65 
72  public function findRemaining(Post $post)
73  {
74  $blog = $post->getBlog();
75  $query = $this->createQuery();
76  return $query
77  ->matching(
78  $query->logicalAnd(
79  $query->equals('blog', $blog),
80  $query->logicalNot(
81  $query->equals('uid', $post->getUid())
82  )
83  )
84  )
85  ->execute();
86  }
87 
94  public function findPrevious(Post $post)
95  {
96  $query = $this->createQuery();
97  return $query
98  ->matching(
99  $query->lessThan('date', $post->getDate())
100  )
101  ->execute()
102  ->getFirst();
103  }
104 
111  public function findNext(Post $post)
112  {
113  $query = $this->createQuery();
114  return $query
115  ->matching(
116  $query->greaterThan('date', $post->getDate())
117  )
118  ->execute()
119  ->getFirst();
120  }
121 
129  public function findRecentByBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog, $limit = 5)
130  {
131  $query = $this->createQuery();
132  return $query
133  ->matching(
134  $query->equals('blog', $blog)
135  )
136  ->setLimit((int)$limit)
137  ->execute();
138  }
139 
146  public function findByCategory($categoryUid)
147  {
148  $query = $this->createQuery();
149  return $query
150  ->matching(
151  $query->contains('categories', $categoryUid)
152  )
153  ->execute();
154  }
155 
156  public function findAllSortedByCategory(array $uids)
157  {
158  $q = $this->createQuery();
159  $q->matching($q->in('uid', $uids));
160  $q->setOrderings([
161  'categories.title' => QueryInterface::ORDER_ASCENDING,
163  ]);
164  return $q->execute();
165  }
166 }
getBlog()
Definition: Post.php:129
findRemaining(Post $post)
$defaultOrderings
getDate()
Definition: Post.php:170
findNext(Post $post)
Definition: Post.php:20
findByCategory($categoryUid)
findAllByBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog)
findPrevious(Post $post)
findByTagAndBlog($tag, \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog)
findAllSortedByCategory(array $uids)
findRecentByBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog, $limit=5)