1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @copyright https://yawik.org/COPYRIGHT.php |
6
|
|
|
* @license MIT |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Applications\Repository\Filter; |
10
|
|
|
|
11
|
|
|
use Core\Repository\Filter\AbstractPaginationQuery; |
12
|
|
|
use Doctrine\MongoDB\Query\Builder; |
|
|
|
|
13
|
|
|
use Laminas\Stdlib\Parameters; |
14
|
|
|
use MongoDB\BSON\Regex; |
15
|
|
|
use Organizations\Entity\EmployeeInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* maps query parameters to entity attributes |
19
|
|
|
* |
20
|
|
|
* @author Carsten Bleek <[email protected]> |
21
|
|
|
* @author Mathias Gelhausen <[email protected]> |
22
|
|
|
* @author Mathias Weitz <[email protected]> |
23
|
|
|
* @since 0.29.2 [mg] - modified to match new ApplicationsFilter form parameters. |
24
|
|
|
*/ |
25
|
|
|
class PaginationQuery extends AbstractPaginationQuery |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Repository to query |
29
|
|
|
* |
30
|
|
|
* @var String |
31
|
|
|
*/ |
32
|
|
|
protected $repositoryName="Applications/Application"; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Sortable fields |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $sortPropertiesMap = array( |
40
|
|
|
'date' => 'dateCreated.date', |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
protected $auth; |
44
|
|
|
|
45
|
|
|
/** |
46
|
2 |
|
* Constructs pagination query. |
47
|
|
|
* |
48
|
2 |
|
* @param \Auth\AuthenticationService $auth |
49
|
|
|
*/ |
50
|
|
|
public function __construct($auth) |
51
|
|
|
{ |
52
|
|
|
$this->auth = $auth; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Creates a query for filtering applications |
57
|
|
|
* @see \Core\Repository\Filter\AbstractPaginationQuery::createQuery() |
58
|
1 |
|
* @param array|Parameters $params |
59
|
|
|
* @param Builder $queryBuilder |
60
|
1 |
|
* @return Builder |
61
|
1 |
|
*/ |
62
|
1 |
|
public function createQuery($params, $queryBuilder) |
63
|
|
|
{ |
64
|
1 |
|
$user = $this->auth->getUser(); |
65
|
|
|
$userID = $user->getId(); |
66
|
|
|
if ($params instanceof Parameters) { |
67
|
1 |
|
$value = $params->toArray(); |
68
|
1 |
|
} else { |
69
|
|
|
$value = $params; |
70
|
|
|
} |
71
|
1 |
|
|
72
|
1 |
|
if (isset($value['job']) && !empty($value['job'])) { |
73
|
|
|
$queryBuilder->field('job')->equals($value['job']); |
74
|
|
|
} |
75
|
1 |
|
|
76
|
1 |
|
if (isset($value['unread']) && !empty($value['unread'])) { |
77
|
1 |
|
$queryBuilder->field('readBy')->notEqual($userID); |
78
|
|
|
} |
79
|
1 |
|
|
80
|
1 |
|
if (isset($value['q']) && !empty($value['q'])) { |
81
|
|
|
$search = strtolower($value['q']); |
82
|
1 |
|
$searchPatterns = array(); |
83
|
|
|
|
84
|
|
|
foreach (explode(' ', $search) as $searchItem) { |
85
|
|
|
$searchPatterns[] = new Regex('^' . $searchItem, 'i'); |
86
|
|
|
} |
87
|
|
|
$queryBuilder->field('keywords')->all($searchPatterns); |
88
|
|
|
} |
89
|
1 |
|
|
90
|
1 |
|
/* |
91
|
|
|
* We only show applications to which the user has view permissions. |
92
|
1 |
|
* and which are not in draft mode |
93
|
1 |
|
*/ |
94
|
|
|
$queryBuilder->field('permissions.view')->equals($userID) |
95
|
|
|
->field('isDraft')->equals(false); |
96
|
1 |
|
|
97
|
1 |
|
if (!isset($value['sort'])) { |
98
|
|
|
$value['sort'] = '-date'; |
99
|
1 |
|
} |
100
|
|
|
|
101
|
1 |
|
if (isset($value['status']) && 'all' != $value['status']) { |
102
|
|
|
$queryBuilder->field('status.name')->equals($value['status']); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if ($user->hasOrganization()) { |
106
|
|
|
$org = $user->getOrganization(); |
107
|
|
|
if (!$org->isOwner()) { |
108
|
|
|
$org = $org->getOrganization(); |
109
|
|
|
$settings = $org->getWorkflowSettings(); |
110
|
|
|
if ($settings->hasActiveWorkflow() && $settings->getAssignDepartmentManagersToJobs()) { |
|
|
|
|
111
|
|
|
$employee = $org->getEmployee($userID); |
112
|
|
|
if ($employee->getRole() === EmployeeInterface::ROLE_DEPARTMENT_MANAGER) { |
113
|
|
|
$queryBuilder->field('refs.jobManagers')->equals($userID); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$queryBuilder->sort($this->filterSort($value['sort'])); |
120
|
|
|
|
121
|
|
|
return $queryBuilder; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths