ILIAS  release_8 Revision v8.24
class.ilMDTaxonPath.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 private string $source = '';
30
31 // METHODS OF CHILD OBJECTS (Taxon)
32
36 public function getTaxonIds(): array
37 {
38 return ilMDTaxon::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_taxon_path');
39 }
40
41 public function getTaxon(int $a_taxon_id): ?ilMDTaxon
42 {
43 if (!$a_taxon_id) {
44 return null;
45 }
46 $tax = new ilMDTaxon();
47 $tax->setMetaId($a_taxon_id);
48
49 return $tax;
50 }
51
52 public function addTaxon(): ilMDTaxon
53 {
54 $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId(), $this->getObjType());
55 $tax->setParentId($this->getMetaId());
56 $tax->setParentType('meta_taxon_path');
57
58 return $tax;
59 }
60
61 // SET/GET
62 public function setSource(string $a_source): void
63 {
64 $this->source = $a_source;
65 }
66
67 public function getSource(): string
68 {
69 return $this->source;
70 }
71
72 public function setSourceLanguage(ilMDLanguageItem $lng_obj): void
73 {
74 $this->source_language = $lng_obj;
75 }
76
78 {
79 return is_object($this->source_language) ? $this->source_language : null;
80 }
81
82 public function getSourceLanguageCode(): string
83 {
84 return is_object($this->source_language) ? $this->source_language->getLanguageCode() : '';
85 }
86
87 public function save(): int
88 {
89 $fields = $this->__getFields();
90 $fields['meta_taxon_path_id'] = array('integer', $next_id = $this->db->nextId('il_meta_taxon_path'));
91
92 if ($this->db->insert('il_meta_taxon_path', $fields)) {
93 $this->setMetaId($next_id);
94 return $this->getMetaId();
95 }
96 return 0;
97 }
98
99 public function update(): bool
100 {
101 return $this->getMetaId() && $this->db->update(
102 'il_meta_taxon_path',
103 $this->__getFields(),
104 array("meta_taxon_path_id" => array('integer', $this->getMetaId()))
105 );
106 }
107
108 public function delete(): bool
109 {
110 if ($this->getMetaId()) {
111 $query = "DELETE FROM il_meta_taxon_path " .
112 "WHERE meta_taxon_path_id = " . $this->db->quote($this->getMetaId(), 'integer');
113 $res = $this->db->manipulate($query);
114
115 foreach ($this->getTaxonIds() as $id) {
116 $tax = $this->getTaxon($id);
117 $tax->delete();
118 }
119
120 return true;
121 }
122 return false;
123 }
124
128 public function __getFields(): array
129 {
130 return array(
131 'rbac_id' => array('integer', $this->getRBACId()),
132 'obj_id' => array('integer', $this->getObjId()),
133 'obj_type' => array('text', $this->getObjType()),
134 'parent_type' => array('text', $this->getParentType()),
135 'parent_id' => array('integer', $this->getParentId()),
136 'source' => array('text', $this->getSource()),
137 'source_language' => array('text', $this->getSourceLanguageCode())
138 );
139 }
140
141 public function read(): bool
142 {
143 if ($this->getMetaId()) {
144 $query = "SELECT * FROM il_meta_taxon_path " .
145 "WHERE meta_taxon_path_id = " . $this->db->quote($this->getMetaId(), 'integer');
146
147 $res = $this->db->query($query);
148 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
149 $this->setRBACId((int) $row->rbac_id);
150 $this->setObjId((int) $row->obj_id);
151 $this->setObjType($row->obj_type);
152 $this->setParentId((int) $row->parent_id);
153 $this->setParentType($row->parent_type);
154 $this->setSource($row->source ?? '');
155 $this->source_language = new ilMDLanguageItem($row->source_language ?? '');
156 }
157 }
158 return true;
159 }
160
161 public function toXML(ilXmlWriter $writer): void
162 {
163 $writer->xmlStartTag('TaxonPath');
164
165 $writer->xmlElement(
166 'Source',
167 array(
168 'Language' => $this->getSourceLanguageCode() ?: 'en'
169 ),
170 $this->getSource()
171 );
172
173 // Taxon
174 $taxs = $this->getTaxonIds();
175 foreach ($taxs as $id) {
176 $tax = $this->getTaxon($id);
177 $tax->toXML($writer);
178 }
179 if (!count($taxs)) {
180 $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId());
181 $tax->toXML($writer);
182 }
183
184 $writer->xmlEndTag('TaxonPath');
185 }
186
190 public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
191 {
192 global $DIC;
193
194 $ilDB = $DIC->database();
195
196 $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path " .
197 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
198 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
199 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
200 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
201
202 $res = $ilDB->query($query);
203 $ids = [];
204 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
205 $ids[] = (int) $row->meta_taxon_path_id;
206 }
207 return $ids;
208 }
209}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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 _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
toXML(ilXmlWriter $writer)
getTaxon(int $a_taxon_id)
ilMDLanguageItem $source_language
setSourceLanguage(ilMDLanguageItem $lng_obj)
setSource(string $a_source)
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)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query