ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
23 class ilObjCloudGUI extends ilObject2GUI {
24 
28  protected $plugin_service;
32  protected $ctrl;
33 
34 
40  public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0) {
41  global $DIC;
42  $lng = $DIC['lng'];
43 
44  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
45  $lng->loadLanguageModule("cld");
46  }
47 
48 
52  final function getType() {
53  return "cld";
54  }
55 
56 
61  public function executeCommand() {
62  global $DIC;
63  $ilCtrl = $DIC['ilCtrl'];
64  $ilTabs = $DIC['ilTabs'];
65  $ilNavigationHistory = $DIC['ilNavigationHistory'];
66  $lng = $DIC['lng'];
67 
68  // Navigation History
69  $link = $ilCtrl->getLinkTarget($this, "render");
70 
71  try {
73  } catch (Exception $e) {
74  ilUtil::sendFailure($lng->txt("cld_no_service_active"), true);
75  ilObjectGUI::redirectToRefId($this->parent_id);
76  }
77 
78  if ($this->object != null) {
79  $ilNavigationHistory->addItem($this->object->getRefId(), $link, "cld");
80 
81  try {
82  ilCloudConnector::checkServiceActive($this->object->getServiceName());
83  } catch (Exception $e) {
84  ilUtil::sendFailure($lng->txt("cld_plugin_not_active"), true);
85  ilObjectGUI::redirectToRefId($this->parent_id);
86  }
87 
88  if ($this->object->getAuthComplete() == false && !$_GET["authMode"]) {
89  if ($this->checkPermissionBool("write")) {
90  $this->serviceAuth($this->object);
91  } else {
92  ilUtil::sendFailure($lng->txt("cld_auth_failed"), true);
93  ilObjectGUI::redirectToRefId($this->parent_id);
94  }
95  }
96  $this->plugin_service = ilCloudConnector::getServiceClass($this->object->getServiceName(), $this->object->getId(), false);
97  }
98 
99  $next_class = $ilCtrl->getNextClass($this);
100 
101  $cmd = $ilCtrl->getCmd($this);
102  switch ($cmd) {
103  case "editSettings" :
104  $next_class = "ilcloudpluginsettingsgui";
105  break;
106  case "afterServiceAuth" :
107  $this->checkPermission("write");
108  $this->$cmd();
109 
110  return;
111  case "render" :
112  $this->addHeaderAction();
113  break;
114  }
115 
116  switch ($next_class) {
117  case "ilinfoscreengui":
118  $this->prepareOutput();
119  $this->infoScreenForward();
120  break;
121  case "ilcommonactiondispatchergui":
122  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
124  $this->ctrl->forwardCommand($gui);
125  break;
126  case "ilpermissiongui":
127  $this->prepareOutput();
128  $ilTabs->activateTab("id_permissions");
129  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
130  $perm_gui = new ilPermissionGUI($this);
131  $this->ctrl->forwardCommand($perm_gui);
132  break;
133  case "ilcloudpluginuploadgui":
134  if ($this->checkPermissionBool("upload")) {
135  $upload_gui = ilCloudConnector::getUploadGUIClass($this->plugin_service);
136  $this->ctrl->forwardCommand($upload_gui);
137  }
138  break;
139  case "ilcloudplugincreatefoldergui":
140  if ($this->checkPermissionBool("folders_create")) {
141  $folder_gui = ilCloudConnector::getCreateFolderGUIClass($this->plugin_service);
142  $this->ctrl->forwardCommand($folder_gui);
143  }
144  break;
145  case "ilcloudplugindeletegui":
146  if ($this->checkPermissionBool("delete_files") || $this->checkPermissionBool("delete_folders")) {
147  $delete_gui = ilCloudConnector::getDeleteGUIClass($this->plugin_service);
148  $this->ctrl->forwardCommand($delete_gui);
149  }
150  break;
151  case "ilcloudpluginsettingsgui":
152  $this->prepareOutput();
153  if ($this->checkPermissionBool("write")) {
154  $settings_gui = ilCloudConnector::getSettingsGUIClass($this->plugin_service);
155  $settings_gui->setCloudObject($this->object);
156  $this->ctrl->forwardCommand($settings_gui);
157  }
158  break;
159  case "ilcloudpluginactionlistgui":
160  $action_list_gui = ilCloudConnector::getActionListGUIClass($this->plugin_service);
161  $this->ctrl->forwardCommand($action_list_gui);
162  break;
163  case "ilcloudpluginitemcreationlistgui":
164  $item_creation_gui = ilCloudConnector::getItemCreationListGUIClass($this->plugin_service);
165  $this->ctrl->forwardCommand($item_creation_gui);
166  break;
167  case "ilcloudpluginfiletreegui":
168  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, ilCloudFileTree::getFileTreeFromSession());
169  $this->ctrl->forwardCommand($file_tree_gui);
170  break;
171  case "ilcloudpluginheaderactiongui":
172  $header_action_gui = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
173  $this->ctrl->forwardCommand($header_action_gui);
174  break;
175  case "ilcloudplugininitgui":
176  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
177  $this->ctrl->forwardCommand($init_gui);
178  break;
179  default:
180  return parent::executeCommand();
181  }
182 
183  return true;
184  }
185 
186 
190  function getStandardCmd() {
191  return "render";
192  }
193 
194 
201  public static function _goto($a_target) {
202  $content = explode("_", $a_target);
203  $_GET["ref_id"] = $content[0];
204  $_POST["path"] = $content[2];
205  $_GET["baseClass"] = "ilrepositorygUI";
206  $_GET["cmdClass"] = "ilobjcloudgui";
207  $_GET["cmd"] = "render";
208  include("ilias.php");
209  }
210 
211 
212  public function infoScreen() {
213  return false;
214  }
215 
216 
217  public function setTabs() {
218  global $DIC;
219  $ilTabs = $DIC['ilTabs'];
220  $ilCtrl = $DIC['ilCtrl'];
221  $ilAccess = $DIC['ilAccess'];
222  $lng = $DIC['lng'];
223 
224  // tab for the "show content" command
225  if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
226  $ilTabs->addTab("content", $lng->txt("content"), $ilCtrl->getLinkTarget($this, "render"));
227  $ilTabs->addTab("id_info", $lng->txt("info_short"), $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
228  }
229 
230  // a "properties" tab
231  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
232  $ilTabs->addTab("settings", $lng->txt("settings"), $ilCtrl->getLinkTargetByClass("ilcloudpluginsettingsgui", "editSettings"));
233  }
234 
235  // edit permissions
236  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
237  $ilTabs->addTab("id_permissions", $lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
238  }
239  }
240 
241 
245  public function getCtrl() {
246  return $this->ctrl;
247  }
248 
249 
253  public function setCtrl(\ilCtrl $ctrl) {
254  $this->ctrl = $ctrl;
255  }
256 
257 
261  public function infoScreenForward() {
262  global $DIC;
263  $ilTabs = $DIC['ilTabs'];
264  $ilErr = $DIC['ilErr'];
265 
266  $ilTabs->activateTab("id_info");
267 
268  if (!$this->checkPermissionBool("visible")) {
269  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
270  }
271 
272  $plugin_info = ilCloudConnector::getInfoScreenGUIClass($this->plugin_service);
273  $info = $plugin_info->getInfoScreen($this);
274  $this->ctrl->forwardCommand($info);
275  }
276 
277 
287  protected function initCreationForms($a_new_type) {
288  $forms = array(
289  self::CFORM_NEW => $this->initCreateForm($a_new_type),
290  );
291 
292  return $forms;
293  }
294 
295 
303  protected function initCreateForm($a_new_type) {
304  global $DIC;
305  $lng = $DIC['lng'];
306 
307  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
308  $form = new ilPropertyFormGUI();
309  $form->setTarget("_top");
310  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
311  $form->setTitle($this->lng->txt($a_new_type . "_new"));
312 
313  // title
314  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
315  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
316  $ti->setMaxLength(ilObject::TITLE_LENGTH);
317  $ti->setRequired(true);
318  $form->addItem($ti);
319 
320  // description
321  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
322  $ta->setCols(40);
323  $ta->setRows(2);
324  $form->addItem($ta);
325 
326  $services_group = new ilRadioGroupInputGUI($lng->txt("cld_service"), "service");
327  $services_group->setRequired(true);
328  foreach (ilCloudConnector::getActiveServices() as $service) {
329  $option = new ilRadioOption($service, $service);
330  $hook_object = ilCloudConnector::getPluginHookClass($option->getValue());
331  $option->setTitle($hook_object->txt($service));
332  $option->setInfo($hook_object->txt("create_info"));
333  $this->plugin_service = ilCloudConnector::getServiceClass($service, 0, false);
334  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
335  if ($init_gui) {
336  $init_gui->initPluginCreationFormSection($option);
337  }
338  $services_group->addOption($option);
339  }
340 
341  //Select first radio-button by default
342  $services_group->setValue(array_shift($services_group->getOptions())->getValue());
343 
344  $form->addItem($services_group);
345 
346  $form = $this->initDidacticTemplate($form);
347 
348  $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
349  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
350 
351  return $form;
352  }
353 
354 
358  protected function afterSave(ilObject $a_new_object) {
359  assert($a_new_object instanceof ilObjCloud);
363  try {
364  $form = $this->initCreateForm("cld");
365 
366  if ($form->checkInput()) {
367  $a_new_object->setServiceName($form->getInput("service"));
368  $a_new_object->setRootFolder("/");
369  $a_new_object->setOnline(false);
370  $a_new_object->setAuthComplete(false);
371  $this->plugin_service = new ilCloudPluginService($a_new_object->getServiceName(), $a_new_object->getId());
372  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
373  if ($init_gui) {
374  $init_gui->afterSavePluginCreation($a_new_object, $form);
375  }
376  $a_new_object->update();
377  $this->serviceAuth($a_new_object);
378  }
379  } catch (Exception $e) {
380  ilUtil::sendFailure($e->getMessage(), true);
381  ilObjectGUI::redirectToRefId($this->parent_id);
382  }
383  }
384 
385 
389  protected function serviceAuth(ilObjCloud $object) {
390  global $DIC;
391  $ilCtrl = $DIC['ilCtrl'];
392  try {
393  $service = ilCloudConnector::getServiceClass($object->getServiceName(), $object->getId());
394  $service->authService($ilCtrl->getLinkTarget($this, "afterServiceAuth") . "&authMode=true");
395  } catch (Exception $e) {
396  ilUtil::sendFailure($e->getMessage(), true);
397  ilObjectGUI::redirectToRefId($this->parent_id);
398  }
399  }
400 
401 
402  protected function afterServiceAuth() {
403  global $DIC;
404  $ilCtrl = $DIC['ilCtrl'];
405  $lng = $DIC['lng'];
406 
407  try {
408  if ($this->plugin_service->afterAuthService()) {
409  $this->object->setRootId("root", true);
410  $this->object->setAuthComplete(true);
411  $this->object->update();
412  ilUtil::sendSuccess($lng->txt("cld_object_added"), true);
413  $ilCtrl->redirectByClass("ilCloudPluginSettingsGUI", "editSettings");
414  } else {
415  include_once("./Services/Repository/classes/class.ilRepUtil.php");
416  ilRepUtil::deleteObjects($this->object->getRefId(), $this->object->getRefId());
417 
418  ilUtil::sendFailure($lng->txt("cld_auth_failed_no_object_created"), true);
419  ilObjectGUI::redirectToRefId($this->parent_id);
420  }
421  } catch (Exception $e) {
422  ilUtil::sendFailure($e->getMessage(), true);
423  ilObjectGUI::redirectToRefId($this->parent_id);
424  }
425  }
426 
427 
431  protected function addHeaderAction() {
432  $lg = $this->initHeaderAction();
433  if ($lg) {
434  $header_action_class = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
435  $header_action_class->addCustomHeaderAction($lg);
436  $this->insertHeaderAction($lg);
437  }
438  }
439 
440 
444  protected function addLocatorItems() {
445  global $DIC;
446  $ilLocator = $DIC['ilLocator'];
447 
448  if (is_object($this->object)) {
449  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
450  }
451  }
452 
453 
454  public function render() {
455  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
456  $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"));
457  }
458 
459 
460  public function asyncGetBlock() {
461  global $DIC;
462  $tpl = $DIC['tpl'];
463 
464  $response = new stdClass();
465  $response->message = null;
466  $response->locator = null;
467  $response->content = null;
468  $response->success = null;
469 
470  try {
472  $file_tree->updateFileTree($_POST["path"]);
473  $node = $file_tree->getNodeFromPath($_POST["path"]);
474  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, $file_tree);
475  $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"));
476 
477  $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
478  $response->success = true;
479  } catch (Exception $e) {
480  $response->message = $tpl->getMessageHTML($e->getMessage(), "failure");
481  }
482 
483  header('Content-type: application/json');
484  echo ilJsonUtil::encode($response);
485  exit;
486  }
487 
488 
489  function getFile() {
490  global $DIC;
491  $ilTabs = $DIC['ilTabs'];
492  if ($this->checkPermissionBool("download")) {
493  try {
495  $file_tree->downloadFromService($_GET['id']);
496  } catch (Exception $e) {
497  $ilTabs->activateTab("content");
498  ilUtil::sendFailure($e->getMessage());
499  }
500  }
501  }
502 
503 
505  $action_list = ilCloudConnector::getActionListGUIClass($this->plugin_service);
507 
508  return $action_list->asyncGetContent($this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $file_tree->getNodeFromId($_GET["node_id"]));
509  }
510 }
511 
512 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilErr
Definition: raiseError.php:16
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.
const TITLE_LENGTH
max length of object title
$_GET["client_id"]
static getInitGUIClass(ilCloudPluginService $plugin_service_class)
static getDeleteGUIClass(ilCloudPluginService $plugin_service_class)
Class ilObject Basic functions for all objects.
static getUploadGUIClass(ilCloudPluginService $plugin_service_class)
$cmd
Definition: sahs_server.php:35
afterSave(ilObject $a_new_object)
Post (successful) object creation hook.
static getCreateFolderGUIClass(ilCloudPluginService $plugin_service_class)
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
$info
Definition: example_052.php:80
This class represents a property in a property form.
static encode($mixed, $suppress_native=false)
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.
prepareOutput($a_show_subobjects=true)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static getCreationGUIClass(ilCloudPluginService $plugin_service_class)
infoScreenForward()
show information screen
global $DIC
static getItemCreationListGUIClass(ilCloudPluginService $plugin_service_class)
update()
update object in db
$_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.