RaCandidateService::getFilterOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 Pagerfanta\Pagerfanta;
22
use Surfnet\Stepup\Identity\Value\Institution;
23
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Value\InstitutionAuthorizationContext;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\RaCandidate;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RaCandidateQuery;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository;
27
28
/** @extends AbstractSearchService<RaCandidate> */
29
class RaCandidateService extends AbstractSearchService
30
{
31
    public function __construct(private readonly RaCandidateRepository $raCandidateRepository)
32
    {
33
    }
34
35
    /**
36
     * @return Pagerfanta<RaCandidate>
37
     */
38
    public function search(RaCandidateQuery $query): Pagerfanta
39
    {
40
        $doctrineQuery = $this->raCandidateRepository->createSearchQuery($query);
41
42
        return $this->createPaginatorFrom($doctrineQuery, $query, false);
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getFilterOptions(RaCandidateQuery $query): array
49
    {
50
        return $this->getFilteredQueryOptions($this->raCandidateRepository->createOptionsQuery($query));
51
    }
52
53
    /**
54
     * @return null|array
55
     */
56
    public function findOneByIdentityId(string $identityId): ?array
57
    {
58
        return $this->raCandidateRepository->findOneByIdentityId($identityId);
59
    }
60
61
    /**
62
     * Set the RA candidates USE RA(A) institutions on the Identity he is going to promote.
63
     * @return non-empty-array[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array[] at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array[].
Loading history...
64
     */
65
    public function setUseRaInstitutionsOnRaCandidate(InstitutionAuthorizationContext $actor, array $raCandidate): array
66
    {
67
        $result = [];
68
        foreach ($actor->getInstitutions() as $raInstitution) {
69
            $raCandidate['ra_institution'] = new Institution($raInstitution->getInstitution());
70
            $result[] = $raCandidate;
71
        }
72
        return $result;
73
    }
74
}
75