ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilECSCmsData.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
15 const MAPPING_MAPPED = 4;
16 const MAPPING_DELETED = 5;
17
18 private $obj_id;
19 private $server_id;
20 private $mid;
21 private $tree_id;
22 private $cms_id;
23 private $title;
24 private $term;
26 private $deleted = false;
27
28 public function __construct($a_obj_id = 0)
29 {
30 $this->obj_id = $a_obj_id;
31 $this->read();
32 }
33
34 public static function treeExists($a_server_id, $a_mid, $a_tree_id)
35 {
36 global $DIC;
37
38 $ilDB = $DIC['ilDB'];
39
40 $query = 'SELECT COUNT(*) num FROM ecs_cms_data ' .
41 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
42 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
43 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer');
44
45 $res = $ilDB->query($query);
46 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
47 return $row->num > 0 ? true : false;
48 }
49 return false;
50 }
51
62 public static function findDeletedNodes($a_server_id, $a_mid, $a_tree_id)
63 {
64 global $DIC;
65
66 $ilDB = $DIC['ilDB'];
67
68 $query = 'SELECT ed.obj_id obj_id FROM ecs_cms_data ed ' .
69 'LEFT JOIN ecs_cms_tree et ON ed.obj_id = et.child ' .
70 'WHERE et.child IS NULL ' .
71 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
72 'AND mid = ' . $ilDB->quote($a_mid) . ' ' .
73 'AND tree_id = ' . $ilDB->quote($a_tree_id);
74 $res = $ilDB->query($query);
75
76 $deleted = array();
77 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
78 $deleted[] = $row->obj_id;
79 }
80 return $deleted;
81 }
82
83 public static function lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
84 {
85 global $DIC;
86
87 $ilDB = $DIC['ilDB'];
88
89 $query = 'SELECT obj_id FROM ecs_cms_data ' .
90 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
91 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
92 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
93 'AND cms_id = ' . $ilDB->quote($cms_id, 'text');
94 $res = $ilDB->query($query);
95
96 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': ' . $query);
97
98 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
99 return $row->obj_id;
100 }
101 return 0;
102 }
103
112 public static function lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
113 {
114 global $DIC;
115
116 $ilDB = $DIC['ilDB'];
117
118 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ':ASDUASDUASDU ' . $a_server_id . ' ' . $a_mid . ' ' . $cms_id);
119
120 $query = 'SELECT tree_id FROM ecs_cms_data ' .
121 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
122 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
123 'AND cms_id = ' . $ilDB->quote($cms_id, 'text') . ' ' .
124 'ORDER BY tree_id ';
125 $res = $ilDB->query($query);
126
127 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
128 return $row->tree_id;
129 }
130 return 0;
131 }
132
137 public static function lookupTitle($a_server_id, $a_mid, $a_tree_id)
138 {
139 global $DIC;
140
141 $ilDB = $DIC['ilDB'];
142
143 $query = 'SELECT * FROM ecs_cms_data ' .
144 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
145 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
146 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer');
147 $res = $ilDB->query($query);
148 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
149 return $row->title;
150 }
151 return '';
152 }
153
161 public static function lookupTopTerm($a_server_id, $a_mid, $a_tree_id)
162 {
163 global $DIC;
164
165 $ilDB = $DIC['ilDB'];
166
167 $query = 'SELECT term FROM ecs_cms_data ' .
168 'JOIN ecs_cms_tree ON obj_id = child ' .
169 'WHERE tree = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
170 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
171 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
172 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
173 'ORDER BY depth';
174 $res = $ilDB->query($query);
175 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
176 return $row->term;
177 }
178 return '';
179 }
180
185 public static function lookupStatusByObjId($a_server_id, $a_mid, $a_tree_id, $obj_id)
186 {
187 global $DIC;
188
189 $ilDB = $DIC['ilDB'];
190
191 $query = 'SELECT status,deleted FROM ecs_cms_data ' .
192 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
193 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
194 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
195 'AND obj_id = ' . $ilDB->quote($obj_id, 'integer');
196 $res = $ilDB->query($query);
197 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
198 if ($row->deleted) {
200 }
201 return $row->status;
202 }
204 }
205
210 public static function lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $cms_id)
211 {
212 global $DIC;
213
214 $ilDB = $DIC['ilDB'];
215
216 $query = 'SELECT status FROM ecs_cms_data ' .
217 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
218 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
219 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
220 'AND cms_id = ' . $ilDB->quote($cms_id, 'text');
221 $res = $ilDB->query($query);
222 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
223 return $row->status;
224 }
226 }
227
228 public static function updateStatus($a_server_id, $a_mid, $a_tree_id)
229 {
230 // Set all status to pending unmapped
231 self::writeAllStatus($a_server_id, $a_mid, $a_tree_id, self::MAPPING_UNMAPPED);
232
233 // Set mapped for mapped and their descendent
234 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
235 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
236 foreach (ilECSNodeMappingAssignments::lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id) as $assignment) {
237 $cmsTree = new ilECSCmsTree($a_tree_id);
238 $subIds = self::lookupCmsIds(array_merge($cmsTree->getSubTreeIds($assignment), array($assignment)));
239
241 $a_server_id,
242 $a_mid,
243 $a_tree_id,
244 $subIds,
245 self::MAPPING_MAPPED
246 );
247 }
248 }
249
254 public static function lookupCmsId($a_obj_id)
255 {
256 $cms_ids = self::lookupCmsIds(array($a_obj_id));
257 return $cms_ids[0];
258 }
259
260
261 public static function lookupCmsIds($a_obj_ids)
262 {
263 global $DIC;
264
265 $ilDB = $DIC['ilDB'];
266
267 $query = 'SELECT cms_id FROM ecs_cms_data ' .
268 'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer');
269 $res = $ilDB->query($query);
270
271 $cms_ids = array();
272 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
273 $cms_ids[] = $row->cms_id;
274 }
275 return $cms_ids;
276 }
277
285 public static function lookupCmsIdsOfTree($a_server_id, $a_mid, $a_tree_id)
286 {
287 global $DIC;
288
289 $ilDB = $DIC['ilDB'];
290
291 $query = 'SELECT cms_id FROM ecs_cms_data ' .
292 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
293 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
294 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer');
295 $res = $ilDB->query($query);
296 $cms_ids = array();
297 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
298 $cms_ids[] = $row->cms_id;
299 }
300 return $cms_ids;
301 }
302
313 public static function writeStatus($a_server_id, $a_mid, $a_tree_id, $cms_ids, $status)
314 {
315 global $DIC;
316
317 $ilDB = $DIC['ilDB'];
318
319 $query = 'UPDATE ecs_cms_data ' .
320 'SET status = ' . $ilDB->quote($status, 'integer') . ' ' .
321 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
322 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
323 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
324 'AND ' . $ilDB->in('cms_id', $cms_ids, false, 'text');
325 $ilDB->manipulate($query);
326 return true;
327 }
328
339 public static function writeAllStatus($a_server_id, $a_mid, $a_tree_id, $status)
340 {
341 global $DIC;
342
343 $ilDB = $DIC['ilDB'];
344
345 $query = 'UPDATE ecs_cms_data ' .
346 'SET status = ' . $ilDB->quote($status, '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') . ' ';
350 $ilDB->manipulate($query);
351 return true;
352 }
353
361 public static function writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag)
362 {
363 global $DIC;
364
365 $ilDB = $DIC['ilDB'];
366
367 $query = 'UPDATE ecs_cms_data ' .
368 'SET deleted = ' . $ilDB->quote($a_deleted_flag, 'integer') . ' ' .
369 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
370 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
371 'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
372 $ilDB->manipulate($query);
373 return true;
374 }
375
376 public static function lookupTreeIds($a_server_id, $a_mid)
377 {
378 global $DIC;
379
380 $ilDB = $DIC['ilDB'];
381
382 $query = 'SELECT DISTINCT(tree_id) tid FROM ecs_cms_data ' .
383 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
384 'AND mid = ' . $ilDB->quote($a_mid, 'integer');
385 $res = $ilDB->query($query);
386
387 $tree_ids = array();
388 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
389 $tree_ids[] = $row->tid;
390 }
391 return (array) $tree_ids;
392 }
393
394
395 public function setTitle($a_title)
396 {
397 $this->title = $a_title;
398 }
399
400 public function getTitle()
401 {
402 return $this->title;
403 }
404
405 public function setTerm($a_term)
406 {
407 $this->term = $a_term;
408 }
409
410 public function getTerm()
411 {
412 return $this->term;
413 }
414
415 public function setObjId($a_id)
416 {
417 $this->obj_id = $a_id;
418 }
419
420 public function getObjId()
421 {
422 return $this->obj_id;
423 }
424
425 public function setCmsId($a_id)
426 {
427 $this->cms_id = $a_id;
428 }
429
430 public function getCmsId()
431 {
432 return $this->cms_id;
433 }
434
435 public function setServerId($a_id)
436 {
437 $this->server_id = $a_id;
438 }
439
440 public function getServerId()
441 {
442 return $this->server_id;
443 }
444
445 public function setTreeId($a_id)
446 {
447 $this->tree_id = $a_id;
448 }
449
450 public function getTreeId()
451 {
452 return $this->tree_id;
453 }
454
455 public function setMid($a_id)
456 {
457 $this->mid = $a_id;
458 }
459
460 public function getMid()
461 {
462 return $this->mid;
463 }
464
465 public function setStatus($a_status)
466 {
467 $this->status = $a_status;
468 }
469
470 public function getStatus()
471 {
472 return $this->status;
473 }
474
475 public function setDeleted($a_is_deleted)
476 {
477 $this->deleted = $a_is_deleted;
478 }
479
480 public function isDeleted()
481 {
482 return $this->deleted;
483 }
484
485
486 public function save()
487 {
488 global $DIC;
489
490 $ilDB = $DIC['ilDB'];
491
492 $this->obj_id = $ilDB->nextId('ecs_cms_data');
493
494 $query = 'INSERT INTO ecs_cms_data (obj_id,server_id,mid,tree_id,cms_id,title,term,status,deleted) ' .
495 'VALUES ( ' .
496 $ilDB->quote($this->obj_id, 'integer') . ', ' .
497 $ilDB->quote($this->server_id, 'integer') . ', ' .
498 $ilDB->quote($this->mid, 'integer') . ', ' .
499 $ilDB->quote($this->tree_id, 'integer') . ', ' .
500 $ilDB->quote($this->cms_id, 'text') . ', ' .
501 $ilDB->quote($this->title, 'text') . ', ' .
502 $ilDB->quote($this->term, 'text') . ', ' .
503 $ilDB->quote($this->status, 'integer') . ', ' .
504 $ilDB->quote($this->deleted, 'integer') . ' ' .
505 ')';
506 $ilDB->manipulate($query);
507 return true;
508 }
509
510 public function update()
511 {
512 global $DIC;
513
514 $ilDB = $DIC['ilDB'];
515
516 $query = "UPDATE ecs_cms_data SET " .
517 'title = ' . $ilDB->quote($this->title, 'text') . ', ' .
518 'term = ' . $ilDB->quote($this->term, 'text') . ', ' .
519 'status = ' . $ilDB->quote($this->status, 'text') . ', ' .
520 'deleted = ' . $ilDB->quote($this->isDeleted(), 'integer') . ' ' .
521 'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
522 $ilDB->manipulate($query);
523 }
524
525 public function delete()
526 {
527 global $DIC;
528
529 $ilDB = $DIC['ilDB'];
530
531 $query = "DELETE FROM ecs_cms_data " .
532 'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
533 $ilDB->manipulate($query);
534 }
535
536 public function deleteTree()
537 {
538 global $DIC;
539
540 $ilDB = $DIC['ilDB'];
541
542 $query = "DELETE FROM ecs_cms_data " .
543 'WHERE server_id = ' . $ilDB->quote($this->server_id, 'integer') . ' ' .
544 'AND mid = ' . $ilDB->quote($this->mid, 'integer') . ' ' .
545 'AND tree_id = ' . $ilDB->quote($this->tree_id, 'integer') . ' ';
546 $ilDB->manipulate($query);
547 }
548
549 public static function deleteByServerId($a_server_id)
550 {
551 global $DIC;
552
553 $ilDB = $DIC['ilDB'];
554
555 $query = "DELETE FROM ecs_cms_data " .
556 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
557 $ilDB->manipulate($query);
558 }
559
560 protected function read()
561 {
562 global $DIC;
563
564 $ilDB = $DIC['ilDB'];
565
566 $query = 'SELECT * FROM ecs_cms_data ' .
567 'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
568 $res = $ilDB->query($query);
569 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
570 $this->title = $row->title;
571 $this->term = $row->term;
572 $this->server_id = $row->server_id;
573 $this->mid = $row->mid;
574 $this->tree_id = $row->tree_id;
575 $this->cms_id = $row->cms_id;
576 $this->status = $row->status;
577 $this->deleted = $row->deleted;
578 }
579 }
580}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
const MAPPING_PENDING_DISCONNECTABLE
static lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
static writeAllStatus($a_server_id, $a_mid, $a_tree_id, $status)
Update status @global $ilDB.
static updateStatus($a_server_id, $a_mid, $a_tree_id)
const MAPPING_PENDING_NOT_DISCONNECTABLE
static lookupCmsIds($a_obj_ids)
static treeExists($a_server_id, $a_mid, $a_tree_id)
static lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $cms_id)
Lookup status.
static findDeletedNodes($a_server_id, $a_mid, $a_tree_id)
Find deleted nodes Uses a left join since this is more robust.
static lookupTopTerm($a_server_id, $a_mid, $a_tree_id)
Lookup term (highest term in cms tree) @global <type> $ilDB.
__construct($a_obj_id=0)
static writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag)
Write deleted status.
static writeStatus($a_server_id, $a_mid, $a_tree_id, $cms_ids, $status)
Update status @global $ilDB.
setDeleted($a_is_deleted)
static lookupCmsId($a_obj_id)
Lookup cms id.
static lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
Lookup first obj_id of cms node @global $ilDB $ilDB.
static lookupStatusByObjId($a_server_id, $a_mid, $a_tree_id, $obj_id)
Lookup status.
static lookupTreeIds($a_server_id, $a_mid)
static lookupCmsIdsOfTree($a_server_id, $a_mid, $a_tree_id)
@global $ilDB $ilDB
static lookupTitle($a_server_id, $a_mid, $a_tree_id)
Lookup title by obj id.
static deleteByServerId($a_server_id)
setStatus($a_status)
static lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
Lookup assignments @global $ilDB.
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB