4 require_once
"Services/Object/classes/class.ilObject2.php";
5 include_once(
'Modules/File/classes/class.ilFSStorageFile.php');
39 $this->raise_upload_error =
true;
40 parent::__construct($a_id,$a_call_by_reference);
58 protected function doCreate($a_upload =
false, $a_prevent_meta_data_creation =
false)
79 $this->file_storage->create();
87 require_once(
"./Services/History/classes/class.ilHistory.php");
92 require_once(
"./Services/News/classes/class.ilNewsItem.php");
94 if ($default_visibility ==
"public")
97 1, 0, $this->
getId());
100 $q =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) " 101 .
"VALUES (".$ilDB->quote($this->
getId() ,
'integer').
"," 104 .$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
"," 105 .$ilDB->quote(1 ,
'integer').
",".$ilDB->quote($this->
getMode() ,
'text').
")";
106 $res = $ilDB->manipulate($q);
109 if ($this->
getMode() !=
"filelist" && !$a_prevent_meta_data_creation)
123 $technical = $md_obj->addTechnical();
126 $format = $technical->addFormat();
129 $technical->update();
136 include_once
'Services/MetaData/classes/class.ilMD.php';
138 if(!is_object($md_gen = $md->getGeneral()))
143 $md_gen->setTitle(
$title);
151 include_once
'Services/MetaData/classes/class.ilMD.php';
159 if(!is_object($md_technical = $md->getTechnical()))
164 foreach($md_technical->getFormatIds() as
$id)
166 $md_format = $md_technical->getFormat(
$id);
180 $version_subdir =
"";
185 $version_subdir = sprintf(
"%03d", $a_version);
189 if(!is_object($this->file_storage))
194 return $this->file_storage->getAbsolutePath().
'/'.$version_subdir;
204 $this->raise_upload_error = $a_raise;
207 function getUploadFile($a_upload_file, $a_filename, $a_prevent_preview =
false)
223 if (!$a_prevent_preview)
236 require_once(
"./Services/History/classes/class.ilHistory.php");
240 $a_filename.
",".$this->getVersion()
242 $this->setFilename($a_filename);
254 require_once(
"./Services/History/classes/class.ilHistory.php");
258 $a_filename.
",".$this->getVersion()
260 $this->setFilename($a_filename);
271 function copy($a_source,$a_destination)
294 require_once(
"./Services/History/classes/class.ilHistory.php");
296 if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1)
298 $ilDB->manipulate(
"UPDATE file_data SET version = 1 WHERE file_id = ".$ilDB->quote($this->getId() ,
'integer'));
304 self::handleQuotaUpdate($this);
308 $actualVersionDeleted =
false;
314 foreach ($a_hist_entry_ids as $hist_id)
319 foreach ($versions as $index => $version)
321 if ($version[
"hist_entry_id"] == $hist_id)
327 $version_dir = $this->
getDirectory($version[
"version"]);
331 if ($version[
"version"] == $this->
getVersion())
332 $actualVersionDeleted =
true;
335 unset($versions[$index]);
342 if ($actualVersionDeleted)
345 $version = reset($versions);
351 self::handleQuotaUpdate($this);
363 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
364 $r = $this->
ilias->db->query($q);
380 if ($this->
getMode() !=
"filelist")
397 $q =
"UPDATE file_data SET file_name = ".$ilDB->quote($this->
getFileName() ,
'text').
398 ", file_type = ".$ilDB->quote($this->getFiletype() ,
'text').
" ".
399 ", file_size = ".$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
" ".
400 ", version = ".$ilDB->quote($this->
getVersion() ,
'integer').
" ".
401 ", f_mode = ".$ilDB->quote($this->
getMode() ,
'text').
" ".
402 ", rating = ".$ilDB->quote($this->
hasRating() ,
'integer').
" ".
403 "WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
404 $res = $ilDB->manipulate($q);
406 self::handleQuotaUpdate($this);
418 if(!is_object($technical = $md_obj->getTechnical()))
420 $technical = $md_obj->addTechnical();
425 $format_ids = $technical->getFormatIds();
426 if (count($format_ids) > 0)
428 $format = $technical->getFormat($format_ids[0]);
434 $format = $technical->addFormat();
438 $technical->update();
446 $this->filename = $a_name;
459 $this->filetype = $a_type;
469 $this->filesize = $a_size;
474 return $this->filesize;
484 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
492 if (is_null($a_hist_entry_id))
498 require_once(
"./Services/History/classes/class.ilHistory.php");
501 if ($entry ===
false)
515 $this->version = $a_version;
520 return $this->version;
530 $this->mode = $a_mode;
547 $q =
"UPDATE file_data SET ".
548 " file_type = ".$ilDB->quote($a_format ,
'text').
549 " WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
550 $res = $ilDB->manipulate($q);
558 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
559 $r = $ilDB->query($q);
569 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
578 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
587 if (is_null($a_hist_entry_id))
593 require_once(
"./Services/History/classes/class.ilHistory.php");
596 if ($entry ===
false)
612 if (is_null($a_hist_entry_id))
617 if (@!is_file(
$file))
624 require_once(
"./Services/History/classes/class.ilHistory.php");
627 if ($entry ===
false)
629 echo
"3";
return false;
636 if (@!is_file(
$file))
647 global $ilClientIniFile;
650 if ($ilClientIniFile->readVariable(
'file_access',
'download_with_uploaded_filename') !=
'1' && is_null($a_hist_entry_id))
670 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
679 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
686 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
699 $path = pathinfo($a_file);
700 if (
$path[
"extension"] !=
"")
702 $filename =
$path[
"basename"];
706 $filename =
"dummy.".$this->getFileExtension();
708 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
763 $a_new_obj->createDirectory();
770 $query =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,rating,f_mode) VALUES (".
771 $ilDB->quote($a_new_obj->getId() ,
'integer').
",".
772 $ilDB->quote($this->getFileName() ,
'text').
",".
773 $ilDB->quote($this->getFileType() ,
'text').
",".
774 $ilDB->quote((
int) $this->getFileSize() ,
'integer').
", ".
775 $ilDB->quote($this->getVersion() ,
'integer').
", ".
776 $ilDB->quote($this->hasRating() ,
'integer').
", ".
777 $ilDB->quote($this->getMode() ,
'text').
")";
778 $res = $ilDB->manipulate($query);
781 require_once(
"./Services/Preview/classes/class.ilPreview.php");
785 require_once(
"./Services/History/classes/class.ilHistory.php");
789 $a_new_obj->addNewsNotification(
"file_created");
800 if (count($usages) == 0)
812 $q =
"DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
813 $this->
ilias->db->query($q);
816 require_once(
"./Services/History/classes/class.ilHistory.php");
826 if ($this->
getMode() !=
"filelist")
831 self::handleQuotaUpdate($this);
846 $subdir =
"il_".IL_INST_ID.
"_file_".$this->
getId();
851 if (@!is_dir($filedir))
866 $and_hist = ($a_usage_hist_nr !==
false)
867 ?
" AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr,
"integer")
871 $set = $ilDB->query(
"SELECT id FROM file_usage".
872 " WHERE usage_type = ".$ilDB->quote($a_type,
"text").
873 " AND usage_id= ".$ilDB->quote($a_id,
"integer").
874 " AND usage_lang= ".$ilDB->quote($a_usage_lang,
"text").
876 while(
$row = $ilDB->fetchAssoc($set))
878 $file_ids[] =
$row[
"id"];
881 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = ".
882 $ilDB->quote($a_type,
"text").
883 " AND usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
884 " AND usage_lang= ".$ilDB->quote($a_usage_lang,
"text").
885 " AND usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer"));
887 foreach($file_ids as $file_id)
889 self::handleQuotaUpdate(
new self($file_id,
false));
896 function _saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang =
"-")
918 $ilDB->replace(
"file_usage",
920 "id" => array(
"integer", (
int) $a_file_id),
921 "usage_type" => array(
"text", (
string) $a_type),
922 "usage_id" => array(
"integer", (
int) $a_id),
923 "usage_hist_nr" => array(
"integer", (
int) $a_usage_hist_nr),
924 "usage_lang" => array(
"text", $a_usage_lang)
929 self::handleQuotaUpdate(
new self($a_file_id,
false));
940 $q =
"SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->
getId(),
"integer");
941 $us_set = $ilDB->query($q);
943 while($us_rec = $ilDB->fetchAssoc($us_set))
945 $ret[] = array(
"type" => $us_rec[
"usage_type"],
946 "id" => $us_rec[
"usage_id"],
947 "lang" => $us_rec[
"usage_lang"],
948 "hist_nr" => $us_rec[
"usage_hist_nr"]);
967 $q =
"SELECT * FROM file_usage WHERE ".
968 "usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
" AND ".
969 "usage_type = ".$ilDB->quote((
string) $a_type,
"text").
" AND ".
970 "usage_lang = ".$ilDB->quote((
string) $a_usage_lang,
"text").
" AND ".
971 "usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer");
972 $file_set = $ilDB->query($q);
974 while($file_rec = $ilDB->fetchAssoc($file_set))
976 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
1006 include_once(
"./Services/News/classes/class.ilNewsItem.php");
1007 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
1009 $news_item->setContext($this->
getId(), $this->
getType());
1011 $news_item->setTitle($a_lang_var);
1012 $news_item->setContentIsLangVar(
true);
1015 $news_item->setContent(
1019 $news_item->setUserId($ilUser->getId());
1021 $news_item->create();
1055 rename($a_upload_file,
$file);
1069 $version_subdir =
"";
1071 if (!is_numeric($a_version))
1075 $version_subdir = DIRECTORY_SEPARATOR.sprintf(
"%03d", $a_version);
1076 return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;
1085 include_once
'./Modules/File/classes/class.ilObjFileAccess.php';
1088 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1092 $suffix = $pi[
"extension"];
1095 if (substr($new_title,
1096 strlen($new_title) - strlen($suffix) - 1)
1099 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1102 $new_title .=
'.'.$fileExtension;
1115 include_once(
"./Services/History/classes/class.ilHistory.php");
1118 if ($version_ids != null && count($version_ids) > 0)
1120 foreach ($versions as $index => $version)
1122 if (!in_array($version[
"hist_entry_id"], $version_ids,
true))
1124 unset($versions[$index]);
1130 foreach ($versions as $index => $version)
1133 $versions[$index] = array_merge($version, $params);
1137 usort($versions, array($this,
"compareVersions"));
1150 include_once(
"./Services/History/classes/class.ilHistory.php");
1152 if ($version ===
false)
1157 $version[
"hist_entry_id"] = $version[
"id"];
1158 $version[
"user_id"] = $version[
"usr_id"];
1159 $version[
"date"] = $version[
"hdate"];
1160 unset($version[
"id"], $version[
"usr_id"], $version[
"hdate"]);
1164 return array_merge($version, $params);
1178 if ($source ===
false)
1180 $this->ilErr->raiseError($this->lng->txt(
"obj_not_found"), $this->ilErr->MESSAGE);
1187 $source_path = $this->
getDirectory($source[
"version"]) .
"/" . $source[
"filename"];
1189 if (@!is_dir($dest_dir))
1192 copy($source_path, $dest_dir .
"/" . $source[
"filename"]);
1195 include_once(
"./Services/History/classes/class.ilHistory.php");
1199 $source[
"filename"] .
"," . $new_version_nr .
"|" . $source[
"version"] .
"|" . $ilUser->getId());
1212 return $new_version;
1251 return (
int)$v2[
"version"] - (int)$v1[
"version"];
1262 $data = preg_split(
"/(.*),(.*)/", $entry[
"info_params"], 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
1266 if (empty(
$data[1]))
1269 $result = array(
"filename" =>
$data[0],
"version" =>
$data[1],
"rollback_version" =>
"",
"rollback_user_id" =>
"");
1272 if ($entry[
"action"] ==
"rollback")
1274 $tokens = explode(
"|",
$result[
"version"]);
1275 if (count($tokens) > 1)
1277 $result[
"version"] = $tokens[0];
1278 $result[
"rollback_version"] = $tokens[1];
1280 if (count($tokens) > 2)
1281 $result[
"rollback_user_id"] = $tokens[2];
1290 include_once
"Services/MediaObjects/classes/class.ilObjMediaObject.php";
1294 $parent_obj_ids = array($a_file->
getId());
1298 $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1299 if($parent_obj_id &&
1300 !in_array($parent_obj_id, $parent_obj_ids))
1302 $parent_obj_ids[]= $parent_obj_id;
1306 include_once
"Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1321 if ($this->
getMode() !=
"object")
1324 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1334 if ($this->
getMode() !=
"object")
1337 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1343 $this->rating = (bool)$a_value;
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static _removeEntryByHistoryID($a_hist_entry_id)
Removes a single entry from the history.
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
setFileName($a_name)
set filename
static _changeUserId($a_hist_entry_id, $new_user_id)
Changes the user id of the specified history entry.
setMode($a_mode)
mode is object or filelist
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
copy($a_source, $a_destination)
copy file
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
clearDataDirectory()
clear data directory
compareVersions($v1, $v2)
Compares two file versions.
getFile($a_hist_entry_id=null)
_deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
static delete all usages of
getMode()
mode is object or filelist
storeUnzipedFile($a_upload_file, $a_filename)
storeUnzipedFile
createProperties($a_upload=false, $a_prevent_meta_data_creation=false)
The basic properties of a file object are stored in table object_data.
_lookupVersion($a_id)
lookup version
doCreateMetaData()
create file object meta data
getDirectory($a_version=0)
_getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
const DB_FETCHMODE_OBJECT
beforeMDUpdateListener($a_element)
checkFileExtension($new_filename, $new_title)
Check if the file extension does still exist after an update of the title.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes. ...
doUpdateMetaData()
update meta data
replaceFile($a_upload_file, $a_filename)
replace file with new file
_saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
save usage
doRead()
read file properties
_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.
static getMimeType($a_file="", $a_filename="", $a_mime="")
Get Mime type.
addFileVersion($a_upload_file, $a_filename)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static createPreview($a_obj, $a_force=false)
Creates the preview for the object with the specified id.
deletePreview()
Deletes the preview of the file object.
sendFile($a_hist_entry_id=null)
isHidden()
Returns true, if this file should be hidden in the repository view.
redirection script todo: (a better solution should control the processing via a xml file) ...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isInline()
Returns true, if this file should be displayed inline in a browser window.
createPreview($force=false)
Creates a preview for the file object.
getSpecificVersion($version_id)
Gets a specific file version.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
_copyEntriesForObject($a_src_id, $a_dst_id)
copy all history entries for an object
_getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
addNewsNotification($a_lang_var)
getUsages()
get all usages of file object
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
doCloneObject($a_new_obj, $a_target_id, $a_copy_id=0)
Clone.
static copyPreviews($a_src_id, $a_dest_id)
Copies the preview images from one preview to a new preview object.
deleteVersions($a_hist_entry_ids=null)
Deletes the specified history entries or all entries if no ids are specified.
getFileExtension()
Returns the extension of the file name converted to lower-case.
static handleQuotaUpdate(ilObjFile $a_file)
rollback($version_id)
Makes the specified version the current one and returns theSummary of rollbackVersion.
export($a_target_dir)
export files of object to target directory note: target directory must be the export target directory...
static escapeShellArg($a_arg)
initFileStorage()
init file storage object
static handleUpdatedSourceObject($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
Find and update/create all related entries for source object.
static deletePreview($a_obj_id)
Deletes the preview for the object with the specified id.
static _lookupAbsolutePath($obj_id, $a_version=null)
return absolute path for version
doCreate($a_upload=false, $a_prevent_meta_data_creation=false)
create object
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
_getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
Class ilObject2 This is an intermediate progress of ilObject class.
_lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id...
raiseUploadError($a_raise=true)
_removeEntriesForObject($a_obj_id)
remove all history entries for an object
doMDUpdateListener($a_element)
_lookupVersion($a_id)
lookup version
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
determineFileSize($a_hist_entry_id=null)
Determine File Size.
_lookupFileSize($a_id)
Lookups the file size of the file in bytes.
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
getVersions($version_ids=null)
Gets the file versions for this object.
_writeFileType($a_id, $a_format)
getUploadFile($a_upload_file, $a_filename, $a_prevent_preview=false)
guessFileType($a_file="")
Guesses the file type based on the current values returned by getFileType() and getFileExtension().
updateWithVersion($version)
Updates the file object with the specified file version.
cloneMetaData($target_obj)
getDiskUsage()
Gets the disk usage of the object in bytes.