ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  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  include_once "Services/Utilities/classes/class.ilFormat.php";
89  }
90 
91  function numericOrdering($a_field)
92  {
93  if ($a_field == "size")
94  {
95  return true;
96  }
97  return false;
98  }
99 
103  function prepareOutput()
104  {
105  $this->determineOffsetAndOrder(true);
106  $this->getEntries();
107  }
108 
109 
113  function getEntries()
114  {
115  if (is_dir($this->cur_dir))
116  {
117  $entries = ilUtil::getDir($this->cur_dir);
118  }
119  else
120  {
121  $entries = array(array("type" => "dir", "entry" => ".."));
122  }
123  $items = array();
124 
125  foreach ($entries as $e)
126  {
127  if(($e["entry"] == ".") || ($e["entry"] == ".." && empty($this->cur_subdir)))
128  {
129  continue;
130  }
131  $cfile = (!empty($this->cur_subdir))
132  ? $this->cur_subdir."/".$e["entry"]
133  : $e["entry"];
134 
135  if ($this->label_enable)
136  {
137  $label = (is_array($this->file_labels[$cfile]))
138  ? implode($this->file_labels[$cfile], ", ")
139  : "";
140  }
141 
142  $pref = ($e["type"] == "dir")
143  ? ( $this->getOrderDirection() != "desc" ? "1_" : "9_")
144  : "5_";
145  $items[] = array("file" => $cfile, "entry" => $e["entry"],
146  "type" => $e["type"], "label" => $label, "size" => $e["size"],
147  "name" => $pref.$e["entry"]);
148  }
149 
150  $this->setData($items);
151  }
152 
153 
157  protected function fillRow($a_set)
158  {
159  global $ilCtrl;
160 
161  $hash = $this->post_dir_path
162  ? md5($a_set["file"])
163  : md5($a_set["entry"]);
164 
165  if($this->has_multi)
166  {
167  $this->tpl->setVariable("CHECKBOX_ID", $hash);
168  }
169 
170  // label
171  if ($this->label_enable)
172  {
173  $this->tpl->setCurrentBlock("Label");
174  $this->tpl->setVariable("TXT_LABEL", $a_set["label"]);
175  $this->tpl->parseCurrentBlock();
176  }
177 
178  $ilCtrl->setParameter($this->parent_obj, "cdir", $this->cur_subdir);
179 
180  //$this->tpl->setVariable("ICON", $obj["title"]);
181  if($a_set["type"] == "dir")
182  {
183  $this->tpl->setCurrentBlock("FileLink");
184  $ilCtrl->setParameter($this->parent_obj, "newdir", $a_set["entry"]);
185  $ilCtrl->setParameter($this->parent_obj, "resetoffset", 1);
186  $this->tpl->setVariable("LINK_FILENAME",
187  $ilCtrl->getLinkTarget($this->parent_obj, "listFiles"));
188  $ilCtrl->setParameter($this->parent_obj, "newdir", "");
189  $this->tpl->setVariable("TXT_FILENAME", $a_set["entry"]);
190  $this->tpl->parseCurrentBlock();
191 
192  $this->tpl->setVariable("ICON", "<img src=\"".
193  ilUtil::getImagePath("icon_cat.svg")."\">");
194  $ilCtrl->setParameter($this->parent_obj, "resetoffset", "");
195  }
196  else
197  {
198  $this->tpl->setCurrentBlock("File");
199  $this->tpl->setVariable("TXT_FILENAME2", $a_set["entry"]);
200  $this->tpl->parseCurrentBlock();
201  }
202 
203  if($a_set["type"] != "dir")
204  {
205  $this->tpl->setVariable("TXT_SIZE", ilFormat::formatSize($a_set["size"]));
206  }
207 
208  // single item commands
209  if(sizeof($this->row_commands) &&
210  !($a_set["type"] == "dir" && $a_set["entry"] == ".."))
211  {
212  $advsel = new ilAdvancedSelectionListGUI();
213  $advsel->setListTitle($this->lng->txt("actions"));
214  foreach($this->row_commands as $rcom)
215  {
216  if($rcom["allow_dir"] || $a_set["type"] != "dir")
217  {
218  $ilCtrl->setParameter($this->parent_obj, "fhsh", $hash);
219  $url = $ilCtrl->getLinkTarget($this->parent_obj, $rcom["cmd"]);
220  $ilCtrl->setParameter($this->parent_obj, "fhsh", "");
221 
222  $advsel->addItem($rcom["caption"], "", $url);
223  }
224  }
225  $this->tpl->setVariable("ACTIONS", $advsel->getHTML());
226  }
227  }
228 
229 }
230 ?>
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
fillRow($a_set)
Fill table row.
$url
Definition: shib_logout.php:72
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.
Class ilTable2GUI.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
__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.
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.
if(!file_exists(getcwd().'/ilias.ini.php')) if(isset( $_GET["client_id"]))
registration confirmation script for ilias
Definition: confirmReg.php:20
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
global $lng
Definition: privfeed.php:40
setEnableHeader($a_enableheader)
Set Enable Header.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setEnableTitle($a_enabletitle)
Set Enable Title.
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.
TableGUI class for file system.