ILIAS  release_8 Revision v8.24
class.ilMD.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27class ilMD extends ilMDBase
28{
29 public function read(): bool
30 {
31 return true;
32 }
33
34 public function getGeneral(): ?ilMDGeneral
35 {
36 if ($id = ilMDGeneral::_getId($this->getRBACId(), $this->getObjId())) {
37 $gen = new ilMDGeneral();
38 $gen->setMetaId($id);
39 return $gen;
40 }
41 return null;
42 }
43
44 public function addGeneral(): ?ilMDGeneral
45 {
46 $gen = new ilMDGeneral($this->getRBACId(), $this->getObjId(), $this->getObjType());
47
48 return $gen;
49 }
50
51 public function getLifecycle(): ?ilMDLifecycle
52 {
53 if ($id = ilMDLifecycle::_getId($this->getRBACId(), $this->getObjId())) {
54 $lif = new ilMDLifecycle();
55 $lif->setMetaId($id);
56
57 return $lif;
58 }
59 return null;
60 }
61
62 public function addLifecycle(): ilMDLifecycle
63 {
64 $lif = new ilMDLifecycle($this->getRBACId(), $this->getObjId(), $this->getObjType());
65
66 return $lif;
67 }
68
70 {
71 if ($id = ilMDMetaMetadata::_getId($this->getRBACId(), $this->getObjId())) {
72 $met = new ilMDMetaMetadata();
73 $met->setMetaId($id);
74
75 return $met;
76 }
77 return null;
78 }
79
81 {
82 $met = new ilMDMetaMetadata($this->getRBACId(), $this->getObjId(), $this->getObjType());
83
84 return $met;
85 }
86
87 public function getTechnical(): ?ilMDTechnical
88 {
89 if ($id = ilMDTechnical::_getId($this->getRBACId(), $this->getObjId())) {
90 $tec = new ilMDTechnical();
91 $tec->setMetaId($id);
92
93 return $tec;
94 }
95 return null;
96 }
97
98 public function addTechnical(): ilMDTechnical
99 {
100 $tec = new ilMDTechnical($this->getRBACId(), $this->getObjId(), $this->getObjType());
101
102 return $tec;
103 }
104
105 public function getEducational(): ?ilMDEducational
106 {
107 if ($id = ilMDEducational::_getId($this->getRBACId(), $this->getObjId())) {
108 $edu = new ilMDEducational();
109 $edu->setMetaId($id);
110
111 return $edu;
112 }
113 return null;
114 }
115
117 {
118 $edu = new ilMDEducational($this->getRBACId(), $this->getObjId(), $this->getObjType());
119
120 return $edu;
121 }
122
123 public function getRights(): ?ilMDRights
124 {
125 if ($id = ilMDRights::_getId($this->getRBACId(), $this->getObjId())) {
126 $rig = new ilMDRights();
127 $rig->setMetaId($id);
128
129 return $rig;
130 }
131 return null;
132 }
133
134 public function addRights(): ilMDRights
135 {
136 $rig = new ilMDRights($this->getRBACId(), $this->getObjId(), $this->getObjType());
137
138 return $rig;
139 }
140
144 public function getRelationIds(): array
145 {
146 return ilMDRelation::_getIds($this->getRBACId(), $this->getObjId());
147 }
148
149 public function getRelation(int $a_relation_id): ?ilMDRelation
150 {
151 if (!$a_relation_id) {
152 return null;
153 }
154
155 $rel = new ilMDRelation();
156 $rel->setMetaId($a_relation_id);
157
158 return $rel;
159 }
160
161 public function addRelation(): ilMDRelation
162 {
163 $rel = new ilMDRelation($this->getRBACId(), $this->getObjId(), $this->getObjType());
164
165 return $rel;
166 }
167
171 public function getAnnotationIds(): array
172 {
173 return ilMDAnnotation::_getIds($this->getRBACId(), $this->getObjId());
174 }
175
176 public function getAnnotation(int $a_annotation_id): ?ilMDAnnotation
177 {
178 if (!$a_annotation_id) {
179 return null;
180 }
181
182 $ann = new ilMDAnnotation();
183 $ann->setMetaId($a_annotation_id);
184
185 return $ann;
186 }
187
188 public function addAnnotation(): ilMDAnnotation
189 {
190 $ann = new ilMDAnnotation($this->getRBACId(), $this->getObjId(), $this->getObjType());
191
192 return $ann;
193 }
194
198 public function getClassificationIds(): array
199 {
200 return ilMDClassification::_getIds($this->getRBACId(), $this->getObjId());
201 }
202
203 public function getClassification(int $a_classification_id): ?ilMDClassification
204 {
205 if (!$a_classification_id) {
206 return null;
207 }
208
209 $cla = new ilMDClassification();
210 $cla->setMetaId($a_classification_id);
211
212 return $cla;
213 }
214
216 {
217 $cla = new ilMDClassification($this->getRBACId(), $this->getObjId(), $this->getObjType());
218
219 return $cla;
220 }
221
222 public function toXML(ilXmlWriter $writer): void
223 {
224 $writer->xmlStartTag('MetaData');
225
226 // General
227 if (is_object($gen = $this->getGeneral())) {
228 $gen->setExportMode($this->getExportMode());
229 $gen->toXML($writer);
230 } else {
231 // Defaults
232
233 $gen = new ilMDGeneral(
234 $this->getRBACId(),
235 $this->getObjId(),
236 $this->getObjType()
237 ); // added type, alex, 31 Oct 2007
238 $gen->setExportMode($this->getExportMode());
239 $gen->toXML($writer);
240 }
241
242 // Lifecycle
243 if (is_object($lif = $this->getLifecycle())) {
244 $lif->toXML($writer);
245 }
246
247 // Meta-Metadata
248 if (is_object($met = $this->getMetaMetadata())) {
249 $met->toXML($writer);
250 }
251
252 // Technical
253 if (is_object($tec = $this->getTechnical())) {
254 $tec->toXML($writer);
255 }
256
257 // Educational
258 if (is_object($edu = $this->getEducational())) {
259 $edu->toXML($writer);
260 }
261
262 // Rights
263 if (is_object($rig = $this->getRights())) {
264 $rig->toXML($writer);
265 }
266
267 // Relations
268 foreach ($this->getRelationIds() as $id) {
269 $rel = $this->getRelation($id);
270 $rel->toXML($writer);
271 }
272
273 // Annotations
274 foreach ($this->getAnnotationIds() as $id) {
275 $ann = $this->getAnnotation($id);
276 $ann->toXML($writer);
277 }
278
279 // Classification
280 foreach ($this->getClassificationIds() as $id) {
281 $cla = $this->getClassification($id);
282 $cla->toXML($writer);
283 }
284
285 $writer->xmlEndTag('MetaData');
286 }
287
288 public function cloneMD(int $a_rbac_id, int $a_obj_id, string $a_obj_type): ilMD
289 {
290 // this method makes an xml export of the original meta data set
291 // and uses this xml string to clone the object
292 $md2xml = new ilMD2XML($this->getRBACId(), $this->getObjId(), $this->getObjType());
293 $md2xml->startExport();
294
295 $mdxmlcopier = new ilMDXMLCopier($md2xml->getXML(), $a_rbac_id, $a_obj_id, $a_obj_type);
296 $mdxmlcopier->startParsing();
297
298 return $mdxmlcopier->getMDObject();
299 }
300
301 public function deleteAll(): bool
302 {
303 $tables = [
304 'il_meta_annotation',
305 'il_meta_classification',
306 'il_meta_contribute',
307 'il_meta_description',
308 'il_meta_educational',
309 'il_meta_entity',
310 'il_meta_format',
311 'il_meta_general',
312 'il_meta_identifier',
313 'il_meta_identifier_',
314 'il_meta_keyword',
315 'il_meta_language',
316 'il_meta_lifecycle',
317 'il_meta_location',
318 'il_meta_meta_data',
319 'il_meta_relation',
320 'il_meta_requirement',
321 'il_meta_rights',
322 'il_meta_taxon',
323 'il_meta_taxon_path',
324 'il_meta_technical',
325 'il_meta_tar'
326 ];
327
328 foreach ($tables as $table) {
329 $query = "DELETE FROM " . $table . " " .
330 "WHERE rbac_id = " . $this->db->quote($this->getRBACId(), ilDBConstants::T_INTEGER) . " " .
331 "AND obj_id = " . $this->db->quote($this->getObjId(), ilDBConstants::T_INTEGER);
332
333 $this->db->query($query);
334 }
335
336 return true;
337 }
338}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getIds(int $a_rbac_id, int $a_obj_id)
static _getIds(int $a_rbac_id, int $a_obj_id)
static _getId(int $a_rbac_id, int $a_obj_id)
static _getId(int $a_rbac_id, int $a_obj_id)
static _getId(int $a_rbac_id, int $a_obj_id)
static _getId(int $a_rbac_id, int $a_obj_id)
static _getIds(int $a_rbac_id, int $a_obj_id)
static _getId(int $a_rbac_id, int $a_obj_id)
static _getId(int $a_rbac_id, int $a_obj_id)
cloneMD(int $a_rbac_id, int $a_obj_id, string $a_obj_type)
Definition: class.ilMD.php:288
addRights()
Definition: class.ilMD.php:134
getClassificationIds()
Definition: class.ilMD.php:198
addEducational()
Definition: class.ilMD.php:116
getEducational()
Definition: class.ilMD.php:105
getGeneral()
Definition: class.ilMD.php:34
getClassification(int $a_classification_id)
Definition: class.ilMD.php:203
getRelation(int $a_relation_id)
Definition: class.ilMD.php:149
addLifecycle()
Definition: class.ilMD.php:62
getLifecycle()
Definition: class.ilMD.php:51
addTechnical()
Definition: class.ilMD.php:98
addAnnotation()
Definition: class.ilMD.php:188
getAnnotationIds()
Definition: class.ilMD.php:171
addMetaMetadata()
Definition: class.ilMD.php:80
deleteAll()
Definition: class.ilMD.php:301
getAnnotation(int $a_annotation_id)
Definition: class.ilMD.php:176
addRelation()
Definition: class.ilMD.php:161
read()
Definition: class.ilMD.php:29
getRelationIds()
Definition: class.ilMD.php:144
toXML(ilXmlWriter $writer)
Definition: class.ilMD.php:222
getMetaMetadata()
Definition: class.ilMD.php:69
getTechnical()
Definition: class.ilMD.php:87
getRights()
Definition: class.ilMD.php:123
addClassification()
Definition: class.ilMD.php:215
addGeneral()
Definition: class.ilMD.php:44
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
$query