‪TYPO3CMS  11.5
PostRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 
32 {
34 
42  {
43  $query = $this->‪createQuery();
44  return $query
45  ->matching(
46  $query->equals('blog', $blog)
47  )
48  ->execute();
49  }
50 
58  public function ‪findByTagAndBlog($tag, ‪Blog $blog): ‪QueryResultInterface
59  {
60  $query = $this->‪createQuery();
61  return $query
62  ->matching(
63  $query->logicalAnd(
64  $query->equals('blog', $blog),
65  $query->equals('tags.name', $tag)
66  )
67  )
68  ->execute();
69  }
70 
78  {
79  $blog = $post->‪getBlog();
80  $query = $this->‪createQuery();
81  return $query
82  ->matching(
83  $query->logicalAnd(
84  $query->equals('blog', $blog),
85  $query->logicalNot(
86  $query->equals('uid', $post->‪getUid())
87  )
88  )
89  )
90  ->execute();
91  }
92 
99  public function ‪findPrevious(‪Post $post): ‪Post
100  {
101  $query = $this->‪createQuery();
102  return $query
103  ->matching(
104  $query->lessThan('date', $post->‪getDate())
105  )
106  ->execute()
107  ->getFirst();
108  }
109 
116  public function ‪findNext(‪Post $post): ‪Post
117  {
118  $query = $this->‪createQuery();
119  return $query
120  ->matching(
121  $query->greaterThan('date', $post->‪getDate())
122  )
123  ->execute()
124  ->getFirst();
125  }
126 
134  public function ‪findRecentByBlog(‪Blog $blog, $limit = 5): ‪QueryResultInterface
135  {
136  $query = $this->‪createQuery();
137  return $query
138  ->matching(
139  $query->equals('blog', $blog)
140  )
141  ->setLimit((int)$limit)
142  ->execute();
143  }
144 
151  public function ‪findByCategory($categoryUid): ‪QueryResultInterface
152  {
153  $query = $this->‪createQuery();
154  return $query
155  ->matching(
156  $query->contains('categories', $categoryUid)
157  )
158  ->execute();
159  }
160 
161  public function ‪findAllSortedByCategory(array $uids)
162  {
163  $q = $this->‪createQuery();
164  $q->matching($q->in('uid', $uids));
165  $q->setOrderings([
166  'categories.title' => ‪QueryInterface::ORDER_ASCENDING,
168  ]);
169  return $q->execute();
170  }
171 }
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findRecentByBlog
‪QueryResultInterface findRecentByBlog(Blog $blog, $limit=5)
Definition: PostRepository.php:134
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int null getUid()
Definition: AbstractDomainObject.php:67
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findRemaining
‪QueryResultInterface findRemaining(Post $post)
Definition: PostRepository.php:77
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:29
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_DESCENDING
‪const ORDER_DESCENDING
Definition: QueryInterface.php:99
‪ExtbaseTeam\BlogExample\Domain\Repository
Definition: AdministratorRepository.php:18
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\$defaultOrderings
‪$defaultOrderings
Definition: PostRepository.php:33
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findNext
‪Post findNext(Post $post)
Definition: PostRepository.php:116
‪ExtbaseTeam\BlogExample\Domain\Model\Post\getBlog
‪ExtbaseTeam BlogExample Domain Model Blog null getBlog()
Definition: Post.php:122
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findAllSortedByCategory
‪findAllSortedByCategory(array $uids)
Definition: PostRepository.php:161
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:98
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findByCategory
‪QueryResultInterface findByCategory($categoryUid)
Definition: PostRepository.php:151
‪TYPO3\CMS\Extbase\Persistence\Repository\createQuery
‪TYPO3 CMS Extbase Persistence QueryInterface createQuery()
Definition: Repository.php:206
‪TYPO3\CMS\Extbase\Persistence\Repository
Definition: Repository.php:29
‪ExtbaseTeam\BlogExample\Domain\Model\Blog
Definition: Blog.php:29
‪ExtbaseTeam\BlogExample\Domain\Model\Post
Definition: Post.php:28
‪TYPO3\CMS\Extbase\Persistence\QueryResultInterface
Definition: QueryResultInterface.php:22
‪ExtbaseTeam\BlogExample\Domain\Model\Post\getDate
‪DateTime getDate()
Definition: Post.php:163
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findPrevious
‪Post findPrevious(Post $post)
Definition: PostRepository.php:99
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository
Definition: PostRepository.php:32
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findAllByBlog
‪QueryResultInterface findAllByBlog(Blog $blog)
Definition: PostRepository.php:41
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository\findByTagAndBlog
‪QueryResultInterface findByTagAndBlog($tag, Blog $blog)
Definition: PostRepository.php:58