ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjFileDAV.php
Go to the documentation of this file.
1<?php
2// BEGIN WebDAV
3/*
4 +-----------------------------------------------------------------------------+
5 | ILIAS open source |
6 +-----------------------------------------------------------------------------+
7 | Copyright (c) 1998-2005 ILIAS open source, University of Cologne |
8 | |
9 | This program is free software; you can redistribute it and/or |
10 | modify it under the terms of the GNU General Public License |
11 | as published by the Free Software Foundation; either version 2 |
12 | of the License, or (at your option) any later version. |
13 | |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 +-----------------------------------------------------------------------------+
23*/
24
25require_once "class.ilObjectDAV.php";
26
27require_once './Services/History/classes/class.ilHistory.php';
28require_once 'Services/Utilities/classes/class.ilUtil.php';
29require_once "Modules/File/classes/class.ilObjFile.php";
30
31// NOTE: I changed class.ilObjFile.php to support the functionality needed by this handler.
32
44{
50 public function __construct($refid, $obj = null)
51 {
52 parent::__construct($refid, $obj);
53
54 // Set debug to true, if you want to get debug output for this
55 // object
56 //$this->isDebug = true;
57 }
58
65 public function initFromNull()
66 {
67 $this->obj->setFileName($this->getResourceName());
68 $this->obj->setFileType($this->obj->guessFileType());
69 $this->write();
70 $this->obj->setPermissions($this->getRefId());
71 }
76 public function createNewVersion()
77 {
78 $this->obj->setVersion($this->obj->getVersion() + 1);
80 $this->obj->getId(),
81 "replace",
82 $this->obj->getFileName() . "," . $this->obj->getVersion()
83 );
84 }
85
86
105 public function getResourceType()
106 {
107 return "";
108 }
109
114 public function getContentType()
115 {
116 //return $this->obj->getFileType();
117 return $this->obj->guessFileType();
118 }
123 public function setContentType($type)
124 {
125 $this->obj->setFileType($type);
126 }
131 public function setContentLength($length)
132 {
133 $this->writeLog('setContentLength(' . $length . ')');
134 $this->obj->setFileSize($length);
135 }
140 public function getContentLength()
141 {
142 return ilObjFile::_lookupFileSize($this->obj->getId());
143 }
148 public function getContentStream()
149 {
150 $file = $this->obj->getFile();
151 return (file_exists($file)) ? fopen($file, 'r') : null;
152 }
157 public function getContentOutputStream()
158 {
159 $file = $this->obj->getFile();
160 $parent = dirname($file);
161 if (!file_exists($parent)) {
162 ilUtil::makeDirParents($parent);
163 }
164
165 return fopen($file, 'w');
166 }
177 {
178 $file = $this->obj->getFile();
179 return file_exists($file) ? filesize($file) : 0;
180 }
186 public function getContentData()
187 {
188 return null;
189 }
194 public function read()
195 {
196 if (is_null($this->obj)) {
197 $this->obj = new ilObjFile($this->getRefId(), true);
198 $this->obj->read();
199 }
200 }
205 public function write()
206 {
207 $this->isNewFile = $this->obj->getVersion() == 0;
208 if ($this->isNewFile) {
209 $this->obj->setVersion(1);
210 }
211 parent::write();
212 /*
213 ilHistory::_createEntry($this->getObjectId(), 'update', '', '','', true);
214 */
215 }
216}
217// END WebDAV
An exception for terminatinating execution or to throw for unit testing.
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
getContentData()
Returns the content of the object as a byte array.
setContentType($type)
Sets the mime type of the content of this object.
getContentOutputStreamLength()
Returns the length of the content output stream.
__construct($refid, $obj=null)
Constructor.
initFromNull()
Initializes the object after it has been converted from the NULL type.
createNewVersion()
Creates a new version of the object.
write()
Writes the object data.
getContentType()
Returns the mime type of the content of this object.
getContentStream()
Returns the content of the object as a stream.
getContentLength()
Returns the number of bytes of the content.
getResourceType()
Returns the display name of this object.
getContentOutputStream()
Returns an output stream to the content.
read()
Reads the object data.
setContentLength($length)
Sets the length (in bytes) of the content of this object.
Class ilObjFile.
static _lookupFileSize($a_id)
Lookups the file size of the file in bytes.
$obj
Application layer object.
getRefId()
Returns the ref id of this object.
getResourceName()
Returns the resource name of this object.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$type
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file