ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  protected $has_multi; // [bool]
17  protected $row_commands = array();
18 
22  public function __construct(
23  $a_parent_obj,
24  $a_parent_cmd,
25  $a_cur_dir,
26  $a_cur_subdir,
27  $a_label_enable = false,
28  $a_file_labels,
29  $a_label_header = "",
30  $a_commands = array(),
31  $a_post_dir_path = false,
32  $a_table_id = ""
33  ) {
34  global $DIC;
35  $ilCtrl = $DIC['ilCtrl'];
36  $lng = $DIC['lng'];
37  $ilAccess = $DIC['ilAccess'];
38  $lng = $DIC['lng'];
39 
40  $this->setId($a_table_id);
41  $this->cur_dir = $a_cur_dir;
42  $this->cur_subdir = $a_cur_subdir;
43  $this->label_enable = $a_label_enable;
44  $this->label_header = $a_label_header;
45  $this->file_labels = $a_file_labels;
46  $this->post_dir_path = $a_post_dir_path;
47  $this->lng = $lng;
48 
49  parent::__construct($a_parent_obj, $a_parent_cmd);
50  $this->setTitle($lng->txt("cont_files") . " " . $this->cur_subdir);
51 
52  $this->has_multi = false;
53  for ($i = 0; $i < count($a_commands); $i++) {
54  if (!$a_commands[$i]["single"]) {
55  // does also handle internal commands
56  $this->addMultiCommand("extCommand_" . $i, $a_commands[$i]["name"]);
57  $this->has_multi = true;
58  } else {
59  $this->row_commands[] = array(
60  "cmd" => "extCommand_" . $i,
61  "caption" => $a_commands[$i]["name"],
62  "allow_dir" => $a_commands[$i]["allow_dir"]
63  );
64  }
65  }
66 
67  $this->addColumns();
68 
69  $this->setDefaultOrderField("name");
70  $this->setDefaultOrderDirection("asc");
71 
72  $this->setEnableHeader(true);
73  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
74  $this->setRowTemplate(
75  "tpl.directory_row.html",
76  "Services/FileSystem"
77  );
78  $this->setEnableTitle(true);
79  }
80 
81  public function numericOrdering($a_field)
82  {
83  if ($a_field == "size") {
84  return true;
85  }
86  return false;
87  }
88 
92  public function prepareOutput()
93  {
94  $this->determineOffsetAndOrder(true);
95  $this->setData($this->getEntries());
96  }
97 
98 
102  public function getEntries()
103  {
104  if (is_dir($this->cur_dir)) {
105  $entries = ilUtil::getDir($this->cur_dir);
106  } else {
107  $entries = array(array("type" => "dir", "entry" => ".."));
108  }
109  $items = array();
110 
111  foreach ($entries as $e) {
112  if (($e["entry"] == ".") || ($e["entry"] == ".." && empty($this->cur_subdir))) {
113  continue;
114  }
115  $cfile = (!empty($this->cur_subdir))
116  ? $this->cur_subdir . "/" . $e["entry"]
117  : $e["entry"];
118 
119  if ($this->label_enable) {
120  $label = (is_array($this->file_labels[$cfile]))
121  ? implode(", ", $this->file_labels[$cfile])
122  : "";
123  }
124 
125  $pref = ($e["type"] == "dir")
126  ? ($this->getOrderDirection() != "desc" ? "1_" : "9_")
127  : "5_";
128  $items[] = array("file" => $cfile, "entry" => $e["entry"],
129  "type" => $e["type"], "label" => $label, "size" => $e["size"],
130  "name" => $pref . $e["entry"]);
131  }
132  return $items;
133  }
134 
135  public function addColumns()
136  {
137  if ($this->has_multi) {
138  $this->setSelectAllCheckbox("file[]");
139  $this->addColumn("", "", "1", true);
140  }
141  $this->addColumn("", "", "1", true); // icon
142 
143  $this->addColumn($this->lng->txt("cont_dir_file"), "name");
144  $this->addColumn($this->lng->txt("cont_size"), "size");
145 
146  if ($this->label_enable) {
147  $this->addColumn($this->label_header, "label");
148  }
149 
150  if (sizeof($this->row_commands)) {
151  $this->addColumn($this->lng->txt("actions"));
152  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
153  }
154  }
155 
160  private function isDoubleDotDirectory(array $entry)
161  {
162  return $entry['entry'] === '..';
163  }
164 
168  protected function fillRow($a_set)
169  {
170  global $DIC;
171  $ilCtrl = $DIC['ilCtrl'];
172 
173  $hash = $this->post_dir_path
174  ? md5($a_set["file"])
175  : md5($a_set["entry"]);
176 
177  if ($this->has_multi) {
178  if ($this->isDoubleDotDirectory($a_set)) {
179  $this->tpl->touchBlock('no_checkbox');
180  } else {
181  $this->tpl->setVariable("CHECKBOX_ID", $hash);
182  }
183  }
184 
185  // label
186  if ($this->label_enable) {
187  $this->tpl->setCurrentBlock("Label");
188  $this->tpl->setVariable("TXT_LABEL", $a_set["label"]);
189  $this->tpl->parseCurrentBlock();
190  }
191 
192  $ilCtrl->setParameter($this->parent_obj, "cdir", $this->cur_subdir);
193 
194  //$this->tpl->setVariable("ICON", $obj["title"]);
195  if ($a_set["type"] == "dir") {
196  $this->tpl->setCurrentBlock("FileLink");
197  $ilCtrl->setParameter($this->parent_obj, "newdir", $a_set["entry"]);
198  $ilCtrl->setParameter($this->parent_obj, "resetoffset", 1);
199  $this->tpl->setVariable(
200  "LINK_FILENAME",
201  $ilCtrl->getLinkTarget($this->parent_obj, "listFiles")
202  );
203  $ilCtrl->setParameter($this->parent_obj, "newdir", "");
204  $this->tpl->setVariable("TXT_FILENAME", $a_set["entry"]);
205  $this->tpl->parseCurrentBlock();
206 
207  $this->tpl->setVariable("ICON", "<img src=\"" .
208  ilUtil::getImagePath("icon_cat.svg") . "\">");
209  $ilCtrl->setParameter($this->parent_obj, "resetoffset", "");
210  } else {
211  $this->tpl->setCurrentBlock("File");
212  $this->tpl->setVariable("TXT_FILENAME2", $a_set["entry"]);
213  $this->tpl->parseCurrentBlock();
214  }
215 
216  if ($a_set["type"] != "dir") {
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  $advsel = new ilAdvancedSelectionListGUI();
224  //$advsel->setListTitle($this->lng->txt("actions"));
225  foreach ($this->row_commands as $rcom) {
226  if ($rcom["allow_dir"] || $a_set["type"] != "dir") {
227  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
228 
229  if (($rcom["caption"] == "Unzip" && ilMimeTypeUtil::getMimeType($this->cur_dir . $a_set['entry']) == "application/zip") || $rcom["caption"] != "Unzip") {
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  }
238  $this->tpl->setVariable("ACTIONS", $advsel->getHTML());
239  }
240  }
241 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
global $DIC
Definition: saml.php:7
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
fillRow($a_set)
Fill table row.
getOrderDirection()
Get order direction.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static getMimeType($a_file='', $a_filename='', $a_mime='')
Class ilTable2GUI.
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.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
addMultiCommand($a_cmd, $a_text)
Add Command button.
prepareOutput()
Get data just before output.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
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.
$i
Definition: disco.tpl.php:19
setEnableHeader($a_enableheader)
Set Enable Header.
$url
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
setEnableTitle($a_enabletitle)
Set Enable Title.
__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.
TableGUI class for file system.