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

Services/MetaData/classes/class.ilMDRelation.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 ilMDRelation extends ilMDBase
00034 {
00035         function ilMDRelation($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
00036         {
00037                 parent::ilMDBase($a_rbac_id,
00038                                                  $a_obj_id,
00039                                                  $a_obj_type);
00040         }
00041 
00042 
00043         // METHODS OF CHILD OBJECTS (Taxon)
00044         function &getIdentifier_Ids()
00045         {
00046                 include_once 'Services/MetaData/classes/class.ilMDIdentifier_.php';
00047 
00048                 return ilMDIdentifier_::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_relation');
00049         }
00050         function &getIdentifier_($a_identifier__id)
00051         {
00052                 include_once 'Services/MetaData/classes/class.ilMDIdentifier_.php';
00053 
00054                 if(!$a_identifier__id)
00055                 {
00056                         return false;
00057                 }
00058                 $ide =& new ilMDIdentifier_();
00059                 $ide->setMetaId($a_identifier__id);
00060 
00061                 return $ide;
00062         }
00063         function &addIdentifier_()
00064         {
00065                 include_once 'Services/MetaData/classes/class.ilMDIdentifier_.php';
00066 
00067                 $ide =& new ilMDIdentifier_($this->getRBACId(),$this->getObjId(),$this->getObjType());
00068                 $ide->setParentId($this->getMetaId());
00069                 $ide->setParentType('meta_relation');
00070 
00071                 return $ide;
00072         }
00073 
00074         function &getDescriptionIds()
00075         {
00076                 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
00077 
00078                 return ilMdDescription::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_relation');
00079         }
00080         function &getDescription($a_description_id)
00081         {
00082                 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
00083                 
00084                 if(!$a_description_id)
00085                 {
00086                         return false;
00087                 }
00088                 $des =& new ilMDDescription();
00089                 $des->setMetaId($a_description_id);
00090 
00091                 return $des;
00092         }
00093         function &addDescription()
00094         {
00095                 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
00096                 
00097                 $des =& new ilMDDescription($this->getRBACId(),$this->getObjId(),$this->getObjType());
00098                 $des->setParentId($this->getMetaId());
00099                 $des->setParentType('meta_relation');
00100 
00101                 return $des;
00102         }
00103         // SET/GET
00104         function setKind($a_kind)
00105         {
00106                 switch($a_kind)
00107                 {
00108                         case 'IsPartOf':
00109                         case 'HasPart':
00110                         case 'IsVersionOf':
00111                         case 'HasVersion':
00112                         case 'IsFormatOf':
00113                         case 'HasFormat':
00114                         case 'References':
00115                         case 'IsReferencedBy':
00116                         case 'IsBasedOn':
00117                         case 'IsBasisFor':
00118                         case 'Requires':
00119                         case 'IsRequiredBy':
00120                                 $this->kind = $a_kind;
00121                                 return true;
00122 
00123                         default:
00124                                 return false;
00125                 }
00126         }
00127         function getKind()
00128         {
00129                 return $this->kind;
00130         }
00131 
00132 
00133         function save()
00134         {
00135                 if($this->db->autoExecute('il_meta_relation',
00136                                                                   $this->__getFields(),
00137                                                                   DB_AUTOQUERY_INSERT))
00138                 {
00139                         $this->setMetaId($this->db->getLastInsertId());
00140 
00141                         return $this->getMetaId();
00142                 }
00143                 return false;
00144         }
00145 
00146         function update()
00147         {
00148                 if($this->getMetaId())
00149                 {
00150                         if($this->db->autoExecute('il_meta_relation',
00151                                                                           $this->__getFields(),
00152                                                                           DB_AUTOQUERY_UPDATE,
00153                                                                           "meta_relation_id = '".$this->getMetaId()."'"))
00154                         {
00155                                 return true;
00156                         }
00157                 }
00158                 return false;
00159         }
00160 
00161         function delete()
00162         {
00163                 if($this->getMetaId())
00164                 {
00165                         $query = "DELETE FROM il_meta_relation ".
00166                                 "WHERE meta_relation_id = '".$this->getMetaId()."'";
00167                         
00168                         $this->db->query($query);
00169 
00170                         foreach($this->getIdentifier_Ids() as $id)
00171                         {
00172                                 $ide = $this->getIdentifier_($id);
00173                                 $ide->delete();
00174                         }
00175                         foreach($this->getDescriptionIds() as $id)
00176                         {
00177                                 $des = $this->getDescription($id);
00178                                 $des->delete();
00179                         }
00180                         
00181                         return true;
00182                 }
00183                 return false;
00184         }
00185                         
00186 
00187         function __getFields()
00188         {
00189                 return array('rbac_id'  => $this->getRBACId(),
00190                                          'obj_id'       => $this->getObjId(),
00191                                          'obj_type'     => $this->getObjType(),
00192                                          'kind'         => $this->getKind());
00193         }
00194 
00195         function read()
00196         {
00197                 if($this->getMetaId())
00198                 {
00199                         $query = "SELECT * FROM il_meta_relation ".
00200                                 "WHERE meta_relation_id = '".$this->getMetaId()."'";
00201 
00202                         $res = $this->db->query($query);
00203                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00204                         {
00205                                 $this->setRBACId($row->rbac_id);
00206                                 $this->setObjId($row->obj_id);
00207                                 $this->setObjType($row->obj_type);
00208                                 $this->setKind($row->kind);
00209                         }
00210                 }
00211                 return true;
00212         }
00213 
00214         /*
00215          * XML Export of all meta data
00216          * @param object (xml writer) see class.ilMD2XML.php
00217          * 
00218          */
00219         function toXML(&$writer)
00220         {
00221                 $writer->xmlStartTag('Relation',array('Kind' => $this->getKind()
00222                                                                                           ? $this->getKind()
00223                                                                                           : 'IsPartOf'));
00224                 $writer->xmlStartTag('Resource');
00225 
00226                 // Identifier_
00227                 $ides = $this->getIdentifier_Ids();
00228                 foreach($ides as $id)
00229                 {
00230                         $ide =& $this->getIdentifier_($id);
00231                         $ide->toXML($writer);
00232                 }
00233                 if(!count($ides))
00234                 {
00235                         include_once 'Services/MetaData/classes/class.ilMDIdentifier_.php';
00236                         $ide = new ilMDIdentifier_($this->getRBACId(),$this->getObjId());
00237                         $ide->toXML($writer);
00238                 }
00239 
00240                 // Description
00241                 $dess = $this->getDescriptionIds();
00242                 foreach($dess as $id)
00243                 {
00244                         $des =& $this->getDescription($id);
00245                         $des->toXML($writer);
00246                 }
00247                 if(!count($dess))
00248                 {
00249                         include_once 'Services/MetaData/classes/class.ilMDDescription.php';
00250                         $des = new ilMDDescription($this->getRBACId(),$this->getObjId());
00251                         $des->toXML($writer);
00252                 }
00253 
00254                 $writer->xmlEndTag('Resource');
00255                 $writer->xmlEndTag('Relation');
00256         }
00257 
00258                                 
00259 
00260         // STATIC
00261         function _getIds($a_rbac_id,$a_obj_id)
00262         {
00263                 global $ilDB;
00264 
00265                 $query = "SELECT meta_relation_id FROM il_meta_relation ".
00266                         "WHERE rbac_id = '".$a_rbac_id."' ".
00267                         "AND obj_id = '".$a_obj_id."' ";
00268 
00269                 $res = $ilDB->query($query);
00270                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00271                 {
00272                         $ids[] = $row->meta_relation_id;
00273                 }
00274                 return $ids ? $ids : array();
00275         }
00276 }
00277 ?>

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