ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
12  const MAPPING_UNMAPPED = 1;
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;
25  private $status = self::MAPPING_UNMAPPED;
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 $ilDB;
37 
38  $query = 'SELECT COUNT(*) num FROM ecs_cms_data ' .
39  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
40  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
41  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer');
42 
43  $res = $ilDB->query($query);
44  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
45  return $row->num > 0 ? true : false;
46  }
47  return false;
48  }
49 
60  public static function findDeletedNodes($a_server_id, $a_mid, $a_tree_id)
61  {
62  global $ilDB;
63 
64  $query = 'SELECT ed.obj_id obj_id FROM ecs_cms_data ed ' .
65  'LEFT JOIN ecs_cms_tree et ON ed.obj_id = et.child ' .
66  'WHERE et.child IS NULL ' .
67  'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
68  'AND mid = ' . $ilDB->quote($a_mid) . ' ' .
69  'AND tree_id = ' . $ilDB->quote($a_tree_id);
70  $res = $ilDB->query($query);
71 
72  $deleted = array();
73  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
74  $deleted[] = $row->obj_id;
75  }
76  return $deleted;
77  }
78 
79  public static function lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
80  {
81  global $ilDB;
82 
83  $query = 'SELECT obj_id FROM ecs_cms_data ' .
84  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
85  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
86  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
87  'AND cms_id = ' . $ilDB->quote($cms_id, 'text');
88  $res = $ilDB->query($query);
89 
90  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $query);
91 
92  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
93  return $row->obj_id;
94  }
95  return 0;
96  }
97 
106  public static function lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
107  {
108  global $ilDB;
109 
110  $GLOBALS['ilLog']->write(__METHOD__ . ':ASDUASDUASDU ' . $a_server_id . ' ' . $a_mid . ' ' . $cms_id);
111 
112  $query = 'SELECT tree_id FROM ecs_cms_data ' .
113  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
114  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
115  'AND cms_id = ' . $ilDB->quote($cms_id, 'text') . ' ' .
116  'ORDER BY tree_id ';
117  $res = $ilDB->query($query);
118 
119  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
120  return $row->tree_id;
121  }
122  return 0;
123  }
124 
129  public static function lookupTitle($a_server_id, $a_mid, $a_tree_id)
130  {
131  global $ilDB;
132 
133  $query = 'SELECT * FROM ecs_cms_data ' .
134  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
135  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
136  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer');
137  $res = $ilDB->query($query);
138  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
139  return $row->title;
140  }
141  return '';
142  }
143 
151  public static function lookupTopTerm($a_server_id, $a_mid, $a_tree_id)
152  {
153  global $ilDB;
154 
155  $query = 'SELECT term FROM ecs_cms_data ' .
156  'JOIN ecs_cms_tree ON obj_id = child ' .
157  'WHERE tree = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
158  'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
159  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
160  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
161  'ORDER BY depth';
162  $res = $ilDB->query($query);
163  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
164  return $row->term;
165  }
166  return '';
167  }
168 
173  public static function lookupStatusByObjId($a_server_id, $a_mid, $a_tree_id, $obj_id)
174  {
175  global $ilDB;
176 
177  $query = 'SELECT status,deleted FROM ecs_cms_data ' .
178  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
179  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
180  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
181  'AND obj_id = ' . $ilDB->quote($obj_id, 'integer');
182  $res = $ilDB->query($query);
183  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
184  if ($row->deleted) {
185  return self::MAPPING_DELETED;
186  }
187  return $row->status;
188  }
189  return self::MAPPING_UNMAPPED;
190  }
191 
196  public static function lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $cms_id)
197  {
198  global $ilDB;
199 
200  $query = 'SELECT status FROM ecs_cms_data ' .
201  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
202  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
203  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
204  'AND cms_id = ' . $ilDB->quote($cms_id, 'text');
205  $res = $ilDB->query($query);
206  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
207  return $row->status;
208  }
209  return self::MAPPING_UNMAPPED;
210  }
211 
212  public static function updateStatus($a_server_id, $a_mid, $a_tree_id)
213  {
214  // Set all status to pending unmapped
215  self::writeAllStatus($a_server_id, $a_mid, $a_tree_id, self::MAPPING_UNMAPPED);
216 
217  // Set mapped for mapped and their descendent
218  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
219  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
220  foreach (ilECSNodeMappingAssignments::lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id) as $assignment) {
221  $cmsTree = new ilECSCmsTree($a_tree_id);
222  $subIds = self::lookupCmsIds(array_merge($cmsTree->getSubTreeIds($assignment), array($assignment)));
223 
224  self::writeStatus(
225  $a_server_id,
226  $a_mid,
227  $a_tree_id,
228  $subIds,
229  self::MAPPING_MAPPED
230  );
231  }
232  }
233 
238  public static function lookupCmsId($a_obj_id)
239  {
240  $cms_ids = self::lookupCmsIds(array($a_obj_id));
241  return $cms_ids[0];
242  }
243 
244 
245  public static function lookupCmsIds($a_obj_ids)
246  {
247  global $ilDB;
248 
249  $query = 'SELECT cms_id FROM ecs_cms_data ' .
250  'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer');
251  $res = $ilDB->query($query);
252 
253  $cms_ids = array();
254  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
255  $cms_ids[] = $row->cms_id;
256  }
257  return $cms_ids;
258  }
259 
267  public static function lookupCmsIdsOfTree($a_server_id, $a_mid, $a_tree_id)
268  {
269  global $ilDB;
270 
271  $query = 'SELECT cms_id FROM ecs_cms_data ' .
272  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
273  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
274  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer');
275  $res = $ilDB->query($query);
276  $cms_ids = array();
277  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
278  $cms_ids[] = $row->cms_id;
279  }
280  return $cms_ids;
281  }
282 
293  public static function writeStatus($a_server_id, $a_mid, $a_tree_id, $cms_ids, $status)
294  {
295  global $ilDB;
296 
297  $query = 'UPDATE ecs_cms_data ' .
298  'SET status = ' . $ilDB->quote($status, 'integer') . ' ' .
299  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
300  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
301  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
302  'AND ' . $ilDB->in('cms_id', $cms_ids, false, 'text');
303  $ilDB->manipulate($query);
304  return true;
305  }
306 
317  public static function writeAllStatus($a_server_id, $a_mid, $a_tree_id, $status)
318  {
319  global $ilDB;
320 
321  $query = 'UPDATE ecs_cms_data ' .
322  'SET status = ' . $ilDB->quote($status, 'integer') . ' ' .
323  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
324  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
325  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
326  $ilDB->manipulate($query);
327  return true;
328  }
329 
337  public static function writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag)
338  {
339  global $ilDB;
340 
341  $query = 'UPDATE ecs_cms_data ' .
342  'SET deleted = ' . $ilDB->quote($a_deleted_flag, 'integer') . ' ' .
343  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
344  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
345  'AND tree_id = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
346  $ilDB->manipulate($query);
347  return true;
348  }
349 
350  public static function lookupTreeIds($a_server_id, $a_mid)
351  {
352  global $ilDB;
353 
354  $query = 'SELECT DISTINCT(tree_id) tid FROM ecs_cms_data ' .
355  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
356  'AND mid = ' . $ilDB->quote($a_mid, 'integer');
357  $res = $ilDB->query($query);
358 
359  $tree_ids = array();
360  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
361  $tree_ids[] = $row->tid;
362  }
363  return (array) $tree_ids;
364  }
365 
366 
367  public function setTitle($a_title)
368  {
369  $this->title = $a_title;
370  }
371 
372  public function getTitle()
373  {
374  return $this->title;
375  }
376 
377  public function setTerm($a_term)
378  {
379  $this->term = $a_term;
380  }
381 
382  public function getTerm()
383  {
384  return $this->term;
385  }
386 
387  public function setObjId($a_id)
388  {
389  $this->obj_id = $a_id;
390  }
391 
392  public function getObjId()
393  {
394  return $this->obj_id;
395  }
396 
397  public function setCmsId($a_id)
398  {
399  $this->cms_id = $a_id;
400  }
401 
402  public function getCmsId()
403  {
404  return $this->cms_id;
405  }
406 
407  public function setServerId($a_id)
408  {
409  $this->server_id = $a_id;
410  }
411 
412  public function getServerId()
413  {
414  return $this->server_id;
415  }
416 
417  public function setTreeId($a_id)
418  {
419  $this->tree_id = $a_id;
420  }
421 
422  public function getTreeId()
423  {
424  return $this->tree_id;
425  }
426 
427  public function setMid($a_id)
428  {
429  $this->mid = $a_id;
430  }
431 
432  public function getMid()
433  {
434  return $this->mid;
435  }
436 
437  public function setStatus($a_status)
438  {
439  $this->status = $a_status;
440  }
441 
442  public function getStatus()
443  {
444  return $this->status;
445  }
446 
447  public function setDeleted($a_is_deleted)
448  {
449  $this->deleted = $a_is_deleted;
450  }
451 
452  public function isDeleted()
453  {
454  return $this->deleted;
455  }
456 
457 
458  public function save()
459  {
460  global $ilDB;
461 
462  $this->obj_id = $ilDB->nextId('ecs_cms_data');
463 
464  $query = 'INSERT INTO ecs_cms_data (obj_id,server_id,mid,tree_id,cms_id,title,term,status,deleted) ' .
465  'VALUES ( ' .
466  $ilDB->quote($this->obj_id, 'integer') . ', ' .
467  $ilDB->quote($this->server_id, 'integer') . ', ' .
468  $ilDB->quote($this->mid, 'integer') . ', ' .
469  $ilDB->quote($this->tree_id, 'integer') . ', ' .
470  $ilDB->quote($this->cms_id, 'text') . ', ' .
471  $ilDB->quote($this->title, 'text') . ', ' .
472  $ilDB->quote($this->term, 'text') . ', ' .
473  $ilDB->quote($this->status, 'integer') . ', ' .
474  $ilDB->quote($this->deleted, 'integer') . ' ' .
475  ')';
476  $ilDB->manipulate($query);
477  return true;
478  }
479 
480  public function update()
481  {
482  global $ilDB;
483 
484  $query = "UPDATE ecs_cms_data SET " .
485  'title = ' . $ilDB->quote($this->title, 'text') . ', ' .
486  'term = ' . $ilDB->quote($this->term, 'text') . ', ' .
487  'status = ' . $ilDB->quote($this->status, 'text') . ', ' .
488  'deleted = ' . $ilDB->quote($this->isDeleted(), 'integer') . ' ' .
489  'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
490  $ilDB->manipulate($query);
491  }
492 
493  public function delete()
494  {
495  global $ilDB;
496 
497  $query = "DELETE FROM ecs_cms_data " .
498  'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
499  $ilDB->manipulate($query);
500  }
501 
502  public function deleteTree()
503  {
504  global $ilDB;
505 
506  $query = "DELETE FROM ecs_cms_data " .
507  'WHERE server_id = ' . $ilDB->quote($this->server_id, 'integer') . ' ' .
508  'AND mid = ' . $ilDB->quote($this->mid, 'integer') . ' ' .
509  'AND tree_id = ' . $ilDB->quote($this->tree_id, 'integer') . ' ';
510  $ilDB->manipulate($query);
511  }
512 
513  public static function deleteByServerId($a_server_id)
514  {
515  global $ilDB;
516 
517  $query = "DELETE FROM ecs_cms_data " .
518  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
519  $ilDB->manipulate($query);
520  }
521 
522  protected function read()
523  {
524  global $ilDB;
525 
526  $query = 'SELECT * FROM ecs_cms_data ' .
527  'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
528  $res = $ilDB->query($query);
529  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
530  $this->title = $row->title;
531  $this->term = $row->term;
532  $this->server_id = $row->server_id;
533  $this->mid = $row->mid;
534  $this->tree_id = $row->tree_id;
535  $this->cms_id = $row->cms_id;
536  $this->status = $row->status;
537  $this->deleted = $row->deleted;
538  }
539  }
540 }
static lookupCmsIdsOfTree($a_server_id, $a_mid, $a_tree_id)
$ilDB $ilDB
const MAPPING_PENDING_DISCONNECTABLE
static writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag)
Write deleted status.
static updateStatus($a_server_id, $a_mid, $a_tree_id)
setDeleted($a_is_deleted)
static treeExists($a_server_id, $a_mid, $a_tree_id)
__construct($a_obj_id=0)
static lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
static lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $cms_id)
Lookup status.
static lookupTitle($a_server_id, $a_mid, $a_tree_id)
Lookup title by obj id.
static lookupStatusByObjId($a_server_id, $a_mid, $a_tree_id, $obj_id)
Lookup status.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
Lookup first obj_id of cms node $ilDB $ilDB.
foreach($_POST as $key=> $value) $res
static lookupTopTerm($a_server_id, $a_mid, $a_tree_id)
Lookup term (highest term in cms tree) <type> $ilDB.
static writeAllStatus($a_server_id, $a_mid, $a_tree_id, $status)
Update status $ilDB.
static lookupCmsIds($a_obj_ids)
$query
setStatus($a_status)
Create styles array
The data for the language used.
static lookupCmsId($a_obj_id)
Lookup cms id.
static findDeletedNodes($a_server_id, $a_mid, $a_tree_id)
Find deleted nodes Uses a left join since this is more robust.
global $ilDB
static writeStatus($a_server_id, $a_mid, $a_tree_id, $cms_ids, $status)
Update status $ilDB.
static lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
Lookup assignments $ilDB.
static lookupTreeIds($a_server_id, $a_mid)
const MAPPING_PENDING_NOT_DISCONNECTABLE
static deleteByServerId($a_server_id)