ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 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 'last_change' => ['integer', time()]
58 ]);
59 }
60
61 public function getById(int $id): ?array
62 {
63 $set = $this->db->queryF(
64 'SELECT * FROM mob_data WHERE id = %s',
65 ['integer'],
66 [$id]
67 );
68
69 $record = $this->db->fetchAssoc($set);
70 if ($record) {
71 return [
72 'id' => (int) $record['id'],
73 'rid' => (string) $record['rid'],
74 'last_change' => (int) $record['last_change']
75 ];
76 }
77
78 return null;
79 }
80
81 public function delete(int $id): void
82 {
83 $this->db->manipulateF(
84 'DELETE FROM mob_data WHERE id = %s',
85 ['integer'],
86 [$id]
87 );
88 }
89
90 protected function getRidForMobId(int $mob_id): string
91 {
92 $set = $this->db->queryF(
93 "SELECT * FROM mob_data " .
94 " WHERE id = %s ",
95 ["integer"],
96 [$mob_id]
97 );
98 if ($rec = $this->db->fetchAssoc($set)) {
99 return $rec["rid"] ?? "";
100 }
101 return "";
102 }
103
104 public function getLastChangeTimestamp(int $mob_id): int
105 {
106 $set = $this->db->queryF(
107 "SELECT last_change FROM mob_data " .
108 " WHERE id = %s ",
109 ["integer"],
110 [$mob_id]
111 );
112 if ($rec = $this->db->fetchAssoc($set)) {
113 return (int) ($rec["last_change"] ?? 0);
114 }
115 return 0;
116 }
117
118 public function updateLastChangeTimestamp(int $mob_id, int $timestamp): void
119 {
120 $this->db->update(
121 'mob_data',
122 ['last_change' => ['integer', $timestamp]],
123 ['id' => ['integer', $mob_id]]
124 );
125 }
126
127 public function addFileFromLegacyUpload(int $mob_id, string $tmp_name, string $target_path = ""): void
128 {
129 if ($rid = $this->getRidForMobId($mob_id)) {
130 if ($target_path === "") {
131 $target_path = "/";
132 }
133 $this->irss->importFileFromLegacyUploadToContainer(
134 $rid,
135 $tmp_name,
136 $target_path
137 );
138 }
139 }
140
141 public function addFileFromUpload(
142 int $mob_id,
143 UploadResult $result,
144 string $path = "/"
145 ): void {
146 if ($rid = $this->getRidForMobId($mob_id)) {
147 $this->irss->importFileFromUploadResultToContainer(
148 $rid,
149 $result,
150 $path
151 );
152 }
153 }
154
155 public function addFileFromLocal(int $mob_id, string $tmp_name, string $path): void
156 {
157 if ($rid = $this->getRidForMobId($mob_id)) {
158 $this->irss->addLocalFileToContainer(
159 $rid,
160 $tmp_name,
161 $path
162 );
163 }
164 }
165
166 public function addLocalDirectory(int $mob_id, string $dir): void
167 {
168 if ($rid = $this->getRidForMobId($mob_id)) {
169 $this->irss->addDirectoryToContainer(
170 $rid,
171 $dir
172 );
173 }
174 }
175
176 public function getLocalSrc(int $mob_id, string $location): string
177 {
178 return $this->irss->getContainerUri($this->getRidForMobId($mob_id), $location);
179 }
180
181 public function hasLocalFile(int $mob_id, string $location): bool
182 {
183 return $this->irss->hasContainerEntry($this->getRidForMobId($mob_id), $location);
184 }
185
186 public function getLocationStream(
187 int $mob_id,
188 string $location
189 ): ZIPStream {
190 return $this->irss->getStreamOfContainerEntry(
191 $this->getRidForMobId($mob_id),
193 );
194 }
195
196 public function getInfoOfEntry(
197 int $mob_id,
198 string $path
199 ): array {
200 return $this->irss->getContainerEntryInfo(
201 $this->getRidForMobId($mob_id),
202 $path
203 );
204 }
205
206 public function deliverEntry(
207 int $mob_id,
208 string $path
209 ): void {
210 $this->irss->deliverContainerEntry(
211 $this->getRidForMobId($mob_id),
212 $path
213 );
214 }
215
216 public function getContainerPath(
217 int $mob_id
218 ): string {
219 return $this->irss->getResourcePath($this->getRidForMobId($mob_id));
220 }
221
222 public function addStream(
223 int $mob_id,
224 string $location,
225 FileStream $stream
226 ): void {
227 $this->irss->addStreamToContainer(
228 $this->getRidForMobId($mob_id),
229 $stream,
231 );
232 }
233
234 public function addString(
235 int $mob_id,
236 string $location,
237 string $content
238 ): void {
239 $this->irss->addStringToContainer(
240 $this->getRidForMobId($mob_id),
241 $content,
243 );
244 }
245
246 public function getContainerResource(
247 int $mob_id
248 ): ?StorableResource {
249 return $this->irss->getResource($this->getRidForMobId($mob_id));
250 }
251
252 public function getContainerResourceId(
253 int $mob_id
255 return $this->irss->getResourceIdForIdString($this->getRidForMobId($mob_id));
256 }
257
258 public function removeLocation(
259 int $mob_id,
260 string $location
261 ): void {
262 $this->irss->removePathFromContainer($this->getRidForMobId($mob_id), $location);
263 }
264
265 public function getFilesOfPath(
266 int $mob_id,
267 string $dir_path
268 ): array {
269 return $this->irss->getContainerEntriesOfPath(
270 $this->getRidForMobId($mob_id),
271 $dir_path
272 );
273 }
274
275}
$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)
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'))