ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjLTIAdministrationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Object/classes/class.ilObjectGUI.php';
5// require_once 'Services/LTI/classes/ActiveRecord/class.ilLTIExternalConsumer.php';
6require_once 'Services/LTI/classes/InternalProvider/class.ilLTIToolConsumer.php';
7require_once 'Services/LTI/classes/class.ilLTIDataConnector.php';
8
9
20{
26 private $dataConnector = null;
27
28 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
29 {
30 $this->type = "ltis";
31 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
32 $this->dataConnector = new ilLTIDataConnector();
33
34 $GLOBALS['DIC']->language()->loadLanguageModule('lti');
35 }
36
37 public function executeCommand()
38 {
39 $next_class = $this->ctrl->getNextClass($this);
40 $cmd = $this->ctrl->getCmd();
41
42 $this->prepareOutput();
43
44 switch ($next_class) {
45 case 'ilpermissiongui':
46 $GLOBALS['ilTabs']->activateTab('perm_settings');
47 require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
48 $perm_gui = new ilPermissionGUI($this);
49 $this->ctrl->forwardCommand($perm_gui);
50 break;
51
52 default:
53 if (!$cmd || $cmd == 'view') {
54 $cmd = 'listConsumers';
55 } elseif ($cmd == 'createconsumer') {
56 $cmd = "initConsumerForm";
57 }
58 $this->$cmd();
59 break;
60 }
61 }
62
63 public function getType()
64 {
65 return "ltis";
66 }
67
68 public function getAdminTabs()
69 {
70 global $rbacsystem;
71
72 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
73 // currently no general settings.
74 // $this->tabs_gui->addTab("settings",
75 // $this->lng->txt("settings"),
76 // $this->ctrl->getLinkTarget($this, "initSettingsForm"));
77
78 $this->tabs_gui->addTab(
79 "consumers",
80 $this->lng->txt("consumers"),
81 $this->ctrl->getLinkTarget($this, "listConsumers")
82 );
83 }
84 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
85 $this->tabs_gui->addTab(
86 "releasedObjects",
87 $this->lng->txt("lti_released_objects"),
88 $this->ctrl->getLinkTarget($this, "releasedObjects")
89 );
90 }
91
92 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
93 $this->tabs_gui->addTab(
94 "perm_settings",
95 $this->lng->txt("perm_settings"),
96 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
97 );
98 }
99 }
100
101 protected function initSettingsForm(ilPropertyFormGUI $form = null)
102 {
103 if (!($form instanceof ilPropertyFormGUI)) {
104 $form = $this->getSettingsForm();
105 }
106 $this->tabs_gui->activateTab("settings");
107 $this->tpl->setContent($form->getHTML());
108 }
109
110
111 protected function getSettingsForm()
112 {
113 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
114
115 $form = new ilPropertyFormGUI();
116 /*
117 $form->setFormAction($this->ctrl->getFormAction($this,'saveSettingsForm'));
118 $form->setTitle($this->lng->txt("lti_settings"));
119
120 // object types
121 $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
122
123 $valid_obj_types = $this->object->getLTIObjectTypes();
124 foreach($valid_obj_types as $obj_type_id => $obj_name)
125 {
126 $cb_obj_types->addOption(new ilCheckboxOption($obj_name, $obj_type_id));
127 }
128 $objs_active = $this->object->getActiveObjectTypes();
129 $cb_obj_types->setValue($objs_active);
130 $form->addItem($cb_obj_types);
131
132 // test roles
133 $roles = $this->object->getLTIRoles();
134 foreach($roles as $role_id => $role_name)
135 {
136 $options[$role_id] = $role_name;
137 }
138 $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'roles');
139 $si_roles->setOptions($options);
140 $si_roles->setValue($this->object->getCurrentRole());
141 $form->addItem($si_roles);
142
143 $form->addCommandButton("saveSettingsForm", $this->lng->txt("save"));
144 */
145 return $form;
146 }
147
148 /*
149 protected function saveSettingsForm()
150 {
151 global $ilCtrl;
152
153 $this->checkPermission("write");
154
155 $form = $this->getSettingsForm();
156 if($form->checkInput())
157 {
158 $obj_types = $form->getInput('types');
159
160 $role = $form->getInput('role');
161
162 $this->object->saveData($obj_types, $role);
163
164 ilUtil::sendSuccess($this->lng->txt("settings_saved"),true);
165 }
166
167 $form->setValuesByPost();
168 $this->initSettingsForm($form);
169 }
170 */
171
172 // consumers
173
174 protected function initConsumerForm(ilPropertyFormGUI $form = null)
175 {
176 if (!($form instanceof ilPropertyFormGUI)) {
177 $form = $this->getConsumerForm();
178 }
179 $this->tpl->setContent($form->getHTML());
180 }
181
186 protected function getConsumerForm($a_mode = '')
187 {
188 $this->tabs_gui->activateTab("consumers");
189
190 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
191
192 $form = new ilPropertyFormGUI();
193
194 $ti_title = new ilTextInputGUI($this->lng->txt("title"), 'title');
195 $ti_title->setRequired(true);
196 $ti_description = new ilTextInputGUI($this->lng->txt("description"), 'description');
197 $ti_prefix = new ilTextInputGUI($this->lng->txt("prefix"), 'prefix');
198 $ti_prefix->setRequired(true);
199 #$ti_key = new ilTextInputGUI($this->lng->txt("lti_consumer_key"), 'key');
200 #$ti_key->setRequired(true);
201 #$ti_secret = new ilTextInputGUI($this->lng->txt("lti_consumer_secret"), 'secret');
202 #$ti_secret->setRequired(true);
203
204 $languages = $this->lng->getInstalledLanguages();
205 $array_lang = array();
206 foreach ($languages as $lang_key) {
207 $array_lang[$lang_key] = ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_" . $lang_key);
208 }
209
210 $si_language = new ilSelectInputGUI($this->lng->txt("language"), "language");
211 $si_language->setOptions($array_lang);
212
213 $cb_active = new ilCheckboxInputGUI($this->lng->txt('active'), 'active');
214
215 $form->addItem($cb_active);
216 $form->addItem($ti_title);
217 $form->addItem($ti_description);
218 $form->addItem($ti_prefix);
219 #$form->addItem($ti_key);
220 #$form->addItem($ti_secret);
221 $form->addItem($si_language);
222
223 // object types
224 $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
225
226 $valid_obj_types = $this->object->getLTIObjectTypes();
227 foreach ($valid_obj_types as $obj_type) {
228 $object_name = $GLOBALS['DIC']->language()->txt('objs_' . $obj_type);
229 $cb_obj_types->addOption(new ilCheckboxOption($object_name, $obj_type));
230 }
231 $form->addItem($cb_obj_types);
232
233 // test roles
234 $roles = $this->object->getLTIRoles();
235 foreach ($roles as $role_id => $role_name) {
236 $options[$role_id] = $role_name;
237 }
238 $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'role');
239 $si_roles->setOptions($options);
240 $form->addItem($si_roles);
241
242 if ($a_mode == 'edit') {
243 $form->setFormAction($this->ctrl->getFormAction($this, 'editLTIConsumer'));
244 $form->setTitle($this->lng->txt("lti_edit_consumer"));
245 $form->addCommandButton("updateLTIConsumer", $this->lng->txt("save"));
246 } else {
247 $form->setFormAction($this->ctrl->getFormAction($this, 'createLTIConsumer'));
248 $form->setTitle($this->lng->txt("lti_create_consumer"));
249 $form->addCommandButton("createLTIConsumer", $this->lng->txt("save"));
250 $form->addCommandButton('listConsumers', $this->lng->txt('cancel'));
251 }
252
253 return $form;
254 }
255
262 protected function editConsumer(ilPropertyFormGUI $a_form = null)
263 {
264 global $ilCtrl, $tpl;
265 $consumer_id = $_REQUEST["cid"];
266 $ilCtrl->setParameter($this, "cid", $consumer_id);
267
268 if (!$consumer_id) {
269 $ilCtrl->redirect($this, "listConsumers");
270 }
271
272 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
273 if (!$a_form instanceof ilPropertyFormGUI) {
274 $a_form = $this->getConsumerForm('edit');
275 $a_form->getItemByPostVar("title")->setValue($consumer->getTitle());
276 $a_form->getItemByPostVar("description")->setValue($consumer->getDescription());
277 $a_form->getItemByPostVar("prefix")->setValue($consumer->getPrefix());
278 $a_form->getItemByPostVar("language")->setValue($consumer->getLanguage());
279 $a_form->getItemByPostVar("active")->setChecked($consumer->getActive());
280 $a_form->getItemByPostVar("role")->setValue($consumer->getRole());
281 $a_form->getItemByPostVar("types")->setValue($this->object->getActiveObjectTypes($consumer_id));
282 }
283 $tpl->setContent($a_form->getHTML());
284 }
285
289 protected function createLTIConsumer()
290 {
291 $this->checkPermission("write");
292
293 $form = $this->getConsumerForm();
294
295 if ($form->checkInput()) {
296 // $consumer = new ilLTIExternalConsumer();
297 // $dataConnector = new ilLTIDataConnector();
298 $consumer = new ilLTIToolConsumer(null, $this->dataConnector);
299 $consumer->setTitle($form->getInput('title'));
300 $consumer->setDescription($form->getInput('description'));
301 $consumer->setPrefix($form->getInput('prefix'));
302 $consumer->setLanguage($form->getInput('language'));
303 $consumer->setActive($form->getInput('active'));
304 $consumer->setRole($form->getInput('role'));
305 $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
306
307 $this->object->saveConsumerObjectTypes(
308 $consumer->getExtConsumerId(),
309 $form->getInput('types')
310 );
311 ilUtil::sendSuccess($this->lng->txt("lti_consumer_created"), true);
312 $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
313 }
314
315 $form->setValuesByPost();
316 $this->listConsumers();
317 return;
318 }
319
324 protected function updateLTIConsumer()
325 {
326 global $ilCtrl;
327
328 $this->checkPermission("write");
329
330 $consumer_id = $_REQUEST["cid"];
331 if (!$consumer_id) {
332 $ilCtrl->redirect($this, "listConsumers");
333 }
334
335 $ilCtrl->setParameter($this, "cid", $consumer_id);
336
337 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
338 $form = $this->getConsumerForm('edit');
339 if ($form->checkInput()) {
340 $consumer->setTitle($form->getInput('title'));
341 $consumer->setDescription($form->getInput('description'));
342 $consumer->setPrefix($form->getInput('prefix'));
343 $consumer->setLanguage($form->getInput('language'));
344 $consumer->setActive($form->getInput('active'));
345 $consumer->setRole($form->getInput('role'));
346 $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
347 $this->object->saveConsumerObjectTypes($consumer_id, $form->getInput('types'));
348
349 ilUtil::sendSuccess($this->lng->txt("lti_consumer_updated"), true);
350 }
351 $this->listConsumers();
352 }
353
358 protected function deleteLTIConsumer()
359 {
360 global $ilCtrl;
361
362 $consumer_id = $_REQUEST['cid'];
363
364 if (!$consumer_id) {
365 $ilCtrl->redirect($this, "listConsumers");
366 }
367 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
368 $consumer->deleteGlobalToolConsumerSettings($this->dataConnector);
369 ilUtil::sendSuccess($this->lng->txt("lti_consumer_deleted"), true);
370 $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
371 }
372
373
379 protected function listConsumers()
380 {
381 global $ilAccess, $ilToolbar;
382
383 if ($this->checkPermissionBool('write')) {
384 $ilToolbar->addButton(
385 $this->lng->txt('lti_create_consumer'),
386 $this->ctrl->getLinkTarget($this, 'createconsumer')
387 );
388 }
389
390 $this->tabs_gui->activateTab("consumers");
391
392 include_once "Services/LTI/classes/Consumer/class.ilLTIConsumerTableGUI.php";
394 $this,
395 "listConsumers"
396 );
397 $tbl->setEditable($this->checkPermissionBool('write'));
398 $this->tpl->setContent($tbl->getHTML());
399 }
400
405 protected function changeStatusLTIConsumer()
406 {
407 global $ilCtrl;
408
409 $consumer_id = $_REQUEST["cid"];
410
411 if (!$consumer_id) {
412 $ilCtrl->redirect($this, "listConsumers");
413 }
414
415 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
416 if ($consumer->getActive()) {
417 $consumer->setActive(0);
418 $msg = "lti_consumer_set_inactive";
419 } else {
420 $consumer->setActive(1);
421 $msg = "lti_consumer_set_active";
422 }
423 $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
424 ilUtil::sendSuccess($this->lng->txt($msg), true);
425
426 $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
427 }
428
432 protected function releasedObjects()
433 {
434 $GLOBALS['DIC']->tabs()->activateTab('releasedObjects');
435
436 $table = new ilLTIProviderReleasedObjectsTableGUI($this, 'releasedObjects', 'ltireleases');
437 $table->init();
438 $table->parse();
439
440 $GLOBALS['DIC']->ui()->mainTemplate()->setContent($table->getHTML());
441 }
442}
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
Class to represent an LTI Data Connector for ILIAS.
LTI provider for LTI launch.
static fromExternalConsumerId($id, $dataConnector)
static _lookupEntry($a_lang_key, $a_mod, $a_id)
Class ilObjLTIAdministrationGUI.
editConsumer(ilPropertyFormGUI $a_form=null)
Edit consumer @global type $ilCtrl @global type $tpl.
getAdminTabs()
administration tabs show only permissions and trash folder
deleteLTIConsumer()
Delete consumers @global type $ilCtrl.
initConsumerForm(ilPropertyFormGUI $form=null)
$dataConnector
Data connector object or string.
updateLTIConsumer()
Update lti consumer settings @global ilCtrl $ilCtrl.
createLTIConsumer()
Create new lti consumer.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
listConsumers()
List consumers @global type $ilAccess @global type $ilToolbar.
changeStatusLTIConsumer()
Change activation status @global type $ilCtrl.
initSettingsForm(ilPropertyFormGUI $form=null)
TableGUI class for LTI consumer listing.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$consumer
Definition: demo.php:30
$tbl
Definition: example_048.php:81
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_POST['submit'])) $form