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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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  $this->log->logStack(ilLogLevel::DEBUG);
243  //ilUtil::printBacktrace(10);
244 
245  if ($this->db->insert('il_meta_general', $fields)) {
246  $this->setMetaId($next_id);
247  return $this->getMetaId();
248  }
249  return false;
250  }
251 
252  public function update()
253  {
254  global $DIC;
255 
256  $ilDB = $DIC['ilDB'];
257 
258  if ($this->getMetaId()) {
259  if ($this->db->update(
260  'il_meta_general',
261  $this->__getFields(),
262  array("meta_general_id" => array('integer',$this->getMetaId()))
263  )) {
264  return true;
265  }
266  }
267  return false;
268  }
269 
270  public function delete()
271  {
272  global $DIC;
273 
274  $ilDB = $DIC['ilDB'];
275 
276  if (!$this->getMetaId()) {
277  return false;
278  }
279  // Identifier
280  foreach ($this->getIdentifierIds() as $id) {
281  $ide = $this->getIdentifier($id);
282  $ide->delete();
283  }
284 
285  // Language
286  foreach ($this->getLanguageIds() as $id) {
287  $lan = $this->getLanguage($id);
288  $lan->delete();
289  }
290 
291  // Description
292  foreach ($this->getDescriptionIds() as $id) {
293  $des = $this->getDescription($id);
294  $des->delete();
295  }
296 
297  // Keyword
298  foreach ($this->getKeywordIds() as $id) {
299  $key = $this->getKeyword($id);
300  $key->delete();
301  }
302 
303  if ($this->getMetaId()) {
304  $query = "DELETE FROM il_meta_general " .
305  "WHERE meta_general_id = " . $ilDB->quote($this->getMetaId(), 'integer');
306  $res = $ilDB->manipulate($query);
307  return true;
308  }
309 
310 
311  return false;
312  }
313 
314 
315  public function __getFields()
316  {
317  return array('rbac_id' => array('integer',$this->getRBACId()),
318  'obj_id' => array('integer',$this->getObjId()),
319  'obj_type' => array('text',$this->getObjType()),
320  'general_structure' => array('text',$this->getStructure()),
321  'title' => array('text',$this->getTitle()),
322  'title_language' => array('text',$this->getTitleLanguageCode()),
323  'coverage' => array('text',$this->getCoverage()),
324  'coverage_language' => array('text',$this->getCoverageLanguageCode()));
325  }
326 
327  public function read()
328  {
329  global $DIC;
330 
331  $ilDB = $DIC['ilDB'];
332 
333  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
334 
335  if ($this->getMetaId()) {
336  $query = "SELECT * FROM il_meta_general " .
337  "WHERE meta_general_id = " . $ilDB->quote($this->getMetaId(), 'integer');
338 
339  $res = $this->db->query($query);
340  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
341  $this->setRBACId($row->rbac_id);
342  $this->setObjId($row->obj_id);
343  $this->setObjType($row->obj_type);
344  $this->setStructure($row->general_structure);
345  $this->setTitle($row->title);
346  $this->setTitleLanguage(new ilMDLanguageItem($row->title_language));
347  $this->setCoverage($row->coverage);
348  $this->setCoverageLanguage(new ilMDLanguageItem($row->coverage_language));
349  }
350  }
351  return true;
352  }
353 
354  /*
355  * XML Export of all meta data
356  * @param object (xml writer) see class.ilMD2XML.php
357  *
358  */
359  public function toXML(&$writer)
360  {
361  $writer->xmlStartTag('General', array('Structure' => $this->getStructure() ?
362  $this->getStructure() :
363  'Atomic'));
364 
365 
366  // Identifier
367  $first = true;
368  $identifiers = array();
369  $identifiers = $this->getIdentifierIds();
370  foreach ($identifiers as $id) {
371  $ide = &$this->getIdentifier($id);
372  $ide->setExportMode($this->getExportMode());
373  $ide->toXML($writer);
374  $first = false;
375  }
376  if (!count($identifiers)) {
377  include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
378  $ide = new ilMDIdentifier(
379  $this->getRBACId(),
380  $this->getObjId(),
381  $this->getObjType()
382  ); // added type, alex, 31 Oct 2007
383  $ide->setExportMode(true);
384  $ide->toXML($writer, true);
385  }
386 
387  // Title
388  $writer->xmlElement(
389  'Title',
390  array('Language' => $this->getTitleLanguageCode() ?
391  $this->getTitleLanguageCode() :
392  'en'),
393  $this->getTitle()
394  );
395 
396  // Language
397  $languages = $this->getLanguageIds();
398  foreach ($languages as $id) {
399  $lan = &$this->getLanguage($id);
400  $lan->toXML($writer);
401  }
402  if (!count($languages)) {
403  // Default
404  include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
405  $lan = new ilMDLanguage($this->getRBACId(), $this->getObjId());
406  $lan->toXML($writer);
407  }
408 
409  // Description
410  $descriptions = $this->getDescriptionIds();
411  foreach ($descriptions as $id) {
412  $des = &$this->getDescription($id);
413  $des->toXML($writer);
414  }
415  if (!count($descriptions)) {
416  // Default
417  include_once 'Services/MetaData/classes/class.ilMDDescription.php';
418  $des = new ilMDDescription($this->getRBACId(), $this->getObjId());
419  $des->toXML($writer);
420  }
421 
422 
423  // Keyword
424  $keywords = $this->getKeywordIds();
425  foreach ($keywords as $id) {
426  $key = &$this->getKeyword($id);
427  $key->toXML($writer);
428  }
429  if (!count($keywords)) {
430  // Default
431  include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
432  $key = new ilMDKeyword($this->getRBACId(), $this->getObjId());
433  $key->toXML($writer);
434  }
435 
436  // Copverage
437  if (strlen($this->getCoverage())) {
438  $writer->xmlElement(
439  'Coverage',
440  array('Language' => $this->getCoverageLanguageCode() ?
441  $this->getCoverageLanguageCode() :
442  'en'),
443  $this->getCoverage()
444  );
445  }
446  $writer->xmlEndTag('General');
447  }
448 
449 
450 
451  // STATIC
452  public static function _getId($a_rbac_id, $a_obj_id)
453  {
454  global $DIC;
455 
456  $ilDB = $DIC['ilDB'];
457 
458  $query = "SELECT meta_general_id FROM il_meta_general " .
459  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
460  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
461 
462 
463  $res = $ilDB->query($query);
464  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
465  return $row->meta_general_id;
466  }
467  return false;
468  }
469 }
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