ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjCloudGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Object/classes/class.ilObject2GUI.php");
5include_once("./Services/JSON/classes/class.ilJsonUtil.php");
6include_once("class.ilCloudPluginFileTreeGUI.php");
7include_once("class.ilCloudFileTree.php");
8include_once("class.ilCloudConnector.php");
9
24{
25
29 protected $plugin_service;
33 protected $ctrl;
34
35
41 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
42 {
43 global $DIC;
44 $lng = $DIC['lng'];
45
46 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
47 $lng->loadLanguageModule("cld");
48 }
49
50
54 final public function getType()
55 {
56 return "cld";
57 }
58
59
64 public function executeCommand()
65 {
66 global $DIC;
67 $ilCtrl = $DIC['ilCtrl'];
68 $ilTabs = $DIC['ilTabs'];
69 $ilNavigationHistory = $DIC['ilNavigationHistory'];
70 $lng = $DIC['lng'];
71
72 // Navigation History
73 $link = $ilCtrl->getLinkTarget($this, "render");
74
75 try {
77 } catch (Exception $e) {
78 ilUtil::sendFailure($lng->txt("cld_no_service_active"), true);
79 ilObjectGUI::redirectToRefId($this->parent_id);
80 }
81
82 if ($this->object != null) {
83 $ilNavigationHistory->addItem($this->object->getRefId(), $link, "cld");
84
85 try {
86 ilCloudConnector::checkServiceActive($this->object->getServiceName());
87 } catch (Exception $e) {
88 ilUtil::sendFailure($lng->txt("cld_plugin_not_active"), true);
89 ilObjectGUI::redirectToRefId($this->parent_id);
90 }
91
92 if ($this->object->getAuthComplete() == false && !$_GET["authMode"]) {
93 if ($this->checkPermissionBool("write")) {
94 $this->serviceAuth($this->object);
95 } else {
96 ilUtil::sendFailure($lng->txt("cld_auth_failed"), true);
97 ilObjectGUI::redirectToRefId($this->parent_id);
98 }
99 }
100 $this->plugin_service = ilCloudConnector::getServiceClass($this->object->getServiceName(), $this->object->getId(), false);
101 }
102
103 $next_class = $ilCtrl->getNextClass($this);
104
105 $cmd = $ilCtrl->getCmd($this);
106 switch ($cmd) {
107 case "editSettings":
108 $next_class = "ilcloudpluginsettingsgui";
109 break;
110 case "afterServiceAuth":
111 $this->checkPermission("write");
112 $this->$cmd();
113
114 return;
115 case "render":
116 $this->addHeaderAction();
117 break;
118 case 'infoScreen':
119 $this->ctrl->redirectByClass(ilInfoScreenGUI::class);
120 break;
121 }
122
123 switch ($next_class) {
124 case "ilinfoscreengui":
125 $this->prepareOutput();
126 $this->infoScreenForward();
127 break;
128 case "ilcommonactiondispatchergui":
129 include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
131 $this->ctrl->forwardCommand($gui);
132 break;
133 case "ilpermissiongui":
134 $this->prepareOutput();
135 $ilTabs->activateTab("id_permissions");
136 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
137 $perm_gui = new ilPermissionGUI($this);
138 $this->ctrl->forwardCommand($perm_gui);
139 break;
140 case "ilcloudpluginuploadgui":
141 if ($this->checkPermissionBool("upload")) {
142 $upload_gui = ilCloudConnector::getUploadGUIClass($this->plugin_service);
143 $this->ctrl->forwardCommand($upload_gui);
144 }
145 break;
146 case "ilcloudplugincreatefoldergui":
147 if ($this->checkPermissionBool("folders_create")) {
148 $folder_gui = ilCloudConnector::getCreateFolderGUIClass($this->plugin_service);
149 $this->ctrl->forwardCommand($folder_gui);
150 }
151 break;
152 case "ilcloudplugindeletegui":
153 if ($this->checkPermissionBool("delete_files") || $this->checkPermissionBool("delete_folders")) {
154 $delete_gui = ilCloudConnector::getDeleteGUIClass($this->plugin_service);
155 $this->ctrl->forwardCommand($delete_gui);
156 }
157 break;
158 case "ilcloudpluginsettingsgui":
159 $this->prepareOutput();
160 if ($this->checkPermissionBool("write")) {
161 $settings_gui = ilCloudConnector::getSettingsGUIClass($this->plugin_service);
162 $settings_gui->setCloudObject($this->object);
163 $this->ctrl->forwardCommand($settings_gui);
164 }
165 break;
166 case "ilcloudpluginactionlistgui":
167 $action_list_gui = ilCloudConnector::getActionListGUIClass($this->plugin_service);
168 $this->ctrl->forwardCommand($action_list_gui);
169 break;
170 case "ilcloudpluginitemcreationlistgui":
171 $item_creation_gui = ilCloudConnector::getItemCreationListGUIClass($this->plugin_service);
172 $this->ctrl->forwardCommand($item_creation_gui);
173 break;
174 case "ilcloudpluginfiletreegui":
176 $this->ctrl->forwardCommand($file_tree_gui);
177 break;
178 case "ilcloudpluginheaderactiongui":
179 $header_action_gui = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
180 $this->ctrl->forwardCommand($header_action_gui);
181 break;
182 case "ilcloudplugininitgui":
183 $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
184 $this->ctrl->forwardCommand($init_gui);
185 break;
186 default:
187 return parent::executeCommand();
188 }
189
190 return true;
191 }
192
193
197 public function getStandardCmd()
198 {
199 return "render";
200 }
201
202
209 public static function _goto($a_target)
210 {
211 $content = explode("_", $a_target);
212
213 $_GET["ref_id"] = $content[0];
214 $_GET["baseClass"] = "ilrepositorygUI";
215 $_GET["cmdClass"] = "ilobjcloudgui";
216 $_GET["cmd"] = "render";
217
218 if (in_array("path", $content)) {
219 // remove ref_id, "path" und "endPath"
220 unset($content[0]);
221 unset($content[1]);
222 array_pop($content);
223 // reconstruct and set path
224 $_POST["path"] = urldecode(implode('_', $content));
225 }
226
227
228 include("ilias.php");
229 }
230
231
232 public function infoScreen()
233 {
234 return false;
235 }
236
237
238 public function setTabs()
239 {
240 global $DIC;
241 $ilTabs = $DIC['ilTabs'];
242 $ilCtrl = $DIC['ilCtrl'];
243 $ilAccess = $DIC['ilAccess'];
244 $lng = $DIC['lng'];
245
246 // tab for the "show content" command
247 if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
248 $ilTabs->addTab("content", $lng->txt("content"), $ilCtrl->getLinkTarget($this, "render"));
249 $ilTabs->addTab("id_info", $lng->txt("info_short"), $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
250 }
251
252 // a "properties" tab
253 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
254 $ilTabs->addTab("settings", $lng->txt("settings"), $ilCtrl->getLinkTargetByClass("ilcloudpluginsettingsgui", "editSettings"));
255 }
256
257 // edit permissions
258 if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
259 $ilTabs->addTab("id_permissions", $lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
260 }
261 }
262
263
267 public function getCtrl()
268 {
269 return $this->ctrl;
270 }
271
272
276 public function setCtrl(\ilCtrl $ctrl)
277 {
278 $this->ctrl = $ctrl;
279 }
280
281
285 public function infoScreenForward()
286 {
287 global $DIC;
288 $ilTabs = $DIC['ilTabs'];
289 $ilErr = $DIC['ilErr'];
290
291 $ilTabs->activateTab("id_info");
292
293 if (!$this->checkPermissionBool("visible")) {
294 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
295 }
296
297 $plugin_info = ilCloudConnector::getInfoScreenGUIClass($this->plugin_service);
298 $info = $plugin_info->getInfoScreen($this);
299 $this->ctrl->forwardCommand($info);
300 }
301
302
312 protected function initCreationForms($a_new_type)
313 {
314 $forms = array(
315 self::CFORM_NEW => $this->initCreateForm($a_new_type),
316 );
317
318 return $forms;
319 }
320
321
329 protected function initCreateForm($a_new_type)
330 {
331 global $DIC;
332 $lng = $DIC['lng'];
333
334 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
335 $form = new ilPropertyFormGUI();
336 $form->setTarget("_top");
337 $this->ctrl->setParameter($this, 'new_type', 'cld');
338 $form->setFormAction($this->ctrl->getFormAction($this, "save"));
339 $form->setTitle($this->lng->txt($a_new_type . "_new"));
340
341 // title
342 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
343 $ti->setSize(min(40, ilObject::TITLE_LENGTH));
344 $ti->setMaxLength(ilObject::TITLE_LENGTH);
345 $ti->setRequired(true);
346 $form->addItem($ti);
347
348 // description
349 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
350 $ta->setCols(40);
351 $ta->setRows(2);
352 $form->addItem($ta);
353
354 $services_group = new ilRadioGroupInputGUI($lng->txt("cld_service"), "service");
355 $services_group->setRequired(true);
357 $option = new ilRadioOption($service, $service);
358 $hook_object = ilCloudConnector::getPluginHookClass($option->getValue());
359 $option->setTitle($hook_object->txt($service));
360 $option->setInfo($hook_object->txt("create_info"));
361 $this->plugin_service = ilCloudConnector::getServiceClass($service, 0, false);
362 $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
363 if ($init_gui) {
364 $init_gui->initPluginCreationFormSection($option);
365 }
366 $services_group->addOption($option);
367 }
368
369 //Select first radio-button by default
370 $services_group->setValue(array_shift($services_group->getOptions())->getValue());
371
372 $form->addItem($services_group);
373
374 $form = $this->initDidacticTemplate($form);
375
376 $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
377 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
378
379 return $form;
380 }
381
382
386 protected function afterSave(ilObject $a_new_object)
387 {
388 assert($a_new_object instanceof ilObjCloud);
392 try {
393 $this->ctrl->setParameter($this, 'ref_id', $this->tree->getParentId($a_new_object->getRefId()));
394 $form = $this->initCreateForm("cld");
395 $this->ctrl->setParameter($this, 'ref_id', $a_new_object->getRefId());
396
397 if ($form->checkInput()) {
398 $a_new_object->setServiceName($form->getInput("service"));
399 $a_new_object->setRootFolder("/");
400 $a_new_object->setOnline(false);
401 $a_new_object->setAuthComplete(false);
402 $this->plugin_service = new ilCloudPluginService($a_new_object->getServiceName(), $a_new_object->getId());
403 $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
404 if ($init_gui) {
405 $init_gui->afterSavePluginCreation($a_new_object, $form);
406 }
407 $a_new_object->update();
408 $this->ctrl->setParameter($this, 'new_type', '');
409 $this->serviceAuth($a_new_object);
410 }
411 } catch (Exception $e) {
412 ilUtil::sendFailure($e->getMessage(), true);
413 $form->setValuesByPost();
414 $this->tpl->setContent($form->getHTML());
415 }
416 }
417
418
422 protected function serviceAuth(ilObjCloud $object)
423 {
424 global $DIC;
425 $ilCtrl = $DIC['ilCtrl'];
426 try {
427 $service = ilCloudConnector::getServiceClass($object->getServiceName(), $object->getId());
428 $service->authService($ilCtrl->getLinkTarget($this, "afterServiceAuth") . "&authMode=true");
429 } catch (Exception $e) {
430 ilUtil::sendFailure($e->getMessage(), true);
431 ilObjectGUI::redirectToRefId($this->parent_id);
432 }
433 }
434
435
436 protected function afterServiceAuth()
437 {
438 global $DIC;
439 $ilCtrl = $DIC['ilCtrl'];
440 $lng = $DIC['lng'];
441
442 try {
443 if ($this->plugin_service->afterAuthService()) {
444 $this->object->setRootId("root", true);
445 $this->object->setAuthComplete(true);
446 $this->object->update();
447 ilUtil::sendSuccess($lng->txt("cld_object_added"), true);
448 $ilCtrl->redirectByClass("ilCloudPluginSettingsGUI", "editSettings");
449 } else {
450 include_once("./Services/Repository/classes/class.ilRepUtil.php");
451 ilRepUtil::deleteObjects($this->object->getRefId(), $this->object->getRefId());
452
453 ilUtil::sendFailure($lng->txt("cld_auth_failed_no_object_created"), true);
454 ilObjectGUI::redirectToRefId($this->parent_id);
455 }
456 } catch (Exception $e) {
457 ilUtil::sendFailure($e->getMessage(), true);
458 ilObjectGUI::redirectToRefId($this->parent_id);
459 }
460 }
461
462
466 protected function addHeaderAction()
467 {
468 $lg = $this->initHeaderAction();
469 if ($lg) {
470 $header_action_class = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
471 $header_action_class->addCustomHeaderAction($lg);
472 $this->insertHeaderAction($lg);
473 }
474 }
475
476
480 protected function addLocatorItems()
481 {
482 global $DIC;
483 $ilLocator = $DIC['ilLocator'];
484
485 if (is_object($this->object)) {
486 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
487 }
488 }
489
490
491 public function render()
492 {
493 $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
494 $init_gui->initGUI(
495 $this,
496 $this->checkPermissionBool("folders_create"),
497 $this->checkPermissionBool("upload"),
498 $this->checkPermissionBool("delete_files"),
499 $this->checkPermissionBool("delete_folders"),
500 $this->checkPermissionBool("download"),
501 $this->checkPermissionBool("files_visible"),
502 $this->checkPermissionBool("folders_visible")
503 );
504 }
505
506
507 public function asyncGetBlock()
508 {
509 global $DIC;
510 $tpl = $DIC['tpl'];
511
512 $response = new stdClass();
513 $response->message = null;
514 $response->locator = null;
515 $response->content = null;
516 $response->success = null;
517
518 try {
520 $file_tree->updateFileTree($_POST["path"]);
521 $node = $file_tree->getNodeFromPath($_POST["path"]);
522 $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, $file_tree);
523 $response->content = $file_tree_gui->getFolderHtml(
524 $this,
525 $node->getId(),
526 $this->checkPermissionBool("delete_files"),
527 $this->checkPermissionBool("delete_folders"),
528 $this->checkPermissionBool("download"),
529 $this->checkPermissionBool("files_visible"),
530 $this->checkPermissionBool("folders_visible")
531 );
532
533 $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
534 $response->success = true;
535 } catch (Exception $e) {
536 $response->message = ilUtil::getSystemMessageHTML($e->getMessage(), "failure");
537 }
538
539 header('Content-type: application/json');
541 exit;
542 }
543
544
545 public function getFile()
546 {
547 global $DIC;
548 $ilTabs = $DIC['ilTabs'];
549 if ($this->checkPermissionBool("download")) {
550 try {
552 $file_tree->downloadFromService($_GET['id']);
553 } catch (Exception $e) {
554 $ilTabs->activateTab("content");
555 ilUtil::sendFailure($e->getMessage());
556 }
557 }
558 }
559
560
562 {
563 $action_list = ilCloudConnector::getActionListGUIClass($this->plugin_service);
565
566 return $action_list->asyncGetContent($this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $file_tree->getNodeFromId($_GET["node_id"]));
567 }
568}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static getHeaderActionGUIClass(ilCloudPluginService $plugin_service_class)
static checkServiceActive($name)
static getInfoScreenGUIClass(ilCloudPluginService $plugin_service_class)
static getCreationGUIClass(ilCloudPluginService $plugin_service_class)
static getServiceClass($service_name, $obj_id, $connect=true)
static getInitGUIClass(ilCloudPluginService $plugin_service_class)
static getFileTreeGUIClass(ilCloudPluginService $plugin_service_class, ilCloudFileTree $file_tree)
static getCreateFolderGUIClass(ilCloudPluginService $plugin_service_class)
static getActionListGUIClass(ilCloudPluginService $plugin_service_class)
static getPluginHookClass($service_name)
static getUploadGUIClass(ilCloudPluginService $plugin_service_class)
static getItemCreationListGUIClass(ilCloudPluginService $plugin_service_class)
static getSettingsGUIClass(ilCloudPluginService $plugin_service_class)
static getDeleteGUIClass(ilCloudPluginService $plugin_service_class)
Class ilCloudPluginService.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
This class provides processing control methods.
static encode($mixed, $suppress_native=false)
Class ilObjCloudGUI.
addHeaderAction()
Add header action menu.
$plugin_service
ilCloudPluginService
setTabs()
create tabs (repository/workspace switch)
infoScreenForward()
show information screen
serviceAuth(ilObjCloud $object)
static _goto($a_target)
_goto Deep link
initCreateForm($a_new_type)
Init object creation form.
getStandardCmd()
Get standard command.
addLocatorItems()
addLocatorItems
setCtrl(\ilCtrl $ctrl)
initCreationForms($a_new_type)
Init creation froms.
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Class ilObjCloud.
New implementation of ilObjectGUI.
prepareOutput($a_show_subobjects=true)
prepare output
initHeaderAction($a_sub_type=null, $a_sub_id=null)
Add header action menu.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_node_id=null)
Check permission.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
insertHeaderAction($a_list_gui)
Insert header action into main template.
afterSave(ilObject $a_new_object)
Post (successful) object creation hook.
initDidacticTemplate(ilPropertyFormGUI $form)
Show didactic template types.
redirectToRefId($a_ref_id, $a_cmd="")
redirects to (repository) view per ref id usually to a container and usually used at the end of a sav...
Class ilObject Basic functions for all objects.
const TITLE_LENGTH
max length of object title
update()
update object in db
getRefId()
get reference id @access public
getId()
get object id @access public
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
static deleteObjects($a_cur_ref_id, $a_ids)
Delete objects.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getSystemMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$response
$service
Definition: result.php:17
$DIC
Definition: xapitoken.php:46