ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjFolder.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/Container/classes/class.ilContainer.php";
25 
34 class ilObjFolder extends ilContainer
35 {
37 
44  function ilObjFolder($a_id = 0,$a_call_by_reference = true)
45  {
46  $this->type = "fold";
47  parent::__construct($a_id,$a_call_by_reference);
48  }
49 
50  function setFolderTree($a_tree)
51  {
52  $this->folder_tree =& $a_tree;
53  }
54 
63  public function cloneObject($a_target_id,$a_copy_id = 0)
64  {
65  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
66 
67  // Copy learning progress settings
68  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
69  $obj_settings = new ilLPObjSettings($this->getId());
70  $obj_settings->cloneSettings($new_obj->getId());
71  unset($obj_settings);
72 
73  return $new_obj;
74  }
75 
80  function putInTree($a_parent)
81  {
82  global $tree;
83 
84  if (!is_object($this->folder_tree))
85  {
86  $this->folder_tree =& $tree;
87  }
88 
89  if ($this->withReferences())
90  {
91  // put reference id into tree
92  $this->folder_tree->insertNode($this->getRefId(), $a_parent);
93  }
94  else
95  {
96  // put object id into tree
97  $this->folder_tree->insertNode($this->getId(), $a_parent);
98  }
99  }
100 
109  public function cloneDependencies($a_target_id,$a_copy_id)
110  {
111  global $tree;
112 
113  parent::cloneDependencies($a_target_id,$a_copy_id);
114 
115  if($course_ref_id = $tree->checkForParentType($this->getRefId(),'crs') and
116  $new_course_ref_id = $tree->checkForParentType($a_target_id,'crs'))
117  {
118  include_once('Modules/Course/classes/class.ilCourseItems.php');
119  $course_obj =& ilObjectFactory::getInstanceByRefId($course_ref_id,false);
120  $course_items = new ilCourseItems($course_obj,$this->getRefId());
121  $course_items->cloneDependencies($a_target_id,$a_copy_id);
122  }
123 
124  include_once('Services/Tracking/classes/class.ilLPCollections.php');
125  $lp_collection = new ilLPCollections($this->getId());
126  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
127 
128  return true;
129  }
130 
139  private static function recurseFolder ($refid, $title, $tmpdir) {
140  global $rbacsystem, $tree, $ilAccess;
141 
142  $tmpdir = $tmpdir.DIRECTORY_SEPARATOR.ilUtil::getASCIIFilename($title);
143  ilUtil::makeDir($tmpdir);
144 
145  $subtree = $tree->getChildsByTypeFilter($refid, array("fold","file"));
146 
147  foreach ($subtree as $child)
148  {
149  if (!$ilAccess->checkAccess("read", "", $child["ref_id"]))
150  {
151  continue;
152  }
153  if (ilObject::_isInTrash($child["ref_id"]))
154  {
155  continue;
156  }
157  if ($child["type"] == "fold")
158  {
159  ilObjFolder::recurseFolder ($child["ref_id"], $child["title"], $tmpdir);
160  } else {
161  $newFilename = $tmpdir.DIRECTORY_SEPARATOR.ilUtil::getASCIIFilename($child["title"]);
162  // copy to temporal directory
163  $oldFilename = ilObjFile::_lookupAbsolutePath($child["obj_id"]);
164  if (!copy ($oldFilename, $newFilename))
165  {
166  throw new ilFileException("Could not copy ".$oldFilename." to ".$newFilename);
167  }
168  touch($newFilename, filectime($oldFilename));
169  }
170  }
171 
172  }
173 
174  public function downloadFolder() {
175  global $lng, $rbacsystem, $ilAccess;
176  include_once "./Services/Utilities/classes/class.ilUtil.php";
177  include_once 'Modules/File/classes/class.ilObjFile.php';
178  include_once 'Modules/File/classes/class.ilFileException.php';
179  if (!$ilAccess->checkAccess("read", "", $this->getRefId()))
180  {
181  $this->ilErr->raiseError(get_class($this)."::downloadFolder(): missing read permission!",$this->ilErr->WARNING);
182  }
183  if (ilObject::_isInTrash($this->getRefId()))
184  {
185  $this->ilErr->raiseError(get_class($this)."::downloadFolder(): object is trashed!",$this->ilErr->WARNING);
186  }
187 
188  $zip = PATH_TO_ZIP;
189  $tmpdir = ilUtil::ilTempnam();
190  ilUtil::makeDir($tmpdir);
191  $basename = ilUtil::getAsciiFilename($this->getTitle());
192  $deliverFilename = $basename.".zip";
193  $zipbasedir = $tmpdir.DIRECTORY_SEPARATOR.$basename;
194  $tmpzipfile = $tmpdir.DIRECTORY_SEPARATOR.$deliverFilename;
195 
196  try {
197  ilObjFolder::recurseFolder ($this->getRefId(), $this->getTitle(), $tmpdir);
198  ilUtil::zip($zipbasedir, $tmpzipfile);
199  rename($tmpzipfile,$zipfile = ilUtil::ilTempnam());
200  ilUtil::delDir($tmpdir);
201  ilUtil::deliverFile($zipfile,$deliverFilename,'',false,true);
202  } catch (ilFileException $e) {
203  ilUtil::sendInfo($e->getMessage(), true);
204  }
205  }
206 
210  function getViewMode()
211  {
212  global $tree;
213 
214  // default: by type
216 
217  // get view mode from course
218  if ($course_ref_id = $tree->checkForParentType($this->ref_id,'crs'))
219  {
220  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
221  $view_mode = ilObjCourseAccess::_lookupViewMode(ilObject::_lookupObjId($course_ref_id));
222  if ($view_mode == ilContainer::VIEW_SESSIONS ||
223  $view_mode == ilContainer::VIEW_BY_TYPE ||
224  $view_mode == ilContainer::VIEW_SIMPLE)
225  {
226  $view = $view_mode;
227  }
228  }
229 
230  return $view;
231  }
232 
237  function addAdditionalSubItemInformation(&$a_item_data)
238  {
239  global $tree;
240 
241  static $items = null;
242 
243  if(!is_object($items[$this->getRefId()]))
244  {
245  if ($course_ref_id = $tree->checkForParentType($this->getRefId(),'crs'))
246  {
247  include_once("./Modules/Course/classes/class.ilObjCourse.php");
248  include_once("./Modules/Course/classes/class.ilCourseItems.php");
249  $course_obj = new ilObjCourse($course_ref_id);
250  $items[$this->getRefId()] = new ilCourseItems($course_obj, $this->getRefId());
251  }
252  }
253  if(is_object($items[$this->getRefId()]))
254  {
255  $items[$this->getRefId()]->addAdditionalSubItemInformation($a_item_data);
256  }
257  }
258 
266  public function read()
267  {
268  global $tree;
269 
270  parent::read();
271 
272  // Inherit order type from parent course (if exists)
273  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
275  }
276 
277 } // END class.ilObjFolder
278 ?>