ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMD.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
32 include_once 'class.ilMDBase.php';
33 
34 class ilMD extends ilMDBase
35 {
36  /*
37  * meta elements
38  *
39  */
40  public function &getGeneral()
41  {
42  include_once 'Services/MetaData/classes/class.ilMDGeneral.php';
43 
44  if ($id = ilMDGeneral::_getId($this->getRBACId(), $this->getObjId())) {
45  $gen = new ilMDGeneral();
46  $gen->setMetaId($id);
47 
48  return $gen;
49  }
50  return false;
51  }
52  public function &addGeneral()
53  {
54  include_once 'Services/MetaData/classes/class.ilMDGeneral.php';
55 
56  $gen = new ilMDGeneral($this->getRBACId(), $this->getObjId(), $this->getObjType());
57 
58  return $gen;
59  }
60 
61 
62  public function &getLifecycle()
63  {
64  include_once 'Services/MetaData/classes/class.ilMDLifecycle.php';
65 
66  if ($id = ilMDLifecycle::_getId($this->getRBACId(), $this->getObjId())) {
67  $lif = new ilMDLifecycle();
68  $lif->setMetaId($id);
69 
70  return $lif;
71  }
72  return false;
73  }
74  public function &addLifecycle()
75  {
76  include_once 'Services/MetaData/classes/class.ilMDLifecycle.php';
77 
78  $lif = new ilMDLifecycle($this->getRBACId(), $this->getObjId(), $this->getObjType());
79 
80  return $lif;
81  }
82 
83  public function &getMetaMetadata()
84  {
85  include_once 'Services/MetaData/classes/class.ilMDMetaMetadata.php';
86 
87  if ($id = ilMDMetaMetadata::_getId($this->getRBACId(), $this->getObjId())) {
88  $met = new ilMDMetaMetadata();
89  $met->setMetaId($id);
90 
91  return $met;
92  }
93  return false;
94  }
95  public function &addMetaMetadata()
96  {
97  include_once 'Services/MetaData/classes/class.ilMDMetaMetadata.php';
98 
99  $met = new ilMDMetaMetadata($this->getRBACId(), $this->getObjId(), $this->getObjType());
100 
101  return $met;
102  }
103 
104  public function &getTechnical()
105  {
106  include_once 'Services/MetaData/classes/class.ilMDTechnical.php';
107 
108  if ($id = ilMDTechnical::_getId($this->getRBACId(), $this->getObjId())) {
109  $tec = new ilMDTechnical();
110  $tec->setMetaId($id);
111 
112  return $tec;
113  }
114  return false;
115  }
116  public function &addTechnical()
117  {
118  include_once 'Services/MetaData/classes/class.ilMDTechnical.php';
119 
120  $tec = new ilMDTechnical($this->getRBACId(), $this->getObjId(), $this->getObjType());
121 
122  return $tec;
123  }
124 
125  public function &getEducational()
126  {
127  include_once 'Services/MetaData/classes/class.ilMDEducational.php';
128 
129  if ($id = ilMDEducational::_getId($this->getRBACId(), $this->getObjId())) {
130  $edu = new ilMDEducational();
131  $edu->setMetaId($id);
132 
133  return $edu;
134  }
135  return false;
136  }
137  public function &addEducational()
138  {
139  include_once 'Services/MetaData/classes/class.ilMDEducational.php';
140 
141  $edu = new ilMDEducational($this->getRBACId(), $this->getObjId(), $this->getObjType());
142 
143  return $edu;
144  }
145  public function &getRights()
146  {
147  include_once 'Services/MetaData/classes/class.ilMDRights.php';
148 
149  if ($id = ilMDRights::_getId($this->getRBACId(), $this->getObjId())) {
150  $rig = new ilMDRights();
151  $rig->setMetaId($id);
152 
153  return $rig;
154  }
155  return false;
156  }
157  public function &addRights()
158  {
159  include_once 'Services/MetaData/classes/class.ilMDRights.php';
160 
161  $rig = new ilMDRights($this->getRBACId(), $this->getObjId(), $this->getObjType());
162 
163  return $rig;
164  }
165 
166  public function &getRelationIds()
167  {
168  include_once 'Services/MetaData/classes/class.ilMDRelation.php';
169 
170  return ilMDRelation::_getIds($this->getRBACId(), $this->getObjId());
171  }
172  public function &getRelation($a_relation_id)
173  {
174  include_once 'Services/MetaData/classes/class.ilMDRelation.php';
175 
176  if (!$a_relation_id) {
177  return false;
178  }
179 
180  $rel = new ilMDRelation();
181  $rel->setMetaId($a_relation_id);
182 
183  return $rel;
184  }
185  public function &addRelation()
186  {
187  include_once 'Services/MetaData/classes/class.ilMDRelation.php';
188 
189  $rel = new ilMDRelation($this->getRBACId(), $this->getObjId(), $this->getObjType());
190 
191  return $rel;
192  }
193 
194 
195  public function &getAnnotationIds()
196  {
197  include_once 'Services/MetaData/classes/class.ilMDAnnotation.php';
198 
199  return ilMDAnnotation::_getIds($this->getRBACId(), $this->getObjId());
200  }
201  public function &getAnnotation($a_annotation_id)
202  {
203  if (!$a_annotation_id) {
204  return false;
205  }
206  include_once 'Services/MetaData/classes/class.ilMDAnnotation.php';
207 
208  $ann = new ilMDAnnotation();
209  $ann->setMetaId($a_annotation_id);
210 
211  return $ann;
212  }
213  public function &addAnnotation()
214  {
215  include_once 'Services/MetaData/classes/class.ilMDAnnotation.php';
216 
217  $ann = new ilMDAnnotation($this->getRBACId(), $this->getObjId(), $this->getObjType());
218 
219  return $ann;
220  }
221 
222  public function &getClassificationIds()
223  {
224  include_once 'Services/MetaData/classes/class.ilMDClassification.php';
225 
226  return ilMDClassification::_getIds($this->getRBACId(), $this->getObjId());
227  }
228  public function &getClassification($a_classification_id)
229  {
230  if (!$a_classification_id) {
231  return false;
232  }
233 
234  include_once 'Services/MetaData/classes/class.ilMDClassification.php';
235 
236  $cla = new ilMDClassification();
237  $cla->setMetaId($a_classification_id);
238 
239  return $cla;
240  }
241  public function &addClassification()
242  {
243  include_once 'Services/MetaData/classes/class.ilMDClassification.php';
244 
245  $cla = new ilMDClassification($this->getRBACId(), $this->getObjId(), $this->getObjType());
246 
247  return $cla;
248  }
249 
250  /*
251  * XML Export of all meta data
252  * @param object (xml writer) see class.ilMD2XML.php
253  *
254  */
255  public function toXML(&$writer)
256  {
257  $writer->xmlStartTag('MetaData');
258 
259  // General
260  if (is_object($gen = &$this->getGeneral())) {
261  $gen->setExportMode($this->getExportMode());
262  $gen->toXML($writer);
263  } else {
264  // Defaults
265  include_once 'Services/MetaData/classes/class.ilMDGeneral.php';
266  $gen = new ilMDGeneral($this->getRBACId(), $this->getObjId(), $this->getObjType()); // added type, alex, 31 Oct 2007
267  $gen->setExportMode($this->getExportMode());
268  $gen->toXML($writer);
269  }
270 
271 
272  // Lifecycle
273  if (is_object($lif = &$this->getLifecycle())) {
274  $lif->toXML($writer);
275  }
276 
277  // Meta-Metadata
278  if (is_object($met = &$this->getMetaMetadata())) {
279  $met->toXML($writer);
280  }
281 
282  // Technical
283  if (is_object($tec = &$this->getTechnical())) {
284  $tec->toXML($writer);
285  }
286 
287  // Educational
288  if (is_object($edu = &$this->getEducational())) {
289  $edu->toXML($writer);
290  }
291 
292  // Rights
293  if (is_object($rig = &$this->getRights())) {
294  $rig->toXML($writer);
295  }
296 
297  // Relations
298  foreach ($this->getRelationIds() as $id) {
299  $rel = &$this->getRelation($id);
300  $rel->toXML($writer);
301  }
302 
303  // Annotations
304  foreach ($this->getAnnotationIds() as $id) {
305  $ann = &$this->getAnnotation($id);
306  $ann->toXML($writer);
307  }
308 
309  // Classification
310  foreach ($this->getClassificationIds() as $id) {
311  $cla = &$this->getClassification($id);
312  $cla->toXML($writer);
313  }
314 
315  $writer->xmlEndTag('MetaData');
316  }
317 
318  /*
319  * Clone all meta data of an object
320  * @param int rbac_id obj_id of rbac object
321  * @param int obj_id obj_id of meta object
322  * @param string type of meta object
323  * @return object new cloned md object
324  *
325  */
326  public function &cloneMD($a_rbac_id, $a_obj_id, $a_obj_type)
327  {
328  include_once 'Services/MetaData/classes/class.ilMD2XML.php';
329 
330  // this method makes an xml export of the original meta data set
331  // and uses this xml string to clone the object
332  $md2xml = new ilMD2XML($this->getRBACId(), $this->getObjId(), $this->getObjType());
333  $md2xml->startExport();
334 
335  // Create copier instance. For pg objects one could instantiate a ilMDXMLPageCopier class
336  switch ($a_obj_type) {
337  default:
338  // delete existing entries from creations process
339  $clone = new ilMD($a_rbac_id, $a_obj_id, $a_obj_type);
340  $clone->deleteAll();
341 
342 
343  include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php';
344  $mdxmlcopier = new ilMDXMLCopier($md2xml->getXML(), $a_rbac_id, $a_obj_id, $a_obj_type);
345 
346  // rewrite autogenerated entry
347  $identifier = new ilMDIdentifier($a_rbac_id, $a_obj_id, $a_obj_type);
348  $identifier->setEntry('il__' . $a_obj_type . '_' . $a_obj_id);
349  $identifier->update();
350  break;
351  }
352  $mdxmlcopier->startParsing();
353 
354  return $mdxmlcopier->getMDObject();
355  }
356 
357  public function deleteAll()
358  {
359  global $DIC;
360 
361  $ilDB = $DIC['ilDB'];
362 
363  $tables = array('il_meta_annotation',
364  'il_meta_classification',
365  'il_meta_contribute',
366  'il_meta_description',
367  'il_meta_educational',
368  'il_meta_entity',
369  'il_meta_format',
370  'il_meta_general',
371  'il_meta_identifier',
372  'il_meta_identifier_',
373  'il_meta_keyword',
374  'il_meta_language',
375  'il_meta_lifecycle',
376  'il_meta_location',
377  'il_meta_meta_data',
378  'il_meta_relation',
379  'il_meta_requirement',
380  'il_meta_rights',
381  'il_meta_taxon',
382  'il_meta_taxon_path',
383  'il_meta_technical',
384  'il_meta_tar');
385 
386  foreach ($tables as $table) {
387  $query = "DELETE FROM " . $table . " " .
388  "WHERE rbac_id = " . $ilDB->quote($this->getRBACId()) . " " .
389  "AND obj_id = " . $ilDB->quote($this->getObjId());
390 
391  $this->db->query($query);
392  }
393 
394  return true;
395  }
396 }
& cloneMD($a_rbac_id, $a_obj_id, $a_obj_type)
Definition: class.ilMD.php:326
static _getIds($a_rbac_id, $a_obj_id)
& addEducational()
Definition: class.ilMD.php:137
static _getIds($a_rbac_id, $a_obj_id)
& getEducational()
Definition: class.ilMD.php:125
& getClassification($a_classification_id)
Definition: class.ilMD.php:228
global $DIC
Definition: saml.php:7
startParsing()
stores xml data in array
deleteAll()
Definition: class.ilMD.php:357
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getIds($a_rbac_id, $a_obj_id)
static _getId($a_rbac_id, $a_obj_id)
& getTechnical()
Definition: class.ilMD.php:104
& getRelation($a_relation_id)
Definition: class.ilMD.php:172
& addMetaMetadata()
Definition: class.ilMD.php:95
static _getId($a_rbac_id, $a_obj_id)
static _getId($a_rbac_id, $a_obj_id)
static _getId($a_rbac_id, $a_obj_id)
& addGeneral()
Definition: class.ilMD.php:52
& getRights()
Definition: class.ilMD.php:145
& addRelation()
Definition: class.ilMD.php:185
& addRights()
Definition: class.ilMD.php:157
& getGeneral()
Definition: class.ilMD.php:40
static _getId($a_rbac_id, $a_obj_id)
$query
& getMetaMetadata()
Definition: class.ilMD.php:83
& getAnnotationIds()
Definition: class.ilMD.php:195
global $ilDB
& addTechnical()
Definition: class.ilMD.php:116
& addClassification()
Definition: class.ilMD.php:241
static _getId($a_rbac_id, $a_obj_id)
& getLifecycle()
Definition: class.ilMD.php:62
& getAnnotation($a_annotation_id)
Definition: class.ilMD.php:201
if(empty($password)) $table
Definition: pwgen.php:24
& addAnnotation()
Definition: class.ilMD.php:213
& addLifecycle()
Definition: class.ilMD.php:74
& getClassificationIds()
Definition: class.ilMD.php:222
toXML(&$writer)
Definition: class.ilMD.php:255
& getRelationIds()
Definition: class.ilMD.php:166