Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 ?>