ILIAS  release_8 Revision v8.24
class.ilMDClassification.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 private string $purpose = '';
29 private string $description = '';
31
32 // METHODS OF CLIENT OBJECTS (TaxonPath, Keyword)
33
37 public function getTaxonPathIds(): array
38 {
39 return ilMDTaxonPath::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_classification');
40 }
41
42 public function getTaxonPath(int $a_taxon_path_id): ?ilMDTaxonPath
43 {
44 if (!$a_taxon_path_id) {
45 return null;
46 }
47 $tax = new ilMDTaxonPath();
48 $tax->setMetaId($a_taxon_path_id);
49
50 return $tax;
51 }
52
53 public function addTaxonPath(): ilMDTaxonPath
54 {
55 $tax = new ilMDTaxonPath($this->getRBACId(), $this->getObjId(), $this->getObjType());
56 $tax->setParentId($this->getMetaId());
57 $tax->setParentType('meta_classification');
58
59 return $tax;
60 }
61
62 public function getKeywordIds(): ?array
63 {
64 return ilMDKeyword::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_classification');
65 }
66
67 public function getKeyword(int $a_keyword_id): ?ilMDKeyword
68 {
69 if (!$a_keyword_id) {
70 return null;
71 }
72 $key = new ilMDKeyword();
73 $key->setMetaId($a_keyword_id);
74
75 return $key;
76 }
77
78 public function addKeyword(): ilMDKeyword
79 {
80 $key = new ilMDKeyword($this->getRBACId(), $this->getObjId(), $this->getObjType());
81 $key->setParentId($this->getMetaId());
82 $key->setParentType('meta_classification');
83
84 return $key;
85 }
86
87 // SET/GET
88 public function setPurpose(string $a_purpose): bool
89 {
90 switch ($a_purpose) {
91 case 'Discipline':
92 case 'Idea':
93 case 'Prerequisite':
94 case 'EducationalObjective':
95 case 'AccessibilityRestrictions':
96 case 'EducationalLevel':
97 case 'SkillLevel':
98 case 'SecurityLevel':
99 case 'Competency':
100 $this->purpose = $a_purpose;
101 return true;
102
103 default:
104 return false;
105 }
106 }
107
108 public function getPurpose(): string
109 {
110 return $this->purpose;
111 }
112
113 public function setDescription(string $a_description): void
114 {
115 $this->description = $a_description;
116 }
117
118 public function getDescription(): string
119 {
120 return $this->description;
121 }
122
123 public function setDescriptionLanguage(ilMDLanguageItem $lng_obj): void
124 {
125 $this->description_language = $lng_obj;
126 }
127
129 {
130 return is_object($this->description_language) ? $this->description_language : null;
131 }
132
133 public function getDescriptionLanguageCode(): string
134 {
135 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : '';
136 }
137
138 public function save(): int
139 {
140 $fields = $this->__getFields();
141 $fields['meta_classification_id'] = array('integer', $next_id = $this->db->nextId('il_meta_classification'));
142
143 if ($this->db->insert('il_meta_classification', $fields)) {
144 $this->setMetaId($next_id);
145 return $this->getMetaId();
146 }
147 return 0;
148 }
149
150 public function update(): bool
151 {
152 return $this->getMetaId() && $this->db->update(
153 'il_meta_classification',
154 $this->__getFields(),
155 ["meta_classification_id" => ['integer', $this->getMetaId()]]
156 );
157 }
158
159 public function delete(): bool
160 {
161 if ($this->getMetaId()) {
162 $query = "DELETE FROM il_meta_classification " .
163 "WHERE meta_classification_id = " . $this->db->quote($this->getMetaId(), 'integer');
164 $res = $this->db->manipulate($query);
165
166 foreach ($this->getTaxonPathIds() as $id) {
167 $tax = $this->getTaxonPath($id);
168 $tax->delete();
169 }
170 foreach ($this->getKeywordIds() as $id) {
171 $key = $this->getKeyword($id);
172 $key->delete();
173 }
174
175 return true;
176 }
177 return false;
178 }
179
183 public function __getFields(): array
184 {
185 return array(
186 'rbac_id' => array('integer', $this->getRBACId()),
187 'obj_id' => array('integer', $this->getObjId()),
188 'obj_type' => array('text', $this->getObjType()),
189 'purpose' => array('text', $this->getPurpose()),
190 'description' => array('text', $this->getDescription()),
191 'description_language' => array('text', $this->getDescriptionLanguageCode())
192 );
193 }
194
195 public function read(): bool
196 {
197 if ($this->getMetaId()) {
198 $query = "SELECT * FROM il_meta_classification " .
199 "WHERE meta_classification_id = " . $this->db->quote($this->getMetaId(), 'integer');
200
201 $res = $this->db->query($query);
202 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
203 $this->setRBACId((int) $row->rbac_id);
204 $this->setObjId((int) $row->obj_id);
205 $this->setObjType($row->obj_type);
206 $this->setPurpose($row->purpose ?? '');
207 $this->setDescription($row->description ?? '');
208 $this->description_language = new ilMDLanguageItem($row->description_language ?? '');
209 }
210 }
211 return true;
212 }
213
214 public function toXML(ilXmlWriter $writer): void
215 {
216 $writer->xmlStartTag('Classification', array(
217 'Purpose' => $this->getPurpose() ?: 'Idea'
218 ));
219
220 // Taxon Path
221 $taxs = $this->getTaxonPathIds();
222 foreach ($taxs as $id) {
223 $tax = $this->getTaxonPath($id);
224 $tax->toXML($writer);
225 }
226 if (!count($taxs)) {
227 $tax = new ilMDTaxonPath($this->getRBACId(), $this->getObjId());
228 $tax->toXML($writer);
229 }
230
231 // Description
232 $writer->xmlElement(
233 'Description',
234 array(
235 'Language' => $this->getDescriptionLanguageCode() ?: 'en'
236 ),
237 $this->getDescription()
238 );
239
240 // Keyword
241 $keys = $this->getKeywordIds();
242 foreach ($keys as $id) {
243 $key = $this->getKeyword($id);
244 $key->toXML($writer);
245 }
246 if (!count($keys)) {
247 $key = new ilMDKeyword($this->getRBACId(), $this->getObjId());
248 $key->toXML($writer);
249 }
250 $writer->xmlEndTag('Classification');
251 }
252
253 // STATIC
254
258 public static function _getIds(int $a_rbac_id, int $a_obj_id): array
259 {
260 global $DIC;
261
262 $ilDB = $DIC['ilDB'];
263
264 $query = "SELECT meta_classification_id FROM il_meta_classification " .
265 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
266 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
267
268 $res = $ilDB->query($query);
269 $ids = [];
270 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
271 $ids[] = (int) $row->meta_classification_id;
272 }
273 return $ids;
274 }
275}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setObjType(string $a_type)
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
ilMDLanguageItem $description_language
toXML(ilXmlWriter $writer)
setDescriptionLanguage(ilMDLanguageItem $lng_obj)
static _getIds(int $a_rbac_id, int $a_obj_id)
setDescription(string $a_description)
getKeyword(int $a_keyword_id)
setPurpose(string $a_purpose)
getTaxonPath(int $a_taxon_path_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
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
$keys
Definition: metadata.php:204
string $key
Consumer key/client ID value.
Definition: System.php:193
$query