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 $writer->xmlElement('Identifier_', array(
123 'Catalog' => $this->getCatalog(),
124 'Entry' => $this->getEntry() ?: "ID1"
125 ));
126 }
127
128 // STATIC
129
133 public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
134 {
135 global $DIC;
136
137 $ilDB = $DIC->database();
138
139 $query = "SELECT meta_identifier__id FROM il_meta_identifier_ " .
140 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
141 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
142 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
143 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
144
145 $res = $ilDB->query($query);
146 $ids = [];
147 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
148 $ids[] = (int) $row->meta_identifier__id;
149 }
150 return $ids;
151 }
152}
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)
toXML(ilXmlWriter $writer)
setEntry(string $a_entry)
setCatalog(string $a_catalog)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
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)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query