ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
24require_once "./Services/Container/classes/class.ilContainer.php";
25
35{
37
44 public function __construct($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, $a_omit_tree = false)
65 {
66 $new_obj = parent::cloneObject($a_target_id,$a_copy_id, $a_omit_tree);
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 return true;
118 }
119
128 private static function recurseFolder ($refid, $title, $tmpdir) {
129 global $rbacsystem, $tree, $ilAccess;
130
131 $tmpdir = $tmpdir.DIRECTORY_SEPARATOR.ilUtil::getASCIIFilename($title);
132 ilUtil::makeDir($tmpdir);
133
134 $subtree = $tree->getChildsByTypeFilter($refid, array("fold","file"));
135
136 foreach ($subtree as $child)
137 {
138 if (!$ilAccess->checkAccess("read", "", $child["ref_id"]))
139 {
140 continue;
141 }
142 if (ilObject::_isInTrash($child["ref_id"]))
143 {
144 continue;
145 }
146 if ($child["type"] == "fold")
147 {
148 ilObjFolder::recurseFolder ($child["ref_id"], $child["title"], $tmpdir);
149 } else {
150 $newFilename = $tmpdir.DIRECTORY_SEPARATOR.ilUtil::getASCIIFilename($child["title"]);
151 // copy to temporal directory
152 $oldFilename = ilObjFile::_lookupAbsolutePath($child["obj_id"]);
153 if (!copy ($oldFilename, $newFilename))
154 {
155 throw new ilFileException("Could not copy ".$oldFilename." to ".$newFilename);
156 }
157 touch($newFilename, filectime($oldFilename));
158 }
159 }
160
161 }
162
163 public function downloadFolder() {
164 global $lng, $rbacsystem, $ilAccess;
165 include_once 'Modules/File/classes/class.ilObjFile.php';
166 include_once 'Modules/File/classes/class.ilFileException.php';
167 if (!$ilAccess->checkAccess("read", "", $this->getRefId()))
168 {
169 $this->ilErr->raiseError(get_class($this)."::downloadFolder(): missing read permission!",$this->ilErr->WARNING);
170 }
171 if (ilObject::_isInTrash($this->getRefId()))
172 {
173 $this->ilErr->raiseError(get_class($this)."::downloadFolder(): object is trashed!",$this->ilErr->WARNING);
174 }
175
176 $zip = PATH_TO_ZIP;
177 $tmpdir = ilUtil::ilTempnam();
178 ilUtil::makeDir($tmpdir);
179 $basename = ilUtil::getAsciiFilename($this->getTitle());
180 $deliverFilename = $basename.".zip";
181 $zipbasedir = $tmpdir.DIRECTORY_SEPARATOR.$basename;
182 $tmpzipfile = $tmpdir.DIRECTORY_SEPARATOR.$deliverFilename;
183
184 try {
185 ilObjFolder::recurseFolder ($this->getRefId(), $this->getTitle(), $tmpdir);
186 ilUtil::zip($zipbasedir, $tmpzipfile);
187 rename($tmpzipfile,$zipfile = ilUtil::ilTempnam());
188 ilUtil::delDir($tmpdir);
189 ilUtil::deliverFile($zipfile,$deliverFilename,'',false,true);
190 } catch (ilFileException $e) {
191 ilUtil::sendInfo($e->getMessage(), true);
192 }
193 }
194
198 function getViewMode()
199 {
200 global $tree;
201
202 // default: by type
204
205 // always inherit from
206 $container_ref_id = $tree->checkForParentType($this->ref_id, 'grp');
207 if(!$container_ref_id)
208 {
209 $container_ref_id = $tree->checkForParentType($this->ref_id, 'crs');
210 }
211 if($container_ref_id)
212 {
213 include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
214 $view_mode = ilObjCourseAccess::_lookupViewMode(ilObject::_lookupObjId($container_ref_id));
215 if ($view_mode == ilContainer::VIEW_SESSIONS ||
216 $view_mode == ilContainer::VIEW_BY_TYPE ||
217 $view_mode == ilContainer::VIEW_SIMPLE)
218 {
219 $view = $view_mode;
220 }
221 }
222
223 return $view;
224 }
225
230 function addAdditionalSubItemInformation(&$a_item_data)
231 {
232 include_once './Services/Object/classes/class.ilObjectActivation.php';
234 }
235
243 public function read()
244 {
245 global $tree;
246
247 parent::read();
248
249 // Inherit order type from parent course (if exists)
250 include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
252 }
253
254} // END class.ilObjFolder
255?>
An exception for terminatinating execution or to throw for unit testing.
static _lookupSortMode($a_obj_id)
lookup sort mode
Class ilContainer.
setOrderType($a_value)
Class to report exception.
static _lookupViewMode($a_id)
Lookup view mode.
static _lookupAbsolutePath($obj_id, $a_version=null)
return absolute path for version
Class ilObjFolder.
getViewMode()
Get container view mode.
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
read()
Overwritten read method.
setFolderTree($a_tree)
putInTree($a_parent)
insert folder into grp_tree
addAdditionalSubItemInformation(&$a_item_data)
Add additional information to sub item, e.g.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone folder.
static recurseFolder($refid, $title, $tmpdir)
private functions which iterates through all folders and files and create an according file structure...
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies (crs items, preconditions)
static cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
Clone dependencies.
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
static _lookupObjId($a_id)
withReferences()
determines wehter objects are referenced or not (got ref ids or not)
getRefId()
get reference id @access public
getId()
get object id @access public
static _isInTrash($a_ref_id)
checks wether object is in trash
getTitle()
get object title @access public
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...