ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDValue.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
34 {
35  private static $instances = array();
36 
37  protected $db;
38 
39  private $obj_id;
40  private $field_id;
41  private $value;
42  private $disabled = false;
43 
52  public function __construct($a_field_id,$a_obj_id = 0)
53  {
54  global $ilDB;
55 
56  $this->db = $ilDB;
57 
58  $this->obj_id = $a_obj_id;
59  $this->field_id = $a_field_id;
60 
61  $this->read();
62  }
63 
72  public static function _getInstance($a_obj_id,$a_field_id)
73  {
74  if(isset(self::$instances[$a_obj_id][$a_field_id]))
75  {
76  return self::$instances[$a_obj_id][$a_field_id];
77  }
78  return self::$instances[$a_obj_id][$a_field_id] = new ilAdvancedMDValue($a_field_id,$a_obj_id);
79  }
80 
87  public function __toString()
88  {
89  return $this->value;
90  }
91 
99  public function setObjId($a_obj_id)
100  {
101  $this->obj_id = $a_obj_id;
102  }
103 
111  public function appendXML($xml_writer)
112  {
113  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
114 
115  $xml_writer->xmlElement('Value',
116  array('id' => ilAdvancedMDFieldDefinition::_lookupImportId($this->field_id)),
117  $this->getValue());
118  }
119 
120 
128  public function setValue($a_value)
129  {
130  $this->value = $a_value;
131  }
132 
138  public function getValue()
139  {
140  return $this->value;
141  }
142 
151  public function isDisabled()
152  {
153  return (bool) $this->disabled;
154  }
155 
163  public function toggleDisabledStatus($a_status)
164  {
165  $this->disabled = (bool) $a_status;
166  }
167 
174  public function delete()
175  {
176  $query = "DELETE FROM adv_md_values ".
177  "WHERE obj_id = ".$this->db->quote($this->obj_id)." ".
178  "AND field_id = ".$this->db->quote($this->field_id);
179  $res = $this->db->query($query);
180  }
181 
188  public function save()
189  {
190  $query = "REPLACE INTO adv_md_values ".
191  "SET obj_id = ".$this->db->quote($this->obj_id).", ".
192  "field_id = ".$this->db->quote($this->field_id).", ".
193  "value = ".$this->db->quote($this->getValue()).", ".
194  "disabled = ".(int) $this->isDisabled()." ";
195  $res = $this->db->query($query);
196  }
197 
203  private function read()
204  {
205  if(!$this->obj_id or !$this->field_id)
206  {
207  return;
208  }
209 
210  $query = "SELECT * FROM adv_md_values ".
211  "WHERE obj_id = ".$this->db->quote($this->obj_id)." ".
212  "AND field_id = ".$this->db->quote($this->field_id)." ";
213  $res = $this->db->query($query);
214  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
215  {
216  $this->setValue($row->value);
217  $this->toggleDisabledStatus((bool) $row->disabled);
218  }
219  return true;
220  }
221 }
222 ?>