|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2017 Francois-Xavier Soubirou. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of ci-report. |
|
6
|
|
|
* |
|
7
|
|
|
* ci-report is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* ci-report is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with ci-report. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
declare(strict_types=1); |
|
21
|
|
|
|
|
22
|
|
|
namespace AppBundle\Repository; |
|
23
|
|
|
|
|
24
|
|
|
use AppBundle\Entity\Campaign; |
|
25
|
|
|
use AppBundle\Entity\Suite; |
|
26
|
|
|
use Gedmo\Sortable\Entity\Repository\SortableRepository; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Suite repository class. |
|
30
|
|
|
* |
|
31
|
|
|
* @category ci-report app |
|
32
|
|
|
* |
|
33
|
|
|
* @author Francois-Xavier Soubirou <[email protected]> |
|
34
|
|
|
* @copyright 2017 Francois-Xavier Soubirou |
|
35
|
|
|
* @license http://www.gnu.org/licenses/ GPLv3 |
|
36
|
|
|
* |
|
37
|
|
|
* @see https://www.ci-report.io |
|
38
|
|
|
*/ |
|
39
|
|
|
class SuiteRepository extends SortableRepository |
|
40
|
|
|
{ |
|
41
|
|
|
/** |
|
42
|
|
|
* Get all suites for a campaign. |
|
43
|
|
|
* |
|
44
|
|
|
* @param Campaign $campaign The campaign |
|
45
|
|
|
* |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function findSuitesByCampaign(Campaign $campaign): array |
|
49
|
|
|
{ |
|
50
|
|
|
$qb = $this->createQueryBuilder('s') |
|
51
|
|
|
->innerJoin('s.campaign', 'c') |
|
52
|
|
|
->where('c.id = :campaignId') |
|
53
|
|
|
->setParameter('campaignId', $campaign->getId()) |
|
54
|
|
|
->orderBy('s.datetimeSuite', 'DESC', 's.position', 'DESC'); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$result = $qb->getQuery()->getResult(); |
|
57
|
|
|
|
|
58
|
|
|
return $result; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get a suite for a campaign refid and its refid. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $prefid The project refid |
|
65
|
|
|
* @param int $crefid The refid of the campaign |
|
66
|
|
|
* @param int $refid Refid of the suite in the campaign |
|
67
|
|
|
* |
|
68
|
|
|
* @return Suite|null |
|
69
|
|
|
*/ |
|
70
|
|
|
public function findSuiteByProjectRefidCampaignRefidAndRefid(string $prefid, int $crefid, int $refid): ?Suite |
|
71
|
|
|
{ |
|
72
|
|
|
$cposition = $crefid - 1; |
|
73
|
|
|
$position = $refid - 1; |
|
74
|
|
|
|
|
75
|
|
|
$qb = $this->createQueryBuilder('s') |
|
76
|
|
|
->innerJoin('s.campaign', 'c') |
|
77
|
|
|
->innerJoin('c.project', 'p') |
|
78
|
|
|
->where('p.refid = :prefid') |
|
79
|
|
|
->andWhere('c.position = :cposition') |
|
80
|
|
|
->andWhere('s.position = :position') |
|
81
|
|
|
->setParameter('prefid', $prefid) |
|
82
|
|
|
->setParameter('cposition', $cposition) |
|
83
|
|
|
->setParameter('position', $position); |
|
84
|
|
|
|
|
85
|
|
|
$result = $qb->getQuery()->getOneOrNullResult(); |
|
86
|
|
|
|
|
87
|
|
|
return $result; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get previous suite for a suite. |
|
92
|
|
|
* |
|
93
|
|
|
* @param Campaign $campaign The campaign |
|
94
|
|
|
* @param Suite $suite The suite |
|
95
|
|
|
* |
|
96
|
|
|
* @return Suite|null |
|
97
|
|
|
*/ |
|
98
|
|
|
public function findPrevSuiteByCampaign(Campaign $campaign, Suite $suite): ?Suite |
|
99
|
|
|
{ |
|
100
|
|
|
$qb = $this->createQueryBuilder('s') |
|
101
|
|
|
->innerJoin('s.campaign', 'c') |
|
102
|
|
|
->where('c.id = :campaignId') |
|
103
|
|
|
->andWhere('s.position < :position') |
|
104
|
|
|
->setParameter('campaignId', $campaign->getId()) |
|
105
|
|
|
->setParameter('position', $suite->getPosition()) |
|
106
|
|
|
->orderBy('s.position', 'DESC') |
|
107
|
|
|
->setMaxResults(1); |
|
108
|
|
|
|
|
109
|
|
|
$result = $qb->getQuery()->getOneOrNullResult(); |
|
110
|
|
|
|
|
111
|
|
|
return $result; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get next campaign for a campaign. |
|
116
|
|
|
* |
|
117
|
|
|
* @param Campaign $campaign The campaign |
|
118
|
|
|
* @param Suite $suite The suite |
|
119
|
|
|
* |
|
120
|
|
|
* @return Suite|null |
|
121
|
|
|
*/ |
|
122
|
|
|
public function findNextSuiteByCampaign(Campaign $campaign, Suite $suite): ?Suite |
|
123
|
|
|
{ |
|
124
|
|
|
$qb = $this->createQueryBuilder('s') |
|
125
|
|
|
->innerJoin('s.campaign', 'c') |
|
126
|
|
|
->where('c.id = :campaignId') |
|
127
|
|
|
->andWhere('s.position > :position') |
|
128
|
|
|
->setParameter('campaignId', $campaign->getId()) |
|
129
|
|
|
->setParameter('position', $suite->getPosition()) |
|
130
|
|
|
->orderBy('s.position', 'ASC') |
|
131
|
|
|
->setMaxResults(1); |
|
132
|
|
|
|
|
133
|
|
|
$result = $qb->getQuery()->getOneOrNullResult(); |
|
134
|
|
|
|
|
135
|
|
|
return $result; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.