ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ]);
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),
168 );
169 }
170
171 public function getInfoOfEntry(
172 int $mob_id,
173 string $path
174 ) {
175 return $this->irss->getContainerEntryInfo(
176 $this->getRidForMobId($mob_id),
177 $path
178 );
179 }
180
181 public function deliverEntry(
182 int $mob_id,
183 string $path
184 ): void {
185 $this->irss->deliverContainerEntry(
186 $this->getRidForMobId($mob_id),
187 $path
188 );
189 }
190
191 public function getContainerPath(
192 int $mob_id
193 ): string {
194 return $this->irss->getResourcePath($this->getRidForMobId($mob_id));
195 }
196
197 public function addStream(
198 int $mob_id,
199 string $location,
200 FileStream $stream
201 ): void {
202 $this->irss->addStreamToContainer(
203 $this->getRidForMobId($mob_id),
204 $stream,
206 );
207 }
208
209 public function addString(
210 int $mob_id,
211 string $location,
212 string $content
213 ): void {
214 $this->irss->addStringToContainer(
215 $this->getRidForMobId($mob_id),
216 $content,
218 );
219 }
220
221 public function getContainerResource(
222 int $mob_id
223 ): ?StorableResource {
224 return $this->irss->getResource($this->getRidForMobId($mob_id));
225 }
226
227 public function getContainerResourceId(
228 int $mob_id
230 return $this->irss->getResourceIdForIdString($this->getRidForMobId($mob_id));
231 }
232
233 public function removeLocation(
234 int $mob_id,
235 string $location
236 ): void {
237 $this->irss->removePathFromContainer($this->getRidForMobId($mob_id), $location);
238 }
239
240 public function getFilesOfPath(
241 int $mob_id,
242 string $dir_path
243 ): array {
244 return $this->irss->getContainerEntriesOfPath(
245 $this->getRidForMobId($mob_id),
246 $dir_path
247 );
248 }
249
250}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$location
Definition: buildRTE.php:22
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)
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'))