24 require_once
"./classes/class.ilObject.php";
25 include_once(
'Modules/File/classes/class.ilFSStorageFile.php');
55 function ilObjFile($a_id = 0,$a_call_by_reference =
true)
59 $this->raise_upload_error =
true;
60 $this->
ilObject($a_id,$a_call_by_reference);
97 $this->file_storage->create();
105 require_once(
"classes/class.ilHistory.php");
110 require_once(
"./Services/News/classes/class.ilNewsItem.php");
112 if ($default_visibility ==
"public")
115 1, 0, $this->
getId());
118 $q =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,mode) "
119 .
"VALUES (".$ilDB->quote($this->
getId()).
","
123 .$ilDB->quote(
"1").
",".$ilDB->quote($this->
getMode()).
")";
124 $this->ilias->db->query($q);
127 if ($this->
getMode() !=
"filelist")
143 $technical = $md_obj->addTechnical();
146 $format = $technical->addFormat();
149 $technical->update();
169 include_once
'Services/MetaData/classes/class.ilMD.php';
177 if(!is_object($md_technical = $md->getTechnical()))
182 foreach($md_technical->getFormatIds() as
$id)
184 $md_format = $md_technical->getFormat(
$id);
200 $version_subdir =
"";
205 $version_subdir = sprintf(
"%03d", $a_version);
209 if(!is_object($this->file_storage))
214 return $this->file_storage->getAbsolutePath().
'/'.$version_subdir;
224 $this->raise_upload_error = $a_raise;
249 require_once(
"classes/class.ilHistory.php");
251 $a_filename.
",".$this->getVersion());
252 $this->setFilename($a_filename);
260 function copy($a_source,$a_destination)
283 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId());
284 $r = $this->ilias->db->query($q);
304 if ($this->
getMode() !=
"filelist")
314 $q =
"UPDATE file_data SET file_name = ".$ilDB->quote($this->
getFileName()).
315 ", file_type = ".$ilDB->quote($this->getFiletype()).
" ".
316 ", file_size = ".$ilDB->quote($this->
getFileSize()).
" ".
317 ", version = ".$ilDB->quote($this->
getVersion()).
" ".
318 ", mode = ".$ilDB->quote($this->
getMode()).
" ".
319 "WHERE file_id = ".$ilDB->quote($this->
getId());
320 $this->ilias->db->query($q);
334 if(!is_object($technical = $md_obj->getTechnical()))
336 $technical = $md_obj->addTechnical();
341 $format_ids = $technical->getFormatIds();
342 if (count($format_ids) > 0)
344 $format = $technical->getFormat($format_ids[0]);
350 $format = $technical->addFormat();
354 $technical->update();
362 $this->filename = $a_name;
375 $this->filetype = $a_type;
385 $this->filesize = $a_size;
390 return $this->filesize;
396 if (is_null($a_hist_entry_id))
402 require_once(
"classes/class.ilHistory.php");
405 if ($entry ===
false)
410 $data = explode(
",",$entry[
"info_params"]);
427 $this->version = $a_version;
432 return $this->version;
442 $this->mode = $a_mode;
459 $q =
"UPDATE file_data SET ".
460 " file_type = ".$ilDB->quote($a_format).
461 " WHERE file_id = ".$ilDB->quote($a_id);
470 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id);
471 $r = $ilDB->query($q);
481 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
491 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
500 if (is_null($a_hist_entry_id))
506 require_once(
"classes/class.ilHistory.php");
509 if ($entry ===
false)
514 $data = explode(
",",$entry[
"info_params"]);
529 if (is_null($a_hist_entry_id))
534 if (@!is_file(
$file))
541 require_once(
"classes/class.ilHistory.php");
544 if ($entry ===
false)
546 echo
"3";
return false;
549 $data = explode(
",",$entry[
"info_params"]);
561 if (@!is_file(
$file))
587 require_once
'class.ilObjFileAccess.php';
596 require_once
'class.ilObjFileAccess.php';
603 require_once
'class.ilObjFileAccess.php';
616 $path = pathinfo($a_file);
617 if ($path[
"extension"] !=
"")
623 $filename =
"dummy.".$this->getFileExtension();
625 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
680 $new_obj->createDirectory();
687 $query =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,mode) VALUES (".
688 $ilDB->quote($new_obj->getId()).
",".
689 $ilDB->quote($this->getFileName()).
",".
690 $ilDB->quote($this->getFileType()).
",".
691 $ilDB->quote($this->getFileSize()).
", ".
692 $ilDB->quote($this->getVersion()).
", ".
693 $ilDB->quote($this->getMode()).
")";
694 $ilDB->query($query);
697 require_once(
"classes/class.ilHistory.php");
701 $new_obj->addNewsNotification(
"file_created");
720 if (count($usages) == 0)
723 if (!parent::delete())
729 $q =
"DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId());
730 $this->ilias->db->query($q);
733 require_once(
"classes/class.ilHistory.php");
743 if ($this->
getMode() !=
"filelist")
763 $subdir =
"il_".IL_INST_ID.
"_file_".$this->
getId();
768 if (@!is_dir($filedir))
783 $q =
"DELETE FROM file_usage WHERE usage_type=".$ilDB->quote($a_type).
" AND usage_id=".$ilDB->quote($a_id).
784 " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr);
785 $this->ilias->db->query($q);
791 function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
795 $q =
"REPLACE INTO file_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
796 " (".$ilDB->quote($a_mob_id).
",".$ilDB->quote($a_type).
",".$ilDB->quote($a_id).
",".
797 $ilDB->quote($a_usage_hist_nr).
")";
798 $this->ilias->db->query($q);
809 $q =
"SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->
getId());
810 $us_set = $ilDB->query($q);
814 $ret[] = array(
"type" => $us_rec[
"usage_type"],
815 "id" => $us_rec[
"usage_id"],
816 "hist_nr" => $us_rec[
"usage_hist_nr"]);
835 $q =
"SELECT * FROM file_usage WHERE usage_id = ".$ilDB->quote($a_id).
836 " AND usage_type = ".$ilDB->quote($a_type).
" AND ".
837 "usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr);
838 $file_set = $ilDB->query($q);
842 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
872 include_once(
"./Services/News/classes/class.ilNewsItem.php");
873 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
875 $news_item->setContext($this->
getId(), $this->
getType());
877 $news_item->setTitle($a_lang_var);
878 $news_item->setContentIsLangVar(
true);
881 $news_item->setContent(
885 $news_item->setUserId($ilUser->getId());
887 $news_item->create();
921 rename($a_upload_file,
$file);
932 $version_subdir =
"";
934 if (!is_numeric($a_version))
938 $version_subdir = DIRECTORY_SEPARATOR.sprintf(
"%03d", $a_version);
939 return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;