ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDParser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("Services/Xml/classes/class.ilSaxParser.php");
5 include_once("Services/Utilities/classes/class.ilSaxController.php");
6 include_once("Services/Utilities/interfaces/interface.ilSaxSubsetParser.php");
7 include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php");
8 
18 {
19  protected $obj_id; // [int]
20  protected $rec_id; // [int]
21  protected $mapping; // [object]
22  protected $current_value; // [ilAdvancedMDValue]
23  protected $cdata; // [string]
24  protected $field_ids; // [array]
25 
26  function __construct($a_obj_id, $a_mapping)
27  {
29 
30  $parts = explode(":", $a_obj_id);
31  $this->obj_id = $parts[0];
32  $this->mapping = $a_mapping;
33  }
34 
35  function setHandlers($a_xml_parser)
36  {
37  $this->sax_controller = new ilSaxController();
38  $this->sax_controller->setHandlers($a_xml_parser);
39  $this->sax_controller->setDefaultElementHandler($this);
40 
41  /* the value parser does not support sub-types and object-specific record selection
42  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php');
43  $this->sax_controller->setElementHandler(
44  $this->adv_md_handler = new ilAdvancedMDValueParser($this->obj_id),
45  'AdvancedMetaData');
46  */
47  }
48 
49  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
50  {
51  switch($a_name)
52  {
53  case 'AdvancedMetaData':
54  break;
55 
56  case 'Value':
57  $this->initValue($a_attribs['id'], $a_attribs['sub_type'], $a_attribs['sub_id']);
58  break;
59  }
60  }
61 
62  function handlerEndTag($a_xml_parser,$a_name)
63  {
64  switch($a_name)
65  {
66  case 'AdvancedMetaData':
67  break;
68 
69  case 'Value':
70  $value = trim($this->cdata);
71  if(is_object($this->current_value) && $value != "")
72  {
73  $this->current_value->setValue($value);
74  $this->current_value->save();
75  }
76  break;
77  }
78  $this->cdata = '';
79  }
80 
81  function handlerCharacterData($a_xml_parser,$a_data)
82  {
83  if($a_data != "\n")
84  {
85  // Replace multiple tabs with one space
86  $a_data = preg_replace("/\t+/"," ",$a_data);
87 
88  $this->cdata .= $a_data;
89  }
90  }
91 
92  protected function initValue($a_import_id, $a_sub_type = "", $a_sub_id = 0)
93  {
94  $this->current_value = null;
95 
96  if($field_id = ilAdvancedMDFieldDefinition::_lookupFieldId($a_import_id))
97  {
98  $new_parent_id = $this->mapping->getMapping("Services/AdvancedMetaData", "parent", $this->obj_id);
99  if(!$new_parent_id)
100  {
101  return;
102  }
103 
104  if($a_sub_type)
105  {
106  $new_sub_id = $this->mapping->getMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:".$a_sub_type.":".$a_sub_id);
107  if(!$new_sub_id)
108  {
109  return;
110  }
111  $md_value = new ilAdvancedMDValue($field_id, $new_parent_id, $a_sub_type, $new_sub_id);
112  }
113  else
114  {
115  $md_value = new ilAdvancedMDValue($field_id, $new_parent_id);
116  }
117  $this->current_value = $md_value;
118 
119  $this->field_ids[$new_parent_id][$a_sub_type][] = $field_id;
120  }
121  }
122 
123  public function getFieldIds()
124  {
125  return $this->field_ids;
126  }
127 }