1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2018 SURFnet B.V. |
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\StepupRa\RaBundle\Service; |
20
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\RaListingSearchQuery; |
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\RaListingService as MiddlewareClientBundleRaListingService; |
24
|
|
|
use Symfony\Component\Form\ChoiceList\ArrayChoiceList; |
25
|
|
|
|
26
|
|
|
class RaListingService |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var MiddlewareClientBundleRaListingService |
30
|
|
|
*/ |
31
|
|
|
private $raListingService; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var LoggerInterface |
35
|
|
|
*/ |
36
|
|
|
private $logger; |
37
|
|
|
|
38
|
|
|
public function __construct( |
39
|
|
|
MiddlewareClientBundleRaListingService $raListingService, |
40
|
|
|
LoggerInterface $logger |
41
|
|
|
) { |
42
|
|
|
$this->raListingService = $raListingService; |
43
|
|
|
$this->logger = $logger; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $institution |
48
|
|
|
* @return ArrayChoiceList |
49
|
|
|
*/ |
50
|
|
|
public function createChoiceListFor($institution) |
51
|
|
|
{ |
52
|
|
|
$query = new RaListingSearchQuery($institution, 1); |
53
|
|
|
$query->setIdentityId($institution->getIdentityInstitution()); |
54
|
|
|
|
55
|
|
|
$collection = $this->raListingService->search($query); |
56
|
|
|
|
57
|
|
|
if ($collection->getTotalItems() === 0) { |
58
|
|
|
$this->logger->warning('No RAA institutions found for identity, unable to build the choice list for the RAA switcher'); |
59
|
|
|
return new ArrayChoiceList(); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$choices = []; |
63
|
|
|
foreach ($collection as $item) { |
64
|
|
|
$choices[$item->institution] = $item->institution; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return new ArrayChoiceList($choices); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks for function calls that miss required arguments.