63 public string $mode = self::MODE_OBJECT;
76 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
true)
79 $this->manager = $DIC->resourceStorage()->manage();
83 $this->
upload = $DIC->upload();
93 $this->file_info = $is_ref_id ? $repository->getByRefId($id) : $repository->getByObjectId($id);
99 return $this->file_info->getHeaderTitle();
104 if ($this->resource_id && (
$id = $this->manager->find(
107 $resource = $this->manager->getResource(
$id);
109 $this->max_version = $resource->getMaxRevision(
false);
110 $this->version = $resource->getCurrentRevision()->getVersionNumber();
118 $this->manager->getCurrentRevision($this->manager->find($this->getResourceId()))
137 $suffix = $this->file_info->getSuffix();
139 if (empty($suffix) || $suffix !== $filename_suffix) {
140 $suffix = $filename_suffix;
154 ?? pathinfo($stream->getMetadata(
'uri'))[
'extension']
157 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
158 $revision = $this->manager->appendNewRevisionFromStream($i, $stream, $this->stakeholder, $title);
160 $i = $this->manager->stream($stream, $this->stakeholder, $title);
161 $revision = $this->manager->getCurrentRevision($i);
168 return $revision->getVersionNumber();
178 $revision = $this->manager->appendNewRevision($i, $result, $this->stakeholder, $title);
180 $i = $this->manager->upload($result, $this->stakeholder, $title);
181 $revision = $this->manager->getCurrentRevision($i);
191 return $revision->getVersionNumber();
199 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
200 $revision = $this->manager->replaceWithStream($i, $stream, $this->stakeholder, $title);
202 throw new LogicException(
'only files with existing resource and revision can be replaced');
207 return $revision->getVersionNumber();
217 $revision = $this->manager->replaceWithUpload($i, $result, $this->stakeholder, $title);
219 throw new LogicException(
'only files with existing resource and revision can be replaced');
227 return $revision->getVersionNumber();
236 return $this->implementation->getFile($a_hist_entry_id);
241 return $this->implementation->getDirectory($a_version);
246 return $this->implementation->getDownloadFilename();
256 $this->important_info = empty($a_important_info) ?
null : $a_important_info;
261 return $this->implementation->getVersion($inclduing_drafts);
266 $this->version = $a_version;
271 return $this->implementation->getFileName();
276 $this->filename = $a_name;
281 $this->rating = $a_value;
292 return $this->resource_id ??
'-';
297 return $this->implementation->getStorageID();
310 $this->mode = $a_mode;
315 return $this->implementation->getFileSize();
328 return $this->implementation->getFileType();
387 return $this->on_click_mode === self::CLICK_MODE_DOWNLOAD;
411 $this->amount_of_downloads = $amount;
431 $new_title = $this->
ensureSuffix($new_title, $this->file_info->getSuffix());
433 $this->implementation->handleChangedObjectTitle($new_title);
436 protected function doCreate(
bool $clone_mode =
false): void
446 $q =
"SELECT * FROM file_data WHERE file_id = %s";
448 $row =
$r->fetchObject();
450 $this->filename = $this->secure($row->file_name ??
'');
451 $this->filetype = $row->file_type ??
'';
452 $this->filesize = $row->file_size ?? 0;
453 $this->version = $row->version ?? 1;
454 $this->max_version = $row->max_version ?? 1;
455 $this->mode = $row->f_mode ?? self::MODE_OBJECT;
456 $this->important_info = $row->important_info ??
"";
457 $this->rating = (bool) ($row->rating ??
false);
458 $this->page_count = (
int) ($row->page_count ?? 0);
459 $this->resource_id = $row->rid ??
null;
460 $this->on_click_mode = (
int) ($row->on_click_mode ?? self::CLICK_MODE_DOWNLOAD);
461 $this->amount_of_downloads = (
int) ($row->downloads ?? 0);
469 $identification = $this->manager->find($this->resource_id);
470 if ($identification ===
null) {
471 throw new RuntimeException(
'Cannot clone file since no corresponding resource identification was found');
476 $new_obj->updateFileData();
479 $cloned_title = $new_obj->
getTitle();
480 $new_resource_identification = $this->manager->clone($identification);
481 $new_current_revision = $this->manager->getCurrentRevision($new_resource_identification);
482 $new_obj->setResourceId($new_resource_identification->serialize());
483 $new_obj->initImplementation();
484 $new_obj->updateObjectFromRevision($new_current_revision);
493 $obj_settings->cloneSettings($new_obj->
getId());
494 unset($obj_settings);
500 $this->
database->update(
'file_data', $a_columns, [
514 $suffix = $this->file_info->getSuffix();
515 if (empty($suffix)) {
521 if ($this->
getMode() !== self::MODE_FILELIST) {
533 $usages = $this->getUsages();
534 return $usages === [];
540 $this->
database->manipulateF(
"DELETE FROM file_data WHERE file_id = %s", [
'integer'], [$this->
getId()]);
546 if ($this->
getMode() !== self::MODE_FILELIST) {
552 if ($identification && $identification !==
'-') {
553 $resource = $this->manager->find($identification);
554 if ($resource !==
null) {
555 $this->manager->remove($resource, $this->stakeholder);
566 'file_id' => [
'integer', $this->
getId()],
568 'f_mode' => [
'text', $this->
getMode()],
571 'rating' => [
'integer', $this->
hasRating()],
572 'rid' => [
'text', $this->resource_id ??
''],
580 $this->type = self::OBJECT_TYPE;
595 if (!$this->
upload->hasBeenProcessed()) {
596 if (defined(
'PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !==
"") {
635 $this->implementation->clearDataDirectory();
644 $this->implementation->deleteVersions($a_hist_entry_ids);
646 if ($this->
getResourceId() && $rid = $this->manager->find($this->getResourceId())) {
647 $latest_revision = $this->manager->getCurrentRevision($rid);
652 public function sendFile(?
int $a_hist_entry_id =
null,
bool $inline =
true): void
658 $this->implementation->sendFile($a_hist_entry_id,
$info->shouldDeliverInline());
664 public function export(
string $a_target_dir): void
675 return $this->implementation->getVersions($version_ids);
684 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
685 $this->manager->rollbackRevision($i, $version_id);
686 $latest_revision = $this->manager->getCurrentRevision($i);
689 throw new LogicException(
'only files with existing resource and revision can be replaced');
703 return $this->implementation->getFileExtension();
708 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.
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)
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
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
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 ...
Class ResourceIdentification.
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)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
__construct(Container $dic, ilPlugin $plugin)
setAmountOfDownloads(int $amount)
sendFile(?int $a_hist_entry_id=null, bool $inline=true)
checkFileExtension(string $new_filename, string $new_title)
notifyCreation(int $obj_id, ?string $additional_message=null)
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)
setCopyrightID(?string $copyright_id)
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)