ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

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

55  {
56  global $ilErr,$ilDB,$lng;
57 
58  $this->ilErr = $ilErr;
59  $this->db = $ilDB;
60  $this->lng = $lng;
61 
62  $this->file_id = $a_file_id;
63  $this->__read();
64  }
+ Here is the call graph for this function:

Member Function Documentation

◆ __read()

ilCourseFile::__read ( )

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

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

Referenced by __construct().

292  {
293  global $ilDB;
294 
295  if (!$this->file_id) {
296  return true;
297  }
298 
299  // read file data
300  $query = "SELECT * FROM crs_file WHERE file_id = " . $ilDB->quote($this->file_id, 'integer');
301  $res = $this->db->query($query);
302  while ($row = $ilDB->fetchObject($res)) {
303  $this->setFileName($row->file_name);
304  $this->setFileSize($row->file_size);
305  $this->setFileType($row->file_type);
306  $this->setCourseId($row->course_id);
307  }
308  $this->fss_storage = new ilFSStorageCourse($this->getCourseId());
309  return true;
310  }
foreach($_POST as $key=> $value) $res
$query
setCourseId($a_course_id)
+ 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.

public

Parameters
intsource id
inttarget_id

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

References $source, $target, and _readFilesByCourse().

Referenced by ilObjCourse\cloneObject().

76  {
77  $source = new ilFSStorageCourse($a_source_id);
78 
79  foreach (ilCourseFile::_readFilesByCourse($a_source_id) as $file_obj) {
80  $new_file = new ilCourseFile();
81  $new_file->setCourseId($a_target_id);
82  $new_file->setFileName($file_obj->getFileName());
83  $new_file->setFileSize($file_obj->getFileSize());
84  $new_file->setFileType($file_obj->getFileType());
85  $new_file->create(false);
86 
87  $target = new ilFSStorageCourse($a_target_id);
88  $target->initInfoDirectory();
89  $source->copyFile($file_obj->getAbsolutePath(), $new_file->getAbsolutePath());
90  }
91  }
static _readFilesByCourse($a_course_id)
$source
Definition: linkback.php:22
+ 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 260 of file class.ilCourseFile.php.

References $ilDB, $query, and $res.

Referenced by ilObjCourse\delete().

261  {
262  global $ilDB;
263 
264  // delete all course ids and delete assigned files
265  $query = "DELETE FROM crs_file " .
266  "WHERE course_id = " . $ilDB->quote($a_course_id, 'integer') . "";
267  $res = $ilDB->manipulate($query);
268 
269  return true;
270  }
foreach($_POST as $key=> $value) $res
$query
+ 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 277 of file class.ilCourseFile.php.

References $files, $ilDB, $query, $res, $row, and array.

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

278  {
279  global $ilDB;
280 
281  $query = "SELECT * FROM crs_file " .
282  "WHERE course_id = " . $ilDB->quote($a_course_id, 'integer') . "";
283 
284  $res = $ilDB->query($query);
285  while ($row = $ilDB->fetchObject($res)) {
286  $files[] = new ilCourseFile($row->file_id);
287  }
288  return is_array($files) ? $files : array();
289  }
$files
Definition: add-vimline.php:18
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ create()

ilCourseFile::create (   $a_upload = true)

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

References $ilDB, $query, $res, getCourseId(), getErrorCode(), getFileId(), getFileName(), getFileSize(), getFileType(), getTemporaryName(), and setFileId().

210  {
211  global $ilDB;
212 
213  if ($this->getErrorCode() != 0) {
214  return false;
215  }
216 
217  $next_id = $ilDB->nextId('crs_file');
218  $query = "INSERT INTO crs_file (file_id,course_id,file_name,file_size,file_type) " .
219  "VALUES( " .
220  $ilDB->quote($next_id, 'integer') . ", " .
221  $ilDB->quote($this->getCourseId(), 'integer') . ", " .
222  $ilDB->quote($this->getFileName(), 'text') . ", " .
223  $ilDB->quote($this->getFileSize(), 'integer') . ", " .
224  $ilDB->quote($this->getFileType(), 'text') . " " .
225  ")";
226  $res = $ilDB->manipulate($query);
227  $this->setFileId($next_id);
228 
229  $this->fss_storage = new ilFSStorageCourse($this->getCourseId());
230  $this->fss_storage->initInfoDirectory();
231 
232  if ($a_upload) {
233  // now create file
234  ilUtil::moveUploadedFile(
235  $this->getTemporaryName(),
236  $this->getFileName(),
237  $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId()
238  );
239  }
240  return true;
241  }
foreach($_POST as $key=> $value) $res
$query
+ Here is the call graph for this function:

◆ delete()

ilCourseFile::delete ( )

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

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

244  {
245  global $ilDB;
246 
247  // Delete db entry
248  $query = "DELETE FROM crs_file " .
249  "WHERE file_id = " . $ilDB->quote($this->getFileId(), 'integer') . "";
250  $res = $ilDB->manipulate($query);
251 
252  // Delete file
253  if (file_exists($this->getAbsolutePath())) {
254  unlink($this->getAbsolutePath());
255  }
256 
257  return true;
258  }
foreach($_POST as $key=> $value) $res
$query
+ Here is the call graph for this function:

◆ getAbsolutePath()

ilCourseFile::getAbsolutePath ( )
Returns
bool|string

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

References $file, and getFileId().

Referenced by delete().

156  {
157  // workaround for "secured" files.
158  if (!$this->fss_storage instanceof \ilFSStorageCourse) {
159  return false;
160  }
161 
162  $file = $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId();
163  if (!file_exists($file)) {
164  $file = $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId() . '.sec';
165  }
166  if (file_exists($file)) {
167  return $file;
168  }
169  return false;
170  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCourseId()

ilCourseFile::getCourseId ( )

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

References $course_id.

Referenced by __read(), and create().

103  {
104  return $this->course_id;
105  }
+ Here is the caller graph for this function:

◆ getErrorCode()

ilCourseFile::getErrorCode ( )

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

Referenced by create(), and validate().

148  {
149  return $this->error_code;
150  }
+ Here is the caller graph for this function:

◆ getFileId()

ilCourseFile::getFileId ( )

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

References $file_id.

Referenced by create(), delete(), and getAbsolutePath().

98  {
99  return $this->file_id;
100  }
+ Here is the caller graph for this function:

◆ getFileName()

ilCourseFile::getFileName ( )

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

Referenced by create().

116  {
117  return $this->file_name;
118  }
+ Here is the caller graph for this function:

◆ getFileSize()

ilCourseFile::getFileSize ( )

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

Referenced by create().

132  {
133  return $this->file_size;
134  }
+ Here is the caller graph for this function:

◆ getFileType()

ilCourseFile::getFileType ( )

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

Referenced by create().

124  {
125  return $this->file_type;
126  }
+ Here is the caller graph for this function:

◆ getInfoDirectory()

ilCourseFile::getInfoDirectory ( )

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

173  {
174  if (is_object($this->fss_storage)) {
175  return $this->fss_storage->getInfoDirectory();
176  }
177  }

◆ getTemporaryName()

ilCourseFile::getTemporaryName ( )

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

Referenced by create().

140  {
141  return $this->tmp_name;
142  }
+ Here is the caller graph for this function:

◆ setCourseId()

ilCourseFile::setCourseId (   $a_course_id)

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

Referenced by __read().

107  {
108  $this->course_id = $a_course_id;
109  }
+ Here is the caller graph for this function:

◆ setErrorCode()

ilCourseFile::setErrorCode (   $a_code)

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

144  {
145  $this->error_code = $a_code;
146  }

◆ setFileId()

ilCourseFile::setFileId (   $a_id)

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

Referenced by create().

94  {
95  $this->file_id = $a_id;
96  }
+ Here is the caller graph for this function:

◆ setFileName()

ilCourseFile::setFileName (   $a_name)

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

Referenced by __read().

112  {
113  $this->file_name = $a_name;
114  }
+ Here is the caller graph for this function:

◆ setFileSize()

ilCourseFile::setFileSize (   $a_size)

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

Referenced by __read().

128  {
129  $this->file_size = $a_size;
130  }
+ Here is the caller graph for this function:

◆ setFileType()

ilCourseFile::setFileType (   $a_type)

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

References $a_type.

Referenced by __read().

120  {
121  $this->file_type = $a_type;
122  }
$a_type
Definition: workflow.php:92
+ Here is the caller graph for this function:

◆ setTemporaryName()

ilCourseFile::setTemporaryName (   $a_name)

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

136  {
137  $this->tmp_name = $a_name;
138  }

◆ validate()

ilCourseFile::validate ( )

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

References getErrorCode().

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