ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4include_once("class.ilObjCloudGUI.php");
5include_once("class.ilCloudFileNode.php");
6include_once("class.ilCloudFileTree.php");
7include_once("class.ilCloudConnector.php");
8
20{
21
25 protected $file_tree;
26
27
31 public function __construct($plugin_service_class, ilCloudFileTree $file_tree)
32 {
33 parent::__construct($plugin_service_class);
34 $this->setFileTree($file_tree);
35 }
36
37
42 {
43 if ($file_tree) {
44 $this->file_tree = $file_tree;
45 }
46 }
47
48
52 public function getFileTree()
53 {
54 return $this->file_tree;
55 }
56
57
70 public function getFolderHtml(ilObjCloudGUI $gui_class, $id, $delete_files = false, $delete_folder = false, $download = false, $files_visible = false, $folders_visible = false)
71 {
72 global $DIC;
73 $lng = $DIC['lng'];
74
75 $node = null;
76
77 $node = $this->getFileTree()->getNodeFromId($id);
78 if (!$node) {
80 }
81 $tree_tpl = new ilTemplate("tpl.cloud_block.html", true, true, "Modules/Cloud/");
82
83 if ($files_visible || $folders_visible) {
84 $tree_tpl->setVariable("NODE_ID", $node->getId());
85
86 $block = new ilTemplate("tpl.container_list_block.html", true, true, "Services/Container/");
87
88 if ($node->hasChildren()) {
89 $block->setVariable("BLOCK_HEADER_CONTENT", $lng->txt("content"));
90
91 $children = $this->getFileTree()->getSortedListOfChildren($node);
92 foreach ($children as $path) {
93 $child_node = $this->getFileTree()->getNodeFromPath($path);
94 if (($child_node->getIsDir() && $folders_visible) || (!$child_node->getIsDir() && $files_visible)) {
95 $block->setCurrentBlock("container_standard_row");
96 if ($child_node->getIsDir()) {
97 $block->setVariable("ROW_ID", "id=xcld_folder_" . $child_node->getId());
98 } else {
99 $block->setVariable("ROW_ID", "id=xcld_file_" . $child_node->getId());
100 }
101 $block->setVariable("BLOCK_ROW_CONTENT", $this->getItemHtml($child_node, $gui_class, $delete_files, $delete_folder, $download));
102 $block->parseCurrentBlock();
103 }
104 }
105 }
106 $this->setBlockVariablePlugin($block);
107 $tree_tpl->setVariable("CONTENT", $block->get());
108 } else {
109 // Nothing is visible
110 // $tree_tpl->setVariable("CONTENT", $lng->txt("file_folder_not_visible"));
111 }
112 $this->setTreeVariablePlugin($tree_tpl, $gui_class, $id, $delete_files, $delete_folder, $download, $files_visible, $folders_visible);
113
114 return $tree_tpl->get();
115 }
116
117
127 public function setTreeVariablePlugin(ilTemplate $tree_tpl, ilObjCloudGUI $gui_class, $id, $delete_files = false, $delete_folder = false, $download = false, $files_visible = false, $folders_visible = false)
128 {
129 }
130
131
135 protected function setBlockVariablePlugin(ilTemplate $block)
136 {
137 }
138
139
149 public function getItemHtml(ilCloudFileNode $node, ilObjCloudGUI $gui_class, $delete_files = false, $delete_folder = false, $download = false)
150 {
151 global $DIC;
152 $ilCtrl = $DIC['ilCtrl'];
153
154 $item = new ilTemplate("tpl.container_list_item.html", true, true, "Services/Container/");
155
156 $action_list_gui = ilCloudConnector::getActionListGUIClass($this->getService());
157 $item->setVariable("COMMAND_SELECTION_LIST", $action_list_gui->getSelectionListItemsHTML($delete_files, $delete_folder, $node));
158
159 $item->setVariable("DIV_CLASS", "ilContainerListItemOuter");
160 $item->touchBlock("d_1");
161
162 include_once('./Services/Calendar/classes/class.ilDate.php');
164
165 if ($node->getIconPath() != "") {
166 $item->setVariable("SRC_ICON", $node->getIconPath());
167 }
168
169 // Folder with content
170 if ($node->getIsDir()) {
171 if ($node->getIconPath() == "") {
172 // $item->setVariable("SRC_ICON", "./Modules/Cloud/templates/images/icon_folder_b.png");
173 $item->setVariable("SRC_ICON", ilUtil::getImagePath('icon_dcl_fold.svg'));
174 }
175 $item->setVariable("TXT_TITLE_LINKED", basename($node->getPath()));
176 $item->setVariable("HREF_TITLE_LINKED", $this->getLinkToFolder($node));
177 } // File
178 else {
179 if ($node->getIconPath() == "") {
180 // $item->setVariable("SRC_ICON", "./Modules/Cloud/templates/images/icon_file_b.png");
181 $item->setVariable("SRC_ICON", ilUtil::getImagePath('icon_dcl_file.svg'));
182 }
183
184 $item->setVariable(
185 "TXT_DESC",
186 $this->formatBytes($node->getSize()) . "&nbsp;&nbsp;&nbsp;" . $modified
187 );
188 if ($download) {
189 $item->setVariable("TXT_TITLE_LINKED", basename($node->getPath()));
190 $item->setVariable("HREF_TITLE_LINKED", $ilCtrl->getLinkTarget($gui_class, "getFile") . "&id=" . $node->getId());
191 } else {
192 $item->setVariable("TXT_TITLE", basename($node->getPath()));
193 }
194 }
195
196 $this->setItemVariablePlugin($item, $node);
197
198 return $item->get();
199 }
200
201
208 protected function formatBytes($bytes, $precision = 2)
209 {
210 if ($bytes >= 1073741824) {
211 $bytes = number_format($bytes / 1073741824, $precision) . ' GB';
212 } elseif ($bytes >= 1048576) {
213 $bytes = number_format($bytes / 1048576, $precision) . ' MB';
214 } elseif ($bytes >= 1024) {
215 $bytes = number_format($bytes / 1024, $precision) . ' KB';
216 } elseif ($bytes > 1) {
217 $bytes = $bytes . ' bytes';
218 } elseif ($bytes == 1) {
219 $bytes = $bytes . ' byte';
220 } else {
221 $bytes = '0 bytes';
222 }
223
224 return $bytes;
225 }
226
227
232 protected function setItemVariablePlugin(ilTemplate $item, ilCloudFileNode $node)
233 {
234 }
235
236
242 public function getLocatorHtml(ilCloudFileNode $node)
243 {
244 static $ilLocator;
245
246 if ($node == $this->getFileTree()->getRootNode()) {
247 $ilLocator = new ilLocatorGUI();
248 $ilLocator->addItem($this->getPluginObject()->getCloudModulObject()->getTitle(), ilCloudPluginFileTreeGUI::getLinkToFolder($node));
249 } else {
250 $this->getLocatorHtml($this->getFileTree()->getNodeFromId($node->getParentId()));
251 $ilLocator->addItem(basename($node->getPath()), $this->getLinkToFolder($node));
252 }
253
254 return "<DIV class='xcld_locator' id='xcld_locator_" . $node->getId() . "'>" . $ilLocator->getHTML() . "</DIV>";
255 }
256
257
263 public static function getLinkToFolder(ilCloudFileNode $node)
264 {
265 return "#/open_folder?id_parent=" . $node->getParentId() . "&current_id=" . $node->getId() . "&current_path=" . self::_urlencode($node->getPath());
266 }
267
268
269 protected function addDropZone()
270 {
271 $options = new stdClass();
272 $options->dropZone = ".ilFileUploadDropZone_1";
273 $options->fileInput = "#ilFileUploadInput_1";
274 $options->submitButton = "uploadFiles";
275 $options->cancelButton = "cancelAll";
276 $options->dropArea = ".ilFileDropTarget";
277 $options->fileList = "#ilFileUploadList_1";
278 $options->fileSelectButton = "#ilFileUploadFileSelect_1";
279 echo "<script language='javascript' type='text/javascript'>var fileUpload1 = new ilFileUpload(1, " . ilJsonUtil::encode($options)
280 . ");</script>";
281 }
282
290 protected static function _urlencode($str)
291 {
292 return str_replace('%2F', '/', rawurlencode($str));
293 }
294}
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static getActionListGUIClass(ilCloudPluginService $plugin_service_class)
Class ilCloudException.
const ID_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION
ilCloudFileTree class
ilCloudFileTree class
setFileTree(ilCloudFileTree $file_tree)
getItemHtml(ilCloudFileNode $node, ilObjCloudGUI $gui_class, $delete_files=false, $delete_folder=false, $download=false)
setTreeVariablePlugin(ilTemplate $tree_tpl, ilObjCloudGUI $gui_class, $id, $delete_files=false, $delete_folder=false, $download=false, $files_visible=false, $folders_visible=false)
static _urlencode($str)
urlencode without encoding slashes
static getLinkToFolder(ilCloudFileNode $node)
__construct($plugin_service_class, ilCloudFileTree $file_tree)
getFolderHtml(ilObjCloudGUI $gui_class, $id, $delete_files=false, $delete_folder=false, $download=false, $files_visible=false, $folders_visible=false)
setItemVariablePlugin(ilTemplate $item, ilCloudFileNode $node)
Class ilCloudPluginGUI.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
@classDescription Date and time handling
static encode($mixed, $suppress_native=false)
locator handling class
Class ilObjCloudGUI.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7