ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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;
29 
30 
36  public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0) {
37  global $lng;
38 
39  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
40  $lng->loadLanguageModule("cld");
41  }
42 
43 
47  final function getType() {
48  return "cld";
49  }
50 
51 
56  public function executeCommand() {
57  global $ilCtrl, $ilTabs, $ilNavigationHistory, $lng;
58 
59  // Navigation History
60  $link = $ilCtrl->getLinkTarget($this, "render");
61 
62  try {
64  } catch (Exception $e) {
65  ilUtil::sendFailure($lng->txt("cld_no_service_active"), true);
66  ilObjectGUI::redirectToRefId($this->parent_id);
67  }
68 
69  if ($this->object != NULL) {
70  $ilNavigationHistory->addItem($this->object->getRefId(), $link, "cld");
71 
72  try {
73  ilCloudConnector::checkServiceActive($this->object->getServiceName());
74  } catch (Exception $e) {
75  ilUtil::sendFailure($lng->txt("cld_plugin_not_active"), true);
76  ilObjectGUI::redirectToRefId($this->parent_id);
77  }
78 
79  if ($this->object->getAuthComplete() == false && !$_GET["authMode"]) {
80  if ($this->checkPermissionBool("write")) {
81  $this->serviceAuth($this->object);
82  } else {
83  ilUtil::sendFailure($lng->txt("cld_auth_failed"), true);
84  ilObjectGUI::redirectToRefId($this->parent_id);
85  }
86  }
87  $this->plugin_service = ilCloudConnector::getServiceClass($this->object->getServiceName(), $this->object->getId(), false);
88  }
89 
90  $next_class = $ilCtrl->getNextClass($this);
91 
92  $cmd = $ilCtrl->getCmd($this);
93  switch ($cmd) {
94  case "editSettings" :
95  $next_class = "ilcloudpluginsettingsgui";
96  break;
97  case "afterServiceAuth" :
98  $this->checkPermission("write");
99  $this->$cmd();
100 
101  return;
102  case "infoScreen":
103  $this->prepareOutput();
104  $this->infoScreenObject();
105  return;
106  case "render" :
107  $this->addHeaderAction();
108  break;
109  }
110 
111  switch ($next_class) {
112  case "ilinfoscreengui":
113  $this->prepareOutput();
114  $this->infoScreen();
115  break;
116  case "ilcommonactiondispatchergui":
117  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
119  $this->ctrl->forwardCommand($gui);
120  break;
121  case "ilpermissiongui":
122  $this->prepareOutput();
123  $ilTabs->activateTab("id_permissions");
124  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
125  $perm_gui = new ilPermissionGUI($this);
126  $this->ctrl->forwardCommand($perm_gui);
127  break;
128  case "ilcloudpluginuploadgui":
129  if ($this->checkPermissionBool("upload")) {
130  $upload_gui = ilCloudConnector::getUploadGUIClass($this->plugin_service);
131  $this->ctrl->forwardCommand($upload_gui);
132  }
133  break;
134  case "ilcloudplugincreatefoldergui":
135  if ($this->checkPermissionBool("folders_create")) {
136  $folder_gui = ilCloudConnector::getCreateFolderGUIClass($this->plugin_service);
137  $this->ctrl->forwardCommand($folder_gui);
138  }
139  break;
140  case "ilcloudplugindeletegui":
141  if ($this->checkPermissionBool("delete_files") || $this->checkPermissionBool("delete_folders")) {
142  $delete_gui = ilCloudConnector::getDeleteGUIClass($this->plugin_service);
143  $this->ctrl->forwardCommand($delete_gui);
144  }
145  break;
146  case "ilcloudpluginsettingsgui":
147  $this->prepareOutput();
148  if ($this->checkPermissionBool("write")) {
149  $settings_gui = ilCloudConnector::getSettingsGUIClass($this->plugin_service);
150  $settings_gui->setCloudObject($this->object);
151  $this->ctrl->forwardCommand($settings_gui);
152  }
153  break;
154  case "ilcloudpluginactionlistgui":
155  $action_list_gui = ilCloudConnector::getActionListGUIClass($this->plugin_service);
156  $this->ctrl->forwardCommand($action_list_gui);
157  break;
158  case "ilcloudpluginitemcreationlistgui":
159  $item_creation_gui = ilCloudConnector::getItemCreationListGUIClass($this->plugin_service);
160  $this->ctrl->forwardCommand($item_creation_gui);
161  break;
162  case "ilcloudpluginfiletreegui":
163  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, ilCloudFileTree::getFileTreeFromSession());
164  $this->ctrl->forwardCommand($file_tree_gui);
165  break;
166  case "ilcloudpluginheaderactiongui":
167  $header_action_gui = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
168  $this->ctrl->forwardCommand($header_action_gui);
169  break;
170  case "ilcloudplugininitgui":
171  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
172  $this->ctrl->forwardCommand($init_gui);
173  break;
174  default:
175  return parent::executeCommand();
176  }
177 
178  return true;
179  }
180 
181 
185  function getStandardCmd() {
186  return "render";
187  }
188 
189 
196  public static function _goto($a_target) {
197  $content = explode("_", $a_target);
198  $_GET["ref_id"] = $content[0];
199  $_POST["path"] = $content[2];
200  $_GET["baseClass"] = "ilrepositorygUI";
201  $_GET["cmdClass"] = "ilobjcloudgui";
202  $_GET["cmd"] = "render";
203  include("ilias.php");
204  }
205 
211  function infoScreenObject()
212  {
213  $this->ctrl->setCmd("showSummary");
214  $this->ctrl->setCmdClass("ilinfoscreengui");
215  $this->infoScreen();
216  }
217 
218 
219 
220  public function setTabs() {
221  global $ilTabs, $ilCtrl, $ilAccess, $lng;
222 
223  // tab for the "show content" command
224  if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
225  $ilTabs->addTab("content", $lng->txt("content"), $ilCtrl->getLinkTarget($this, "render"));
226  $ilTabs->addTab("id_info", $lng->txt("info_short"), $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
227  }
228 
229  // a "properties" tab
230  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
231  $ilTabs->addTab("settings", $lng->txt("settings"), $ilCtrl->getLinkTargetByClass("ilcloudpluginsettingsgui", "editSettings"));
232  }
233 
234  // edit permissions
235  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
236  $ilTabs->addTab("id_permissions", $lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
237  }
238  }
239 
240 
244  public function infoScreen() {
245  global $ilTabs, $ilErr;
246 
247  $ilTabs->activateTab("id_info");
248 
249  if (!$this->checkPermissionBool("visible")) {
250  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
251  }
252 
253  $plugin_info = ilCloudConnector::getInfoScreenGUIClass($this->plugin_service);
254  $info = $plugin_info->getInfoScreen($this);
255  $this->ctrl->forwardCommand($info);
256  }
257 
258 
268  protected function initCreationForms($a_new_type) {
269  $forms = array(
270  self::CFORM_NEW => $this->initCreateForm($a_new_type)
271  );
272 
273  return $forms;
274  }
275 
276 
284  protected function initCreateForm($a_new_type) {
285  global $lng;
286 
287  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
288  $form = new ilPropertyFormGUI();
289  $form->setTarget("_top");
290  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
291  $form->setTitle($this->lng->txt($a_new_type . "_new"));
292 
293  // title
294  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
295  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
296  $ti->setMaxLength(ilObject::TITLE_LENGTH);
297  $ti->setRequired(true);
298  $form->addItem($ti);
299 
300  // description
301  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
302  $ta->setCols(40);
303  $ta->setRows(2);
304  $form->addItem($ta);
305 
306  $services_group = new ilRadioGroupInputGUI($lng->txt("cld_service"), "service");
307  $services_group->setRequired(true);
308  foreach (ilCloudConnector::getActiveServices() as $service) {
309  $option = new ilRadioOption($service, $service);
310  $hook_object = ilCloudConnector::getPluginHookClass($option->getValue());
311  $option->setTitle($hook_object->txt($service));
312  $option->setInfo($hook_object->txt("create_info"));
313  $this->plugin_service = ilCloudConnector::getServiceClass($service, 0, false);
314  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
315  if ($init_gui) {
316  $init_gui->initPluginCreationFormSection($option);
317  }
318  $services_group->addOption($option);
319  }
320 
321  //Select first radio-button by default
322  $services_group->setValue(array_shift($services_group->getOptions())->getValue());
323 
324  $form->addItem($services_group);
325 
326  $form = $this->initDidacticTemplate($form);
327 
328  $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
329  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
330 
331  return $form;
332  }
333 
334 
338  protected function afterSave(ilObjCloud $a_new_object) {
339  try {
340  $form = $this->initCreateForm("cld");
341 
342  if ($form->checkInput()) {
343  $a_new_object->setServiceName($form->getInput("service"));
344  $a_new_object->setRootFolder("/");
345  $a_new_object->setOnline(false);
346  $a_new_object->setAuthComplete(false);
347  $this->plugin_service = new ilCloudPluginService($a_new_object->getServiceName(), $a_new_object->getId());
348  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
349  if ($init_gui) {
350  $init_gui->afterSavePluginCreation($a_new_object, $form);
351  }
352  $a_new_object->update();
353  $this->serviceAuth($a_new_object);
354  }
355  } catch (Exception $e) {
356  ilUtil::sendFailure($e->getMessage(), true);
357  ilObjectGUI::redirectToRefId($this->parent_id);
358  }
359  }
360 
361 
365  protected function serviceAuth(ilObjCloud $object) {
366  global $ilCtrl;
367  try {
368  $service = ilCloudConnector::getServiceClass($object->getServiceName(), $object->getId());
369  $service->authService($ilCtrl->getLinkTarget($this, "afterServiceAuth") . "&authMode=true");
370  } catch (Exception $e) {
371  ilUtil::sendFailure($e->getMessage(), true);
372  ilObjectGUI::redirectToRefId($this->parent_id);
373  }
374  }
375 
376  protected function afterServiceAuth() {
377  global $ilCtrl, $lng;
378 
379  try {
380  if ($this->plugin_service->afterAuthService()) {
381  $this->object->setRootId("root", true);
382  $this->object->setAuthComplete(true);
383  $this->object->update();
384  ilUtil::sendSuccess($lng->txt("cld_object_added"), true);
385  $ilCtrl->redirectByClass("ilCloudPluginSettingsGUI", "editSettings");
386  } else {
387  include_once("./Services/Repository/classes/class.ilRepUtil.php");
388  ilRepUtil::deleteObjects($this->object->getRefId(), $this->object->getRefId());
389 
390  ilUtil::sendFailure($lng->txt("cld_auth_failed_no_object_created"), true);
391  ilObjectGUI::redirectToRefId($this->parent_id);
392  }
393  } catch (Exception $e) {
394  ilUtil::sendFailure($e->getMessage(), true);
395  ilObjectGUI::redirectToRefId($this->parent_id);
396  }
397  }
398 
399 
403  protected function addHeaderAction() {
404  $lg = $this->initHeaderAction();
405  if ($lg) {
406  $header_action_class = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
407  $header_action_class->addCustomHeaderAction($lg);
408  $this->insertHeaderAction($lg);
409  }
410  }
411 
412 
416  protected function addLocatorItems() {
417  global $ilLocator;
418 
419  if (is_object($this->object)) {
420  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
421  }
422  }
423 
424 
425  public function render() {
426  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
427  $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"));
428  }
429 
430 
431  public function asyncGetBlock() {
432  global $tpl;
433 
434  $response = new stdClass();
435  $response->message = NULL;
436  $response->locator = NULL;
437  $response->content = NULL;
438  $response->success = NULL;
439 
440  try {
442  $file_tree->updateFileTree($_POST["path"]);
443  $node = $file_tree->getNodeFromPath($_POST["path"]);
444  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, $file_tree);
445  $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"));
446 
447  $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
448  $response->success = true;
449  } catch (Exception $e) {
450  $response->message = $tpl->getMessageHTML($e->getMessage(), "failure");
451  }
452 
453  header('Content-type: application/json');
454  echo ilJsonUtil::encode($response);
455  exit;
456  }
457 
458 
459  function getFile() {
460  global $ilTabs;
461  if ($this->checkPermissionBool("download")) {
462  try {
464  $file_tree->downloadFromService($_GET['id']);
465  } catch (Exception $e) {
466  $ilTabs->activateTab("content");
467  ilUtil::sendFailure($e->getMessage());
468  }
469  }
470  }
471 
472 
474  $action_list = ilCloudConnector::getActionListGUIClass($this->plugin_service);
476 
477  return $action_list->asyncGetContent($this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $file_tree->getNodeFromId($_GET["node_id"]));
478  }
479 }
480 
481 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
getStandardCmd()
Get standard command.
afterSave(ilObjCloud $a_new_object)
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
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)
infoScreen()
show information screen
static getDeleteGUIClass(ilCloudPluginService $plugin_service_class)
static getUploadGUIClass(ilCloudPluginService $plugin_service_class)
$cmd
Definition: sahs_server.php:35
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.
setServiceName($a_val)
Set service.
setOnline($a_val)
Set online.
$plugin_service
ilCloudPluginService
Class ilObjCloudGUI.
addLocatorItems()
addLocatorItems
global $ilCtrl
Definition: ilias.php:18
checkPermission($a_perm, $a_cmd="")
This class represents a property in a property form.
static encode($mixed, $suppress_native=false)
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)
Class ilCloudPluginService.
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...
__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)
setRootFolder($a_val, $no_check=false)
Set root_folder, this may only be changed by the owner of the object.
Class ilObjCloud.
infoScreenObject()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually...
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static getCreationGUIClass(ilCloudPluginService $plugin_service_class)
static getItemCreationListGUIClass(ilCloudPluginService $plugin_service_class)
getServiceName()
Get service.
setRequired($a_required)
Set Required.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
setAuthComplete($auth_complete)
static deleteObjects($a_cur_ref_id, $a_ids)
Delete objects.