ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5
15{
16 protected $has_multi; // [bool]
17 protected $row_commands = array();
18
22 function __construct($a_parent_obj, $a_parent_cmd, $a_cur_dir,
23 $a_cur_subdir, $a_label_enable = false,
24 $a_file_labels, $a_label_header = "", $a_commands = array(),
25 $a_post_dir_path = false, $a_table_id = "")
26 {
27 global $ilCtrl, $lng, $ilAccess, $lng;
28
29 $this->setId($a_table_id);
30 $this->cur_dir = $a_cur_dir;
31 $this->cur_subdir = $a_cur_subdir;
32 $this->label_enable = $a_label_enable;
33 $this->label_header = $a_label_header;
34 $this->file_labels = $a_file_labels;
35 $this->post_dir_path = $a_post_dir_path;
36
37 parent::__construct($a_parent_obj, $a_parent_cmd);
38 $this->setTitle($lng->txt("cont_files")." ".$this->cur_subdir);
39
40 $this->has_multi = false;
41 for ($i=0; $i < count($a_commands); $i++)
42 {
43 if (!$a_commands[$i]["single"])
44 {
45 // does also handle internal commands
46 $this->addMultiCommand("extCommand_".$i, $a_commands[$i]["name"]);
47 $this->has_multi = true;
48 }
49 else
50 {
51 $this->row_commands[] = array(
52 "cmd" => "extCommand_".$i,
53 "caption" => $a_commands[$i]["name"],
54 "allow_dir" => $a_commands[$i]["allow_dir"]
55 );
56 }
57 }
58 if($this->has_multi)
59 {
60 $this->setSelectAllCheckbox("file[]");
61 $this->addColumn("", "", "1", true);
62 }
63
64 $this->addColumn("", "", "1", true); // icon
65 $this->addColumn($lng->txt("cont_dir_file"), "name");
66 $this->addColumn($lng->txt("cont_size"), "size");
67
68 if ($this->label_enable)
69 {
70 $this->addColumn($this->label_header, "label");
71 }
72
73 if(sizeof($this->row_commands))
74 {
75 $this->addColumn($lng->txt("actions"));
76 include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
77 }
78
79 $this->setDefaultOrderField("name");
80 $this->setDefaultOrderDirection("asc");
81
82 $this->setEnableHeader(true);
83 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
84 $this->setRowTemplate("tpl.directory_row.html",
85 "Services/FileSystem");
86 $this->setEnableTitle(true);
87 }
88
89 function numericOrdering($a_field)
90 {
91 if ($a_field == "size")
92 {
93 return true;
94 }
95 return false;
96 }
97
101 function prepareOutput()
102 {
103 $this->determineOffsetAndOrder(true);
104 $this->getEntries();
105 }
106
107
111 function getEntries()
112 {
113 if (is_dir($this->cur_dir))
114 {
115 $entries = ilUtil::getDir($this->cur_dir);
116 }
117 else
118 {
119 $entries = array(array("type" => "dir", "entry" => ".."));
120 }
121 $items = array();
122
123 foreach ($entries as $e)
124 {
125 if(($e["entry"] == ".") || ($e["entry"] == ".." && empty($this->cur_subdir)))
126 {
127 continue;
128 }
129 $cfile = (!empty($this->cur_subdir))
130 ? $this->cur_subdir."/".$e["entry"]
131 : $e["entry"];
132
133 if ($this->label_enable)
134 {
135 $label = (is_array($this->file_labels[$cfile]))
136 ? implode($this->file_labels[$cfile], ", ")
137 : "";
138 }
139
140 $pref = ($e["type"] == "dir")
141 ? ( $this->getOrderDirection() != "desc" ? "1_" : "9_")
142 : "5_";
143 $items[] = array("file" => $cfile, "entry" => $e["entry"],
144 "type" => $e["type"], "label" => $label, "size" => $e["size"],
145 "name" => $pref.$e["entry"]);
146 }
147
148 $this->setData($items);
149 }
150
151
157 private function isDoubleDotDirectory($entry) {
158 return (is_array($entry) && isset($entry) && $entry['entry'] === '..');
159 }
160
161
165 protected function fillRow($a_set)
166 {
167 global $ilCtrl;
168
169 $hash = $this->post_dir_path
170 ? md5($a_set["file"])
171 : md5($a_set["entry"]);
172
173 if($this->has_multi)
174 {
175 if ($this->isDoubleDotDirectory($a_set)) {
176 $this->tpl->touchBlock('no_checkbox');
177 } else {
178 $this->tpl->setVariable("CHECKBOX_ID", $hash);
179 }
180 }
181
182 // label
183 if ($this->label_enable)
184 {
185 $this->tpl->setCurrentBlock("Label");
186 $this->tpl->setVariable("TXT_LABEL", $a_set["label"]);
187 $this->tpl->parseCurrentBlock();
188 }
189
190 $ilCtrl->setParameter($this->parent_obj, "cdir", $this->cur_subdir);
191
192 //$this->tpl->setVariable("ICON", $obj["title"]);
193 if($a_set["type"] == "dir")
194 {
195 $this->tpl->setCurrentBlock("FileLink");
196 $ilCtrl->setParameter($this->parent_obj, "newdir", $a_set["entry"]);
197 $ilCtrl->setParameter($this->parent_obj, "resetoffset", 1);
198 $this->tpl->setVariable("LINK_FILENAME",
199 $ilCtrl->getLinkTarget($this->parent_obj, "listFiles"));
200 $ilCtrl->setParameter($this->parent_obj, "newdir", "");
201 $this->tpl->setVariable("TXT_FILENAME", $a_set["entry"]);
202 $this->tpl->parseCurrentBlock();
203
204 $this->tpl->setVariable("ICON", "<img src=\"".
205 ilUtil::getImagePath("icon_cat.svg")."\">");
206 $ilCtrl->setParameter($this->parent_obj, "resetoffset", "");
207 }
208 else
209 {
210 $this->tpl->setCurrentBlock("File");
211 $this->tpl->setVariable("TXT_FILENAME2", $a_set["entry"]);
212 $this->tpl->parseCurrentBlock();
213 }
214
215 if($a_set["type"] != "dir")
216 {
217 $this->tpl->setVariable("TXT_SIZE", ilUtil::formatSize($a_set["size"]));
218 }
219
220 // single item commands
221 if(sizeof($this->row_commands) &&
222 !($a_set["type"] == "dir" && $a_set["entry"] == ".."))
223 {
224 $advsel = new ilAdvancedSelectionListGUI();
225 //$advsel->setListTitle($this->lng->txt("actions"));
226 foreach($this->row_commands as $rcom)
227 {
228 if($rcom["allow_dir"] || $a_set["type"] != "dir")
229 {
230 $ilCtrl->setParameter($this->parent_obj, "fhsh", $hash);
231 $url = $ilCtrl->getLinkTarget($this->parent_obj, $rcom["cmd"]);
232 $ilCtrl->setParameter($this->parent_obj, "fhsh", "");
233
234 $advsel->addItem($rcom["caption"], "", $url);
235 }
236 }
237 $this->tpl->setVariable("ACTIONS", $advsel->getHTML());
238 }
239 }
240
241}
242?>
PHPExcel root directory.
Definition: PHPExcel.php:30
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?
prepareOutput()
Get data just before output.
__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.
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
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.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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 $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$url
Definition: shib_logout.php:72