|
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
|
|
|
|
|
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 string $identityId |
|
48
|
|
|
* @param string $institution |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
public function createChoiceListFor($identityId, $institution) |
|
52
|
|
|
{ |
|
53
|
|
|
$collection = $this->searchBy($identityId, $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 []; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$choices = []; |
|
61
|
|
|
foreach ($collection->getElements() as $item) { |
|
62
|
|
|
$choices[$item->raInstitution] = $item->raInstitution; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Sort the list alphabetically while preserving the keys |
|
66
|
|
|
asort($choices); |
|
67
|
|
|
return $choices; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $identityId |
|
72
|
|
|
* @param string $institution |
|
73
|
|
|
* @return RaListingCollection |
|
74
|
|
|
*/ |
|
75
|
|
|
public function searchBy($identityId, $institution) |
|
76
|
|
|
{ |
|
77
|
|
|
$query = new RaListingSearchQuery($institution, 1); |
|
78
|
|
|
$query->setIdentityId($identityId); |
|
79
|
|
|
return $this->raListingService->search($query); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|