ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMDEntity.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 class ilMDEntity extends ilMDBase
28 {
29  private string $entity = '';
30 
31  // SET/GET
32  public function setEntity(string $a_entity): void
33  {
34  $this->entity = $a_entity;
35  }
36 
37  public function getEntity(): string
38  {
39  return $this->entity;
40  }
41 
42  public function save(): int
43  {
44  $fields = $this->__getFields();
45  $fields['meta_entity_id'] = array('integer', $next_id = $this->db->nextId('il_meta_entity'));
46 
47  if ($this->db->insert('il_meta_entity', $fields)) {
48  $this->setMetaId($next_id);
49  return $this->getMetaId();
50  }
51  return 0;
52  }
53 
54  public function update(): bool
55  {
56  return $this->getMetaId() && $this->db->update(
57  'il_meta_entity',
58  $this->__getFields(),
59  array("meta_entity_id" => array('integer', $this->getMetaId()))
60  );
61  }
62 
63  public function delete(): bool
64  {
65  if ($this->getMetaId()) {
66  $query = "DELETE FROM il_meta_entity " .
67  "WHERE meta_entity_id = " . $this->db->quote($this->getMetaId(), 'integer');
68  $res = $this->db->manipulate($query);
69 
70  $this->db->query($query);
71 
72  return true;
73  }
74  return false;
75  }
76 
80  public function __getFields(): array
81  {
82  return array(
83  'rbac_id' => array('integer', $this->getRBACId()),
84  'obj_id' => array('integer', $this->getObjId()),
85  'obj_type' => array('text', $this->getObjType()),
86  'parent_type' => array('text', $this->getParentType()),
87  'parent_id' => array('integer', $this->getParentId()),
88  'entity' => array('text', $this->getEntity())
89  );
90  }
91 
92  public function read(): bool
93  {
94  if ($this->getMetaId()) {
95  $query = "SELECT * FROM il_meta_entity " .
96  "WHERE meta_entity_id = " . $this->db->quote($this->getMetaId(), 'integer');
97 
98  $res = $this->db->query($query);
99  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
100  $this->setRBACId((int) $row->rbac_id);
101  $this->setObjId((int) $row->obj_id);
102  $this->setObjType($row->obj_type ?? '');
103  $this->setParentId((int) $row->parent_id);
104  $this->setParentType($row->parent_type ?? '');
105  $this->setEntity($row->entity ?? '');
106  }
107  }
108  return true;
109  }
110 
111  public function toXML(ilXmlWriter $writer): void
112  {
113  $writer->xmlElement('Entity', null, $this->getEntity());
114  }
115 
116  // STATIC
117 
121  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
122  {
123  global $DIC;
124 
125  $ilDB = $DIC->database();
126 
127  $query = "SELECT meta_entity_id FROM il_meta_entity " .
128  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
129  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
130  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
131  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
132  "ORDER BY meta_entity_id ";
133 
134  $res = $ilDB->query($query);
135  $ids = [];
136  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
137  $ids[] = (int) $row->meta_entity_id;
138  }
139  return $ids;
140  }
141 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRBACId(int $a_id)
global $DIC
Definition: feed.php:28
setObjId(int $a_id)
setEntity(string $a_entity)
setParentId(int $a_id)
setParentType(string $a_parent_type)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setObjType(string $a_type)
toXML(ilXmlWriter $writer)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)