1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: dsmrt |
5
|
|
|
* Date: 3/10/18 |
6
|
|
|
* Time: 8:40 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\saml\core\controllers\cp\view\metadata; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use craft\helpers\UrlHelper; |
13
|
|
|
use flipbox\saml\core\AbstractPlugin; |
14
|
|
|
use flipbox\saml\core\controllers\cp\view\AbstractController; |
15
|
|
|
use flipbox\saml\core\records\AbstractProvider; |
16
|
|
|
use flipbox\saml\core\records\ProviderInterface; |
17
|
|
|
use flipbox\saml\core\EnsureSAMLPlugin; |
18
|
|
|
use flipbox\saml\core\models\SettingsInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class AbstractEditController |
22
|
|
|
* @package flipbox\saml\core\controllers\cp\view\metadata |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractEditController extends AbstractController implements EnsureSAMLPlugin |
25
|
|
|
{ |
26
|
|
|
use VariablesTrait; |
27
|
|
|
|
28
|
|
|
const TEMPLATE_INDEX = DIRECTORY_SEPARATOR . '_cp' . DIRECTORY_SEPARATOR . 'metadata'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string|null $providerId |
32
|
|
|
* @return \yii\web\Response |
33
|
|
|
*/ |
34
|
|
|
public function actionIndex($providerId = null, $overwriteVariables = []) |
35
|
|
|
{ |
36
|
|
|
$variables = $this->getPlugin()->getEditProvider()->prepVariables($providerId); |
37
|
|
|
/** @var AbstractProvider $provider */ |
38
|
|
|
$provider = $variables['provider']; |
39
|
|
|
|
40
|
|
|
$variables['title'] = Craft::t( |
41
|
|
|
$this->getPlugin()->getHandle(), |
42
|
|
|
'Edit ' . $this->getPlugin()->getEditProvider()->getTitle($provider->getType()) |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$variables['createType'] = $provider->getType(); |
46
|
|
|
|
47
|
|
|
if (isset($variables['provider']) && $variables['provider'] instanceof ProviderInterface) { |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Actions |
51
|
|
|
*/ |
52
|
|
|
$variables['actions'] = $this->getPlugin()->getEditProvider()->getActions($variables['provider']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$variables = array_merge($variables, $overwriteVariables); |
56
|
|
|
return $this->renderTemplate( |
57
|
|
|
$this->getPlugin()->getEditProvider()->getTemplateIndex() . static::TEMPLATE_INDEX . DIRECTORY_SEPARATOR . 'edit', |
58
|
|
|
$variables |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return \yii\web\Response |
64
|
|
|
*/ |
65
|
|
|
public function actionNewIdp() |
66
|
|
|
{ |
67
|
|
|
/** @var AbstractPlugin $plugin */ |
68
|
|
|
$plugin = $this->getPlugin(); |
69
|
|
|
$providerRecord = $this->getPlugin()->getProviderRecordClass(); |
70
|
|
|
return $this->actionIndex(null, [ |
71
|
|
|
'title' => 'New ' . $this->getPlugin()->getEditProvider()->getTitle(SettingsInterface::IDP), |
72
|
|
|
'createType' => SettingsInterface::IDP, |
73
|
|
|
'provider' => new $providerRecord([ |
74
|
|
|
'providerType' => SettingsInterface::IDP, |
75
|
|
|
]), |
76
|
|
|
'crumbs' => [ |
77
|
|
|
[ |
78
|
|
|
'url' => UrlHelper::cpUrl( |
79
|
|
|
implode( |
80
|
|
|
'/', |
81
|
|
|
[ |
82
|
|
|
$plugin->getHandle(), |
83
|
|
|
] |
84
|
|
|
) |
85
|
|
|
), |
86
|
|
|
'label' => $plugin->name, |
87
|
|
|
], |
88
|
|
|
[ |
89
|
|
|
'url' => UrlHelper::cpUrl( |
90
|
|
|
implode( |
91
|
|
|
'/', |
92
|
|
|
[ |
93
|
|
|
$plugin->getHandle(), |
94
|
|
|
'metadata', |
95
|
|
|
] |
96
|
|
|
) |
97
|
|
|
), |
98
|
|
|
'label' => 'Provider List', |
99
|
|
|
], |
100
|
|
|
[ |
101
|
|
|
'url' => UrlHelper::cpUrl( |
102
|
|
|
implode( |
103
|
|
|
'/', |
104
|
|
|
[ |
105
|
|
|
$plugin->getHandle(), |
106
|
|
|
'metadata', |
107
|
|
|
'new-idp', |
108
|
|
|
] |
109
|
|
|
) |
110
|
|
|
), |
111
|
|
|
'label' => 'New IDP', |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
]); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return \yii\web\Response |
119
|
|
|
*/ |
120
|
|
|
public function actionNewSp() |
121
|
|
|
{ |
122
|
|
|
/** @var AbstractPlugin $plugin */ |
123
|
|
|
$plugin = $this->getPlugin(); |
124
|
|
|
$providerRecord = $this->getPlugin()->getProviderRecordClass(); |
125
|
|
|
return $this->actionIndex(null, [ |
126
|
|
|
'title' => 'New ' . $this->getPlugin()->getEditProvider()->getTitle(SettingsInterface::SP), |
127
|
|
|
'createType' => SettingsInterface::SP, |
128
|
|
|
'provider' => new $providerRecord([ |
129
|
|
|
'providerType' => SettingsInterface::SP, |
130
|
|
|
]), |
131
|
|
|
'crumbs' => [ |
132
|
|
|
[ |
133
|
|
|
'url' => UrlHelper::cpUrl( |
134
|
|
|
implode( |
135
|
|
|
'/', |
136
|
|
|
[ |
137
|
|
|
$plugin->getHandle(), |
138
|
|
|
] |
139
|
|
|
) |
140
|
|
|
), |
141
|
|
|
'label' => $plugin->name, |
142
|
|
|
], |
143
|
|
|
[ |
144
|
|
|
'url' => UrlHelper::cpUrl( |
145
|
|
|
implode( |
146
|
|
|
'/', |
147
|
|
|
[ |
148
|
|
|
$plugin->getHandle(), |
149
|
|
|
'metadata', |
150
|
|
|
] |
151
|
|
|
) |
152
|
|
|
), |
153
|
|
|
'label' => 'Provider List', |
154
|
|
|
], |
155
|
|
|
[ |
156
|
|
|
'url' => UrlHelper::cpUrl( |
157
|
|
|
implode( |
158
|
|
|
'/', |
159
|
|
|
[ |
160
|
|
|
$plugin->getHandle(), |
161
|
|
|
'metadata', |
162
|
|
|
'new-sp', |
163
|
|
|
] |
164
|
|
|
) |
165
|
|
|
), |
166
|
|
|
'label' => 'New SP', |
167
|
|
|
], |
168
|
|
|
], |
169
|
|
|
]); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return \yii\web\Response |
174
|
|
|
*/ |
175
|
|
|
public function actionMyProvider() |
176
|
|
|
{ |
177
|
|
|
$provider = $this->getPlugin()->getProvider()->findOwn(); |
178
|
|
|
$variables = $this->getPlugin()->getEditProvider()->prepVariables( |
179
|
|
|
$provider ? $provider : null |
180
|
|
|
); |
181
|
|
|
|
182
|
|
|
if ($provider) { |
183
|
|
|
$variables['provider'] = $provider; |
184
|
|
|
|
185
|
|
|
$variables = array_merge( |
186
|
|
|
$variables, |
187
|
|
|
$this->getPlugin()->getEditProvider()->addUrls($provider) |
188
|
|
|
); |
189
|
|
|
} else { |
190
|
|
|
$provider = $variables['provider']; |
191
|
|
|
$variables['provider']->entityId = $this->getPlugin()->getSettings()->getEntityId(); |
192
|
|
|
$variables['provider']->providerType = $this->getPlugin()->getMyType(); |
193
|
|
|
$variables['provider']->label = 'My Provider'; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Actions |
198
|
|
|
*/ |
199
|
|
|
$variables['actions'] = $this->getPlugin()->getEditProvider()->getActions($provider); |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Edit Title |
203
|
|
|
*/ |
204
|
|
|
$variables['title'] = Craft::t( |
205
|
|
|
$this->getPlugin()->getHandle(), |
206
|
|
|
'My Provider (' . strtoupper($variables['provider']->providerType) . ')' |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
$variables['createType'] = $variables['myType']; |
210
|
|
|
|
211
|
|
|
return $this->renderTemplate( |
212
|
|
|
$this->getPlugin()->getEditProvider()->getTemplateIndex() . static::TEMPLATE_INDEX . DIRECTORY_SEPARATOR . 'edit', |
213
|
|
|
$variables |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|