ILIAS  release_8 Revision v8.24
class.ilObjFileImplementationStorage.php
Go to the documentation of this file.
1<?php
2
23
29{
31 protected Services $storage;
33
38 {
39 global $DIC;
43 $this->resource = $resource;
44 $this->storage = $DIC->resourceStorage();
45 $this->download_with_uploaded_filename = (bool) $DIC->clientIni()->readVariable(
46 'file_access',
47 'download_with_uploaded_filename'
48 );
49 }
50
51 public function handleChangedObjectTitle(string $new_title): void
52 {
53 $current_revision = $this->resource->getCurrentRevision();
54 $current_revision->setTitle($new_title);
55 $this->storage->manage()->updateRevision($current_revision);
56 }
57
61 public function getFile(?int $a_hist_entry_id = null): string
62 {
63 $stream = $this->storage->consume()->stream($this->resource->getIdentification());
64 if ($a_hist_entry_id) {
65 $stream = $stream->setRevisionNumber($a_hist_entry_id);
66 }
67 return $stream->getStream()->getMetadata('uri');
68 }
69
70 public function getFileSize(): int
71 {
72 return $this->resource->getCurrentRevision()->getInformation()->getSize() ?: 0;
73 }
74
78 public function getFileType(): string
79 {
80 return $this->resource->getCurrentRevision()->getInformation()->getMimeType();
81 }
82
83 public function getDirectory(int $a_version = 0): string
84 {
85 $consumer = $this->storage->consume()->stream($this->resource->getIdentification());
86 if ($a_version) {
87 $consumer->setRevisionNumber($a_version);
88 }
89 $stream = $consumer->getStream();
90
91 return dirname($stream->getMetadata('uri'));
92 }
93
94 public function sendFile(?int $a_hist_entry_id = null, bool $inline = true): void
95 {
96 if ($inline) {
97 $consumer = $this->storage->consume()->inline($this->resource->getIdentification());
98 } else {
99 $consumer = $this->storage->consume()->download($this->resource->getIdentification());
100 }
101
102 if ($a_hist_entry_id) {
103 $revision = $this->resource->getSpecificRevision($a_hist_entry_id);
104 $consumer->setRevisionNumber($a_hist_entry_id);
105 } else {
106 $revision = $this->resource->getCurrentRevision();
107 }
108
109 if ($this->download_with_uploaded_filename) {
110 $consumer->overrideFileName($revision->getInformation()->getTitle());
111 } else {
112 $consumer->overrideFileName($revision->getTitle());
113 }
114
115 $consumer->run();
116 }
117
118
119 public function deleteVersions(?array $a_hist_entry_ids = null): void
120 {
121 if (is_array($a_hist_entry_ids)) {
122 foreach ($a_hist_entry_ids as $id) {
123 $this->storage->manage()->removeRevision($this->resource->getIdentification(), $id);
124 }
125 }
126 }
127
128 public function getFileExtension(): string
129 {
130 return $this->resource->getCurrentRevision()->getInformation()->getSuffix();
131 }
132
136 public function getVersions(?array $version_ids = null): array
137 {
138 $versions = [];
139 foreach ($this->resource->getAllRevisions() as $revision) {
140 if (is_array($version_ids) && !in_array($revision->getVersionNumber(), $version_ids)) {
141 continue;
142 }
143 $information = $revision->getInformation();
144 $v = new ilObjFileVersion();
145 $v->setVersion($revision->getVersionNumber());
146 $v->setHistEntryId($revision->getVersionNumber());
147 $v->setFilename($information->getTitle());
148 $v->setAction($revision->getVersionNumber() === 1 ? 'create' : 'new_version');
149 $v->setTitle($revision->getTitle());
150 $v->setDate($information->getCreationDate()->format(DATE_ATOM));
151 $v->setUserId($revision->getOwnerId() !== 0 ? $revision->getOwnerId() : 6);
152 $v->setSize($information->getSize());
153
154 $versions[] = $v;
155 }
156
157 return $versions;
158 }
159
160 public function getStorageID(): ?string
161 {
162 return $this->resource->getStorageID();
163 }
164
165 public function getVersion(): int
166 {
167 return $this->resource->getCurrentRevision()->getVersionNumber();
168 }
169
170 public function getMaxVersion(): int
171 {
172 return $this->resource->getMaxRevision();
173 }
174}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileImplementationStorage.
getFileExtension()
Returns the extension of the file name converted to lower-case.
deleteVersions(?array $a_hist_entry_ids=null)
Deletes the specified history entries or all entries if no ids are specified.
getFile(?int $a_hist_entry_id=null)
@inheritDoc
sendFile(?int $a_hist_entry_id=null, bool $inline=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc