ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSImportManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 protected ilDBInterface $db;
31
32 private function __construct()
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 }
38
43 public static function getInstance(): ilECSImportManager
44 {
45 if (!isset(self::$instance)) {
46 self::$instance = new ilECSImportManager();
47 }
48 return self::$instance;
49 }
50
57 public function lookupContentId($a_server_id, $a_mid, $a_econtent_id): string
58 {
59 $query = 'SELECT * from ecs_import ' .
60 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ' .
61 'AND mid = ' . $this->db->quote($a_mid, 'integer') . ' ' .
62 'AND econtent_id = ' . $this->db->quote($a_econtent_id, 'text');
63 $res = $this->db->query($query);
64 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
65 return $row->content_id;
66 }
67 return '';
68 }
69
73 public function lookupObjIdByContentId(int $a_server_id, int $a_mid, int $a_content_id, ?string $a_sub_id = null): int
74 {
75 $query = "SELECT obj_id FROM ecs_import " .
76 "WHERE content_id = " . $this->db->quote($a_content_id, 'integer') . " " .
77 "&& mid = " . $this->db->quote($a_mid, 'integer') . " " .
78 '&& server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ';
79
80 if (!is_null($a_sub_id)) {
81 $query .= 'AND sub_id = ' . $this->db->quote($a_sub_id, 'text');
82 } else {
83 $query .= 'AND sub_id IS NULL';
84 }
85 $res = $this->db->query($query);
86
87 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
88 return (int) $row->obj_id;
89 }
90 return 0;
91 }
92
93 public function lookupObjIdsByContentId($a_content_id): array
94 {
95 $query = "SELECT obj_id FROM ecs_import " .
96 "WHERE content_id = " . $this->db->quote($a_content_id, 'integer');
97
98 $res = $this->db->query($query);
99
100 $obj_ids = array();
101 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
102 $obj_ids[] = $row->obj_id;
103 }
104 return $obj_ids;
105 }
106
112 public function lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id): int
113 {
114 $query = 'SELECT * from ecs_import ' .
115 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ' .
116 'AND mid = ' . $this->db->quote($a_mid, 'integer') . ' ' .
117 'AND content_id = ' . $this->db->quote($a_content_id, 'text');
118 $res = $this->db->query($query);
119 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
120 return (int) $row->econtent_id;
121 }
122 return 0;
123 }
124
129 public function getAllImportedRemoteObjects($a_server_id): array
130 {
131 $all = array();
132 $query = "SELECT * FROM ecs_import ei JOIN object_data obd ON ei.obj_id = obd.obj_id " .
133 'WHERE server_id = ' . $this->db->quote($a_server_id) . ' ' .
134 'AND ' . $this->db->in('type', ilECSUtils::getPossibleRemoteTypes(), false, 'text');
135 $res = $this->db->query($query);
136 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
137 $all[$row->econtent_id] = $row->obj_id;
138 }
139
140 return $all;
141 }
142
149 public function _lookupObjIdsByMID($a_server_id, $a_mid): array
150 {
151 $query = "SELECT * FROM ecs_import " .
152 "WHERE mid = " . $this->db->quote($a_mid, 'integer') . " " .
153 'AND server_id = ' . $this->db->quote($a_server_id, 'integer');
154
155 $res = $this->db->query($query);
156 $obj_ids = [];
157 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158 $obj_ids[] = $row->obj_id;
159 }
160 return $obj_ids;
161 }
162
166 public function _lookupEContentId(int $a_obj_id): string
167 {
168 $query = "SELECT * FROM ecs_import WHERE obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
169 $res = $this->db->query($query);
170 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
171 return $row->econtent_id;
172 }
173 return "";
174 }
175
179 public function lookupServerId(int $a_obj_id): int
180 {
181 $query = 'SELECT * FROM ecs_import WHERE obj_id = ' . $this->db->quote($a_obj_id, 'integer');
182 $res = $this->db->query($query);
183 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
184 return (int) $row->server_id;
185 }
186 return 0;
187 }
188
193 public function _lookupObjIds($a_server_id, $a_econtent_id): array
194 {
195 $query = "SELECT obj_id FROM ecs_import WHERE econtent_id = " . $this->db->quote($a_econtent_id, 'text') . " " .
196 'AND server_id = ' . $this->db->quote($a_server_id, 'integer');
197 $res = $this->db->query($query);
198 $obj_ids = [];
199 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
200 $obj_ids[] = (int) $row->obj_id;
201 }
202 return $obj_ids;
203 }
204
208 public function _lookupObjId(int $a_server_id, string $a_econtent_id, int $a_mid, ?string $a_sub_id = null): int
209 {
210 $query = "SELECT obj_id FROM ecs_import " .
211 "WHERE econtent_id = " . $this->db->quote($a_econtent_id, 'text') . " " .
212 "AND mid = " . $this->db->quote($a_mid, 'integer') . " " .
213 'AND server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ';
214
215 if (!is_null($a_sub_id)) {
216 $query .= 'AND sub_id = ' . $this->db->quote($a_sub_id, 'text');
217 } else {
218 $query .= 'AND sub_id IS NULL';
219 }
220 $res = $this->db->query($query);
221
222 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
223 return (int) $row->obj_id;
224 }
225 return 0;
226 }
227
233 public function _deleteByObjId($a_obj_id): bool
234 {
235 $query = "DELETE FROM ecs_import " .
236 "WHERE obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
237 $this->db->manipulate($query);
238 return true;
239 }
240
244 public function deleteByServer(int $a_server_id): void
245 {
246 $query = 'DELETE FROM ecs_import ' .
247 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer');
248 $this->db->manipulate($query);
249 }
250
256 public function deleteRessources(int $a_server_id, int $a_mid, array $a_econtent_ids): bool
257 {
258 $query = 'DELETE FROM ecs_import ' .
259 'WHERE server_id = ' . $this->db->quote($a_server_id, 'integer') . ' ' .
260 'AND mid = ' . $this->db->quote($a_mid, 'integer') . ' ' .
261 'AND ' . $this->db->in('econtent_id', $a_econtent_ids, false, 'text');
262 $this->db->manipulate($query);
263 return true;
264 }
265
269 public function _isImported(int $a_server_id, string $a_econtent_id, int $a_mid, ?string $a_sub_id = null): int
270 {
271 return $this->_lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id);
272 }
273
274 public function resetServerId($a_server_id): bool
275 {
276 $query = 'UPDATE ecs_import SET server_id = ' . $this->db->quote(0, 'integer') .
277 ' WHERE server_id = ' . $this->db->quote($a_server_id, 'integer');
278 $this->db->manipulate($query);
279 return true;
280 }
281}
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.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26