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

Services/MetaData/classes/class.ilMDMetaMetadata.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 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 
00024 
00031 include_once 'class.ilMDBase.php';
00032 
00033 class ilMDMetaMetadata extends ilMDBase
00034 {
00035 
00036         function ilMDMetaMetadata($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
00037         {
00038                 parent::ilMDBase($a_rbac_id,
00039                                                  $a_obj_id,
00040                                                  $a_obj_type);
00041         }
00042 
00043         function getPossibleSubelements()
00044         {
00045                 $subs['Identifier'] = 'meta_identifier';
00046                 $subs['Contribute'] = 'meta_contribute';
00047 
00048                 return $subs;
00049         }
00050 
00051 
00052         // SUBELEMENTS
00053         function &getIdentifierIds()
00054         {
00055                 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
00056 
00057                 return ilMDIdentifier::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
00058         }
00059         function &getIdentifier($a_identifier_id)
00060         {
00061                 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
00062                 
00063                 if(!$a_identifier_id)
00064                 {
00065                         return false;
00066                 }
00067                 $ide =& new ilMDIdentifier();
00068                 $ide->setMetaId($a_identifier_id);
00069 
00070                 return $ide;
00071         }
00072         function &addIdentifier()
00073         {
00074                 include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
00075 
00076                 $ide =& new ilMDIdentifier($this->getRBACId(),$this->getObjId(),$this->getObjType());
00077                 $ide->setParentId($this->getMetaId());
00078                 $ide->setParentType('meta_meta_data');
00079 
00080                 return $ide;
00081         }
00082         
00083         function &getContributeIds()
00084         {
00085                 include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00086 
00087                 return ilMDContribute::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
00088         }
00089         function &getContribute($a_contribute_id)
00090         {
00091                 include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00092                 
00093                 if(!$a_contribute_id)
00094                 {
00095                         return false;
00096                 }
00097                 $con =& new ilMDContribute();
00098                 $con->setMetaId($a_contribute_id);
00099 
00100                 return $con;
00101         }
00102         function &addContribute()
00103         {
00104                 include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00105 
00106                 $con =& new ilMDContribute($this->getRBACId(),$this->getObjId(),$this->getObjType());
00107                 $con->setParentId($this->getMetaId());
00108                 $con->setParentType('meta_meta_data');
00109 
00110                 return $con;
00111         }
00112 
00113 
00114 
00115         // SET/GET
00116         function setMetaDataScheme($a_val)
00117         {
00118                 $this->meta_data_scheme = $a_val;
00119         }
00120         function getMetaDataScheme()
00121         {
00122                 // Fixed attribute
00123                 return 'LOM v 1.0';
00124         }
00125         function setLanguage(&$lng_obj)
00126         {
00127                 if(is_object($lng_obj))
00128                 {
00129                         $this->language = $lng_obj;
00130                 }
00131         }
00132         function &getLanguage()
00133         {
00134                 return is_object($this->language) ? $this->language : false;
00135         }
00136         function getLanguageCode()
00137         {
00138                 return is_object($this->language) ? $this->language->getLanguageCode() : false;
00139         }
00140         
00141 
00142         function save()
00143         {
00144                 if($this->db->autoExecute('il_meta_meta_data',
00145                                                                   $this->__getFields(),
00146                                                                   DB_AUTOQUERY_INSERT))
00147                 {
00148                         $this->setMetaId($this->db->getLastInsertId());
00149 
00150                         return $this->getMetaId();
00151                 }
00152                 return false;
00153         }
00154 
00155         function update()
00156         {
00157                 if($this->getMetaId())
00158                 {
00159                         if($this->db->autoExecute('il_meta_meta_data',
00160                                                                           $this->__getFields(),
00161                                                                           DB_AUTOQUERY_UPDATE,
00162                                                                           "meta_meta_data_id = '".$this->getMetaId()."'"))
00163                         {
00164                                 return true;
00165                         }
00166                 }
00167                 return false;
00168         }
00169 
00170         function delete()
00171         {
00172                 if($this->getMetaId())
00173                 {
00174                         $query = "DELETE FROM il_meta_meta_data ".
00175                                 "WHERE meta_meta_data_id = '".$this->getMetaId()."'";
00176                         
00177                         $this->db->query($query);
00178                         
00179 
00180                         foreach($this->getIdentifierIds() as $id)
00181                         {
00182                                 $ide = $this->getIdentifier($id);
00183                                 $ide->delete();
00184                         }
00185                 
00186                         foreach($this->getContributeIds() as $id)
00187                         {
00188                                 $con = $this->getContribute($id);
00189                                 $con->delete();
00190                         }
00191                         return true;
00192                 }
00193 
00194                 return false;
00195         }
00196                         
00197 
00198         function __getFields()
00199         {
00200                 return array('rbac_id'  => $this->getRBACId(),
00201                                          'obj_id'       => $this->getObjId(),
00202                                          'obj_type'     => ilUtil::prepareDBString($this->getObjType()),
00203                                          'meta_data_scheme'     => $this->getMetaDataScheme(),
00204                                          'language' => $this->getLanguageCode());
00205         }
00206 
00207         function read()
00208         {
00209                 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00210 
00211 
00212                 if($this->getMetaId())
00213                 {
00214 
00215                         $query = "SELECT * FROM il_meta_meta_data ".
00216                                 "WHERE meta_meta_data_id = '".$this->getMetaId()."'";
00217 
00218                 
00219                         $res = $this->db->query($query);
00220                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00221                         {
00222                                 $this->setRBACId($row->rbac_id);
00223                                 $this->setObjId($row->obj_id);
00224                                 $this->setObjType($row->obj_type);
00225                                 $this->setMetaDataScheme($row->meta_data_scheme);
00226                                 $this->setLanguage(new ilMDLanguageItem($row->language));
00227                         }
00228                         return true;
00229                 }
00230                 return false;
00231         }
00232                                 
00233         /*
00234          * XML Export of all meta data
00235          * @param object (xml writer) see class.ilMD2XML.php
00236          * 
00237          */
00238         function toXML(&$writer)
00239         {
00240                 if($this->getMetaDataScheme())
00241                 {
00242                         $attr['MetadataScheme'] = $this->getMetaDataScheme();
00243                 }
00244                 if($this->getLanguageCode())
00245                 {
00246                         $attr['Language'] = $this->getLanguageCode();
00247                 }
00248                 $writer->xmlStartTag('Meta-Metadata',$attr ? $attr : null);
00249 
00250                 // ELEMENT IDENTIFIER
00251                 $identifiers = $this->getIdentifierIds();
00252                 foreach($identifiers as $id)
00253                 {
00254                         $ide =& $this->getIdentifier($id);
00255                         $ide->toXML($writer);
00256                 }
00257                 if(!count($identifiers))
00258                 {
00259                         include_once 'Services/Metadata/classes/class.ilMDIdentifier.php';
00260                         $ide = new ilMDIdentifier($this->getRBACId(),$this->getObjId());
00261                         $ide->toXML($writer);
00262                 }
00263                 
00264                 // ELEMETN Contribute
00265                 $contributes = $this->getContributeIds();
00266                 foreach($contributes as $id)
00267                 {
00268                         $con =& $this->getContribute($id);
00269                         $con->toXML($writer);
00270                 }
00271                 if(!count($contributes))
00272                 {
00273                         include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00274                         $con = new ilMDContribute($this->getRBACId(),$this->getObjId());
00275                         $con->toXML($writer);
00276                 }
00277 
00278                 $writer->xmlEndTag('Meta-Metadata');
00279         }
00280 
00281         // STATIC
00282         function _getId($a_rbac_id,$a_obj_id)
00283         {
00284                 global $ilDB;
00285 
00286                 $query = "SELECT meta_meta_data_id FROM il_meta_meta_data ".
00287                         "WHERE rbac_id = '".$a_rbac_id."' ".
00288                         "AND obj_id = '".$a_obj_id."'";
00289 
00290                 $res = $ilDB->query($query);
00291                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00292                 {
00293                         return $row->meta_meta_data_id;
00294                 }
00295                 return false;
00296         }
00297 }
00298 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1