ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
MediaObjectRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\MediaObjects;
22 
23 use ilDBInterface;
30 
32 {
33  public function __construct(
34  protected ilDBInterface $db,
35  protected IRSSWrapper $irss
36  ) {
37  }
38 
39  public function create(
40  int $id,
41  string $title,
42  \ilMobStakeholder $stakeholder,
43  int $from_mob_id = 0
44  ) : void {
45  if ($from_mob_id > 0) {
46  $from_rid = $this->getRidForMobId($from_mob_id);
47  $rid = $this->irss->cloneContainer($from_rid);
48  } else {
49  $rid = $this->irss->createContainer(
50  $stakeholder,
51  "mob.zip"
52  );
53  }
54  $this->db->insert('mob_data', [
55  'id' => ['integer', $id],
56  'rid' => ['text', $rid]
57  ]);
58  }
59 
60  public function getById(int $id) : ?array
61  {
62  $set = $this->db->queryF(
63  'SELECT * FROM mob_data WHERE id = %s',
64  ['integer'],
65  [$id]
66  );
67 
68  $record = $this->db->fetchAssoc($set);
69  if ($record) {
70  return [
71  'id' => (int) $record['id'],
72  'rid' => (string) $record['rid']
73  ];
74  }
75 
76  return null;
77  }
78 
79  public function delete(int $id) : void
80  {
81  $this->db->manipulateF(
82  'DELETE FROM mob_data WHERE id = %s',
83  ['integer'],
84  [$id]
85  );
86  }
87 
88  protected function getRidForMobId(int $mob_id) : string
89  {
90  $set = $this->db->queryF(
91  "SELECT * FROM mob_data " .
92  " WHERE id = %s ",
93  ["integer"],
94  [$mob_id]
95  );
96  if ($rec = $this->db->fetchAssoc($set)) {
97  return $rec["rid"] ?? "";
98  }
99  return "";
100  }
101 
102  public function addFileFromLegacyUpload(int $mob_id, string $tmp_name, string $target_path = "") : void
103  {
104  if ($rid = $this->getRidForMobId($mob_id)) {
105  if ($target_path === "") {
106  $target_path = "/";
107  }
108  $this->irss->importFileFromLegacyUploadToContainer(
109  $rid,
110  $tmp_name,
111  $target_path
112  );
113  }
114  }
115 
116  public function addFileFromUpload(
117  int $mob_id,
118  UploadResult $result,
119  string $path = "/"
120  ) : void {
121  if ($rid = $this->getRidForMobId($mob_id)) {
122  $this->irss->importFileFromUploadResultToContainer(
123  $rid,
124  $result,
125  $path
126  );
127  }
128  }
129 
130  public function addFileFromLocal(int $mob_id, string $tmp_name, string $path) : void
131  {
132  if ($rid = $this->getRidForMobId($mob_id)) {
133  $this->irss->addLocalFileToContainer(
134  $rid,
135  $tmp_name,
136  $path
137  );
138  }
139  }
140 
141  public function addLocalDirectory(int $mob_id, string $dir) : void
142  {
143  if ($rid = $this->getRidForMobId($mob_id)) {
144  $this->irss->addDirectoryToContainer(
145  $rid,
146  $dir
147  );
148  }
149  }
150 
151  public function getLocalSrc(int $mob_id, string $location) : string
152  {
153  return $this->irss->getContainerUri($this->getRidForMobId($mob_id), $location);
154  }
155 
156  public function hasLocalFile(int $mob_id, string $location) : bool
157  {
158  return $this->irss->hasContainerEntry($this->getRidForMobId($mob_id), $location);
159  }
160 
161  public function getLocationStream(
162  int $mob_id,
163  string $location
164  ) : ZIPStream {
165  return $this->irss->getStreamOfContainerEntry(
166  $this->getRidForMobId($mob_id),
167  $location
168  );
169  }
170 
171  public function getInfoOfEntry(
172  int $mob_id,
173  string $path
174  )
175  {
176  return $this->irss->getContainerEntryInfo(
177  $this->getRidForMobId($mob_id),
178  $path
179  );
180  }
181 
182  public function deliverEntry(
183  int $mob_id,
184  string $path
185  ) : void
186  {
187  $this->irss->deliverContainerEntry(
188  $this->getRidForMobId($mob_id),
189  $path
190  );
191  }
192 
193  public function getContainerPath(
194  int $mob_id
195  ) : string {
196  return $this->irss->getResourcePath($this->getRidForMobId($mob_id));
197  }
198 
199  public function addStream(
200  int $mob_id,
201  string $location,
202  FileStream $stream
203  ) : void {
204  $this->irss->addStreamToContainer(
205  $this->getRidForMobId($mob_id),
206  $stream,
207  $location
208  );
209  }
210 
211  public function addString(
212  int $mob_id,
213  string $location,
214  string $content
215  ) : void {
216  $this->irss->addStringToContainer(
217  $this->getRidForMobId($mob_id),
218  $content,
219  $location
220  );
221  }
222 
223  public function getContainerResource(
224  int $mob_id
225  ) : ?StorableResource {
226  return $this->irss->getResource($this->getRidForMobId($mob_id));
227  }
228 
229  public function getContainerResourceId(
230  int $mob_id
232  return $this->irss->getResourceIdForIdString($this->getRidForMobId($mob_id));
233  }
234 
235  public function removeLocation(
236  int $mob_id,
237  string $location
238  ) : void {
239  $this->irss->removePathFromContainer($this->getRidForMobId($mob_id), $location);
240  }
241 
242  public function getFilesOfPath(
243  int $mob_id,
244  string $dir_path
245  ) : array {
246  return $this->irss->getContainerEntriesOfPath(
247  $this->getRidForMobId($mob_id),
248  $dir_path
249  );
250  }
251 
252 }
getLocationStream(int $mob_id, string $location)
addFileFromLocal(int $mob_id, string $tmp_name, string $path)
getFilesOfPath(int $mob_id, string $dir_path)
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
addStream(int $mob_id, string $location, FileStream $stream)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addString(int $mob_id, string $location, string $content)
__construct(protected ilDBInterface $db, protected IRSSWrapper $irss)
$path
Definition: ltiservices.php:30
removeLocation(int $mob_id, string $location)
addFileFromLegacyUpload(int $mob_id, string $tmp_name, string $target_path="")
hasLocalFile(int $mob_id, string $location)
create(int $id, string $title, \ilMobStakeholder $stakeholder, int $from_mob_id=0)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
getLocalSrc(int $mob_id, string $location)
addFileFromUpload(int $mob_id, UploadResult $result, string $path="/")
The base interface for all filesystem streams.
Definition: FileStream.php:31