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