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

Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.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 ilAdvancedMDValues
00034 {
00035         private static $cached_values = array();
00036 
00046         public static function _getValuesByObjId($a_obj_id)
00047         {
00048                 global $ilDB;
00049                 
00050                 if(isset(self::$cached_values[$a_obj_id]))
00051                 {
00052                         return self::$cached_values[$a_obj_id];
00053                 }
00054                 $query = "SELECT field_id,value FROM adv_md_values ".
00055                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00056                 $res = $ilDB->query($query);
00057                 
00058                 self::$cached_values[$a_obj_id] = array();
00059                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00060                 {
00061                         self::$cached_values[$a_obj_id][$row->field_id] = $row->value;
00062                 }
00063                 return self::$cached_values[$a_obj_id];
00064         }
00065         
00075         public static function _cloneValues($a_source_id,$a_target_id)
00076         {
00077                 global $ilLog;
00078                 
00079                 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00080                 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
00081                 
00082                 
00083                 if(!count($defs = ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType(ilObject::_lookupType($a_source_id))))
00084                 {
00085                         $ilLog->write(__METHOD__.': No advanced meta data found.');
00086                         return true;
00087                 }
00088                 
00089                 $ilLog->write(__METHOD__.': Start cloning advanced meta data.');
00090                 
00091                 foreach(self::_getValuesByObjId($a_source_id) as $field_id => $value)
00092                 {
00093                         if(!in_array($field_id,$defs))
00094                         {
00095                                 continue;
00096                         }
00097                         $new_value = new ilAdvancedMDValue($field_id,$a_target_id);
00098                         $new_value->setValue($value);
00099                         $new_value->save();
00100                         
00101                 }
00102                 return true;            
00103         }
00104         
00113         public static function _appendXMLByObjId(ilXmlWriter $xml_writer,$a_obj_id)
00114         {
00115                 global $ilDB;
00116                 
00117                 $type = ilObject::_lookupType($a_obj_id);
00118 
00119                 // Get active field_definitions
00120                 $query = "SELECT field_id FROM adv_md_record AS amr ".
00121                         "JOIN adv_md_record_objs AS amro ON amr.record_id = amro.record_id ".
00122                         "JOIN adv_md_field_definition AS amfd ON amr.record_id = amfd.record_id ".
00123                         "WHERE active = 1 ".
00124                         "AND obj_type = ".$ilDB->quote($type)." ";
00125                         
00126                 $xml_writer->xmlStartTag('AdvancedMetaData');   
00127                 
00128                 $res = $ilDB->query($query);
00129                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00130                 {
00131                         include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
00132                         $value = ilAdvancedMDValue::_getInstance($a_obj_id,$row->field_id);
00133                         $value->appendXML($xml_writer);
00134                 }
00135                 $xml_writer->xmlEndTag('AdvancedMetaData');     
00136         }
00137         
00146         public static function _preloadValuesByObjIds($obj_ids)
00147         {
00148                 global $ilDB;
00149                 
00150                 $query = "SELECT obj_id,field_id,value FROM adv_md_values ".
00151                         "WHERE obj_id IN (".implode("','",$obj_ids).")";
00152                 $res = $ilDB->query($query);
00153                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00154                 {
00155                         self::$cached_values[$row->obj_id][$row->field_id] = $row->value;
00156                 }
00157                 return true;
00158         }
00159         
00169         public static function _deleteByFieldId($a_field_id)
00170         {
00171                 global $ilDB;
00172                 
00173                 $query = "DELETE FROM adv_md_values ".
00174                         "WHERE field_id = ".$ilDB->quote($a_field_id)." ";
00175                 $ilDB->query($query);   
00176         }
00177         
00186         public static function _deleteByObjId($a_obj_id)
00187         {
00188                 global $ilDB;
00189                 
00190                 $query = "DELETE FROM adv_md_values ".
00191                         "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ";
00192                 $ilDB->query($query);
00193         }
00194 }
00195 ?>

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