ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCFileList.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Services/COPage/classes/class.ilPageContent.php");
25 
37 {
39 
43  function init()
44  {
45  $this->setType("flst");
46  }
47 
48  function setNode(&$a_node)
49  {
50  parent::setNode($a_node); // this is the PageContent node
51  $this->list_node =& $a_node->first_child(); // this is the Table node
52  }
53 
54  function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
55  {
56  $this->node = $this->createPageContentNode();
57  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
58  $this->list_node =& $this->dom->create_element("FileList");
59  $this->list_node =& $this->node->append_child($this->list_node);
60  }
61 
62  /*
63  function addItems($a_nr)
64  {
65  for ($i=1; $i<=$a_nr; $i++)
66  {
67  $new_item =& $this->dom->create_element("ListItem");
68  $new_item =& $this->list_node->append_child($new_item);
69  }
70  }*/
71 
72  function appendItem($a_id, $a_location, $a_format)
73  {
74  // File Item
75  $new_item =& $this->dom->create_element("FileItem");
76  $new_item =& $this->list_node->append_child($new_item);
77 
78  // Identifier
79  $id_node =& $this->dom->create_element("Identifier");
80  $id_node =& $new_item->append_child($id_node);
81  $id_node->set_attribute("Catalog", "ILIAS");
82  $id_node->set_attribute("Entry", "il__file_".$a_id);
83 
84  // Location
85  $loc_node =& $this->dom->create_element("Location");
86  $loc_node =& $new_item->append_child($loc_node);
87  $loc_node->set_attribute("Type", "LocalFile");
88  $loc_node->set_content($a_location);
89 
90  // Format
91  $form_node =& $this->dom->create_element("Format");
92  $form_node =& $new_item->append_child($form_node);
93  $form_node->set_content($a_format);
94  }
95 
96  function setListTitle($a_title, $a_language)
97  {
99  $this->list_node, "Title", array("FileItem"),
100  $a_title, array("Language" => $a_language));
101  }
102 
103  function getListTitle()
104  {
105  $chlds =& $this->list_node->child_nodes();
106  for($i=0; $i<count($chlds); $i++)
107  {
108  if ($chlds[$i]->node_name() == "Title")
109  {
110  return $chlds[$i]->get_content();
111  }
112  }
113  return "";
114  }
115 
116  function getLanguage()
117  {
118  $chlds =& $this->list_node->child_nodes();
119  for($i=0; $i<count($chlds); $i++)
120  {
121  if ($chlds[$i]->node_name() == "Title")
122  {
123  return $chlds[$i]->get_attribute("Language");
124  }
125  }
126  return "";
127  }
128 
132  function getFileList()
133  {
134  $files = array();
135 
136  // File Item
137  $childs = $this->list_node->child_nodes();
138  for ($i=0; $i<count($childs); $i++)
139  {
140  if ($childs[$i]->node_name() == "FileItem")
141  {
142  $id = $entry = "";
143  $pc_id = $childs[$i]->get_attribute("PCID");
144  $hier_id = $childs[$i]->get_attribute("HierId");
145  $class = $childs[$i]->get_attribute("Class");
146 
147  // Identifier
148  $id_node = $childs[$i]->first_child();
149  if ($id_node->node_name() == "Identifier")
150  {
151  $entry = $id_node->get_attribute("Entry");
152  if (substr($entry, 0, 9) == "il__file_")
153  {
154  $id = substr($entry, 9);
155  }
156  }
157  $files[] = array("entry" => $entry, "id" => $id,
158  "pc_id" => $pc_id, "hier_id" => $hier_id,
159  "class" => $class);
160  }
161  }
162 
163  return $files;
164  }
165 
169  function deleteFileItems($a_ids)
170  {
171  $files = array();
172 
173  // File Item
174  $childs = $this->list_node->child_nodes();
175 
176  for ($i=0; $i<count($childs); $i++)
177  {
178  if ($childs[$i]->node_name() == "FileItem")
179  {
180  $id = $entry = "";
181  $pc_id = $childs[$i]->get_attribute("PCID");
182  $hier_id = $childs[$i]->get_attribute("HierId");
183 
184  if (in_array($hier_id.":".$pc_id, $a_ids))
185  {
186  $childs[$i]->unlink($childs[$i]);
187  }
188  }
189  }
190  }
191 
195  function savePositions($a_pos)
196  {
197  asort($a_pos);
198 
199  // File Item
200  $childs = $this->list_node->child_nodes();
201  $nodes = array();
202  for ($i=0; $i<count($childs); $i++)
203  {
204  if ($childs[$i]->node_name() == "FileItem")
205  {
206  $id = $entry = "";
207  $pc_id = $childs[$i]->get_attribute("PCID");
208  $hier_id = $childs[$i]->get_attribute("HierId");
209  $nodes[$hier_id.":".$pc_id] = $childs[$i];
210  $childs[$i]->unlink($childs[$i]);
211  }
212  }
213 
214  foreach($a_pos as $k => $v)
215  {
216  if (is_object($nodes[$k]))
217  {
218  $nodes[$k] = $this->list_node->append_child($nodes[$k]);
219  }
220  }
221  }
222 
226  function getAllClasses()
227  {
228  $classes = array();
229 
230  // File Item
231  $childs = $this->list_node->child_nodes();
232 
233  for ($i=0; $i<count($childs); $i++)
234  {
235  if ($childs[$i]->node_name() == "FileItem")
236  {
237  $classes[$childs[$i]->get_attribute("HierId").":".
238  $childs[$i]->get_attribute("PCID")] = $childs[$i]->get_attribute("Class");
239  }
240  }
241 
242  return $classes;
243  }
244 
248  function saveStyleClasses($a_class)
249  {
250  // File Item
251  $childs = $this->list_node->child_nodes();
252  for ($i=0; $i<count($childs); $i++)
253  {
254  if ($childs[$i]->node_name() == "FileItem")
255  {
256  $childs[$i]->set_attribute("Class",
257  $a_class[$childs[$i]->get_attribute("HierId").":".
258  $childs[$i]->get_attribute("PCID")]);
259  }
260  }
261  }
262 
263 }
264 ?>