ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDValues.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 $cached_values = array();
36 
46  public static function _getValuesByObjId($a_obj_id)
47  {
48  global $ilDB;
49 
50  if(isset(self::$cached_values[$a_obj_id]))
51  {
52  return self::$cached_values[$a_obj_id];
53  }
54  $query = "SELECT field_id,value FROM adv_md_values ".
55  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
56  $res = $ilDB->query($query);
57 
58  self::$cached_values[$a_obj_id] = array();
59  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
60  {
61  self::$cached_values[$a_obj_id][$row->field_id] = $row->value;
62  }
63  return self::$cached_values[$a_obj_id];
64  }
65 
75  public static function _cloneValues($a_source_id,$a_target_id)
76  {
77  global $ilLog;
78 
79  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
80  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
81 
82 
84  {
85  $ilLog->write(__METHOD__.': No advanced meta data found.');
86  return true;
87  }
88 
89  $ilLog->write(__METHOD__.': Start cloning advanced meta data.');
90 
91  foreach(self::_getValuesByObjId($a_source_id) as $field_id => $value)
92  {
93  if(!in_array($field_id,$defs))
94  {
95  continue;
96  }
97  $new_value = new ilAdvancedMDValue($field_id,$a_target_id);
98  $new_value->setValue($value);
99  $new_value->save();
100 
101  }
102  return true;
103  }
104 
113  public static function _appendXMLByObjId(ilXmlWriter $xml_writer,$a_obj_id)
114  {
115  global $ilDB;
116 
117  $type = ilObject::_lookupType($a_obj_id);
118 
119  // Get active field_definitions
120  $query = "SELECT field_id FROM adv_md_record amr ".
121  "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id ".
122  "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id ".
123  "WHERE active = 1 ".
124  "AND obj_type = ".$ilDB->quote($type ,'text')." ";
125 
126  $xml_writer->xmlStartTag('AdvancedMetaData');
127 
128  $res = $ilDB->query($query);
129  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
130  {
131  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
132  $value = ilAdvancedMDValue::_getInstance($a_obj_id,$row->field_id);
133  $value->appendXML($xml_writer);
134  }
135  $xml_writer->xmlEndTag('AdvancedMetaData');
136  }
137 
146  public static function _preloadValuesByObjIds($obj_ids)
147  {
148  global $ilDB;
149 
150  $query = "SELECT obj_id,field_id,value FROM adv_md_values ".
151  "WHERE ".$ilDB->in('obj_id',$obj_ids,false,'integer');
152 
153  $res = $ilDB->query($query);
154  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
155  {
156  self::$cached_values[$row->obj_id][$row->field_id] = $row->value;
157  }
158  return true;
159  }
160 
170  public static function _deleteByFieldId($a_field_id)
171  {
172  global $ilDB;
173 
174  $query = "DELETE FROM adv_md_values ".
175  "WHERE field_id = ".$ilDB->quote($a_field_id ,'integer')." ";
176  $res = $ilDB->manipulate($query);
177  }
178 
187  public static function _deleteByObjId($a_obj_id)
188  {
189  global $ilDB;
190 
191  $query = "DELETE FROM adv_md_values ".
192  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
193  $res = $ilDB->manipulate($query);
194  }
195 }
196 ?>