ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilCourseFile Class Reference
+ Inheritance diagram for ilCourseFile:
+ Collaboration diagram for ilCourseFile:

Public Member Functions

 __construct ($a_file_id=null)
 Constructor. More...
 
 setFileId ($a_id)
 
 getFileId ()
 
 getCourseId ()
 
 setCourseId ($a_course_id)
 
 setFileName ($a_name)
 
 getFileName ()
 
 setFileType ($a_type)
 
 getFileType ()
 
 setFileSize ($a_size)
 
 getFileSize ()
 
 setTemporaryName ($a_name)
 
 getTemporaryName ()
 
 setErrorCode ($a_code)
 
 getErrorCode ()
 
 getAbsolutePath ()
 
 getInfoDirectory ()
 
 validate ()
 
 create ($a_upload=true)
 
 delete ()
 
 __read ()
 

Static Public Member Functions

static _cloneFiles ($a_source_id, $a_target_id)
 Clone course files. More...
 
static _deleteByCourse ($a_course_id)
 
static _readFilesByCourse ($a_course_id)
 

Data Fields

 $ilErr
 
 $ilDB
 
 $tree
 
 $lng
 
 $course_id = null
 
 $file_id = null
 

Private Attributes

 $fss_storage = null
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 35 of file class.ilCourseFile.php.

Constructor & Destructor Documentation

◆ __construct()

ilCourseFile::__construct (   $a_file_id = null)

Constructor.

Parameters
int$a_file_id

Definition at line 54 of file class.ilCourseFile.php.

55 {
56 global $DIC;
57
58 $ilErr = $DIC['ilErr'];
59 $ilDB = $DIC['ilDB'];
60 $lng = $DIC['lng'];
61
62 $this->ilErr = $ilErr;
63 $this->db = $ilDB;
64 $this->lng = $lng;
65
66 $this->file_id = $a_file_id;
67 $this->__read();
68 }
$DIC
Definition: xapitoken.php:46

References $DIC, $ilDB, $ilErr, $lng, and __read().

+ Here is the call graph for this function:

Member Function Documentation

◆ __read()

ilCourseFile::__read ( )

Definition at line 303 of file class.ilCourseFile.php.

304 {
305 global $DIC;
306
307 $ilDB = $DIC['ilDB'];
308
309 if (!$this->file_id) {
310 return true;
311 }
312
313 // read file data
314 $query = "SELECT * FROM crs_file WHERE file_id = " . $ilDB->quote($this->file_id, 'integer');
315 $res = $this->db->query($query);
316 while ($row = $ilDB->fetchObject($res)) {
317 $this->setFileName($row->file_name);
318 $this->setFileSize($row->file_size);
319 $this->setFileType($row->file_type);
320 $this->setCourseId($row->course_id);
321 }
322 $this->fss_storage = new ilFSStorageCourse($this->getCourseId());
323 return true;
324 }
setCourseId($a_course_id)
$query
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $query, $res, getCourseId(), setCourseId(), setFileName(), setFileSize(), and setFileType().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cloneFiles()

static ilCourseFile::_cloneFiles (   $a_source_id,
  $a_target_id 
)
static

Clone course files.

@access public

Parameters
intsource id
inttarget_id

Definition at line 79 of file class.ilCourseFile.php.

80 {
81 $source = new ilFSStorageCourse($a_source_id);
82
83 foreach (ilCourseFile::_readFilesByCourse($a_source_id) as $file_obj) {
84 $new_file = new ilCourseFile();
85 $new_file->setCourseId($a_target_id);
86 $new_file->setFileName($file_obj->getFileName());
87 $new_file->setFileSize($file_obj->getFileSize());
88 $new_file->setFileType($file_obj->getFileType());
89 $new_file->create(false);
90
91 $target = new ilFSStorageCourse($a_target_id);
92 $target->initInfoDirectory();
93 $source->copyFile($file_obj->getAbsolutePath(), $new_file->fss_storage->getInfoDirectory() . '/' . $new_file->getFileId());
94 }
95 }
static _readFilesByCourse($a_course_id)
$source
Definition: metadata.php:76

References $source, and _readFilesByCourse().

Referenced by ilObjCourse\cloneObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteByCourse()

static ilCourseFile::_deleteByCourse (   $a_course_id)
static

Definition at line 268 of file class.ilCourseFile.php.

269 {
270 global $DIC;
271
272 $ilDB = $DIC['ilDB'];
273
274 // delete all course ids and delete assigned files
275 $query = "DELETE FROM crs_file " .
276 "WHERE course_id = " . $ilDB->quote($a_course_id, 'integer') . "";
277 $res = $ilDB->manipulate($query);
278
279 return true;
280 }

References $DIC, $ilDB, $query, and $res.

Referenced by ilObjCourse\delete().

+ Here is the caller graph for this function:

◆ _readFilesByCourse()

static ilCourseFile::_readFilesByCourse (   $a_course_id)
static
Parameters
int$a_course_idobj_id of course
Returns
ilCourseFile[]

Definition at line 287 of file class.ilCourseFile.php.

288 {
289 global $DIC;
290
291 $ilDB = $DIC['ilDB'];
292
293 $query = "SELECT * FROM crs_file " .
294 "WHERE course_id = " . $ilDB->quote($a_course_id, 'integer') . "";
295
296 $res = $ilDB->query($query);
297 while ($row = $ilDB->fetchObject($res)) {
298 $files[] = new ilCourseFile($row->file_id);
299 }
300 return is_array($files) ? $files : array();
301 }

References $DIC, $ilDB, $query, and $res.

Referenced by _cloneFiles(), ilAppointmentPresentationCourseGUI\collectPropertiesAndActions(), ilObjCourseGUI\editInfoObject(), ilAppointmentCourseFileHandler\getFiles(), and ilObjCourseGUI\infoScreen().

+ Here is the caller graph for this function:

◆ create()

ilCourseFile::create (   $a_upload = true)

Definition at line 213 of file class.ilCourseFile.php.

214 {
215 global $DIC;
216
217 $ilDB = $DIC['ilDB'];
218
219 if ($this->getErrorCode() != 0) {
220 return false;
221 }
222
223 $next_id = $ilDB->nextId('crs_file');
224 $query = "INSERT INTO crs_file (file_id,course_id,file_name,file_size,file_type) " .
225 "VALUES( " .
226 $ilDB->quote($next_id, 'integer') . ", " .
227 $ilDB->quote($this->getCourseId(), 'integer') . ", " .
228 $ilDB->quote($this->getFileName(), 'text') . ", " .
229 $ilDB->quote($this->getFileSize(), 'integer') . ", " .
230 $ilDB->quote($this->getFileType(), 'text') . " " .
231 ")";
232 $res = $ilDB->manipulate($query);
233 $this->setFileId($next_id);
234
235 $this->fss_storage = new ilFSStorageCourse($this->getCourseId());
236 $this->fss_storage->initInfoDirectory();
237
238 if ($a_upload) {
239 // now create file
241 $this->getTemporaryName(),
242 $this->getFileName(),
243 $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId()
244 );
245 }
246 return true;
247 }
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file

References $DIC, $ilDB, $query, $res, getCourseId(), getErrorCode(), getFileName(), getFileSize(), getFileType(), getTemporaryName(), ilUtil\moveUploadedFile(), and setFileId().

+ Here is the call graph for this function:

◆ delete()

ilCourseFile::delete ( )

Definition at line 249 of file class.ilCourseFile.php.

250 {
251 global $DIC;
252
253 $ilDB = $DIC['ilDB'];
254
255 // Delete db entry
256 $query = "DELETE FROM crs_file " .
257 "WHERE file_id = " . $ilDB->quote($this->getFileId(), 'integer') . "";
258 $res = $ilDB->manipulate($query);
259
260 // Delete file
261 if (file_exists($this->getAbsolutePath())) {
262 unlink($this->getAbsolutePath());
263 }
264
265 return true;
266 }

References $DIC, $ilDB, $query, $res, getAbsolutePath(), and getFileId().

+ Here is the call graph for this function:

◆ getAbsolutePath()

ilCourseFile::getAbsolutePath ( )
Returns
bool|string

Definition at line 159 of file class.ilCourseFile.php.

160 {
161 // workaround for "secured" files.
162 if (!$this->fss_storage instanceof \ilFSStorageCourse) {
163 return false;
164 }
165
166 $file = $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId();
167 if (!file_exists($file)) {
168 $file = $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId() . '.sec';
169 }
170 if (file_exists($file)) {
171 return $file;
172 }
173 return false;
174 }

References getFileId().

Referenced by delete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCourseId()

ilCourseFile::getCourseId ( )

Definition at line 106 of file class.ilCourseFile.php.

107 {
108 return $this->course_id;
109 }

References $course_id.

Referenced by __read(), and create().

+ Here is the caller graph for this function:

◆ getErrorCode()

ilCourseFile::getErrorCode ( )

Definition at line 151 of file class.ilCourseFile.php.

152 {
153 return $this->error_code;
154 }

Referenced by create(), and validate().

+ Here is the caller graph for this function:

◆ getFileId()

ilCourseFile::getFileId ( )

Definition at line 101 of file class.ilCourseFile.php.

102 {
103 return $this->file_id;
104 }

References $file_id.

Referenced by delete(), and getAbsolutePath().

+ Here is the caller graph for this function:

◆ getFileName()

ilCourseFile::getFileName ( )

Definition at line 119 of file class.ilCourseFile.php.

120 {
121 return $this->file_name;
122 }

Referenced by create().

+ Here is the caller graph for this function:

◆ getFileSize()

ilCourseFile::getFileSize ( )

Definition at line 135 of file class.ilCourseFile.php.

136 {
137 return $this->file_size;
138 }

Referenced by create().

+ Here is the caller graph for this function:

◆ getFileType()

ilCourseFile::getFileType ( )

Definition at line 127 of file class.ilCourseFile.php.

128 {
129 return $this->file_type;
130 }

Referenced by create().

+ Here is the caller graph for this function:

◆ getInfoDirectory()

ilCourseFile::getInfoDirectory ( )

Definition at line 176 of file class.ilCourseFile.php.

177 {
178 if (is_object($this->fss_storage)) {
179 return $this->fss_storage->getInfoDirectory();
180 }
181 }

◆ getTemporaryName()

ilCourseFile::getTemporaryName ( )

Definition at line 143 of file class.ilCourseFile.php.

144 {
145 return $this->tmp_name;
146 }

Referenced by create().

+ Here is the caller graph for this function:

◆ setCourseId()

ilCourseFile::setCourseId (   $a_course_id)

Definition at line 110 of file class.ilCourseFile.php.

111 {
112 $this->course_id = $a_course_id;
113 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setErrorCode()

ilCourseFile::setErrorCode (   $a_code)

Definition at line 147 of file class.ilCourseFile.php.

148 {
149 $this->error_code = $a_code;
150 }

◆ setFileId()

ilCourseFile::setFileId (   $a_id)

Definition at line 97 of file class.ilCourseFile.php.

98 {
99 $this->file_id = $a_id;
100 }

Referenced by create().

+ Here is the caller graph for this function:

◆ setFileName()

ilCourseFile::setFileName (   $a_name)

Definition at line 115 of file class.ilCourseFile.php.

116 {
117 $this->file_name = $a_name;
118 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setFileSize()

ilCourseFile::setFileSize (   $a_size)

Definition at line 131 of file class.ilCourseFile.php.

132 {
133 $this->file_size = $a_size;
134 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setFileType()

ilCourseFile::setFileType (   $a_type)

Definition at line 123 of file class.ilCourseFile.php.

124 {
125 $this->file_type = $a_type;
126 }
$a_type
Definition: workflow.php:92

References $a_type.

Referenced by __read().

+ Here is the caller graph for this function:

◆ setTemporaryName()

ilCourseFile::setTemporaryName (   $a_name)

Definition at line 139 of file class.ilCourseFile.php.

140 {
141 $this->tmp_name = $a_name;
142 }

◆ validate()

ilCourseFile::validate ( )

Definition at line 183 of file class.ilCourseFile.php.

184 {
185 switch ($this->getErrorCode()) {
186 case UPLOAD_ERR_INI_SIZE:
187 $this->ilErr->appendMessage($this->lng->txt('file_upload_ini_size'));
188 break;
189 case UPLOAD_ERR_FORM_SIZE:
190 $this->ilErr->appendMessage($this->lng->txt('file_upload_form_size'));
191 break;
192
193 case UPLOAD_ERR_PARTIAL:
194 $this->ilErr->appendMessage($this->lng->txt('file_upload_only_partial'));
195 break;
196
197 case UPLOAD_ERR_NO_TMP_DIR:
198 $this->ilErr->appendMessage($this->lng->txt('file_upload_no_tmp_dir'));
199 break;
200
201 // not possible with php 4
202 #case UPLOAD_ERR_CANT_WRITE:
203 # $this->ilErr->appendMessage($this->lng->txt('file_upload_no_write'));
204 # break;
205
206 case UPLOAD_ERR_OK:
207 case UPLOAD_ERR_NO_FILE:
208 default:
209 return true;
210 }
211 }

References getErrorCode().

+ Here is the call graph for this function:

Field Documentation

◆ $course_id

ilCourseFile::$course_id = null

Definition at line 42 of file class.ilCourseFile.php.

Referenced by getCourseId().

◆ $file_id

ilCourseFile::$file_id = null

Definition at line 43 of file class.ilCourseFile.php.

Referenced by getFileId().

◆ $fss_storage

ilCourseFile::$fss_storage = null
private

Definition at line 48 of file class.ilCourseFile.php.

◆ $ilDB

ilCourseFile::$ilDB

◆ $ilErr

ilCourseFile::$ilErr

Definition at line 37 of file class.ilCourseFile.php.

Referenced by __construct().

◆ $lng

ilCourseFile::$lng

Definition at line 40 of file class.ilCourseFile.php.

Referenced by __construct().

◆ $tree

ilCourseFile::$tree

Definition at line 39 of file class.ilCourseFile.php.


The documentation for this class was generated from the following file: