ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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((string) $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  match ($version_number) {
144  1 => $v->setAction('create'),
145  $current_revision->getVersionNumber() => $v->setAction('published_version'),
146  default => $v->setAction('intermediate_version'),
147  };
148  }
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(bool $inclduing_drafts = false): int
166  {
167  try {
168  if ($inclduing_drafts) {
169  return $this->resource->getCurrentRevisionIncludingDraft()->getVersionNumber();
170  }
171  return $this->resource->getCurrentRevision()->getVersionNumber();
172  } catch (Throwable) {
173  return 0;
174  }
175  }
176 
177  public function getMaxVersion(): int
178  {
179  return $this->resource->getMaxRevision(false);
180  }
181 }
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__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:26
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23