ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjFileImplementationStorage.php
Go to the documentation of this file.
1 <?php
2 
23 
29 {
30  protected Services $storage;
31 
35  public function __construct(protected StorableResource $resource)
36  {
37  global $DIC;
38  $settings = new General();
39  $this->storage = $DIC->resourceStorage();
40  }
41 
42  public function handleChangedObjectTitle(string $new_title): void
43  {
44  $current_revision = $this->resource->getCurrentRevision();
45  $current_revision->setTitle($new_title);
46  $this->storage->manage()->updateRevision($current_revision);
47  }
48 
52  public function getFile(?int $a_hist_entry_id = null): string
53  {
54  $stream = $this->storage->consume()->stream($this->resource->getIdentification());
55  if ($a_hist_entry_id) {
56  $stream = $stream->setRevisionNumber($a_hist_entry_id);
57  }
58  return $stream->getStream()->getMetadata('uri');
59  }
60 
61  public function getFileName(): string
62  {
63  return $this->resource->getCurrentRevision()->getInformation()->getTitle();
64  }
65 
66  public function getFileSize(): int
67  {
68  return $this->resource->getCurrentRevision()->getInformation()->getSize() ?: 0;
69  }
70 
74  public function getFileType(): string
75  {
76  return $this->resource->getCurrentRevision()->getInformation()->getMimeType();
77  }
78 
79  public function getDirectory(int $a_version = 0): string
80  {
81  $consumer = $this->storage->consume()->stream($this->resource->getIdentification());
82  if ($a_version !== 0) {
83  $consumer->setRevisionNumber($a_version);
84  }
85  $stream = $consumer->getStream();
86 
87  return dirname($stream->getMetadata('uri'));
88  }
89 
90  public function sendFile(?int $a_hist_entry_id = null, bool $inline = true): void
91  {
92  if ($inline) {
93  $consumer = $this->storage->consume()->inline($this->resource->getIdentification());
94  } else {
95  $consumer = $this->storage->consume()->download($this->resource->getIdentification());
96  }
97 
98  if ($a_hist_entry_id) {
99  $revision = $this->resource->getSpecificRevision($a_hist_entry_id);
100  $consumer->setRevisionNumber($a_hist_entry_id);
101  } else {
102  $revision = $this->resource->getCurrentRevision();
103  }
104  $consumer->overrideFileName($revision->getTitle());
105 
106  $consumer->run();
107  }
108 
109  public function deleteVersions(?array $a_hist_entry_ids = null): void
110  {
111  if (is_array($a_hist_entry_ids)) {
112  foreach ($a_hist_entry_ids as $id) {
113  $this->storage->manage()->removeRevision($this->resource->getIdentification(), $id);
114  }
115  }
116  }
117 
118  public function getFileExtension(): string
119  {
120  return $this->resource->getCurrentRevision()->getInformation()->getSuffix();
121  }
122 
126  public function getVersions(?array $version_ids = null): array
127  {
128  $versions = [];
129  $current_revision = $this->resource->getCurrentRevisionIncludingDraft();
130  foreach ($this->resource->getAllRevisionsIncludingDraft() as $revision) {
131  if (is_array($version_ids) && !in_array($revision->getVersionNumber(), $version_ids)) {
132  continue;
133  }
134  $information = $revision->getInformation();
135  $v = new ilObjFileVersion();
136  $v->setVersion($revision->getVersionNumber());
137  $v->setHistEntryId($revision->getVersionNumber());
138  $v->setFilename($information->getTitle());
139  if ($revision->getStatus() === RevisionStatus::DRAFT) {
140  $v->setAction('draft');
141  } else {
142  $version_number = $revision->getVersionNumber();
143  switch ($version_number) {
144  case 1:
145  $v->setAction('create');
146  break;
147  case $current_revision->getVersionNumber():
148  $v->setAction('published_version');
149  break;
150  default:
151  $v->setAction('intermediate_version');
152  break;
153  }
154  }
155  $v->setTitle($revision->getTitle());
156  $v->setDate($information->getCreationDate()->format(DATE_ATOM));
157  $v->setUserId($revision->getOwnerId() !== 0 ? $revision->getOwnerId() : 6);
158  $v->setSize($information->getSize());
159 
160  $versions[] = $v;
161  }
162 
163  return $versions;
164  }
165 
166  public function getStorageID(): ?string
167  {
168  return $this->resource->getStorageID();
169  }
170 
171  public function getVersion(bool $inclduing_drafts = false): int
172  {
173  try {
174  if ($inclduing_drafts) {
175  return $this->resource->getCurrentRevisionIncludingDraft()->getVersionNumber();
176  }
177  return $this->resource->getCurrentRevision()->getVersionNumber();
178  } catch (Throwable) {
179  return 0;
180  }
181  }
182 
183  public function getMaxVersion(): int
184  {
185  return $this->resource->getMaxRevision(false);
186  }
187 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileImplementationStorage.
deleteVersions(?array $a_hist_entry_ids=null)
Deletes the specified history entries or all entries if no ids are specified.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFileExtension()
Returns the extension of the file name converted to lower-case.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
sendFile(?int $a_hist_entry_id=null, bool $inline=true)
__construct(protected StorableResource $resource)
ilObjFileImplementationStorage constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:25
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24