‪TYPO3CMS  ‪main
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 
41  {
42  $query = $this->‪createQuery();
43  return $query
44  ->matching(
45  $query->equals('blog', $blog)
46  )
47  ->execute();
48  }
49 
55  public function ‪findByTagAndBlog(string $tag, ‪Blog $blog): ‪QueryResultInterface
56  {
57  $query = $this->‪createQuery();
58  return $query
59  ->matching(
60  $query->logicalAnd(
61  $query->equals('blog', $blog),
62  $query->equals('tags.name', $tag)
63  )
64  )
65  ->execute();
66  }
67 
72  {
73  $blog = $post->‪getBlog();
74  $query = $this->‪createQuery();
75  return $query
76  ->matching(
77  $query->logicalAnd(
78  $query->equals('blog', $blog),
79  $query->logicalNot(
80  $query->equals('uid', $post->‪getUid())
81  )
82  )
83  )
84  ->execute();
85  }
86 
92  public function ‪findPrevious(‪Post $post): ‪Post
93  {
94  $query = $this->‪createQuery();
95  return $query
96  ->matching(
97  $query->lessThan('date', $post->‪getDate())
98  )
99  ->execute()
100  ->getFirst();
101  }
102 
108  public function ‪findNext(‪Post $post): ‪Post
109  {
110  $query = $this->‪createQuery();
111  return $query
112  ->matching(
113  $query->greaterThan('date', $post->‪getDate())
114  )
115  ->execute()
116  ->getFirst();
117  }
118 
126  public function ‪findRecentByBlog(‪Blog $blog, int $limit = 5): ‪QueryResultInterface
127  {
128  $query = $this->‪createQuery();
129  return $query
130  ->matching(
131  $query->equals('blog', $blog)
132  )
133  ->setLimit((int)$limit)
134  ->execute();
135  }
136 
140  public function ‪findByCategory(int $categoryUid): ‪QueryResultInterface
141  {
142  $query = $this->‪createQuery();
143  return $query
144  ->matching(
145  $query->contains('categories', $categoryUid)
146  )
147  ->execute();
148  }
149 
151  {
152  $q = $this->‪createQuery();
153  $q->matching($q->in('uid', $uids));
154  $q->setOrderings([
155  'categories.title' => ‪QueryInterface::ORDER_ASCENDING,
157  ]);
158  return $q->execute();
159  }
160 }
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findAllByBlog
‪findAllByBlog(Blog $blog)
Definition: PostRepository.php:40
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findByCategory
‪findByCategory(int $categoryUid)
Definition: PostRepository.php:140
‪TYPO3Tests\BlogExample\Domain\Repository
Definition: AdministratorRepository.php:18
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:30
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findPrevious
‪findPrevious(Post $post)
Definition: PostRepository.php:92
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_DESCENDING
‪const ORDER_DESCENDING
Definition: QueryInterface.php:100
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findNext
‪findNext(Post $post)
Definition: PostRepository.php:108
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:99
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findRecentByBlog
‪QueryResultInterface findRecentByBlog(Blog $blog, int $limit=5)
Definition: PostRepository.php:126
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface\getUid
‪getUid()
‪TYPO3Tests\BlogExample\Domain\Model\Post\getDate
‪getDate()
Definition: Post.php:130
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findByTagAndBlog
‪findByTagAndBlog(string $tag, Blog $blog)
Definition: PostRepository.php:55
‪TYPO3\CMS\Extbase\Persistence\Repository
Definition: Repository.php:30
‪TYPO3Tests\BlogExample\Domain\Model\Post
Definition: Post.php:28
‪TYPO3\CMS\Extbase\Persistence\QueryResultInterface
Definition: QueryResultInterface.php:26
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\$defaultOrderings
‪$defaultOrderings
Definition: PostRepository.php:33
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findAllSortedByCategory
‪findAllSortedByCategory(array $uids)
Definition: PostRepository.php:150
‪TYPO3Tests\BlogExample\Domain\Model\Blog
Definition: Blog.php:30
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository\findRemaining
‪findRemaining(Post $post)
Definition: PostRepository.php:71
‪TYPO3Tests\BlogExample\Domain\Repository\PostRepository
Definition: PostRepository.php:32
‪TYPO3\CMS\Extbase\Persistence\Repository\createQuery
‪QueryInterface createQuery()
Definition: Repository.php:203
‪TYPO3Tests\BlogExample\Domain\Model\Post\getBlog
‪getBlog()
Definition: Post.php:110