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