ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
MediaObjectRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\MediaObjects;
22
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 $rid = "";
46 if ($from_mob_id > 0) {
47 $from_rid = $this->getRidForMobId($from_mob_id);
48 if ($from_rid !== "") {
49 $rid = $this->irss->cloneContainer($from_rid);
50 }
51 }
52 if ($rid === "") {
53 $rid = $this->irss->createContainer(
54 $stakeholder,
55 "mob.zip"
56 );
57 }
58 $this->db->insert('mob_data', [
59 'id' => ['integer', $id],
60 'rid' => ['text', $rid],
61 'last_change' => ['integer', time()]
62 ]);
63 }
64
65 public function getById(int $id): ?array
66 {
67 $set = $this->db->queryF(
68 'SELECT * FROM mob_data WHERE id = %s',
69 ['integer'],
70 [$id]
71 );
72
73 $record = $this->db->fetchAssoc($set);
74 if ($record) {
75 return [
76 'id' => (int) $record['id'],
77 'rid' => (string) $record['rid'],
78 'last_change' => (int) $record['last_change']
79 ];
80 }
81
82 return null;
83 }
84
85 public function delete(int $id): void
86 {
87 $this->db->manipulateF(
88 'DELETE FROM mob_data WHERE id = %s',
89 ['integer'],
90 [$id]
91 );
92 }
93
94 protected function getRidForMobId(int $mob_id): string
95 {
96 $set = $this->db->queryF(
97 "SELECT * FROM mob_data " .
98 " WHERE id = %s ",
99 ["integer"],
100 [$mob_id]
101 );
102 if ($rec = $this->db->fetchAssoc($set)) {
103 return $rec["rid"] ?? "";
104 }
105 return "";
106 }
107
108 public function getLastChangeTimestamp(int $mob_id): int
109 {
110 $set = $this->db->queryF(
111 "SELECT last_change FROM mob_data " .
112 " WHERE id = %s ",
113 ["integer"],
114 [$mob_id]
115 );
116 if ($rec = $this->db->fetchAssoc($set)) {
117 return (int) ($rec["last_change"] ?? 0);
118 }
119 return 0;
120 }
121
122 public function updateLastChangeTimestamp(int $mob_id, int $timestamp): void
123 {
124 $this->db->update(
125 'mob_data',
126 ['last_change' => ['integer', $timestamp]],
127 ['id' => ['integer', $mob_id]]
128 );
129 }
130
131 public function addFileFromLegacyUpload(int $mob_id, string $tmp_name, string $target_path = ""): void
132 {
133 if ($rid = $this->getRidForMobId($mob_id)) {
134 if ($target_path === "") {
135 $target_path = "/";
136 }
137 $this->irss->importFileFromLegacyUploadToContainer(
138 $rid,
139 $tmp_name,
140 $target_path
141 );
142 }
143 }
144
145 public function addFileFromUpload(
146 int $mob_id,
147 UploadResult $result,
148 string $path = "/"
149 ): void {
150 if ($rid = $this->getRidForMobId($mob_id)) {
151 $this->irss->importFileFromUploadResultToContainer(
152 $rid,
153 $result,
154 $path
155 );
156 }
157 }
158
159 public function addFileFromLocal(int $mob_id, string $tmp_name, string $path): void
160 {
161 if ($rid = $this->getRidForMobId($mob_id)) {
162 $this->irss->addLocalFileToContainer(
163 $rid,
164 $tmp_name,
165 $path
166 );
167 }
168 }
169
170 public function addLocalDirectory(int $mob_id, string $dir): void
171 {
172 if ($rid = $this->getRidForMobId($mob_id)) {
173 $this->irss->addDirectoryToContainer(
174 $rid,
175 $dir
176 );
177 }
178 }
179
180 public function getLocalSrc(int $mob_id, string $location): string
181 {
182 $rid = $this->getRidForMobId($mob_id);
183 if ($rid === "") {
184 return "";
185 }
186 return $this->irss->getContainerUri($rid, $location);
187 }
188
189 public function hasLocalFile(int $mob_id, string $location): bool
190 {
191 $rid = $this->getRidForMobId($mob_id);
192 if ($rid === "") {
193 return false;
194 }
195 return $this->irss->hasContainerEntry($rid, $location);
196 }
197
198 public function getLocationStream(
199 int $mob_id,
200 string $location
201 ): ZIPStream {
202 return $this->irss->getStreamOfContainerEntry(
203 $this->getRidForMobId($mob_id),
205 );
206 }
207
208 public function getLocationContent(
209 int $mob_id,
210 string $location
211 ): string {
212 $content = "";
213 if (str_starts_with($location, "/")) {
214 $location = substr($location, 1);
215 }
216 if ($this->irss->hasContainerEntry($this->getRidForMobId($mob_id), $location)) {
217 $content = stream_get_contents($this->getLocationStream($mob_id, $location)->detach());
218 }
219 return $content;
220 }
221
222 public function getInfoOfEntry(
223 int $mob_id,
224 string $path
225 ): array {
226 return $this->irss->getContainerEntryInfo(
227 $this->getRidForMobId($mob_id),
228 $path
229 );
230 }
231
232 public function deliverEntry(
233 int $mob_id,
234 string $path
235 ): void {
236 $this->irss->deliverContainerEntry(
237 $this->getRidForMobId($mob_id),
238 $path
239 );
240 }
241
242 public function getContainerPath(
243 int $mob_id
244 ): string {
245 return $this->irss->getResourcePath($this->getRidForMobId($mob_id));
246 }
247
248 public function addStream(
249 int $mob_id,
250 string $location,
251 FileStream $stream
252 ): void {
253 $this->irss->addStreamToContainer(
254 $this->getRidForMobId($mob_id),
255 $stream,
257 );
258 }
259
260 public function addString(
261 int $mob_id,
262 string $location,
263 string $content
264 ): void {
265 $this->irss->addStringToContainer(
266 $this->getRidForMobId($mob_id),
267 $content,
269 );
270 }
271
272 public function getContainerResource(
273 int $mob_id
274 ): ?StorableResource {
275 return $this->irss->getResource($this->getRidForMobId($mob_id));
276 }
277
278 public function getContainerResourceId(
279 int $mob_id
281 return $this->irss->getResourceIdForIdString($this->getRidForMobId($mob_id));
282 }
283
284 public function removeLocation(
285 int $mob_id,
286 string $location
287 ): void {
288 $this->irss->removePathFromContainer($this->getRidForMobId($mob_id), $location);
289 }
290
291 public function getFilesOfPath(
292 int $mob_id,
293 string $dir_path
294 ): array {
295 return $this->irss->getContainerEntriesOfPath(
296 $this->getRidForMobId($mob_id),
297 $dir_path
298 );
299 }
300
301}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$location
Definition: buildRTE.php:22
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
addString(int $mob_id, string $location, string $content)
removeLocation(int $mob_id, string $location)
getLocationContent(int $mob_id, string $location)
getFilesOfPath(int $mob_id, string $dir_path)
hasLocalFile(int $mob_id, string $location)
addFileFromLocal(int $mob_id, string $tmp_name, string $path)
addStream(int $mob_id, string $location, FileStream $stream)
updateLastChangeTimestamp(int $mob_id, int $timestamp)
getLocalSrc(int $mob_id, string $location)
addFileFromUpload(int $mob_id, UploadResult $result, string $path="/")
create(int $id, string $title, \ilMobStakeholder $stakeholder, int $from_mob_id=0)
getLocationStream(int $mob_id, string $location)
addFileFromLegacyUpload(int $mob_id, string $tmp_name, string $target_path="")
__construct(protected ilDBInterface $db, protected IRSSWrapper $irss)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The base interface for all filesystem streams.
Definition: FileStream.php:32
Interface ilDBInterface.
$path
Definition: ltiservices.php:30
if(!file_exists('../ilias.ini.php'))