Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 include_once 'class.ilMDBase.php';
00032
00033 class ilMDTaxonPath extends ilMDBase
00034 {
00035 function ilMDTaxonPath($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 function &getTaxonIds()
00044 {
00045 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
00046
00047 return ilMDTaxon::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_taxon_path');
00048 }
00049 function &getTaxon($a_taxon_id)
00050 {
00051 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
00052
00053 if(!$a_taxon_id)
00054 {
00055 return false;
00056 }
00057 $tax =& new ilMDTaxon();
00058 $tax->setMetaId($a_taxon_id);
00059
00060 return $tax;
00061 }
00062 function &addTaxon()
00063 {
00064 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
00065
00066 $tax =& new ilMDTaxon($this->getRBACId(),$this->getObjId(),$this->getObjType());
00067 $tax->setParentId($this->getMetaId());
00068 $tax->setParentType('meta_taxon_path');
00069
00070 return $tax;
00071 }
00072
00073
00074 function setSource($a_source)
00075 {
00076 $this->source = $a_source;
00077 }
00078 function getSource()
00079 {
00080 return $this->source;
00081 }
00082 function setSourceLanguage(&$lng_obj)
00083 {
00084 if(is_object($lng_obj))
00085 {
00086 $this->source_language = $lng_obj;
00087 }
00088 }
00089 function &getSourceLanguage()
00090 {
00091 return is_object($this->source_language) ? $this->source_language : false;
00092 }
00093 function getSourceLanguageCode()
00094 {
00095 return is_object($this->source_language) ? $this->source_language->getLanguageCode() : false;
00096 }
00097
00098
00099 function save()
00100 {
00101 if($this->db->autoExecute('il_meta_taxon_path',
00102 $this->__getFields(),
00103 DB_AUTOQUERY_INSERT))
00104 {
00105 $this->setMetaId($this->db->getLastInsertId());
00106
00107 return $this->getMetaId();
00108 }
00109 return false;
00110 }
00111
00112 function update()
00113 {
00114 if($this->getMetaId())
00115 {
00116 if($this->db->autoExecute('il_meta_taxon_path',
00117 $this->__getFields(),
00118 DB_AUTOQUERY_UPDATE,
00119 "meta_taxon_path_id = '".$this->getMetaId()."'"))
00120 {
00121 return true;
00122 }
00123 }
00124 return false;
00125 }
00126
00127 function delete()
00128 {
00129 if($this->getMetaId())
00130 {
00131 $query = "DELETE FROM il_meta_taxon_path ".
00132 "WHERE meta_taxon_path_id = '".$this->getMetaId()."'";
00133
00134 $this->db->query($query);
00135
00136 foreach($this->getTaxonIds() as $id)
00137 {
00138 $tax = $this->getTaxon($id);
00139 $tax->delete();
00140 }
00141
00142 return true;
00143 }
00144 return false;
00145 }
00146
00147
00148 function __getFields()
00149 {
00150 return array('rbac_id' => $this->getRBACId(),
00151 'obj_id' => $this->getObjId(),
00152 'obj_type' => $this->getObjType(),
00153 'parent_type' => $this->getParentType(),
00154 'parent_id' => $this->getParentId(),
00155 'source' => $this->getSource(),
00156 'source_language' => $this->getSourceLanguageCode());
00157 }
00158
00159 function read()
00160 {
00161 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00162
00163 if($this->getMetaId())
00164 {
00165 $query = "SELECT * FROM il_meta_taxon_path ".
00166 "WHERE meta_taxon_path_id = '".$this->getMetaId()."'";
00167
00168 $res = $this->db->query($query);
00169 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00170 {
00171 $this->setRBACId($row->rbac_id);
00172 $this->setObjId($row->obj_id);
00173 $this->setObjType($row->obj_type);
00174 $this->setParentId($row->parent_id);
00175 $this->setParentType($row->parent_type);
00176 $this->setSource($row->source);
00177 $this->source_language = new ilMDLanguageItem($row->source_language);
00178 }
00179 }
00180 return true;
00181 }
00182
00183
00184
00185
00186
00187
00188 function toXML(&$writer)
00189 {
00190 $writer->xmlStartTag('TaxonPath');
00191
00192 $writer->xmlElement('Source',array('Language' => $this->getSourceLanguageCode()
00193 ? $this->getSourceLanguageCode()
00194 : 'en'),
00195 $this->getSource());
00196
00197
00198 $taxs = $this->getTaxonIds();
00199 foreach($taxs as $id)
00200 {
00201 $tax =& $this->getTaxon($id);
00202 $tax->toXML($writer);
00203 }
00204 if(!count($taxs))
00205 {
00206 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
00207 $tax = new ilMDTaxon($this->getRBACId(),$this->getObjId());
00208 $tax->toXML($writer);
00209 }
00210
00211 $writer->xmlEndTag('TaxonPath');
00212 }
00213
00214
00215
00216
00217 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
00218 {
00219 global $ilDB;
00220
00221 $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path ".
00222 "WHERE rbac_id = '".$a_rbac_id."' ".
00223 "AND obj_id = '".$a_obj_id."' ".
00224 "AND parent_id = '".$a_parent_id."' ".
00225 "AND parent_type = '".$a_parent_type."'";
00226
00227 $res = $ilDB->query($query);
00228 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00229 {
00230 $ids[] = $row->meta_taxon_path_id;
00231 }
00232 return $ids ? $ids : array();
00233 }
00234 }
00235 ?>