ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
AbstractStorableResource.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
31 abstract class AbstractStorableResource implements StorableResource
32 {
33  protected \ILIAS\ResourceStorage\Revision\RevisionCollection $revisions;
37  protected array $stakeholders = [];
38  protected string $storage_id = '';
40 
44  public function __construct(ResourceIdentification $identification)
45  {
46  $this->identification = $identification;
47  $this->revisions = new RevisionCollection($identification);
48  }
49 
51  {
52  return $this->identification;
53  }
54 
55  public function getCurrentRevision(): Revision
56  {
57  return $this->revisions->getCurrent(false);
58  }
59 
61  {
62  return $this->revisions->getCurrent(true);
63  }
64 
65  public function getSpecificRevision(int $number): ?Revision
66  {
67  foreach ($this->getAllRevisionsIncludingDraft() as $revision) {
68  if ($revision->getVersionNumber() === $number) {
69  return $revision;
70  }
71  }
72  return null;
73  }
74 
75  public function hasSpecificRevision(int $number): bool
76  {
77  foreach ($this->getAllRevisionsIncludingDraft() as $revision) {
78  if ($revision->getVersionNumber() === $number) {
79  return true;
80  }
81  }
82  return false;
83  }
84 
88  public function getAllRevisions(): array
89  {
90  return $this->revisions->getAll(false);
91  }
92 
96  public function getAllRevisionsIncludingDraft(): array
97  {
98  return $this->revisions->getAll(true);
99  }
100 
101  public function addRevision(Revision $revision): void
102  {
103  $this->revisions->add($revision);
104  }
105 
106  public function removeRevision(Revision $revision): void
107  {
108  $this->revisions->remove($revision);
109  }
110 
111  public function replaceRevision(Revision $revision): void
112  {
113  $this->revisions->replaceSingleRevision($revision);
114  }
115 
116  public function setRevisions(RevisionCollection $collection): void
117  {
118  $this->revisions = $collection;
119  }
120 
124  public function getStakeholders(): array
125  {
126  return $this->stakeholders;
127  }
128 
129  public function addStakeholder(ResourceStakeholder $s): void
130  {
131  $this->stakeholders[] = $s;
132  }
133 
134  public function removeStakeholder(ResourceStakeholder $s): void
135  {
136  foreach ($this->stakeholders as $k => $stakeholder) {
137  if ($stakeholder->getId() === $s->getId()) {
138  unset($this->stakeholders[$k]);
139  }
140  }
141  }
142 
146  public function setStakeholders(array $stakeholders): self
147  {
148  $this->stakeholders = $stakeholders;
149 
150  return $this;
151  }
152 
153  public function getStorageId(): string
154  {
155  return $this->storage_id;
156  }
157 
158  public function setStorageId(string $storage_id): void
159  {
160  $this->storage_id = $storage_id;
161  }
162 
167  public function getMaxRevision(bool $including_drafts = false): int
168  {
169  return $this->revisions->getMax($including_drafts);
170  }
171 
172  public function getFullSize(): int
173  {
174  return $this->revisions->getFullSize();
175  }
176 
177  abstract public function getType(): ResourceType;
178 }
__construct(ResourceIdentification $identification)
StorableFileResource constructor.
ILIAS ResourceStorage Revision RevisionCollection $revisions
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...