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

Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.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 class ilAdvancedMDValue
00034 {
00035         private static $instances = array();
00036         
00037         protected $db;
00038         
00039         private $obj_id;
00040         private $field_id;
00041         private $value;
00042         private $disabled = false;
00043 
00052         public function __construct($a_field_id,$a_obj_id = 0)
00053         {
00054                 global $ilDB;
00055                 
00056                 $this->db = $ilDB;
00057                 
00058                 $this->obj_id = $a_obj_id;
00059                 $this->field_id = $a_field_id;
00060                 
00061                 $this->read();
00062         }
00063         
00072         public static function _getInstance($a_obj_id,$a_field_id)
00073         {
00074                 if(isset(self::$instances[$a_obj_id][$a_field_id]))
00075                 {
00076                         return self::$instances[$a_obj_id][$a_field_id];
00077                 }
00078                 return self::$instances[$a_obj_id][$a_field_id] = new ilAdvancedMDValue($a_field_id,$a_obj_id);
00079         }
00080         
00087         public function __toString()
00088         {
00089                 return $this->value;
00090         }
00091         
00099         public function setObjId($a_obj_id)
00100         {
00101                 $this->obj_id = $a_obj_id;
00102         }
00103         
00111         public function appendXML($xml_writer)
00112         {
00113                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00114                 
00115                 $xml_writer->xmlElement('Value',
00116                         array('id' => ilAdvancedMDFieldDefinition::_lookupImportId($this->field_id)),
00117                         $this->getValue());
00118         }
00119         
00120         
00128         public function setValue($a_value)
00129         {
00130                 $this->value = $a_value;
00131         }
00132         
00138         public function getValue()
00139         {
00140                 return $this->value;
00141         }
00142         
00151         public function isDisabled()
00152         {
00153                 return (bool) $this->disabled;
00154         }
00155         
00163         public function toggleDisabledStatus($a_status)
00164         {
00165                 $this->disabled = (bool) $a_status;
00166         }
00167         
00174         public function delete()
00175         {
00176                 $query = "DELETE FROM adv_md_values ".
00177                         "WHERE obj_id = ".$this->db->quote($this->obj_id)." ".
00178                         "AND field_id = ".$this->db->quote($this->field_id);
00179                 $res = $this->db->query($query);
00180         }
00181         
00188         public function save()
00189         {
00190                 $query = "REPLACE INTO adv_md_values ".
00191                         "SET obj_id = ".$this->db->quote($this->obj_id).", ".
00192                         "field_id = ".$this->db->quote($this->field_id).", ".
00193                         "value = ".$this->db->quote($this->getValue()).", ".
00194                         "disabled = ".(int) $this->isDisabled()." ";
00195                 $res = $this->db->query($query);
00196         }
00197         
00203         private function read()
00204         {
00205                 if(!$this->obj_id or !$this->field_id)
00206                 {
00207                         return;
00208                 }
00209                 
00210                 $query = "SELECT * FROM adv_md_values ".
00211                         "WHERE obj_id = ".$this->db->quote($this->obj_id)." ".
00212                         "AND field_id = ".$this->db->quote($this->field_id)." ";
00213                 $res = $this->db->query($query);
00214                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00215                 {
00216                         $this->setValue($row->value);
00217                         $this->toggleDisabledStatus((bool) $row->disabled);
00218                 }
00219                 return true;    
00220         }
00221 }
00222 ?>

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