18 declare(strict_types=1);
40 private int $status = self::MAPPING_UNMAPPED;
46 $this->db = $DIC->database();
48 $this->obj_id = $a_obj_id;
52 public static function treeExists(
int $a_server_id,
int $a_mid,
int $a_tree_id): bool
58 $query =
'SELECT COUNT(*) num FROM ecs_cms_data ' .
59 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
60 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
61 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer');
75 public static function findDeletedNodes(
int $a_server_id,
int $a_mid,
int $a_tree_id): array
81 $query =
'SELECT ed.obj_id obj_id FROM ecs_cms_data ed ' .
82 'LEFT JOIN ecs_cms_tree et ON ed.obj_id = et.child ' .
83 'WHERE et.child IS NULL ' .
84 'AND server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
85 'AND mid = ' .
$ilDB->quote($a_mid) .
' ' .
86 'AND tree_id = ' .
$ilDB->quote($a_tree_id);
91 $deleted[] = $row->obj_id;
96 public static function lookupObjId(
int $a_server_id,
int $a_mid,
int $a_tree_id,
string $cms_id):
int 100 $ilDB = $DIC[
'ilDB'];
101 $logger = $DIC->logger()->wsrv();
103 $query =
'SELECT obj_id FROM ecs_cms_data ' .
104 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
105 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
106 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ' .
107 'AND cms_id = ' .
$ilDB->quote($cms_id,
'text');
125 $ilDB = $DIC->database();
126 $logger = $DIC->logger()->wsrv();
128 $logger->debug($a_server_id .
' ' . $a_mid .
' ' . $cms_id);
130 $query =
'SELECT tree_id FROM ecs_cms_data ' .
131 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
132 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
133 'AND cms_id = ' .
$ilDB->quote($cms_id,
'text') .
' ' .
138 return $row->tree_id;
146 public static function lookupTitle(
int $a_server_id,
int $a_mid,
int $a_tree_id): string
150 $ilDB = $DIC[
'ilDB'];
152 $query =
'SELECT * FROM ecs_cms_data ' .
153 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
154 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
155 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer');
166 public static function lookupTopTerm(
int $a_server_id,
int $a_mid,
int $a_tree_id): string
170 $ilDB = $DIC[
'ilDB'];
172 $query =
'SELECT term FROM ecs_cms_data ' .
173 'JOIN ecs_cms_tree ON obj_id = child ' .
174 'WHERE tree = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ' .
175 'AND server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
176 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
177 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ' .
193 $ilDB = $DIC[
'ilDB'];
195 $query =
'SELECT status,deleted FROM ecs_cms_data ' .
196 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
197 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
198 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ' .
199 'AND obj_id = ' .
$ilDB->quote($obj_id,
'integer');
203 return self::MAPPING_DELETED;
205 return (
int) $row->status;
207 return self::MAPPING_UNMAPPED;
217 $ilDB = $DIC[
'ilDB'];
219 $query =
'SELECT status FROM ecs_cms_data ' .
220 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
221 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
222 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ' .
223 'AND cms_id = ' .
$ilDB->quote($cms_id,
'text');
226 return (
int) $row->status;
228 return self::MAPPING_UNMAPPED;
231 public static function updateStatus(
int $a_server_id,
int $a_mid,
int $a_tree_id): void
234 self::writeAllStatus($a_server_id, $a_mid, $a_tree_id, self::MAPPING_UNMAPPED);
239 $subIds = self::lookupCmsIds(array_merge($cmsTree->getSubTreeIds($assignment), array($assignment)));
256 $cms_ids = self::lookupCmsIds(array($a_obj_id));
268 $ilDB = $DIC[
'ilDB'];
270 $query =
'SELECT cms_id FROM ecs_cms_data ' .
271 'WHERE ' .
$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer');
276 $cms_ids[] = $row->cms_id;
285 $ilDB = $DIC[
'ilDB'];
287 $query =
'SELECT cms_id FROM ecs_cms_data ' .
288 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
289 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
290 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer');
294 $cms_ids[] = $row->cms_id;
302 public static function writeStatus($a_server_id, $a_mid, $a_tree_id, $cms_ids, $status): bool
306 $ilDB = $DIC[
'ilDB'];
308 $query =
'UPDATE ecs_cms_data ' .
309 'SET status = ' .
$ilDB->quote($status,
'integer') .
' ' .
310 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
311 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
312 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ' .
313 'AND ' .
$ilDB->in(
'cms_id', $cms_ids,
false,
'text');
321 public static function writeAllStatus($a_server_id, $a_mid, $a_tree_id, $status): bool
325 $ilDB = $DIC[
'ilDB'];
327 $query =
'UPDATE ecs_cms_data ' .
328 'SET status = ' .
$ilDB->quote($status,
'integer') .
' ' .
329 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
330 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
331 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ';
339 public static function writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag): bool
343 $ilDB = $DIC[
'ilDB'];
345 $query =
'UPDATE ecs_cms_data ' .
346 'SET deleted = ' .
$ilDB->quote($a_deleted_flag,
'integer') .
' ' .
347 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
348 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
349 'AND tree_id = ' .
$ilDB->quote($a_tree_id,
'integer') .
' ';
363 $ilDB = $DIC[
'ilDB'];
365 $query =
'SELECT DISTINCT(tree_id) tid FROM ecs_cms_data ' .
366 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer') .
' ' .
367 'AND mid = ' .
$ilDB->quote($a_mid,
'integer');
372 $tree_ids[] = (
int) $row->tid;
380 $this->title = $a_title;
390 $this->term = $a_term;
400 $this->obj_id = $a_id;
410 $this->cms_id = $a_id;
420 $this->server_id = $a_id;
430 $this->tree_id = $a_id;
450 $this->status = $a_status;
460 $this->deleted = $a_is_deleted;
471 $this->obj_id = $this->db->nextId(
'ecs_cms_data');
473 $query =
'INSERT INTO ecs_cms_data (obj_id,server_id,mid,tree_id,cms_id,title,term,status,deleted) ' .
475 $this->db->quote($this->obj_id,
'integer') .
', ' .
476 $this->db->quote($this->server_id,
'integer') .
', ' .
477 $this->db->quote($this->mid,
'integer') .
', ' .
478 $this->db->quote($this->tree_id,
'integer') .
', ' .
479 $this->db->quote($this->cms_id,
'text') .
', ' .
480 $this->db->quote($this->title,
'text') .
', ' .
481 $this->db->quote($this->term,
'text') .
', ' .
482 $this->db->quote($this->status,
'integer') .
', ' .
483 $this->db->quote($this->deleted,
'integer') .
' ' .
485 $this->db->manipulate(
$query);
491 $query =
"UPDATE ecs_cms_data SET " .
492 'title = ' . $this->db->quote($this->title,
'text') .
', ' .
493 'term = ' . $this->db->quote($this->term,
'text') .
', ' .
494 'status = ' . $this->db->quote($this->status,
'text') .
', ' .
495 'deleted = ' . $this->db->quote($this->
isDeleted(),
'integer') .
' ' .
496 'WHERE obj_id = ' . $this->db->quote($this->obj_id,
'integer');
497 $this->db->manipulate(
$query);
500 public function delete():
void 502 $query =
"DELETE FROM ecs_cms_data " .
503 'WHERE obj_id = ' . $this->db->quote($this->obj_id,
'integer');
504 $this->db->manipulate(
$query);
509 $query =
"DELETE FROM ecs_cms_data " .
510 'WHERE server_id = ' . $this->db->quote($this->server_id,
'integer') .
' ' .
511 'AND mid = ' . $this->db->quote($this->mid,
'integer') .
' ' .
512 'AND tree_id = ' . $this->db->quote($this->tree_id,
'integer') .
' ';
513 $this->db->manipulate(
$query);
520 $ilDB = $DIC[
'ilDB'];
522 $query =
"DELETE FROM ecs_cms_data " .
523 'WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer');
527 protected function read(): void
529 $query =
'SELECT * FROM ecs_cms_data ' .
530 'WHERE obj_id = ' . $this->db->quote($this->obj_id,
'integer');
533 $this->title = $row->title;
534 $this->term = $row->term;
535 $this->server_id = $row->server_id;
536 $this->mid = $row->mid;
537 $this->tree_id = $row->tree_id;
538 $this->cms_id = $row->cms_id;
539 $this->status = $row->status;
540 $this->deleted = $row->deleted;
static lookupCmsIdsOfTree($a_server_id, $a_mid, $a_tree_id)
const MAPPING_PENDING_DISCONNECTABLE
static writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag)
Write deleted status.
static lookupTreeIds(int $a_server_id, int $a_mid)
setDeleted($a_is_deleted)
__construct(int $a_obj_id=0)
static lookupAssignmentIds(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup assignments.
static treeExists(int $a_server_id, int $a_mid, int $a_tree_id)
static lookupObjId(int $a_server_id, int $a_mid, int $a_tree_id, string $cms_id)
static updateStatus(int $a_server_id, int $a_mid, int $a_tree_id)
static findDeletedNodes(int $a_server_id, int $a_mid, int $a_tree_id)
Find deleted nodes Uses a left join since this is more robust.
static lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
Lookup first obj_id of cms node.
static lookupStatusByObjId(int $a_server_id, int $a_mid, int $a_tree_id, int $obj_id)
Lookup status.
static lookupTopTerm(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup term (highest term in cms tree)
static writeAllStatus($a_server_id, $a_mid, $a_tree_id, $status)
Update status.
static lookupCmsIds(array $a_obj_ids)
static lookupTitle(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup title by obj id.
static lookupStatusByCmsId(int $a_server_id, int $a_mid, int $a_tree_id, string $cms_id)
Lookup status.
static lookupCmsId($a_obj_id)
Lookup cms id.
static writeStatus($a_server_id, $a_mid, $a_tree_id, $cms_ids, $status)
Update status.
const MAPPING_PENDING_NOT_DISCONNECTABLE
static deleteByServerId($a_server_id)