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