1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
namespace Chamilo\PluginBundle\Form; |
5
|
|
|
|
6
|
|
|
use Category; |
7
|
|
|
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
8
|
|
|
use Display; |
9
|
|
|
use Exception; |
10
|
|
|
use FormValidator; |
11
|
|
|
use ImsLti; |
12
|
|
|
use ImsLtiPlugin; |
13
|
|
|
use LtiAssignmentGradesService; |
14
|
|
|
use LtiNamesRoleProvisioningService; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class FrmAdd. |
18
|
|
|
*/ |
19
|
|
|
class FrmEdit extends FormValidator |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var ImsLtiTool|null |
23
|
|
|
*/ |
24
|
|
|
private $tool; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* FrmAdd constructor. |
28
|
|
|
* |
29
|
|
|
* @param string $name |
30
|
|
|
* @param array $attributes |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
$name, |
34
|
|
|
$attributes = [], |
35
|
|
|
ImsLtiTool $tool = null |
36
|
|
|
) { |
37
|
|
|
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true); |
38
|
|
|
|
39
|
|
|
$this->tool = $tool; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Build the form. |
44
|
|
|
* |
45
|
|
|
* @param bool $globalMode |
46
|
|
|
*/ |
47
|
|
|
public function build($globalMode = true) |
48
|
|
|
{ |
49
|
|
|
$plugin = ImsLtiPlugin::create(); |
50
|
|
|
$course = $this->tool->getCourse(); |
|
|
|
|
51
|
|
|
$parent = $this->tool->getParent(); |
52
|
|
|
|
53
|
|
|
$this->addHeader($plugin->get_lang('ToolSettings')); |
54
|
|
|
|
55
|
|
|
if (null !== $course && $globalMode) { |
56
|
|
|
$this->addHtml( |
57
|
|
|
Display::return_message( |
58
|
|
|
sprintf($plugin->get_lang('ToolAddedOnCourseX'), $course->getTitle()), |
59
|
|
|
'normal', |
60
|
|
|
false |
61
|
|
|
) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->addText('name', get_lang('Name')); |
66
|
|
|
$this->addTextarea('description', get_lang('Description')); |
67
|
|
|
$this->addRadio( |
68
|
|
|
'version', |
69
|
|
|
$plugin->get_lang('LtiVersion'), |
70
|
|
|
[ |
71
|
|
|
ImsLti::V_1P1 => 'LTI 1.0 / 1.1', |
72
|
|
|
ImsLti::V_1P3 => 'LTI 1.3.0', |
73
|
|
|
] |
74
|
|
|
); |
75
|
|
|
$this->freeze(['version']); |
76
|
|
|
|
77
|
|
|
if (null === $parent) { |
78
|
|
|
$this->addUrl('launch_url', $plugin->get_lang('LaunchUrl'), true); |
79
|
|
|
if ($this->tool->getVersion() === ImsLti::V_1P1) { |
80
|
|
|
$this->addText('consumer_key', $plugin->get_lang('ConsumerKey'), false); |
81
|
|
|
$this->addText('shared_secret', $plugin->get_lang('SharedSecret'), false); |
82
|
|
|
} elseif ($this->tool->getVersion() === ImsLti::V_1P3) { |
83
|
|
|
$this->addText('client_id', $plugin->get_lang('ClientId'), true); |
84
|
|
|
$this->freeze(['client_id']); |
85
|
|
|
if (!empty($this->tool->getJwksUrl())) { |
86
|
|
|
$this->addUrl('jwks_url', $plugin->get_lang('PublicKeyset')); |
87
|
|
|
} else { |
88
|
|
|
$this->addTextarea( |
89
|
|
|
'public_key', |
90
|
|
|
$plugin->get_lang('PublicKey'), |
91
|
|
|
['style' => 'font-family: monospace;', 'rows' => 5], |
92
|
|
|
true |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
$this->addUrl('login_url', $plugin->get_lang('LoginUrl')); |
96
|
|
|
$this->addUrl('redirect_url', $plugin->get_lang('RedirectUrl')); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->addButtonAdvancedSettings('lti_adv'); |
101
|
|
|
$this->addHtml('<div id="lti_adv_options" style="display:none;">'); |
102
|
|
|
$this->addTextarea( |
103
|
|
|
'custom_params', |
104
|
|
|
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')] |
105
|
|
|
); |
106
|
|
|
$this->addSelect( |
107
|
|
|
'document_target', |
108
|
|
|
get_lang('LinkTarget'), |
109
|
|
|
['iframe' => 'iframe', 'window' => 'window'] |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
if (null === $parent |
113
|
|
|
|| (null !== $parent && !$parent->isActiveDeepLinking()) |
114
|
|
|
) { |
115
|
|
|
$this->addCheckBox( |
116
|
|
|
'deep_linking', |
117
|
|
|
[null, $plugin->get_lang('SupportDeppLinkingHelp'), null], |
118
|
|
|
$plugin->get_lang('SupportDeepLinking') |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if (null === $parent && $this->tool->getVersion() === ImsLti::V_1P3) { |
123
|
|
|
$showAGS = false; |
124
|
|
|
|
125
|
|
|
if (api_get_course_int_id()) { |
126
|
|
|
$caterories = Category::load(null, null, api_get_course_id()); |
127
|
|
|
|
128
|
|
|
if (!empty($caterories)) { |
129
|
|
|
$showAGS = true; |
130
|
|
|
} |
131
|
|
|
} else { |
132
|
|
|
$showAGS = true; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if ($showAGS) { |
136
|
|
|
$this->addRadio( |
137
|
|
|
'1p3_ags', |
138
|
|
|
$plugin->get_lang('AssigmentAndGradesService'), |
139
|
|
|
[ |
140
|
|
|
LtiAssignmentGradesService::AGS_NONE => $plugin->get_lang('DontUseService'), |
141
|
|
|
LtiAssignmentGradesService::AGS_SIMPLE => $plugin->get_lang('AGServiceSimple'), |
142
|
|
|
LtiAssignmentGradesService::AGS_FULL => $plugin->get_lang('AGServiceFull'), |
143
|
|
|
] |
144
|
|
|
); |
145
|
|
|
} else { |
146
|
|
|
$gradebookUrl = api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(); |
147
|
|
|
|
148
|
|
|
$this->addLabel( |
149
|
|
|
$plugin->get_lang('AssigmentAndGradesService'), |
150
|
|
|
sprintf( |
151
|
|
|
$plugin->get_lang('YouNeedCreateTheGradebokInCourseFirst'), |
152
|
|
|
Display::url($gradebookUrl, $gradebookUrl) |
153
|
|
|
) |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->addRadio( |
158
|
|
|
'1p3_nrps', |
159
|
|
|
$plugin->get_lang('NamesAndRoleProvisioningService'), |
160
|
|
|
[ |
161
|
|
|
LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'), |
162
|
|
|
LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService'), |
163
|
|
|
] |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
if (!$parent) { |
168
|
|
|
$this->addText( |
169
|
|
|
'replacement_user_id', |
170
|
|
|
[ |
171
|
|
|
$plugin->get_lang('ReplacementUserId'), |
172
|
|
|
$plugin->get_lang('ReplacementUserIdHelp'), |
173
|
|
|
], |
174
|
|
|
false |
175
|
|
|
); |
176
|
|
|
$this->applyFilter('replacement_user_id', 'trim'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->addHtml('</div>'); |
180
|
|
|
$this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy')); |
181
|
|
|
$this->addHtml('<div id="lti_privacy_options" style="display:none;">'); |
182
|
|
|
$this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName')); |
183
|
|
|
$this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail')); |
184
|
|
|
$this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture')); |
185
|
|
|
$this->addHtml('</div>'); |
186
|
|
|
$this->addButtonUpdate($plugin->get_lang('EditExternalTool')); |
187
|
|
|
$this->addHidden('id', $this->tool->getId()); |
188
|
|
|
$this->addHidden('action', 'edit'); |
189
|
|
|
$this->applyFilter('__ALL__', 'trim'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @throws Exception |
194
|
|
|
*/ |
195
|
|
|
public function setDefaultValues() |
196
|
|
|
{ |
197
|
|
|
$advServices = $this->tool->getAdvantageServices(); |
198
|
|
|
|
199
|
|
|
$this->setDefaults( |
200
|
|
|
[ |
201
|
|
|
'name' => $this->tool->getName(), |
202
|
|
|
'description' => $this->tool->getDescription(), |
203
|
|
|
'launch_url' => $this->tool->getLaunchUrl(), |
204
|
|
|
'consumer_key' => $this->tool->getConsumerKey(), |
205
|
|
|
'shared_secret' => $this->tool->getSharedSecret(), |
206
|
|
|
'custom_params' => $this->tool->getCustomParams(), |
207
|
|
|
'deep_linking' => $this->tool->isActiveDeepLinking(), |
208
|
|
|
'share_name' => $this->tool->isSharingName(), |
209
|
|
|
'share_email' => $this->tool->isSharingEmail(), |
210
|
|
|
'share_picture' => $this->tool->isSharingPicture(), |
211
|
|
|
'version' => $this->tool->getVersion(), |
212
|
|
|
'client_id' => $this->tool->getClientId(), |
213
|
|
|
'public_key' => $this->tool->publicKey, |
214
|
|
|
'jwks_url' => $this->tool->getJwksUrl(), |
215
|
|
|
'login_url' => $this->tool->getLoginUrl(), |
216
|
|
|
'redirect_url' => $this->tool->getRedirectUrl(), |
217
|
|
|
'1p3_ags' => $advServices['ags'], |
218
|
|
|
'1p3_nrps' => $advServices['nrps'], |
219
|
|
|
'document_target' => $this->tool->getDocumentTarget(), |
220
|
|
|
'replacement_user_id' => $this->tool->getReplacementForUserId(), |
221
|
|
|
] |
222
|
|
|
); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.