• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
00034 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00035 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
00036 
00037 class ilAdvancedMDValueParser implements ilSaxSubsetParser
00038 {
00039         protected $cdata = '';
00040         protected $obj_id;
00041         protected $values = array();
00042         protected $current_value = null;
00043         
00051         public function __construct($a_new_obj_id = 0)
00052         {
00053                 $this->obj_id = $a_new_obj_id;
00054         }
00055         
00063         public function setObjId($a_obj_id)
00064         {
00065                 $this->obj_id = $a_obj_id;
00066         }
00067         
00073         public function save()
00074         {
00075                 foreach($this->values as $value)
00076                 {
00077                         $value->setObjId($this->obj_id);
00078                         $value->save();
00079                 }
00080                 return true;
00081         }
00082         
00092         public function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00093         {
00094                 switch($a_name)
00095                 {
00096                         case 'AdvancedMetaData':
00097                                 $this->values = array();
00098                                 break;
00099                                 
00100                         case 'Value':
00101                                 $this->initValue($a_attribs['id']);
00102                                 break;
00103                 }
00104                 
00105         }
00106 
00115         public function handlerEndTag($a_xml_parser,$a_name)
00116         {
00117                 switch($a_name)
00118                 {
00119                         case 'AdvancedMetaData':
00120                                 break;
00121                                 
00122                         case 'Value':
00123                                 if(is_object($this->current_value))
00124                                 {
00125                                         $this->current_value->setValue(trim($this->cdata));
00126                                 }
00127                                 break;
00128                 }
00129                 $this->cdata = '';
00130         }
00131         
00139         public function handlerCharacterData($a_xml_parser,$a_data)
00140         {
00141                 if($a_data != "\n")
00142                 {
00143                         // Replace multiple tabs with one space
00144                         $a_data = preg_replace("/\t+/"," ",$a_data);
00145 
00146                         $this->cdata .= $a_data;
00147                 }
00148         }
00149         
00157         private function initValue($a_import_id)
00158         {
00159                 if($field_id = ilAdvancedMDFieldDefinition::_lookupFieldId($a_import_id))
00160                 {
00161                         $this->current_value = new ilAdvancedMDValue($field_id,$this->obj_id);
00162                         $this->values[] = $this->current_value;
00163                 }
00164                 else
00165                 {
00166                         $this->current_value = null;
00167                 }
00168                 
00169         }
00170 }
00171 
00172 
00173 ?>

Generated on Fri Dec 13 2013 17:56:55 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1