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