ILIAS  release_8 Revision v8.24
class.ilECSImportManager.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
27{
28 protected ilDBInterface $db;
30
31 private function __construct()
32 {
33 global $DIC;
34
35 $this->db = $DIC->database();
36 }
37
42 public static function getInstance(): ilECSImportManager
43 {
44 if (!isset(self::$instance)) {
45 self::$instance = new ilECSImportManager();
46 }
47 return self::$instance;
48 }
49
56 public function lookupContentId($a_server_id, $a_mid, $a_econtent_id): string
57 {
58 $query = 'SELECT * from ecs_import ' .
59 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ' .
60 'AND mid = ' . $this->db->quote($a_mid, 'integer') . ' ' .
61 'AND econtent_id = ' . $this->db->quote($a_econtent_id, 'text');
62 $res = $this->db->query($query);
63 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
64 return $row->content_id;
65 }
66 return '';
67 }
68
72 public function lookupObjIdByContentId(int $a_server_id, int $a_mid, int $a_content_id, ?string $a_sub_id = null): int
73 {
74 $query = "SELECT obj_id FROM ecs_import " .
75 "WHERE content_id = " . $this->db->quote($a_content_id, 'integer') . " " .
76 "&& mid = " . $this->db->quote($a_mid, 'integer') . " " .
77 '&& server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ';
78
79 if (!is_null($a_sub_id)) {
80 $query .= 'AND sub_id = ' . $this->db->quote($a_sub_id, 'text');
81 } else {
82 $query .= 'AND sub_id IS NULL';
83 }
84 $res = $this->db->query($query);
85
86 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
87 return (int) $row->obj_id;
88 }
89 return 0;
90 }
91
92 public function lookupObjIdsByContentId($a_content_id): array
93 {
94 $query = "SELECT obj_id FROM ecs_import " .
95 "WHERE content_id = " . $this->db->quote($a_content_id, 'integer');
96
97 $res = $this->db->query($query);
98
99 $obj_ids = array();
100 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
101 $obj_ids[] = $row->obj_id;
102 }
103 return $obj_ids;
104 }
105
111 public function lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id): int
112 {
113 $query = 'SELECT * from ecs_import ' .
114 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ' .
115 'AND mid = ' . $this->db->quote($a_mid, 'integer') . ' ' .
116 'AND content_id = ' . $this->db->quote($a_content_id, 'text');
117 $res = $this->db->query($query);
118 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119 return (int) $row->econtent_id;
120 }
121 return 0;
122 }
123
128 public function getAllImportedRemoteObjects($a_server_id): array
129 {
130 $all = array();
131 $query = "SELECT * FROM ecs_import ei JOIN object_data obd ON ei.obj_id = obd.obj_id " .
132 'WHERE server_id = ' . $this->db->quote($a_server_id) . ' ' .
133 'AND ' . $this->db->in('type', ilECSUtils::getPossibleRemoteTypes(), false, 'text');
134 $res = $this->db->query($query);
135 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
136 $all[$row->econtent_id] = $row->obj_id;
137 }
138
139 return $all;
140 }
141
148 public function _lookupObjIdsByMID($a_server_id, $a_mid): array
149 {
150 $query = "SELECT * FROM ecs_import " .
151 "WHERE mid = " . $this->db->quote($a_mid, 'integer') . " " .
152 'AND server_id = ' . $this->db->quote($a_server_id, 'integer');
153
154 $res = $this->db->query($query);
155 $obj_ids = [];
156 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
157 $obj_ids[] = $row->obj_id;
158 }
159 return $obj_ids;
160 }
161
165 public function _lookupEContentId(int $a_obj_id): string
166 {
167 $query = "SELECT * FROM ecs_import WHERE obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
168 $res = $this->db->query($query);
169 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
170 return $row->econtent_id;
171 }
172 return "";
173 }
174
178 public function lookupServerId(int $a_obj_id): int
179 {
180 $query = 'SELECT * FROM ecs_import WHERE obj_id = ' . $this->db->quote($a_obj_id, 'integer');
181 $res = $this->db->query($query);
182 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
183 return (int) $row->server_id;
184 }
185 return 0;
186 }
187
192 public function _lookupObjIds($a_server_id, $a_econtent_id): array
193 {
194 $query = "SELECT obj_id FROM ecs_import WHERE econtent_id = " . $this->db->quote($a_econtent_id, 'text') . " " .
195 'AND server_id = ' . $this->db->quote($a_server_id, 'integer');
196 $res = $this->db->query($query);
197 $obj_ids = [];
198 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199 $obj_ids[] = (int) $row->obj_id;
200 }
201 return $obj_ids;
202 }
203
207 public function _lookupObjId(int $a_server_id, string $a_econtent_id, int $a_mid, ?string $a_sub_id = null): int
208 {
209 $query = "SELECT obj_id FROM ecs_import " .
210 "WHERE econtent_id = " . $this->db->quote($a_econtent_id, 'text') . " " .
211 "AND mid = " . $this->db->quote($a_mid, 'integer') . " " .
212 'AND server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ';
213
214 if (!is_null($a_sub_id)) {
215 $query .= 'AND sub_id = ' . $this->db->quote($a_sub_id, 'text');
216 } else {
217 $query .= 'AND sub_id IS NULL';
218 }
219 $res = $this->db->query($query);
220
221 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
222 return (int) $row->obj_id;
223 }
224 return 0;
225 }
226
232 public function _deleteByObjId($a_obj_id): bool
233 {
234 $query = "DELETE FROM ecs_import " .
235 "WHERE obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
236 $this->db->manipulate($query);
237 return true;
238 }
239
243 public function deleteByServer(int $a_server_id): void
244 {
245 $query = 'DELETE FROM ecs_import ' .
246 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer');
247 $this->db->manipulate($query);
248 }
249
255 public function deleteRessources(int $a_server_id, int $a_mid, array $a_econtent_ids): bool
256 {
257 $query = 'DELETE FROM ecs_import ' .
258 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ' .
259 'AND mid = ' . $this->db->quote($a_mid, 'integer') . ' ' .
260 'AND ' . $this->db->in('econtent_id', $a_econtent_ids, false, 'text');
261 $this->db->manipulate($query);
262 return true;
263 }
264
268 public function _isImported(int $a_server_id, string $a_econtent_id, int $a_mid, ?string $a_sub_id = null): int
269 {
270 return $this->_lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id);
271 }
272
273 public function resetServerId($a_server_id): bool
274 {
275 $query = 'UPDATE ecs_import SET server_id = ' . $this->db->quote(0, 'integer') .
276 ' WHERE server_id = ' . $this->db->quote($a_server_id, 'integer');
277 $this->db->manipulate($query);
278 return true;
279 }
280}
Manage the ECS imported contents.
_deleteByObjId($a_obj_id)
Delete by obj_id.
deleteByServer(int $a_server_id)
Delete by server id.
static getInstance()
Get the singleton instance of this ilECSImportManager.
lookupServerId(int $a_obj_id)
Lookup server id of imported content.
_lookupObjIds($a_server_id, $a_econtent_id)
Lookup obj_id.
lookupObjIdByContentId(int $a_server_id, int $a_mid, int $a_content_id, ?string $a_sub_id=null)
Lookup obj_id by content id.
lookupContentId($a_server_id, $a_mid, $a_econtent_id)
Lookup content id The content is the - not necessarily unique - id provided by the econtent type.
lookupObjIdsByContentId($a_content_id)
deleteRessources(int $a_server_id, int $a_mid, array $a_econtent_ids)
Delete ressources.
static ilECSImportManager $instance
_lookupEContentId(int $a_obj_id)
get econent_id
_lookupObjIdsByMID($a_server_id, $a_mid)
lookup obj ids by mid
getAllImportedRemoteObjects($a_server_id)
get all imported links
_lookupObjId(int $a_server_id, string $a_econtent_id, int $a_mid, ?string $a_sub_id=null)
loogup obj_id by econtent and mid and server_id
_isImported(int $a_server_id, string $a_econtent_id, int $a_mid, ?string $a_sub_id=null)
check if econtent is imported for a specific mid
lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id)
Lookup econtent id The econtent id is the unique id from ecs.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query