|
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\Controller; |
|
20
|
|
|
|
|
21
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
|
22
|
|
|
use Surfnet\StepupRa\RaBundle\Service\InstitutionListingService; |
|
23
|
|
|
use Surfnet\StepupRa\RaBundle\Service\ProfileService; |
|
24
|
|
|
use Surfnet\StepupRa\RaBundle\Command\SelectInstitutionCommand; |
|
25
|
|
|
use Surfnet\StepupRa\RaBundle\Form\Type\SelectInstitutionType; |
|
26
|
|
|
use Surfnet\StepupRa\RaBundle\Service\InstitutionConfigurationOptionsService; |
|
27
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
28
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
29
|
|
|
|
|
30
|
|
|
class RaaController extends Controller |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
public function institutionConfigurationAction(Request $request) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RAA', 'ROLE_SRAA']); |
|
35
|
|
|
|
|
36
|
|
|
$logger = $this->get('logger'); |
|
37
|
|
|
/** @var Identity $identity */ |
|
38
|
|
|
$identity = $this->getUser(); |
|
39
|
|
|
|
|
40
|
|
|
$profile = $this->getProfileService()->findByIdentityId($identity->id); |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
if ($this->isGranted('ROLE_SRAA')) { |
|
|
|
|
|
|
43
|
|
|
$institution = $identity->institution; |
|
44
|
|
|
$choices = $this->getInstitutionListingService()->getAll(); |
|
45
|
|
|
} else { |
|
46
|
|
|
$choices = $profile->getRaaInstitutions(); |
|
47
|
|
|
$institution = reset($choices); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// Only show the form if more than one institutions where found. |
|
51
|
|
View Code Duplication |
if (count($choices) > 1) { |
|
|
|
|
|
|
52
|
|
|
$command = new SelectInstitutionCommand(); |
|
53
|
|
|
$command->institution = $institution; |
|
54
|
|
|
$command->availableInstitutions = $choices; |
|
55
|
|
|
|
|
56
|
|
|
$form = $this->createForm(SelectInstitutionType::class, $command); |
|
57
|
|
|
$form->handleRequest($request); |
|
58
|
|
|
|
|
59
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
60
|
|
|
$institution = $command->institution; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$logger->notice(sprintf('Opening the institution configuration for "%s"', $institution)); |
|
65
|
|
|
|
|
66
|
|
|
// Load the configuration for the institution that was selected. |
|
67
|
|
|
$configuration = $this->getInstitutionConfigurationOptionsService() |
|
68
|
|
|
->getInstitutionConfigurationOptionsFor($institution); |
|
69
|
|
|
|
|
70
|
|
|
if (!$configuration) { |
|
71
|
|
|
$logger->warning(sprintf('Unable to find the institution configuration for "%s"', $institution)); |
|
72
|
|
|
return $this->createNotFoundException('The institution configuration could not be found'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->render( |
|
76
|
|
|
'@SurfnetStepupRaRa/institution_configuration/overview.html.twig', |
|
77
|
|
|
[ |
|
78
|
|
|
'configuration' => (array)$configuration, |
|
79
|
|
|
'form' => isset($form) ? $form->createView() : null, |
|
80
|
|
|
'institution' => $institution, |
|
81
|
|
|
] |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return InstitutionConfigurationOptionsService |
|
87
|
|
|
*/ |
|
88
|
|
|
private function getInstitutionConfigurationOptionsService() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->get('ra.service.institution_configuration_options'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return ProfileService |
|
95
|
|
|
*/ |
|
96
|
|
|
private function getProfileService() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->get('ra.service.profile'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return InstitutionListingService |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getInstitutionListingService() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->get('ra.service.institution_listing'); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.