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