ILIAS  release_4-3 Revision
 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  $this->lng->loadLanguageModule('fold');
49  }
50 
51  function setFolderTree($a_tree)
52  {
53  $this->folder_tree =& $a_tree;
54  }
55 
64  public function cloneObject($a_target_id,$a_copy_id = 0)
65  {
66  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
67 
68  // Copy learning progress settings
69  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
70  $obj_settings = new ilLPObjSettings($this->getId());
71  $obj_settings->cloneSettings($new_obj->getId());
72  unset($obj_settings);
73 
74  return $new_obj;
75  }
76 
81  function putInTree($a_parent)
82  {
83  global $tree;
84 
85  if (!is_object($this->folder_tree))
86  {
87  $this->folder_tree =& $tree;
88  }
89 
90  if ($this->withReferences())
91  {
92  // put reference id into tree
93  $this->folder_tree->insertNode($this->getRefId(), $a_parent);
94  }
95  else
96  {
97  // put object id into tree
98  $this->folder_tree->insertNode($this->getId(), $a_parent);
99  }
100  }
101 
110  public function cloneDependencies($a_target_id,$a_copy_id)
111  {
112  parent::cloneDependencies($a_target_id,$a_copy_id);
113 
114  include_once('Services/Object/classes/class.ilObjectActivation.php');
115  ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
116 
117  include_once('Services/Tracking/classes/class.ilLPCollections.php');
118  $lp_collection = new ilLPCollections($this->getId());
119  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
120 
121  return true;
122  }
123 
132  private static function recurseFolder ($refid, $title, $tmpdir) {
133  global $rbacsystem, $tree, $ilAccess;
134 
135  $tmpdir = $tmpdir.DIRECTORY_SEPARATOR.ilUtil::getASCIIFilename($title);
136  ilUtil::makeDir($tmpdir);
137 
138  $subtree = $tree->getChildsByTypeFilter($refid, array("fold","file"));
139 
140  foreach ($subtree as $child)
141  {
142  if (!$ilAccess->checkAccess("read", "", $child["ref_id"]))
143  {
144  continue;
145  }
146  if (ilObject::_isInTrash($child["ref_id"]))
147  {
148  continue;
149  }
150  if ($child["type"] == "fold")
151  {
152  ilObjFolder::recurseFolder ($child["ref_id"], $child["title"], $tmpdir);
153  } else {
154  $newFilename = $tmpdir.DIRECTORY_SEPARATOR.ilUtil::getASCIIFilename($child["title"]);
155  // copy to temporal directory
156  $oldFilename = ilObjFile::_lookupAbsolutePath($child["obj_id"]);
157  if (!copy ($oldFilename, $newFilename))
158  {
159  throw new ilFileException("Could not copy ".$oldFilename." to ".$newFilename);
160  }
161  touch($newFilename, filectime($oldFilename));
162  }
163  }
164 
165  }
166 
167  public function downloadFolder() {
168  global $lng, $rbacsystem, $ilAccess;
169  include_once "./Services/Utilities/classes/class.ilUtil.php";
170  include_once 'Modules/File/classes/class.ilObjFile.php';
171  include_once 'Modules/File/classes/class.ilFileException.php';
172  if (!$ilAccess->checkAccess("read", "", $this->getRefId()))
173  {
174  $this->ilErr->raiseError(get_class($this)."::downloadFolder(): missing read permission!",$this->ilErr->WARNING);
175  }
176  if (ilObject::_isInTrash($this->getRefId()))
177  {
178  $this->ilErr->raiseError(get_class($this)."::downloadFolder(): object is trashed!",$this->ilErr->WARNING);
179  }
180 
181  $zip = PATH_TO_ZIP;
182  $tmpdir = ilUtil::ilTempnam();
183  ilUtil::makeDir($tmpdir);
184  $basename = ilUtil::getAsciiFilename($this->getTitle());
185  $deliverFilename = $basename.".zip";
186  $zipbasedir = $tmpdir.DIRECTORY_SEPARATOR.$basename;
187  $tmpzipfile = $tmpdir.DIRECTORY_SEPARATOR.$deliverFilename;
188 
189  try {
190  ilObjFolder::recurseFolder ($this->getRefId(), $this->getTitle(), $tmpdir);
191  ilUtil::zip($zipbasedir, $tmpzipfile);
192  rename($tmpzipfile,$zipfile = ilUtil::ilTempnam());
193  ilUtil::delDir($tmpdir);
194  ilUtil::deliverFile($zipfile,$deliverFilename,'',false,true);
195  } catch (ilFileException $e) {
196  ilUtil::sendInfo($e->getMessage(), true);
197  }
198  }
199 
203  function getViewMode()
204  {
205  global $tree;
206 
207  // default: by type
209 
210  // always inherit from
211  $container_ref_id = $tree->checkForParentType($this->ref_id, 'grp');
212  if(!$container_ref_id)
213  {
214  $container_ref_id = $tree->checkForParentType($this->ref_id, 'crs');
215  }
216  if($container_ref_id)
217  {
218  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
219  $view_mode = ilObjCourseAccess::_lookupViewMode(ilObject::_lookupObjId($container_ref_id));
220  if ($view_mode == ilContainer::VIEW_SESSIONS ||
221  $view_mode == ilContainer::VIEW_BY_TYPE ||
222  $view_mode == ilContainer::VIEW_SIMPLE)
223  {
224  $view = $view_mode;
225  }
226  }
227 
228  return $view;
229  }
230 
235  function addAdditionalSubItemInformation(&$a_item_data)
236  {
237  include_once './Services/Object/classes/class.ilObjectActivation.php';
239  }
240 
248  public function read()
249  {
250  global $tree;
251 
252  parent::read();
253 
254  // Inherit order type from parent course (if exists)
255  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
257  }
258 
259 } // END class.ilObjFolder
260 ?>