ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMDGeneral.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
32include_once 'class.ilMDBase.php';
33
34class ilMDGeneral extends ilMDBase
35{
36 function ilMDGeneral($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
37 {
38 parent::ilMDBase($a_rbac_id,
39 $a_obj_id,
40 $a_obj_type);
41 }
43 {
44 $subs['Keyword'] = 'meta_keyword';
45 $subs['Language'] = 'meta_language';
46 $subs['Identifier'] = 'meta_identifier';
47 $subs['Description'] = 'meta_description';
48
49 return $subs;
50 }
51
52
53 // Subelements (Identifier, Language, Description, Keyword)
54 function &getIdentifierIds()
55 {
56 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
57
58 return ilMDIdentifier::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
59 }
60 function &getIdentifier($a_identifier_id)
61 {
62 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
63
64 if(!$a_identifier_id)
65 {
66 return false;
67 }
68 $ide =& new ilMDIdentifier();
69 $ide->setMetaId($a_identifier_id);
70
71 return $ide;
72 }
73 function &addIdentifier()
74 {
75 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
76
77 $ide =& new ilMDIdentifier($this->getRBACId(),$this->getObjId(),$this->getObjType());
78 $ide->setParentId($this->getMetaId());
79 $ide->setParentType('meta_general');
80
81 return $ide;
82 }
83 function &getLanguageIds()
84 {
85 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
86
87 return ilMDLanguage::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
88 }
89 function &getLanguage($a_language_id)
90 {
91 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
92
93 if(!$a_language_id)
94 {
95 return false;
96 }
97 $lan =& new ilMDLanguage();
98 $lan->setMetaId($a_language_id);
99
100 return $lan;
101
102 }
103 function &addLanguage()
104 {
105 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
106
107 $lan =& new ilMDLanguage($this->getRBACId(),$this->getObjId(),$this->getObjType());
108 $lan->setParentId($this->getMetaId());
109 $lan->setParentType('meta_general');
110
111 return $lan;
112 }
114 {
115 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
116
117 return ilMDDescription::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
118 }
119 function &getDescription($a_description_id)
120 {
121 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
122
123
124 if(!$a_description_id)
125 {
126 return false;
127 }
128 $des =& new ilMDDescription();
129 $des->setMetaId($a_description_id);
130
131 return $des;
132 }
133 function &addDescription()
134 {
135 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
136
137 $des =& new ilMDDescription($this->getRBACId(),$this->getObjId(),$this->getObjType());
138 $des->setParentId($this->getMetaId());
139 $des->setParentType('meta_general');
140
141 return $des;
142 }
143 function &getKeywordIds()
144 {
145 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
146
147 return ilMDKeyword::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
148 }
149 function &getKeyword($a_keyword_id)
150 {
151 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
152
153 if(!$a_keyword_id)
154 {
155 return false;
156 }
157 $key =& new ilMDKeyword();
158 $key->setMetaId($a_keyword_id);
159
160 return $key;
161 }
162 function &addKeyword()
163 {
164 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
165
166 $key =& new ilMDKeyword($this->getRBACId(),$this->getObjId(),$this->getObjType());
167 $key->setParentId($this->getMetaId());
168 $key->setParentType('meta_general');
169
170 return $key;
171 }
172
173
174
175 // SET/GET
176 function setStructure($a_structure)
177 {
178 switch($a_structure)
179 {
180 case 'Atomic':
181 case 'Collection':
182 case 'Networked':
183 case 'Hierarchical':
184 case 'Linear':
185 $this->structure = $a_structure;
186 return true;
187
188 default:
189 return false;
190 }
191 }
192 function getStructure()
193 {
194 return $this->structure;
195 }
196 function setTitle($a_title)
197 {
198 $this->title = $a_title;
199 }
200 function getTitle()
201 {
202 return $this->title;
203 }
204 function setTitleLanguage(&$lng_obj)
205 {
206 if(is_object($lng_obj))
207 {
208 $this->title_language = $lng_obj;
209 }
210 }
212 {
213 return is_object($this->title_language) ? $this->title_language : false;
214 }
216 {
217 return is_object($this->title_language) ? $this->title_language->getLanguageCode() : false;
218 }
219
220 function setCoverage($a_coverage)
221 {
222 $this->coverage = $a_coverage;
223 }
224 function getCoverage()
225 {
226 return $this->coverage;
227 }
228
229 function setCoverageLanguage(&$lng_obj)
230 {
231 if(is_object($lng_obj))
232 {
233 $this->coverage_language = $lng_obj;
234 }
235 }
237 {
238 return is_object($this->coverage_language) ? $this->coverage_language : false;
239 }
241 {
242 return is_object($this->coverage_language) ? $this->coverage_language->getLanguageCode() : false;
243 }
244
245
246 function save()
247 {
248 global $ilDB;
249
250 $fields = $this->__getFields();
251 $fields['meta_general_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_general'));
252
253 if($this->db->insert('il_meta_general',$fields))
254 {
255 $this->setMetaId($next_id);
256 return $this->getMetaId();
257 }
258 return false;
259 }
260
261 function update()
262 {
263 global $ilDB;
264
265 if($this->getMetaId())
266 {
267 if($this->db->update('il_meta_general',
268 $this->__getFields(),
269 array("meta_general_id" => array('integer',$this->getMetaId()))))
270 {
271 return true;
272 }
273 }
274 return false;
275 }
276
277 function delete()
278 {
279 global $ilDB;
280
281 if(!$this->getMetaId())
282 {
283 return false;
284 }
285 // Identifier
286 foreach($this->getIdentifierIds() as $id)
287 {
288 $ide = $this->getIdentifier($id);
289 $ide->delete();
290 }
291
292 // Language
293 foreach($this->getLanguageIds() as $id)
294 {
295 $lan = $this->getLanguage($id);
296 $lan->delete();
297 }
298
299 // Description
300 foreach($this->getDescriptionIds() as $id)
301 {
302 $des = $this->getDescription($id);
303 $des->delete();
304 }
305
306 // Keyword
307 foreach($this->getKeywordIds() as $id)
308 {
309 $key = $this->getKeyword($id);
310 $key->delete();
311 }
312
313 if($this->getMetaId())
314 {
315 $query = "DELETE FROM il_meta_general ".
316 "WHERE meta_general_id = ".$ilDB->quote($this->getMetaId() ,'integer');
317 $res = $ilDB->manipulate($query);
318 return true;
319 }
320
321
322 return false;
323 }
324
325
326 function __getFields()
327 {
328 return array('rbac_id' => array('integer',$this->getRBACId()),
329 'obj_id' => array('integer',$this->getObjId()),
330 'obj_type' => array('text',$this->getObjType()),
331 'general_structure' => array('text',$this->getStructure()),
332 'title' => array('text',$this->getTitle()),
333 'title_language' => array('text',$this->getTitleLanguageCode()),
334 'coverage' => array('text',$this->getCoverage()),
335 'coverage_language' => array('text',$this->getCoverageLanguageCode()));
336 }
337
338 function read()
339 {
340 global $ilDB;
341
342 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
343
344 if($this->getMetaId())
345 {
346 $query = "SELECT * FROM il_meta_general ".
347 "WHERE meta_general_id = ".$ilDB->quote($this->getMetaId() ,'integer');
348
349 $res = $this->db->query($query);
350 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
351 {
352 $this->setRBACId($row->rbac_id);
353 $this->setObjId($row->obj_id);
354 $this->setObjType($row->obj_type);
355 $this->setStructure($row->general_structure);
356 $this->setTitle($row->title);
357 $this->setTitleLanguage(new ilMDLanguageItem($row->title_language));
358 $this->setCoverage($row->coverage);
359 $this->setCoverageLanguage(new ilMDLanguageItem($row->coverage_language));
360 }
361 }
362 return true;
363 }
364
365 /*
366 * XML Export of all meta data
367 * @param object (xml writer) see class.ilMD2XML.php
368 *
369 */
370 function toXML(&$writer)
371 {
372 $writer->xmlStartTag('General',array('Structure' => $this->getStructure() ?
373 $this->getStructure() :
374 'Atomic'));
375
376
377 // Identifier
378 $first = true;
379 $identifiers = array();
380 $identifiers = $this->getIdentifierIds();
381 foreach($identifiers as $id)
382 {
383 $ide =& $this->getIdentifier($id);
384 $ide->setExportMode($this->getExportMode());
385 $ide->toXML($writer);
386 $first = false;
387 }
388 if(!count($identifiers))
389 {
390 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
391 $ide = new ilMDIdentifier($this->getRBACId(),$this->getObjId(),
392 $this->getObjType()); // added type, alex, 31 Oct 2007
393 $ide->setExportMode(true);
394 $ide->toXML($writer,true);
395 }
396
397 // Title
398 $writer->xmlElement('Title',array('Language' => $this->getTitleLanguageCode() ?
399 $this->getTitleLanguageCode() :
400 'en'),
401 $this->getTitle());
402
403 // Language
404 $languages = $this->getLanguageIds();
405 foreach($languages as $id)
406 {
407 $lan =& $this->getLanguage($id);
408 $lan->toXML($writer);
409 }
410 if(!count($languages))
411 {
412 // Default
413 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
414 $lan = new ilMDLanguage($this->getRBACId(),$this->getObjId());
415 $lan->toXML($writer);
416 }
417
418 // Description
419 $descriptions = $this->getDescriptionIds();
420 foreach($descriptions as $id)
421 {
422 $des =& $this->getDescription($id);
423 $des->toXML($writer);
424 }
425 if(!count($descriptions))
426 {
427 // Default
428 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
429 $des = new ilMDDescription($this->getRBACId(),$this->getObjId());
430 $des->toXML($writer);
431 }
432
433
434 // Keyword
435 $keywords = $this->getKeywordIds();
436 foreach($keywords as $id)
437 {
438 $key =& $this->getKeyword($id);
439 $key->toXML($writer);
440 }
441 if(!count($keywords))
442 {
443 // Default
444 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
445 $key = new ilMDKeyword($this->getRBACId(),$this->getObjId());
446 $key->toXML($writer);
447 }
448
449 // Copverage
450 if(strlen($this->getCoverage()))
451 {
452 $writer->xmlElement('Coverage',array('Language' => $this->getCoverageLanguageCode() ?
453 $this->getCoverageLanguageCode() :
454 'en'),
455 $this->getCoverage());
456 }
457 $writer->xmlEndTag('General');
458 }
459
460
461
462 // STATIC
463 function _getId($a_rbac_id,$a_obj_id)
464 {
465 global $ilDB;
466
467 $query = "SELECT meta_general_id FROM il_meta_general ".
468 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
469 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
470
471
472 $res = $ilDB->query($query);
473 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
474 {
475 return $row->meta_general_id;
476 }
477 return false;
478 }
479}
480?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setObjId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getDescription($a_description_id)
setStructure($a_structure)
setCoverage($a_coverage)
_getId($a_rbac_id, $a_obj_id)
& getIdentifier($a_identifier_id)
& getKeyword($a_keyword_id)
setTitle($a_title)
setCoverageLanguage(&$lng_obj)
ilMDGeneral($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
& getLanguage($a_language_id)
setTitleLanguage(&$lng_obj)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
global $ilDB