1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Service; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
22
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Value\InstitutionAuthorizationContext; |
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RaCandidateQuery; |
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository; |
25
|
|
|
|
26
|
|
|
class RaCandidateService extends AbstractSearchService |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var RaCandidateRepository |
30
|
|
|
*/ |
31
|
|
|
private $raCandidateRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param RaCandidateRepository $raCandidateRepository |
35
|
|
|
*/ |
36
|
|
|
public function __construct(RaCandidateRepository $raCandidateRepository) |
37
|
|
|
{ |
38
|
|
|
$this->raCandidateRepository = $raCandidateRepository; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param RaCandidateQuery $query |
43
|
|
|
* @return \Pagerfanta\Pagerfanta |
44
|
|
|
*/ |
45
|
|
|
public function search(RaCandidateQuery $query) |
46
|
|
|
{ |
47
|
|
|
$doctrineQuery = $this->raCandidateRepository->createSearchQuery($query); |
48
|
|
|
|
49
|
|
|
$paginator = $this->createPaginatorFrom($doctrineQuery, $query, false); |
50
|
|
|
|
51
|
|
|
return $paginator; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param RaCandidateQuery $query |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function getFilterOptions(RaCandidateQuery $query) |
59
|
|
|
{ |
60
|
|
|
return $this->getFilteredQueryOptions($this->raCandidateRepository->createOptionsQuery($query)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $identityId |
65
|
|
|
* @return null|array |
66
|
|
|
*/ |
67
|
|
|
public function findOneByIdentityId($identityId) |
68
|
|
|
{ |
69
|
|
|
return $this->raCandidateRepository->findOneByIdentityId($identityId); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set the RA candidates USE RA(A) institutions on the Identity he is going to promote. |
74
|
|
|
*/ |
75
|
|
|
public function setUseRaInstitutionsOnRaCandidate(InstitutionAuthorizationContext $actor, array $raCandidate) |
76
|
|
|
{ |
77
|
|
|
$result = []; |
78
|
|
|
foreach ($actor->getInstitutions() as $raInstitution) { |
|
|
|
|
79
|
|
|
$raCandidate['ra_institution'] = new Institution($raInstitution->getInstitution()); |
80
|
|
|
$result[] = $raCandidate; |
81
|
|
|
} |
82
|
|
|
return $result; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.