ILIAS  Release_4_0_x_branch Revision 61816
 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  global $ilDB;
177 
178  $query = "DELETE FROM adv_md_values ".
179  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ".
180  "AND field_id = ".$this->db->quote($this->field_id ,'integer');
181  $res = $ilDB->manipulate($query);
182  }
183 
190  public function save()
191  {
192  global $ilDB;
193 
194  $this->delete();
195 
196  $query = "INSERT INTO adv_md_values (obj_id,field_id,value,disabled) ".
197  "VALUES( ".
198  $this->db->quote($this->obj_id ,'integer').", ".
199  $this->db->quote($this->field_id ,'integer').", ".
200  $this->db->quote($this->getValue() ,'text').", ".
201  $ilDB->quote($this->isDisabled(),'integer')." ".
202  ")";
203  $res = $ilDB->manipulate($query);
204  }
205 
211  private function read()
212  {
213  global $ilDB;
214 
215  if(!$this->obj_id or !$this->field_id)
216  {
217  return;
218  }
219 
220  $query = "SELECT * FROM adv_md_values ".
221  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ".
222  "AND field_id = ".$this->db->quote($this->field_id ,'integer')." ";
223  $res = $this->db->query($query);
224  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
225  {
226  $this->setValue($row->value);
227  $this->toggleDisabledStatus((bool) $row->disabled);
228  }
229  return true;
230  }
231 }
232 ?>