1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Kreta package. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kreta\Component\Comment\Repository; |
14
|
|
|
|
15
|
|
|
use Kreta\Component\Core\Repository\EntityRepository; |
16
|
|
|
use Kreta\Component\Issue\Model\Interfaces\IssueInterface; |
17
|
|
|
use Kreta\Component\User\Model\Interfaces\UserInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class CommentRepository. |
21
|
|
|
* |
22
|
|
|
* @author Beñat Espiña <[email protected]> |
23
|
|
|
* @author Gorka Laucirica <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class CommentRepository extends EntityRepository |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Finds all the comments of issue given ordering by createdAt. |
29
|
|
|
* The result can be more strict adding user and createAt criteria. |
30
|
|
|
* Can do limit and offset. |
31
|
|
|
* |
32
|
|
|
* @param \Kreta\Component\Issue\Model\Interfaces\IssueInterface $issue The issue |
33
|
|
|
* @param \DateTime $createdAt The created at |
|
|
|
|
34
|
|
|
* @param string $writtenBy The email of user |
|
|
|
|
35
|
|
|
* @param int $limit The limit |
|
|
|
|
36
|
|
|
* @param int $offset The offset |
|
|
|
|
37
|
|
|
* |
38
|
|
|
* @return \Kreta\Component\Comment\Model\Interfaces\CommentInterface[] |
39
|
|
|
*/ |
40
|
|
|
public function findByIssue( |
41
|
|
|
IssueInterface $issue, |
42
|
|
|
\DateTime $createdAt = null, |
43
|
|
|
$writtenBy = null, |
44
|
|
|
$limit = null, |
45
|
|
|
$offset = null |
46
|
|
|
) { |
47
|
|
|
$queryBuilder = $this->getQueryBuilder(); |
48
|
|
|
if ($createdAt instanceof \DateTime) { |
49
|
|
|
$this->addCriteria($queryBuilder, ['between' => ['createdAt' => $createdAt]]); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
if ($writtenBy !== null) { |
52
|
|
|
$this->addCriteria($queryBuilder, ['wb.email' => $writtenBy]); |
53
|
|
|
} |
54
|
|
|
$this->addCriteria($queryBuilder, ['issue' => $issue]); |
|
|
|
|
55
|
|
|
$this->orderBy($queryBuilder, ['createdAt' => 'ASC']); |
56
|
|
|
|
57
|
|
|
if ($limit) { |
|
|
|
|
58
|
|
|
$queryBuilder->setMaxResults($limit); |
59
|
|
|
} |
60
|
|
|
if ($offset) { |
|
|
|
|
61
|
|
|
$queryBuilder->setFirstResult($offset); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $queryBuilder->getQuery()->getResult(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Finds the comments of given id if the user given is its writer. |
69
|
|
|
* |
70
|
|
|
* @param string $commentId The comment id |
71
|
|
|
* @param \Kreta\Component\User\Model\Interfaces\UserInterface $user The user |
72
|
|
|
* |
73
|
|
|
* @return \Kreta\Component\Comment\Model\Interfaces\CommentInterface |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
public function findByUser($commentId, UserInterface $user) |
76
|
|
|
{ |
77
|
|
|
return $this->findOneBy(['id' => $commentId, 'writtenBy' => $user], false); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
protected function getQueryBuilder() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
return parent::getQueryBuilder() |
86
|
|
|
->addSelect(['i', 'wb']) |
87
|
|
|
->join('c.issue', 'i') |
88
|
|
|
->join('c.writtenBy', 'wb'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
protected function getAlias() |
95
|
|
|
{ |
96
|
|
|
return 'c'; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.