ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_once("./Services/Object/classes/class.ilObject2GUI.php");
5 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
6 include_once("class.ilCloudPluginFileTreeGUI.php");
7 include_once("class.ilCloudFileTree.php");
8 include_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":
175  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, ilCloudFileTree::getFileTreeFromSession());
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 
212  $content = explode("_", $a_target);
213 
214  $_GET["ref_id"] = $content[0];
215  $_GET["baseClass"] = "ilrepositorygUI";
216  $_GET["cmdClass"] = "ilobjcloudgui";
217  $_GET["cmd"] = "render";
218 
219  if (in_array("path", $content)) {
220  // remove ref_id, "path" und "endPath"
221  unset($content[0]);
222  unset($content[1]);
223  array_pop($content);
224  // reconstruct and set path
225  $_POST["path"] = implode('_', $content);
226  }
227 
228 
229  include("ilias.php");
230  }
231 
232 
233  public function infoScreen()
234  {
235  return false;
236  }
237 
238 
239  public function setTabs()
240  {
241  global $DIC;
242  $ilTabs = $DIC['ilTabs'];
243  $ilCtrl = $DIC['ilCtrl'];
244  $ilAccess = $DIC['ilAccess'];
245  $lng = $DIC['lng'];
246 
247  // tab for the "show content" command
248  if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
249  $ilTabs->addTab("content", $lng->txt("content"), $ilCtrl->getLinkTarget($this, "render"));
250  $ilTabs->addTab("id_info", $lng->txt("info_short"), $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
251  }
252 
253  // a "properties" tab
254  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
255  $ilTabs->addTab("settings", $lng->txt("settings"), $ilCtrl->getLinkTargetByClass("ilcloudpluginsettingsgui", "editSettings"));
256  }
257 
258  // edit permissions
259  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
260  $ilTabs->addTab("id_permissions", $lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
261  }
262  }
263 
264 
268  public function getCtrl()
269  {
270  return $this->ctrl;
271  }
272 
273 
277  public function setCtrl(\ilCtrl $ctrl)
278  {
279  $this->ctrl = $ctrl;
280  }
281 
282 
286  public function infoScreenForward()
287  {
288  global $DIC;
289  $ilTabs = $DIC['ilTabs'];
290  $ilErr = $DIC['ilErr'];
291 
292  $ilTabs->activateTab("id_info");
293 
294  if (!$this->checkPermissionBool("visible")) {
295  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
296  }
297 
298  $plugin_info = ilCloudConnector::getInfoScreenGUIClass($this->plugin_service);
299  $info = $plugin_info->getInfoScreen($this);
300  $this->ctrl->forwardCommand($info);
301  }
302 
303 
313  protected function initCreationForms($a_new_type)
314  {
315  $forms = array(
316  self::CFORM_NEW => $this->initCreateForm($a_new_type),
317  );
318 
319  return $forms;
320  }
321 
322 
330  protected function initCreateForm($a_new_type)
331  {
332  global $DIC;
333  $lng = $DIC['lng'];
334 
335  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
336  $form = new ilPropertyFormGUI();
337  $form->setTarget("_top");
338  $this->ctrl->setParameter($this, 'new_type', 'cld');
339  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
340  $form->setTitle($this->lng->txt($a_new_type . "_new"));
341 
342  // title
343  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
344  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
345  $ti->setMaxLength(ilObject::TITLE_LENGTH);
346  $ti->setRequired(true);
347  $form->addItem($ti);
348 
349  // description
350  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
351  $ta->setCols(40);
352  $ta->setRows(2);
353  $form->addItem($ta);
354 
355  $services_group = new ilRadioGroupInputGUI($lng->txt("cld_service"), "service");
356  $services_group->setRequired(true);
358  $option = new ilRadioOption($service, $service);
359  $hook_object = ilCloudConnector::getPluginHookClass($option->getValue());
360  $option->setTitle($hook_object->txt($service));
361  $option->setInfo($hook_object->txt("create_info"));
362  $this->plugin_service = ilCloudConnector::getServiceClass($service, 0, false);
363  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
364  if ($init_gui) {
365  $init_gui->initPluginCreationFormSection($option);
366  }
367  $services_group->addOption($option);
368  }
369 
370  //Select first radio-button by default
371  $services_group->setValue(array_shift($services_group->getOptions())->getValue());
372 
373  $form->addItem($services_group);
374 
375  $form = $this->initDidacticTemplate($form);
376 
377  $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
378  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
379 
380  return $form;
381  }
382 
383 
387  protected function afterSave(ilObject $a_new_object)
388  {
389  assert($a_new_object instanceof ilObjCloud);
393  try {
394  $this->ctrl->setParameter($this, 'ref_id', $this->tree->getParentId($a_new_object->getRefId()));
395  $form = $this->initCreateForm("cld");
396  $this->ctrl->setParameter($this, 'ref_id', $a_new_object->getRefId());
397 
398  if ($form->checkInput()) {
399  $a_new_object->setServiceName($form->getInput("service"));
400  $a_new_object->setRootFolder("/");
401  $a_new_object->setOnline(false);
402  $a_new_object->setAuthComplete(false);
403  $this->plugin_service = new ilCloudPluginService($a_new_object->getServiceName(), $a_new_object->getId());
404  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
405  if ($init_gui) {
406  $init_gui->afterSavePluginCreation($a_new_object, $form);
407  }
408  $a_new_object->update();
409  $this->ctrl->setParameter($this, 'new_type', '');
410  $this->serviceAuth($a_new_object);
411  }
412  } catch (Exception $e) {
413  ilUtil::sendFailure($e->getMessage(), true);
414  $form->setValuesByPost();
415  $this->tpl->setContent($form->getHTML());
416  }
417  }
418 
419 
423  protected function serviceAuth(ilObjCloud $object)
424  {
425  global $DIC;
426  $ilCtrl = $DIC['ilCtrl'];
427  try {
429  $service->authService($ilCtrl->getLinkTarget($this, "afterServiceAuth") . "&authMode=true");
430  } catch (Exception $e) {
431  ilUtil::sendFailure($e->getMessage(), true);
432  ilObjectGUI::redirectToRefId($this->parent_id);
433  }
434  }
435 
436 
437  protected function afterServiceAuth()
438  {
439  global $DIC;
440  $ilCtrl = $DIC['ilCtrl'];
441  $lng = $DIC['lng'];
442 
443  try {
444  if ($this->plugin_service->afterAuthService()) {
445  $this->object->setRootId("root", true);
446  $this->object->setAuthComplete(true);
447  $this->object->update();
448  ilUtil::sendSuccess($lng->txt("cld_object_added"), true);
449  $ilCtrl->redirectByClass("ilCloudPluginSettingsGUI", "editSettings");
450  } else {
451  include_once("./Services/Repository/classes/class.ilRepUtil.php");
452  ilRepUtil::deleteObjects($this->object->getRefId(), $this->object->getRefId());
453 
454  ilUtil::sendFailure($lng->txt("cld_auth_failed_no_object_created"), true);
455  ilObjectGUI::redirectToRefId($this->parent_id);
456  }
457  } catch (Exception $e) {
458  ilUtil::sendFailure($e->getMessage(), true);
459  ilObjectGUI::redirectToRefId($this->parent_id);
460  }
461  }
462 
463 
467  protected function addHeaderAction()
468  {
469  $lg = $this->initHeaderAction();
470  if ($lg) {
471  $header_action_class = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
472  $header_action_class->addCustomHeaderAction($lg);
473  $this->insertHeaderAction($lg);
474  }
475  }
476 
477 
481  protected function addLocatorItems()
482  {
483  global $DIC;
484  $ilLocator = $DIC['ilLocator'];
485 
486  if (is_object($this->object)) {
487  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
488  }
489  }
490 
491 
492  public function render()
493  {
494  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
495  $init_gui->initGUI($this, $this->checkPermissionBool("folders_create"), $this->checkPermissionBool("upload"), $this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $this->checkPermissionBool("download"), $this->checkPermissionBool("files_visible"), $this->checkPermissionBool("folders_visible"));
496  }
497 
498 
499  public function asyncGetBlock()
500  {
501  global $DIC;
502  $tpl = $DIC['tpl'];
503 
504  $response = new stdClass();
505  $response->message = null;
506  $response->locator = null;
507  $response->content = null;
508  $response->success = null;
509 
510  try {
512  $file_tree->updateFileTree($_POST["path"]);
513  $node = $file_tree->getNodeFromPath($_POST["path"]);
514  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, $file_tree);
515  $response->content = $file_tree_gui->getFolderHtml($this, $node->getId(), $this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $this->checkPermissionBool("download"), $this->checkPermissionBool("files_visible"), $this->checkPermissionBool("folders_visible"));
516 
517  $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
518  $response->success = true;
519  } catch (Exception $e) {
520  $response->message = $tpl->getMessageHTML($e->getMessage(), "failure");
521  }
522 
523  header('Content-type: application/json');
525  exit;
526  }
527 
528 
529  public function getFile()
530  {
531  global $DIC;
532  $ilTabs = $DIC['ilTabs'];
533  if ($this->checkPermissionBool("download")) {
534  try {
536  $file_tree->downloadFromService($_GET['id']);
537  } catch (Exception $e) {
538  $ilTabs->activateTab("content");
539  ilUtil::sendFailure($e->getMessage());
540  }
541  }
542  }
543 
544 
545  public function asyncGetActionListContent()
546  {
547  $action_list = ilCloudConnector::getActionListGUIClass($this->plugin_service);
549 
550  return $action_list->asyncGetContent($this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $file_tree->getNodeFromId($_GET["node_id"]));
551  }
552 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
$lg
Definition: example_018.php:62
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
This class provides processing control methods.
getStandardCmd()
Get standard command.
setCtrl(\ilCtrl $ctrl)
serviceAuth(ilObjCloud $object)
This class represents a property form user interface.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_node_id=null)
Check permission.
static getActionListGUIClass(ilCloudPluginService $plugin_service_class)
New implementation of ilObjectGUI.
global $DIC
Definition: saml.php:7
const TITLE_LENGTH
max length of object title
$_GET["client_id"]
static getInitGUIClass(ilCloudPluginService $plugin_service_class)
static getDeleteGUIClass(ilCloudPluginService $plugin_service_class)
static getUploadGUIClass(ilCloudPluginService $plugin_service_class)
afterSave(ilObject $a_new_object)
Post (successful) object creation hook.
static getCreateFolderGUIClass(ilCloudPluginService $plugin_service_class)
$service
Definition: login.php:15
static getFileTreeGUIClass(ilCloudPluginService $plugin_service_class, ilCloudFileTree $file_tree)
initHeaderAction($a_sub_type=null, $a_sub_id=null)
Add header action menu.
$plugin_service
ilCloudPluginService
Class ilObjCloudGUI.
addLocatorItems()
addLocatorItems
global $ilCtrl
Definition: ilias.php:18
This class represents a property in a property form.
static encode($mixed, $suppress_native=false)
if(isset($_POST['submit'])) $form
getId()
get object id public
initDidacticTemplate(ilPropertyFormGUI $form)
Show didactic template types.
setSize($a_size)
Set Size.
This class represents a text property in a property form.
initCreateForm($a_new_type)
Init object creation form.
static _goto($a_target)
_goto Deep link
static checkServiceActive($name)
Add a drawing to the header
Definition: 04printing.php:69
Class ilCloudPluginService.
Create styles array
The data for the language used.
initCreationForms($a_new_type)
Init creation froms.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getPluginHookClass($service_name)
addHeaderAction()
Add header action menu.
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...
Create new PHPExcel object
obj_idprivate
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
This class represents a text area property in a property form.
static getHeaderActionGUIClass(ilCloudPluginService $plugin_service_class)
static getServiceClass($service_name, $obj_id, $connect=true)
insertHeaderAction($a_list_gui)
Insert header action into main template.
static getInfoScreenGUIClass(ilCloudPluginService $plugin_service_class)
static getSettingsGUIClass(ilCloudPluginService $plugin_service_class)
Class ilObjCloud.
getRefId()
get reference id public
prepareOutput($a_show_subobjects=true)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static getCreationGUIClass(ilCloudPluginService $plugin_service_class)
infoScreenForward()
show information screen
static getItemCreationListGUIClass(ilCloudPluginService $plugin_service_class)
update()
update object in db
$info
Definition: index.php:5
$response
$_POST["username"]
getServiceName()
Get service.
setRequired($a_required)
Set Required.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static deleteObjects($a_cur_ref_id, $a_ids)
Delete objects.