ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
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['Identifier'] = 'meta_identifier';
45  $subs['Language'] = 'meta_language';
46  $subs['Description'] = 'meta_description';
47  $subs['Keyword'] = 'meta_keyword';
48 
49  return $subs;
50  }
51 
52 
53  // Subelements (Identifier, Language, Description, Keyword)
54  function &getIdentifierIds()
55  {
56  include_once 'Services/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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  }
113  function &getDescriptionIds()
114  {
115  include_once 'Services/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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  }
211  function &getTitleLanguage()
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  if($this->db->autoExecute('il_meta_general',
249  $this->__getFields(),
250  DB_AUTOQUERY_INSERT))
251  {
252  $this->setMetaId($this->db->getLastInsertId());
253 
254  return $this->getMetaId();
255  }
256  return false;
257  }
258 
259  function update()
260  {
261  global $ilDB;
262 
263  if($this->getMetaId())
264  {
265  if($this->db->autoExecute('il_meta_general',
266  $this->__getFields(),
267  DB_AUTOQUERY_UPDATE,
268  "meta_general_id = ".$ilDB->quote($this->getMetaId())))
269  {
270  return true;
271  }
272  }
273  return false;
274  }
275 
276  function delete()
277  {
278  global $ilDB;
279 
280  if(!$this->getMetaId())
281  {
282  return false;
283  }
284  // Identifier
285  foreach($this->getIdentifierIds() as $id)
286  {
287  $ide = $this->getIdentifier($id);
288  $ide->delete();
289  }
290 
291  // Language
292  foreach($this->getLanguageIds() as $id)
293  {
294  $lan = $this->getLanguage($id);
295  $lan->delete();
296  }
297 
298  // Description
299  foreach($this->getDescriptionIds() as $id)
300  {
301  $des = $this->getDescription($id);
302  $des->delete();
303  }
304 
305  // Keyword
306  foreach($this->getKeywordIds() as $id)
307  {
308  $key = $this->getKeyword($id);
309  $key->delete();
310  }
311 
312  if($this->getMetaId())
313  {
314  $query = "DELETE FROM il_meta_general ".
315  "WHERE meta_general_id = ".$ilDB->quote($this->getMetaId());
316 
317  $this->db->query($query);
318 
319  return true;
320  }
321 
322 
323  return false;
324  }
325 
326 
327  function __getFields()
328  {
329  return array('rbac_id' => $this->getRBACId(),
330  'obj_id' => $this->getObjId(),
331  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
332  'general_structure' => ilUtil::prepareDBString($this->getStructure()),
333  'title' => ilUtil::prepareDBString($this->getTitle()),
334  'title_language' => ilUtil::prepareDBString($this->getTitleLanguageCode()),
335  'coverage' => ilUtil::prepareDBString($this->getCoverage()),
336  'coverage_language' => ilUtil::prepareDBString($this->getCoverageLanguageCode()));
337  }
338 
339  function read()
340  {
341  global $ilDB;
342 
343  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
344 
345  if($this->getMetaId())
346  {
347  $query = "SELECT * FROM il_meta_general ".
348  "WHERE meta_general_id = ".$ilDB->quote($this->getMetaId());
349 
350  $res = $this->db->query($query);
351  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
352  {
353  $this->setRBACId($row->rbac_id);
354  $this->setObjId($row->obj_id);
355  $this->setObjType($row->obj_type);
356  $this->setStructure(ilUtil::stripSlashes($row->general_structure));
357  $this->setTitle(ilUtil::stripSlashes($row->title));
358  $this->setTitleLanguage(new ilMDLanguageItem($row->title_language));
359  $this->setCoverage(ilUtil::stripSlashes($row->coverage));
360  $this->setCoverageLanguage(new ilMDLanguageItem($row->coverage_language));
361  }
362  }
363  return true;
364  }
365 
366  /*
367  * XML Export of all meta data
368  * @param object (xml writer) see class.ilMD2XML.php
369  *
370  */
371  function toXML(&$writer)
372  {
373  $writer->xmlStartTag('General',array('Structure' => $this->getStructure()));
374 
375  // Identifier
376  foreach($this->getIdentifierIds() as $id)
377  {
378  $ide =& $this->getIdentifier($id);
379  $ide->toXML($writer);
380  }
381 
382  // TItle
383  $writer->xmlElement('Title',array('Language' => $this->getTitleLanguageCode()),$this->getTitle());
384 
385  // Language
386  foreach($this->getLanguageIds() as $id)
387  {
388  $lan =& $this->getLanguage($id);
389  $lan->toXML($writer);
390  }
391 
392  // Description
393  foreach($this->getDescriptionIds() as $id)
394  {
395  $des =& $this->getDescription($id);
396  $des->toXML($writer);
397  }
398 
399  // Keyword
400  foreach($this->getKeywordIds() as $id)
401  {
402  $key =& $this->getKeyword($id);
403  $key->toXML($writer);
404  }
405 
406  // Copverage
407  if(strlen($this->getCoverage()))
408  {
409  $writer->xmlElement('Coverage',array('Language' => $this->getCoverageLanguageCode()),$this->getCoverage());
410  }
411  $writer->xmlEndTag('General');
412  }
413 
414 
415 
416  // STATIC
417  function _getId($a_rbac_id,$a_obj_id)
418  {
419  global $ilDB;
420 
421  $query = "SELECT meta_general_id FROM il_meta_general ".
422  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
423  "AND obj_id = ".$ilDB->quote($a_obj_id);
424 
425 
426  $res = $ilDB->query($query);
427  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
428  {
429  return $row->meta_general_id;
430  }
431  return false;
432  }
433 }
434 ?>