ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilFileSystemTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use ILIAS\ResourceStorage\Preloader\SecureString;
5
6include_once("./Services/Table/classes/class.ilTable2GUI.php");
7
17{
18 use SecureString; // This is just for those legacy classes which will be removed soon anyway.
19 protected $has_multi; // [bool]
20 protected $row_commands = array();
21
25 public function __construct(
26 $a_parent_obj,
27 $a_parent_cmd,
28 $a_cur_dir,
29 $a_cur_subdir,
30 $a_label_enable = false,
31 $a_file_labels,
32 $a_label_header = "",
33 $a_commands = array(),
34 $a_post_dir_path = false,
35 $a_table_id = ""
36 ) {
37 global $DIC;
38 $ilCtrl = $DIC['ilCtrl'];
39 $lng = $DIC['lng'];
40 $ilAccess = $DIC['ilAccess'];
41 $lng = $DIC['lng'];
42
43 $this->setId($a_table_id);
44 $this->cur_dir = $a_cur_dir;
45 $this->cur_subdir = $a_cur_subdir;
46 $this->label_enable = $a_label_enable;
47 $this->label_header = $a_label_header;
48 $this->file_labels = $a_file_labels;
49 $this->post_dir_path = $a_post_dir_path;
50 $this->lng = $lng;
51
52 parent::__construct($a_parent_obj, $a_parent_cmd);
53 $this->setTitle($lng->txt("cont_files") . " " . $this->cur_subdir);
54
55 $this->has_multi = false;
56 for ($i = 0; $i < count($a_commands); $i++) {
57 if (!$a_commands[$i]["single"]) {
58 // does also handle internal commands
59 $this->addMultiCommand("extCommand_" . $i, $a_commands[$i]["name"]);
60 $this->has_multi = true;
61 } else {
62 $this->row_commands[] = array(
63 "cmd" => "extCommand_" . $i,
64 "caption" => $a_commands[$i]["name"],
65 "allow_dir" => $a_commands[$i]["allow_dir"]
66 );
67 }
68 }
69
70 $this->addColumns();
71
72 $this->setDefaultOrderField("name");
73 $this->setDefaultOrderDirection("asc");
74
75 $this->setEnableHeader(true);
76 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
77 $this->setRowTemplate(
78 "tpl.directory_row.html",
79 "Services/FileSystem"
80 );
81 $this->setEnableTitle(true);
82 }
83
84 public function numericOrdering($a_field)
85 {
86 if ($a_field == "size") {
87 return true;
88 }
89 return false;
90 }
91
95 public function prepareOutput()
96 {
97 $this->determineOffsetAndOrder(true);
98 $this->setData($this->getEntries());
99 }
100
101
105 public function getEntries()
106 {
107 if (is_dir($this->cur_dir)) {
108 $entries = ilUtil::getDir($this->cur_dir);
109 } else {
110 $entries = array(array("type" => "dir", "entry" => ".."));
111 }
112 $items = array();
113
114 foreach ($entries as $e) {
115 if (($e["entry"] == ".") || ($e["entry"] == ".." && empty($this->cur_subdir))) {
116 continue;
117 }
118 $cfile = (!empty($this->cur_subdir))
119 ? $this->cur_subdir . "/" . $e["entry"]
120 : $e["entry"];
121
122 if ($this->label_enable) {
123 $label = (is_array($this->file_labels[$cfile]))
124 ? implode(", ", $this->file_labels[$cfile])
125 : "";
126 }
127
128 $pref = ($e["type"] == "dir")
129 ? ($this->getOrderDirection() != "desc" ? "1_" : "9_")
130 : "5_";
131 $items[] = array("file" => $cfile, "entry" => $e["entry"],
132 "type" => $e["type"], "label" => $label, "size" => $e["size"],
133 "name" => $pref . $e["entry"]);
134 }
135 return $items;
136 }
137
138 public function addColumns()
139 {
140 if ($this->has_multi) {
141 $this->setSelectAllCheckbox("file[]");
142 $this->addColumn("", "", "1", true);
143 }
144 $this->addColumn("", "", "1", true); // icon
145
146 $this->addColumn($this->lng->txt("cont_dir_file"), "name");
147 $this->addColumn($this->lng->txt("cont_size"), "size");
148
149 if ($this->label_enable) {
150 $this->addColumn($this->label_header, "label");
151 }
152
153 if (sizeof($this->row_commands)) {
154 $this->addColumn($this->lng->txt("actions"));
155 include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
156 }
157 }
158
163 private function isDoubleDotDirectory(array $entry)
164 {
165 return $entry['entry'] === '..';
166 }
167
171 protected function fillRow($a_set)
172 {
173 global $DIC;
174 $ilCtrl = $DIC['ilCtrl'];
175
176 $hash = $this->post_dir_path
177 ? md5($a_set["file"])
178 : md5($a_set["entry"]);
179
180 if ($this->has_multi) {
181 if ($this->isDoubleDotDirectory($a_set)) {
182 $this->tpl->touchBlock('no_checkbox');
183 } else {
184 $this->tpl->setVariable("CHECKBOX_ID", $hash);
185 }
186 }
187
188 // label
189 if ($this->label_enable) {
190 $this->tpl->setCurrentBlock("Label");
191 $this->tpl->setVariable("TXT_LABEL", $a_set["label"]);
192 $this->tpl->parseCurrentBlock();
193 }
194
195 $ilCtrl->setParameter($this->parent_obj, "cdir", $this->cur_subdir);
196
197 //$this->tpl->setVariable("ICON", $obj["title"]);
198 if ($a_set["type"] == "dir") {
199 $this->tpl->setCurrentBlock("FileLink");
200 $ilCtrl->setParameter($this->parent_obj, "newdir", $a_set["entry"]);
201 $ilCtrl->setParameter($this->parent_obj, "resetoffset", 1);
202 $this->tpl->setVariable(
203 "LINK_FILENAME",
204 $ilCtrl->getLinkTarget($this->parent_obj, "listFiles")
205 );
206 $ilCtrl->setParameter($this->parent_obj, "newdir", "");
207 $this->tpl->setVariable("TXT_FILENAME", $a_set["entry"]);
208 $this->tpl->parseCurrentBlock();
209
210 $this->tpl->setVariable("ICON", "<img src=\"" .
211 ilUtil::getImagePath("icon_cat.svg") . "\">");
212 $ilCtrl->setParameter($this->parent_obj, "resetoffset", "");
213 } else {
214 $this->tpl->setCurrentBlock("File");
215 $this->tpl->setVariable("TXT_FILENAME2", $this->secure($a_set["entry"]));
216 $this->tpl->parseCurrentBlock();
217 }
218
219 if ($a_set["type"] != "dir") {
220 $this->tpl->setVariable("TXT_SIZE", ilUtil::formatSize($a_set["size"]));
221 }
222
223 // single item commands
224 if (sizeof($this->row_commands) &&
225 !($a_set["type"] == "dir" && $a_set["entry"] == "..")) {
226 $advsel = new ilAdvancedSelectionListGUI();
227 //$advsel->setListTitle($this->lng->txt("actions"));
228 foreach ($this->row_commands as $rcom) {
229 if ($rcom["allow_dir"] || $a_set["type"] != "dir") {
230 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
231
232 if (($rcom["caption"] == "Unzip" && ilMimeTypeUtil::getMimeType($this->cur_dir . $a_set['entry']) == "application/zip") || $rcom["caption"] != "Unzip") {
233 $ilCtrl->setParameter($this->parent_obj, "fhsh", $hash);
234 $url = $ilCtrl->getLinkTarget($this->parent_obj, $rcom["cmd"]);
235 $ilCtrl->setParameter($this->parent_obj, "fhsh", "");
236
237 $advsel->addItem($rcom["caption"], "", $url);
238 }
239 }
240 }
241 $this->tpl->setVariable("ACTIONS", $advsel->getHTML());
242 }
243 }
244}
An exception for terminatinating execution or to throw for unit testing.
User interface class for advanced drop-down selection lists.
TableGUI class for file system.
fillRow($a_set)
Fill table row.
numericOrdering($a_field)
Should this field be sorted numeric?
__construct( $a_parent_obj, $a_parent_cmd, $a_cur_dir, $a_cur_subdir, $a_label_enable=false, $a_file_labels, $a_label_header="", $a_commands=array(), $a_post_dir_path=false, $a_table_id="")
Constructor.
prepareOutput()
Get data just before output.
static getMimeType($a_file='', $a_filename='', $a_mime='')
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
getOrderDirection()
Get order direction.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url