[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Fixtures / Extensions / blog_example / Classes / Domain / Repository / PostRepository.php
1 <?php
2 namespace ExtbaseTeam\BlogExample\Domain\Repository;
3 /**
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16 /**
17 * A repository for blog posts
18 */
19 class PostRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
20
21 protected $defaultOrderings = array('date' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING);
22
23 /**
24 * Finds all posts by the specified blog
25 *
26 * @param \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog The blog the post must refer to
27 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface The posts
28 */
29 public function findAllByBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog) {
30 $query = $this->createQuery();
31 return $query
32 ->matching(
33 $query->equals('blog', $blog)
34 )
35 ->execute();
36 }
37
38 /**
39 * Finds posts by the specified tag and blog
40 *
41 * @param string $tag
42 * @param \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog The blog the post must refer to
43 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface The posts
44 */
45 public function findByTagAndBlog($tag, \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog) {
46 $query = $this->createQuery();
47 return $query
48 ->matching(
49 $query->logicalAnd(
50 $query->equals('blog', $blog),
51 $query->equals('tags.name', $tag)
52 )
53 )
54 ->execute();
55 }
56
57 /**
58 * Finds all remaining posts of the blog
59 *
60 * @param \ExtbaseTeam\BlogExample\Domain\Model\Post $post The reference post
61 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface The posts
62 */
63 public function findRemaining(\ExtbaseTeam\BlogExample\Domain\Model\Post $post) {
64 $blog = $post->getBlog();
65 $query = $this->createQuery();
66 return $query
67 ->matching(
68 $query->logicalAnd(
69 $query->equals('blog', $blog),
70 $query->logicalNot(
71 $query->equals('uid', $post->getUid())
72 )
73 )
74 )
75 ->execute();
76 }
77
78 /**
79 * Finds the previous of the given post
80 *
81 * @param \ExtbaseTeam\BlogExample\Domain\Model\Post $post The reference post
82 * @return \ExtbaseTeam\BlogExample\Domain\Model\Post
83 */
84 public function findPrevious(\ExtbaseTeam\BlogExample\Domain\Model\Post $post) {
85 $query = $this->createQuery();
86 return $query
87 ->matching(
88 $query->lessThan('date', $post->getDate())
89 )
90 ->execute()
91 ->getFirst();
92 }
93
94 /**
95 * Finds the post next to the given post
96 *
97 * @param \ExtbaseTeam\BlogExample\Domain\Model\Post $post The reference post
98 * @return \ExtbaseTeam\BlogExample\Domain\Model\Post
99 */
100 public function findNext(\ExtbaseTeam\BlogExample\Domain\Model\Post $post) {
101 $query = $this->createQuery();
102 return $query
103 ->matching(
104 $query->greaterThan('date', $post->getDate())
105 )
106 ->execute()
107 ->getFirst();
108 }
109
110 /**
111 * Finds most recent posts by the specified blog
112 *
113 * @param \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog The blog the post must refer to
114 * @param integer $limit The number of posts to return at max
115 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface The posts
116 */
117 public function findRecentByBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog, $limit = 5) {
118 $query = $this->createQuery();
119 return $query
120 ->matching(
121 $query->equals('blog', $blog)
122 )
123 ->setLimit((integer)$limit)
124 ->execute();
125 }
126
127 /**
128 * Find posts by category
129 *
130 * @param int $categoryUid
131 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
132 */
133 public function findByCategory($categoryUid) {
134 $query = $this->createQuery();
135 return $query
136 ->matching(
137 $query->contains('categories', $categoryUid)
138 )
139 ->execute();
140 }
141
142 }
143 ?>