ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCloudPluginFileTreeGUI.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("class.ilObjCloudGUI.php");
5 include_once("class.ilCloudFileNode.php");
6 include_once("class.ilCloudFileTree.php");
7 include_once("class.ilCloudConnector.php");
8 
20 
24  protected $file_tree;
25 
26 
30  public function __construct($plugin_service_class, ilCloudFileTree $file_tree) {
31  parent::__construct($plugin_service_class);
32  $this->setFileTree($file_tree);
33  }
34 
35 
40  if ($file_tree) {
41  $this->file_tree = $file_tree;
42  }
43  }
44 
45 
49  public function getFileTree() {
50  return $this->file_tree;
51  }
52 
53 
66  public function getFolderHtml(ilObjCloudGUI $gui_class, $id, $delete_files = false, $delete_folder = false, $download = false, $files_visible = false, $folders_visible = false) {
67  global $lng;
68 
69  $node = NULL;
70 
71  $node = $this->getFileTree()->getNodeFromId($id);
72  if (!$node) {
74  }
75  $tree_tpl = new ilTemplate("tpl.cloud_block.html", true, true, "Modules/Cloud/");
76 
77  if ($files_visible || $folders_visible) {
78  $tree_tpl->setVariable("NODE_ID", $node->getId());
79 
80  $block = new ilTemplate("tpl.container_list_block.html", true, true, "Services/Container/");
81 
82  if ($node->hasChildren()) {
83  $block->setVariable("BLOCK_HEADER_CONTENT", $lng->txt("content"));
84 
85  $children = $this->getFileTree()->getSortedListOfChildren($node);
86  foreach ($children as $path) {
87  $child_node = $this->getFileTree()->getNodeFromPath($path);
88  if (($child_node->getIsDir() && $folders_visible) || (!$child_node->getIsDir() && $files_visible)) {
89 
90  $block->setCurrentBlock("container_standard_row");
91  if ($child_node->getIsDir()) {
92  $block->setVariable("ROW_ID", "id=xcld_folder_" . $child_node->getId());
93  } else {
94  $block->setVariable("ROW_ID", "id=xcld_file_" . $child_node->getId());
95  }
96  $block->setVariable("BLOCK_ROW_CONTENT", $this->getItemHtml($child_node, $gui_class, $delete_files, $delete_folder, $download));
97  $block->parseCurrentBlock();
98  }
99  }
100  }
101  $this->setBlockVariablePlugin($block);
102  $tree_tpl->setVariable("CONTENT", $block->get());
103  } else {
104  // Nothing is visible
105  // $tree_tpl->setVariable("CONTENT", $lng->txt("file_folder_not_visible"));
106  }
107  $this->setTreeVariablePlugin($tree_tpl, $gui_class, $id, $delete_files, $delete_folder, $download, $files_visible, $folders_visible);
108 
109  return $tree_tpl->get();
110  }
111 
112 
122  public function setTreeVariablePlugin(ilTemplate $tree_tpl, ilObjCloudGUI $gui_class, $id, $delete_files = false, $delete_folder = false, $download = false, $files_visible = false, $folders_visible = false) { }
123 
124 
128  protected function setBlockVariablePlugin(ilTemplate $block) { }
129 
130 
140  public function getItemHtml(ilCloudFileNode $node, ilObjCloudGUI $gui_class, $delete_files = false, $delete_folder = false, $download = false) {
141  global $ilCtrl;
142 
143  $item = new ilTemplate("tpl.container_list_item.html", true, true, "Services/Container/");
144 
145  $action_list_gui = ilCloudConnector::getActionListGUIClass($this->getService());
146  $item->setVariable("COMMAND_SELECTION_LIST", $action_list_gui->getSelectionListItemsHTML($delete_files, $delete_folder, $node));
147 
148  $item->setVariable("DIV_CLASS", "ilContainerListItemOuter");
149  $item->touchBlock("d_1");
150 
151  include_once('./Services/Calendar/classes/class.ilDate.php');
153 
154  if ($node->getIconPath() != "") {
155  $item->setVariable("SRC_ICON", $node->getIconPath());
156  }
157 
158  // Folder with content
159  if ($node->getIsDir()) {
160  if ($node->getIconPath() == "") {
161  // $item->setVariable("SRC_ICON", "./Modules/Cloud/templates/images/icon_folder_b.png");
162  $item->setVariable("SRC_ICON", ilUtil::getImagePath('icon_dcl_fold.svg'));
163  }
164  $item->setVariable("TXT_DESC", '&nbsp;');
165  $item->setVariable("TXT_TITLE_LINKED", basename($node->getPath()));
166  $item->setVariable("HREF_TITLE_LINKED", $this->getLinkToFolder($node));
167  } // File
168  else {
169  if ($node->getIconPath() == "") {
170  // $item->setVariable("SRC_ICON", "./Modules/Cloud/templates/images/icon_file_b.png");
171  $item->setVariable("SRC_ICON", ilUtil::getImagePath('icon_dcl_file.svg'));
172  }
173 
174  $item->setVariable("TXT_DESC",
175  pathinfo($node->getPath(), PATHINFO_EXTENSION) . "&nbsp;&nbsp;&nbsp;" . $node->getSize() . "&nbsp;&nbsp;&nbsp;" . $modified);
176  if ($download) {
177  $item->setVariable("TXT_TITLE_LINKED", basename($node->getPath()));
178  $item->setVariable("HREF_TITLE_LINKED", $ilCtrl->getLinkTarget($gui_class, "getFile") . "&id=" . $node->getId());
179  } else {
180  $item->setVariable("TXT_TITLE", basename($node->getPath()));
181  }
182  }
183 
184  $this->setItemVariablePlugin($item, $node);
185 
186  return $item->get();
187  }
188 
189 
194  protected function setItemVariablePlugin(ilTemplate $item, ilCloudFileNode $node) { }
195 
196 
202  public function getLocatorHtml(ilCloudFileNode $node) {
203  global $ilLocator;
204 
205  if ($node == $this->getFileTree()->getRootNode()) {
206  $ilLocator = new ilLocatorGUI();
207  $ilLocator->addItem($this->getPluginObject()->getCloudModulObject()->getTitle(), ilCloudPluginFileTreeGUI::getLinkToFolder($node));
208  } else {
209  $this->getLocatorHtml($this->getFileTree()->getNodeFromId($node->getParentId()));
210  $ilLocator->addItem(basename($node->getPath()), $this->getLinkToFolder($node));
211  }
212 
213  return "<DIV class='xcld_locator' id='xcld_locator_" . $node->getId() . "'>" . $ilLocator->getHTML() . "</DIV>";
214  }
215 
216 
222  static function getLinkToFolder(ilCloudFileNode $node) {
223  return "#/open_folder?id_parent=" . $node->getParentId() . "&current_id=" . $node->getId() . "&current_path=" . $node->getPath();
224  }
225 
226 
227  protected function addDropZone() {
228  $options = new stdClass();
229  $options->dropZone = ".ilFileUploadDropZone_1";
230  $options->fileInput = "#ilFileUploadInput_1";
231  $options->submitButton = "uploadFiles";
232  $options->cancelButton = "cancelAll";
233  $options->dropArea = ".ilFileDropTarget";
234  $options->fileList = "#ilFileUploadList_1";
235  $options->fileSelectButton = "#ilFileUploadFileSelect_1";
236  echo "<script language='javascript' type='text/javascript'>var fileUpload1 = new ilFileUpload(1, " . ilJsonUtil::encode($options)
237  . ");</script>";
238  }
239 }
240 
241 ?>