ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMDEntity.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
26 class ilMDEntity extends ilMDBase
27 {
28  private string $entity = '';
29 
30  // SET/GET
31  public function setEntity(string $a_entity): void
32  {
33  $this->entity = $a_entity;
34  }
35 
36  public function getEntity(): string
37  {
38  return $this->entity;
39  }
40 
41  public function save(): int
42  {
43  $fields = $this->__getFields();
44  $fields['meta_entity_id'] = array('integer', $next_id = $this->db->nextId('il_meta_entity'));
45 
46  if ($this->db->insert('il_meta_entity', $fields)) {
47  $this->setMetaId($next_id);
48  return $this->getMetaId();
49  }
50  return 0;
51  }
52 
53  public function update(): bool
54  {
55  return $this->getMetaId() && $this->db->update(
56  'il_meta_entity',
57  $this->__getFields(),
58  array("meta_entity_id" => array('integer', $this->getMetaId()))
59  );
60  }
61 
62  public function delete(): bool
63  {
64  if ($this->getMetaId()) {
65  $query = "DELETE FROM il_meta_entity " .
66  "WHERE meta_entity_id = " . $this->db->quote($this->getMetaId(), 'integer');
67  $res = $this->db->manipulate($query);
68 
69  $this->db->query($query);
70 
71  return true;
72  }
73  return false;
74  }
75 
79  public function __getFields(): array
80  {
81  return array(
82  'rbac_id' => array('integer', $this->getRBACId()),
83  'obj_id' => array('integer', $this->getObjId()),
84  'obj_type' => array('text', $this->getObjType()),
85  'parent_type' => array('text', $this->getParentType()),
86  'parent_id' => array('integer', $this->getParentId()),
87  'entity' => array('text', $this->getEntity())
88  );
89  }
90 
91  public function read(): bool
92  {
93  if ($this->getMetaId()) {
94  $query = "SELECT * FROM il_meta_entity " .
95  "WHERE meta_entity_id = " . $this->db->quote($this->getMetaId(), 'integer');
96 
97  $res = $this->db->query($query);
98  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
99  $this->setRBACId((int) $row->rbac_id);
100  $this->setObjId((int) $row->obj_id);
101  $this->setObjType($row->obj_type);
102  $this->setParentId((int) $row->parent_id);
103  $this->setParentType($row->parent_type);
104  $this->setEntity($row->entity ?? '');
105  }
106  }
107  return true;
108  }
109 
110  public function toXML(ilXmlWriter $writer): void
111  {
112  $writer->xmlElement('Entity', null, $this->getEntity());
113  }
114 
115  // STATIC
116 
120  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
121  {
122  global $DIC;
123 
124  $ilDB = $DIC->database();
125 
126  $query = "SELECT meta_entity_id FROM il_meta_entity " .
127  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
128  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
129  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
130  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
131  "ORDER BY meta_entity_id ";
132 
133  $res = $ilDB->query($query);
134  $ids = [];
135  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
136  $ids[] = (int) $row->meta_entity_id;
137  }
138  return $ids;
139  }
140 }
$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)
$query
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)