ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCourseFile Class Reference
+ Inheritance diagram for ilCourseFile:
+ Collaboration diagram for ilCourseFile:

Public Member Functions

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

Static Public Member Functions

static _cloneFiles (int $a_source_id, int $a_target_id)
 
static _deleteByCourse (int $a_course_id)
 
static _readFilesByCourse (int $a_course_id)
 

Protected Attributes

ilDBInterface $db
 
ilLanguage $lng
 
ilErrorHandling $error
 
ilFSStorageCourse $fss_storage = null
 

Private Attributes

int $course_id = 0
 
int $file_id = 0
 
string $file_name = ''
 
string $file_type = ''
 
int $file_size = 0
 
string $tmp_name = ''
 
int $error_code = 0
 

Detailed Description

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

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

Constructor & Destructor Documentation

◆ __construct()

ilCourseFile::__construct ( int  $a_file_id = 0)

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

41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->db = $DIC->database();
46 $this->error = $DIC['ilErr'];
47 $this->file_id = $a_file_id;
48 $this->__read();
49 }
error(string $a_errmsg)
global $DIC
Definition: shib_login.php:26

References $DIC, __read(), error(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ __read()

ilCourseFile::__read ( )

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

270 : void
271 {
272 if (!$this->file_id) {
273 return;
274 }
275
276 // read file data
277 $query = "SELECT * FROM crs_file WHERE file_id = " . $this->db->quote($this->file_id, 'integer');
278 $res = $this->db->query($query);
279 while ($row = $this->db->fetchObject($res)) {
280 $this->setFileName((string) $row->file_name);
281 $this->setFileSize((int) $row->file_size);
282 $this->setFileType((string) $row->file_type);
283 $this->setCourseId((int) $row->course_id);
284 }
285 $this->fss_storage = new ilFSStorageCourse($this->getCourseId());
286 }
setFileSize(int $a_size)
setFileName(string $a_name)
setCourseId(int $a_course_id)
setFileType(string $a_type)
$res
Definition: ltiservices.php:69

References $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 ( int  $a_source_id,
int  $a_target_id 
)
static

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

51 : void
52 {
53 $source = new ilFSStorageCourse($a_source_id);
54
55 foreach (ilCourseFile::_readFilesByCourse($a_source_id) as $file_obj) {
56 $new_file = new ilCourseFile();
57 $new_file->setCourseId($a_target_id);
58 $new_file->setFileName($file_obj->getFileName());
59 $new_file->setFileSize($file_obj->getFileSize());
60 $new_file->setFileType($file_obj->getFileType());
61 $new_file->create(false);
62
63 $target = new ilFSStorageCourse($a_target_id);
64 $target->initInfoDirectory();
65 $source->copyFile(
66 $file_obj->getAbsolutePath(),
67 $new_file->fss_storage->getInfoDirectory() . '/' . $new_file->getFileId()
68 );
69 }
70 }
static _readFilesByCourse(int $a_course_id)

References _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 ( int  $a_course_id)
static

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

238 : void
239 {
240 global $DIC;
241
242 $ilDB = $DIC['ilDB'];
243
244 // delete all course ids and delete assigned files
245 $query = "DELETE FROM crs_file " .
246 "WHERE course_id = " . $ilDB->quote($a_course_id, 'integer') . "";
247 $res = $ilDB->manipulate($query);
248 }

References $DIC, $ilDB, and $res.

Referenced by ilObjCourse\delete().

+ Here is the caller graph for this function:

◆ _readFilesByCourse()

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

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

254 : array
255 {
256 global $DIC;
257
258 $ilDB = $DIC->database();
259 $query = "SELECT * FROM crs_file " .
260 "WHERE course_id = " . $ilDB->quote($a_course_id, 'integer') . "";
261
262 $res = $ilDB->query($query);
263 $files = [];
264 while ($row = $ilDB->fetchObject($res)) {
265 $files[] = new ilCourseFile((int) $row->file_id);
266 }
267 return $files;
268 }

References $DIC, $ilDB, 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 ( bool  $a_upload = true)

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

194 : bool
195 {
196 if ($this->getErrorCode() != 0) {
197 return false;
198 }
199 $next_id = $this->db->nextId('crs_file');
200 $query = "INSERT INTO crs_file (file_id,course_id,file_name,file_size,file_type) " .
201 "VALUES( " .
202 $this->db->quote($next_id, 'integer') . ", " .
203 $this->db->quote($this->getCourseId(), 'integer') . ", " .
204 $this->db->quote($this->getFileName(), 'text') . ", " .
205 $this->db->quote($this->getFileSize(), 'integer') . ", " .
206 $this->db->quote($this->getFileType(), 'text') . " " .
207 ")";
208 $res = $this->db->manipulate($query);
209 $this->setFileId($next_id);
210
211 $this->fss_storage = new ilFSStorageCourse($this->getCourseId());
212 $this->fss_storage->initInfoDirectory();
213
214 if ($a_upload) {
215 // now create file
217 $this->getTemporaryName(),
218 $this->getFileName(),
219 $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId()
220 );
221 }
222 return true;
223 }
setFileId(int $a_id)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file

References $res, getCourseId(), getErrorCode(), getFileName(), getFileSize(), getFileType(), getTemporaryName(), ilFileUtils\moveUploadedFile(), and setFileId().

+ Here is the call graph for this function:

◆ delete()

ilCourseFile::delete ( )

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

225 : void
226 {
227 // Delete db entry
228 $query = "DELETE FROM crs_file " .
229 "WHERE file_id = " . $this->db->quote($this->getFileId(), 'integer') . "";
230 $res = $this->db->manipulate($query);
231
232 // Delete file
233 if (file_exists($this->getAbsolutePath())) {
234 unlink($this->getAbsolutePath());
235 }
236 }

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

+ Here is the call graph for this function:

◆ getAbsolutePath()

ilCourseFile::getAbsolutePath ( )

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

142 : string
143 {
144 // workaround for "secured" files.
145 if (!$this->fss_storage instanceof \ilFSStorageCourse) {
146 return '';
147 }
148
149 $file = $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId();
150 if (!file_exists($file)) {
151 $file = $this->fss_storage->getInfoDirectory() . '/' . $this->getFileId() . '.sec';
152 }
153 if (file_exists($file)) {
154 return $file;
155 }
156 return '';
157 }

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 82 of file class.ilCourseFile.php.

82 : int
83 {
84 return $this->course_id;
85 }

References $course_id.

Referenced by __read(), and create().

+ Here is the caller graph for this function:

◆ getErrorCode()

ilCourseFile::getErrorCode ( )

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

137 : int
138 {
139 return $this->error_code;
140 }

References $error_code.

Referenced by create(), and validate().

+ Here is the caller graph for this function:

◆ getFileId()

ilCourseFile::getFileId ( )

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

77 : int
78 {
79 return $this->file_id;
80 }

References $file_id.

Referenced by delete(), and getAbsolutePath().

+ Here is the caller graph for this function:

◆ getFileName()

ilCourseFile::getFileName ( )

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

97 : string
98 {
99 return $this->file_name;
100 }

References $file_name.

Referenced by create().

+ Here is the caller graph for this function:

◆ getFileSize()

ilCourseFile::getFileSize ( )

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

117 : int
118 {
119 return $this->file_size;
120 }

References $file_size.

Referenced by create().

+ Here is the caller graph for this function:

◆ getFileType()

ilCourseFile::getFileType ( )

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

107 : string
108 {
109 return $this->file_type;
110 }

References $file_type.

Referenced by create().

+ Here is the caller graph for this function:

◆ getInfoDirectory()

ilCourseFile::getInfoDirectory ( )

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

159 : string
160 {
161 if (is_object($this->fss_storage)) {
162 return $this->fss_storage->getInfoDirectory();
163 }
164 return '';
165 }

◆ getTemporaryName()

ilCourseFile::getTemporaryName ( )

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

127 : string
128 {
129 return $this->tmp_name;
130 }

References $tmp_name.

Referenced by create().

+ Here is the caller graph for this function:

◆ setCourseId()

ilCourseFile::setCourseId ( int  $a_course_id)

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

87 : void
88 {
89 $this->course_id = $a_course_id;
90 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setErrorCode()

ilCourseFile::setErrorCode ( int  $a_code)

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

132 : void
133 {
134 $this->error_code = $a_code;
135 }

◆ setFileId()

ilCourseFile::setFileId ( int  $a_id)

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

72 : void
73 {
74 $this->file_id = $a_id;
75 }

Referenced by create().

+ Here is the caller graph for this function:

◆ setFileName()

ilCourseFile::setFileName ( string  $a_name)

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

92 : void
93 {
94 $this->file_name = $a_name;
95 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setFileSize()

ilCourseFile::setFileSize ( int  $a_size)

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

112 : void
113 {
114 $this->file_size = $a_size;
115 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setFileType()

ilCourseFile::setFileType ( string  $a_type)

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

102 : void
103 {
104 $this->file_type = $a_type;
105 }

Referenced by __read().

+ Here is the caller graph for this function:

◆ setTemporaryName()

ilCourseFile::setTemporaryName ( string  $a_name)

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

122 : void
123 {
124 $this->tmp_name = $a_name;
125 }

◆ validate()

ilCourseFile::validate ( )

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

167 : bool
168 {
169 switch ($this->getErrorCode()) {
170 case UPLOAD_ERR_INI_SIZE:
171 $this->error->appendMessage($this->lng->txt('file_upload_ini_size'));
172 return false;
173 case UPLOAD_ERR_FORM_SIZE:
174 $this->error->appendMessage($this->lng->txt('file_upload_form_size'));
175 return false;
176
177 case UPLOAD_ERR_PARTIAL:
178 $this->error->appendMessage($this->lng->txt('file_upload_only_partial'));
179 return false;
180
181 case UPLOAD_ERR_NO_TMP_DIR:
182 $this->error->appendMessage($this->lng->txt('file_upload_no_tmp_dir'));
183 return false;
184
185 case UPLOAD_ERR_NO_FILE:
186 return false;
187
188 case UPLOAD_ERR_OK:
189 default:
190 return true;
191 }
192 }

References error(), getErrorCode(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Field Documentation

◆ $course_id

int ilCourseFile::$course_id = 0
private

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

Referenced by getCourseId().

◆ $db

ilDBInterface ilCourseFile::$db
protected

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

◆ $error

ilErrorHandling ilCourseFile::$error
protected

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

◆ $error_code

int ilCourseFile::$error_code = 0
private

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

Referenced by getErrorCode().

◆ $file_id

int ilCourseFile::$file_id = 0
private

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

Referenced by getFileId().

◆ $file_name

string ilCourseFile::$file_name = ''
private

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

Referenced by getFileName().

◆ $file_size

int ilCourseFile::$file_size = 0
private

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

Referenced by getFileSize().

◆ $file_type

string ilCourseFile::$file_type = ''
private

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

Referenced by getFileType().

◆ $fss_storage

ilFSStorageCourse ilCourseFile::$fss_storage = null
protected

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

◆ $lng

ilLanguage ilCourseFile::$lng
protected

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

◆ $tmp_name

string ilCourseFile::$tmp_name = ''
private

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

Referenced by getTemporaryName().


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