ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilECSCmsTree.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
23 class ilECSCmsTree extends ilTree
24 {
25  public function __construct(int $a_tree_id)
26  {
27  parent::__construct($a_tree_id, self::lookupRootId($a_tree_id));
28 
29  $this->setObjectTablePK('obj_id');
30  $this->setTableNames('ecs_cms_tree', 'ecs_cms_data');
31  $this->useCache(false);
32  }
33 
34  public function insertRootNode(int $tree, int $a_child): bool
35  {
36  $query = 'INSERT INTO ecs_cms_tree ' .
37  '(tree,child,parent,lft,rgt,depth) ' .
38  'VALUES ( ' .
39  $this->db->quote($tree, 'integer') . ', ' .
40  $this->db->quote($a_child, 'integer') . ', ' .
41  $this->db->quote(0, 'integer') . ', ' .
42  $this->db->quote(1, 'integer') . ', ' .
43  $this->db->quote(100, 'integer') . ', ' .
44  $this->db->quote(1, 'integer') . ' )';
45 
46  $this->db->manipulate($query);
47 
48  return true;
49  }
50 
54  public static function deleteByTreeId(int $a_tree_id): bool
55  {
56  global $DIC;
57 
58  $ilDB = $DIC['ilDB'];
59 
60  $DIC->logger()->wsrv()->debug('Deleting cms tree: ' . $a_tree_id);
61  $query = 'DELETE FROM ecs_cms_tree ' .
62  'WHERE tree = ' . $ilDB->quote($a_tree_id, 'integer');
63  $ilDB->manipulate($query);
64  return true;
65  }
66 
70  public function treeExists(int $a_tree_id): bool
71  {
72  $query = 'SELECT COUNT(*) num FROM ecs_cms_tree WHERE tree = ' . $this->db->quote($a_tree_id, 'integer');
73  $res = $this->db->query($query);
74  if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
75  return $row->num > 0;
76  }
77  return false;
78  }
79 
80 
84  public static function lookupRootId($a_tree_id): int
85  {
86  global $DIC;
87 
88  $ilDB = $DIC['ilDB'];
89 
90  $query = 'SELECT child FROM ecs_cms_tree WHERE tree = ' . $ilDB->quote($a_tree_id, 'integer');
91  $res = $ilDB->query($query);
92  if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
93  return (int) $row->child;
94  }
95  return 0;
96  }
97 }
$res
Definition: ltiservices.php:69
setObjectTablePK(string $a_column_name)
set column containing primary key in object table
static lookupRootId($a_tree_id)
lookup root id
useCache(bool $a_use=true)
Use Cache (usually activated)
treeExists(int $a_tree_id)
Check if tree exists.
global $DIC
Definition: feed.php:28
setTableNames(string $a_table_tree, string $a_table_obj_data, string $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be &#39;obj_id&#39; You may use...
$query
static deleteByTreeId(int $a_tree_id)
Delete tree by tree_id.
__construct(Container $dic, ilPlugin $plugin)
insertRootNode(int $tree, int $a_child)
__construct(int $a_tree_id)