61 public string $mode = self::MODE_OBJECT;
74 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
true)
77 $this->manager = $DIC->resourceStorage()->manage();
78 $this->database = $DIC->database();
81 $this->
upload = $DIC->upload();
83 $this->max_version = 0;
94 $this->file_info = $repository->getByRefId($id);
96 $this->file_info = $repository->getByObjectId($id);
102 return $this->file_info->getHeaderTitle();
107 if ($this->resource_id && (
$id = $this->manager->find(
110 $resource = $this->manager->getResource(
$id);
112 $this->max_version = $resource->getMaxRevision(
false);
113 $this->version = $resource->getCurrentRevision()->getVersionNumber();
121 $this->manager->getCurrentRevision($this->manager->find($this->getResourceId()))
140 $suffix = $this->file_info->getSuffix();
142 if (empty($suffix) || $suffix !== $filename_suffix) {
143 $suffix = $filename_suffix;
159 ?? pathinfo($stream->getMetadata(
'uri'))[
'extension']
162 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
163 $revision = $this->manager->appendNewRevisionFromStream($i, $stream, $this->stakeholder, $title);
165 $i = $this->manager->stream($stream, $this->stakeholder, $title);
166 $revision = $this->manager->getCurrentRevision($i);
173 return $revision->getVersionNumber();
183 $revision = $this->manager->appendNewRevision($i, $result, $this->stakeholder, $title);
185 $i = $this->manager->upload($result, $this->stakeholder, $title);
186 $revision = $this->manager->getCurrentRevision($i);
196 return $revision->getVersionNumber();
204 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
205 $revision = $this->manager->replaceWithStream($i, $stream, $this->stakeholder, $title);
207 throw new LogicException(
'only files with existing resource and revision can be replaced');
212 return $revision->getVersionNumber();
222 $revision = $this->manager->replaceWithUpload($i, $result, $this->stakeholder, $title);
224 throw new LogicException(
'only files with existing resource and revision can be replaced');
232 return $revision->getVersionNumber();
238 public function getFile(?
int $a_hist_entry_id = null): string
241 return $this->implementation->getFile($a_hist_entry_id);
246 return $this->implementation->getDirectory($a_version);
251 return $this->implementation->getDownloadFilename();
261 $this->important_info = empty($a_important_info) ? null : $a_important_info;
266 return $this->implementation->getVersion($inclduing_drafts);
271 $this->version = $a_version;
276 return $this->implementation->getFileName();
281 $this->filename = $a_name;
286 $this->rating = $a_value;
297 return $this->resource_id ??
'-';
302 return $this->implementation->getStorageID();
315 $this->mode = $a_mode;
320 return $this->implementation->getFileSize();
333 return $this->implementation->getFileType();
392 return $this->on_click_mode === self::CLICK_MODE_DOWNLOAD;
416 $this->amount_of_downloads = $amount;
436 $new_title = $this->
ensureSuffix($new_title, $this->file_info->getSuffix());
438 $this->implementation->handleChangedObjectTitle($new_title);
441 protected function doCreate(
bool $clone_mode =
false): void
451 $q =
"SELECT * FROM file_data WHERE file_id = %s";
452 $r = $this->database->queryF(
$q, [
'integer'], [$this->
getId()]);
453 $row =
$r->fetchObject();
455 $this->filename = $this->secure($row->file_name ??
'');
456 $this->filetype = $row->file_type ??
'';
457 $this->filesize = $row->file_size ?? 0;
458 $this->version = $row->version ?? 1;
459 $this->max_version = $row->max_version ?? 1;
460 $this->mode = $row->f_mode ?? self::MODE_OBJECT;
461 $this->important_info = $row->important_info ??
"";
462 $this->rating = (bool) ($row->rating ??
false);
463 $this->page_count = (
int) ($row->page_count ?? 0);
464 $this->resource_id = $row->rid ?? null;
465 $this->on_click_mode = (
int) ($row->on_click_mode ?? self::CLICK_MODE_DOWNLOAD);
466 $this->amount_of_downloads = (
int) ($row->downloads ?? 0);
474 $identification = $this->manager->find($this->resource_id);
475 if ($identification === null) {
476 throw new RuntimeException(
'Cannot clone file since no corresponding resource identification was found');
481 $new_obj->updateFileData();
484 $cloned_title = $new_obj->
getTitle();
485 $new_resource_identification = $this->manager->clone($identification);
486 $new_current_revision = $this->manager->getCurrentRevision($new_resource_identification);
487 $new_obj->setResourceId($new_resource_identification->serialize());
488 $new_obj->initImplementation();
489 $new_obj->updateObjectFromRevision($new_current_revision);
498 $obj_settings->cloneSettings($new_obj->
getId());
499 unset($obj_settings);
505 $this->database->update(
'file_data', $a_columns, [
518 $suffix = $this->file_info->getSuffix();
519 if (empty($suffix)) {
525 if ($this->
getMode() !== self::MODE_FILELIST) {
536 $usages = $this->getUsages();
537 return count($usages) === 0;
543 $this->database->manipulateF(
"DELETE FROM file_data WHERE file_id = %s", [
'integer'], [$this->
getId()]);
549 if ($this->
getMode() != self::MODE_FILELIST) {
555 if ($identification && $identification !=
'-') {
556 $resource = $this->manager->find($identification);
557 if ($resource !== null) {
558 $this->manager->remove($resource, $this->stakeholder);
569 'file_id' => [
'integer', $this->
getId()],
571 'f_mode' => [
'text', $this->
getMode()],
574 'rating' => [
'integer', $this->
hasRating()],
575 'rid' => [
'text', $this->resource_id ??
''],
583 $this->type = self::OBJECT_TYPE;
598 if (!$this->
upload->hasBeenProcessed()) {
599 if (defined(
'PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !==
"") {
638 $this->implementation->clearDataDirectory();
647 $this->implementation->deleteVersions($a_hist_entry_ids);
649 if ($this->
getResourceId() && $rid = $this->manager->find($this->getResourceId())) {
650 $latest_revision = $this->manager->getCurrentRevision($rid);
655 public function sendFile(?
int $a_hist_entry_id = null,
bool $inline =
true): void
661 $this->implementation->sendFile($a_hist_entry_id, $info->shouldDeliverInline());
667 public function export(
string $a_target_dir): void
678 return $this->implementation->getVersions($version_ids);
687 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
688 $this->manager->rollbackRevision($i, $version_id);
689 $latest_revision = $this->manager->getCurrentRevision($i);
692 throw new LogicException(
'only files with existing resource and revision can be replaced');
706 return $this->implementation->getFileExtension();
711 return $this->secure(preg_replace(
'/\.[^.]*$/',
'', $a_title));
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileStakeholder.
setCopyrightID(?int $copyright_id)
Class ilObjFileImplementationStorage.
setFileName(string $a_name)
static getLogger(string $a_component_id)
Get component logger.
updateObjectFromRevision(Revision $r)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
replaceWithUpload(UploadResult $result, string $title)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=0)
Class ChatMainBarProvider .
appendSuffixToTitle(string $title, string $filename)
rollback(int $version_id)
Makes the specified version the current one.
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
getDirectory($a_version=0)
updateObjectFromCurrentRevision()
appendUpload(UploadResult $result, string $title)
doCreate(bool $clone_mode=false)
ilObjFileImplementationInterface $implementation
replaceFile($a_upload_file, $a_filename)
setAction(string $a_action)
initFileInfo(int $id, bool $is_ref_id)
static _removeEntriesForObject(int $a_obj_id)
remove all history entries for an object
getVersion(bool $inclduing_drafts=false)
appendStream(FileStream $stream, string $title)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
stripTitleOfFileExtension(string $a_title)
ilObjFileStakeholder $stakeholder
const CLICK_MODE_DOWNLOAD
getUploadFile($a_upload_file, string $title, bool $a_prevent_preview=false)
This Method is used to append a fileupload by it's POST-name to the current ilObjFile ...
setPageCount(int $page_count)
extractSuffixFromFilename(string $filename)
setVersion(int $a_version)
setMaxVersion(int $a_max_version)
__construct(int $a_id=0, bool $a_call_by_reference=true)
ilObjFile constructor.
setOnclickMode(int $on_click_mode)
deleteVersions($a_hist_entry_ids=null)
trait ilObjFileSecureString
Trait ilObjFileSecureString.
getFileExtension()
Returns the extension of the file name converted to lower-case.
notifyUpdate(int $obj_id, string $additional_message=null)
replaceWithStream(FileStream $stream, string $title)
notifyCreation(int $obj_id, string $additional_message=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
setAmountOfDownloads(int $amount)
sendFile(?int $a_hist_entry_id=null, bool $inline=true)
checkFileExtension(string $new_filename, string $new_title)
Class ilCountPDFPagesPreProcessors.
setFileType(string $a_type)
setImportantInfo(string $a_important_info)
setResourceId(?string $resource_id)
handleChangedObjectTitle(string $new_title)
static getInstance(int $obj_id)
The base interface for all filesystem streams.
getVersions($version_ids=null)
export(string $a_target_dir)
ensureSuffix(string $title, ?string $suffix=null)
const CLICK_MODE_INFOPAGE
trait ilObjFileNews
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFile(?int $a_hist_entry_id=null)