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