ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMDIdentifier.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 class ilMDIdentifier extends ilMDBase
28 {
29  private string $catalog = '';
30  private string $entry = '';
31 
32  // SET/GET
33  public function setCatalog(string $a_catalog): void
34  {
35  $this->catalog = $a_catalog;
36  }
37 
38  public function getCatalog(): string
39  {
40  return $this->catalog;
41  }
42 
43  public function setEntry(string $a_entry): void
44  {
45  $this->entry = $a_entry;
46  }
47 
48  public function getEntry(): string
49  {
50  return $this->entry;
51  }
52 
53  public function save(): int
54  {
55  $fields = $this->__getFields();
56  $fields['meta_identifier_id'] = array('integer', $next_id = $this->db->nextId('il_meta_identifier'));
57 
58  if ($this->db->insert('il_meta_identifier', $fields)) {
59  $this->setMetaId($next_id);
60  return $this->getMetaId();
61  }
62  return 0;
63  }
64 
65  public function update(): bool
66  {
67  return $this->getMetaId() && $this->db->update(
68  'il_meta_identifier',
69  $this->__getFields(),
70  array("meta_identifier_id" => array('integer', $this->getMetaId()))
71  );
72  }
73 
74  public function delete(): bool
75  {
76  if ($this->getMetaId()) {
77  $query = "DELETE FROM il_meta_identifier " .
78  "WHERE meta_identifier_id = " . $this->db->quote($this->getMetaId(), 'integer');
79  $res = $this->db->manipulate($query);
80  return true;
81  }
82  return false;
83  }
84 
88  public function __getFields(): array
89  {
90  return array(
91  'rbac_id' => array('integer', $this->getRBACId()),
92  'obj_id' => array('integer', $this->getObjId()),
93  'obj_type' => array('text', $this->getObjType()),
94  'parent_type' => array('text', $this->getParentType()),
95  'parent_id' => array('integer', $this->getParentId()),
96  'catalog' => array('text', $this->getCatalog()),
97  'entry' => array('text', $this->getEntry())
98  );
99  }
100 
101  public function read(): bool
102  {
103  if ($this->getMetaId()) {
104  $query = "SELECT * FROM il_meta_identifier " .
105  "WHERE meta_identifier_id = " . $this->db->quote($this->getMetaId(), 'integer');
106 
107  $res = $this->db->query($query);
108  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
109  $this->setRBACId((int) $row->rbac_id);
110  $this->setObjId((int) $row->obj_id);
111  $this->setObjType($row->obj_type ?? '');
112  $this->setParentId((int) $row->parent_id);
113  $this->setParentType($row->parent_type);
114  $this->setCatalog($row->catalog ?? '');
115  $this->setEntry($row->entry ?? '');
116  }
117  }
118  return true;
119  }
120 
121  public function toXML(ilXmlWriter $writer): void
122  {
123  $entry_default = ($this->getObjId() === 0)
124  ? "il_" . IL_INST_ID . "_" . $this->getObjType() . "_" . $this->getRBACId()
125  : "il_" . IL_INST_ID . "_" . $this->getObjType() . "_" . $this->getObjId();
126 
127  $entry = $this->getEntry() ?: $entry_default;
128  $catalog = $this->getCatalog();
129 
130  if ($this->getExportMode() && $this->getCatalog() !== "ILIAS_NID") {
131  $entry = $entry_default;
132  $catalog = "ILIAS";
133  }
134 
135  if ($catalog !== '') {
136  $writer->xmlElement('Identifier', array(
137  'Catalog' => $catalog,
138  'Entry' => $entry
139  ));
140  } else {
141  $writer->xmlElement('Identifier', array('Entry' => $entry));
142  }
143  }
144 
145  // STATIC
146 
150  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
151  {
152  global $DIC;
153 
154  $ilDB = $DIC->database();
155 
156  $query = "SELECT meta_identifier_id FROM il_meta_identifier " .
157  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
158  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
159  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
160  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
161 
162  $res = $ilDB->query($query);
163  $ids = [];
164  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
165  $ids[] = (int) $row->meta_identifier_id;
166  }
167  return $ids;
168  }
169 
173  public static function _getEntriesForObj(int $a_rbac_id, int $a_obj_id, string $a_obj_type): array
174  {
175  global $DIC;
176 
177  $ilDB = $DIC->database();
178 
179  $query = "SELECT meta_identifier_id, catalog, entry FROM il_meta_identifier " .
180  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
181  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
182  "AND obj_type = " . $ilDB->quote($a_obj_type, 'text');
183 
184  $res = $ilDB->query($query);
185  $entries = array();
186  while ($r = $ilDB->fetchAssoc($res)) {
187  $entries[$r["meta_identifier_id"]] =
188  array(
189  "catalog" => $r["catalog"],
190  "entry" => $r["entry"]
191  );
192  }
193  return $entries;
194  }
195 
199  public static function _getEntriesForRbacObj(int $a_rbac_id, string $a_obj_type = ""): array
200  {
201  global $DIC;
202 
203  $ilDB = $DIC->database();
204 
205  $query = "SELECT meta_identifier_id, catalog, entry, obj_id FROM il_meta_identifier " .
206  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer');
207 
208  if ($a_obj_type !== "") {
209  $query .=
210  " AND obj_type = " . $ilDB->quote($a_obj_type, 'text');
211  }
212 
213  $res = $ilDB->query($query);
214  $entries = array();
215  while ($r = $ilDB->fetchAssoc($res)) {
216  $entries[$r["meta_identifier_id"]] =
217  array(
218  "catalog" => $r["catalog"],
219  "entry" => $r["entry"],
220  "obj_id" => $r["obj_id"]
221  );
222  }
223  return $entries;
224  }
225 
226  public static function existsIdInRbacObject(
227  int $a_rbac_id,
228  string $a_obj_type,
229  string $a_catalog,
230  string $a_entry
231  ): bool {
232  global $DIC;
233 
234  $ilDB = $DIC->database();
235 
236  $query = "SELECT meta_identifier_id, obj_id FROM il_meta_identifier " .
237  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') .
238  " AND obj_type = " . $ilDB->quote($a_obj_type, 'text') .
239  " AND catalog = " . $ilDB->quote($a_catalog, 'text') .
240  " AND entry = " . $ilDB->quote($a_entry, 'text');
241  $s = $ilDB->query($query);
242  if ($r = $ilDB->fetchAssoc($s)) {
243  return true;
244  }
245  return false;
246  }
247 
251  public static function readIdData(int $a_rbac_id, string $a_obj_type, string $a_catalog, string $a_entry): array
252  {
253  global $DIC;
254 
255  $ilDB = $DIC->database();
256 
257  $query = "SELECT * FROM il_meta_identifier " .
258  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') .
259  " AND obj_type = " . $ilDB->quote($a_obj_type, 'text') .
260  " AND catalog = " . $ilDB->quote($a_catalog, 'text') .
261  " AND entry = " . $ilDB->quote($a_entry, 'text');
262  $s = $ilDB->query($query);
263  $data = array();
264  while ($r = $ilDB->fetchAssoc($s)) {
265  $data[] = $r;
266  }
267  return $data;
268  }
269 }
$res
Definition: ltiservices.php:66
static readIdData(int $a_rbac_id, string $a_obj_type, string $a_catalog, string $a_entry)
const IL_INST_ID
Definition: constants.php:40
static existsIdInRbacObject(int $a_rbac_id, string $a_obj_type, string $a_catalog, string $a_entry)
setRBACId(int $a_id)
toXML(ilXmlWriter $writer)
setObjId(int $a_id)
setEntry(string $a_entry)
static _getEntriesForObj(int $a_rbac_id, int $a_obj_id, string $a_obj_type)
global $DIC
Definition: shib_login.php:22
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
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)
static _getEntriesForRbacObj(int $a_rbac_id, string $a_obj_type="")
setObjType(string $a_type)
setCatalog(string $a_catalog)
$r