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 ilMDClassification extends ilMDBase
00034 {
00035 function ilMDClassification($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 &getTaxonPathIds()
00044 {
00045 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
00046
00047 return ilMDTaxonPath::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_classification');
00048 }
00049 function &getTaxonPath($a_taxon_path_id)
00050 {
00051 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
00052
00053 if(!$a_taxon_path_id)
00054 {
00055 return false;
00056 }
00057 $tax =& new ilMDTaxonPath();
00058 $tax->setMetaId($a_taxon_path_id);
00059
00060 return $tax;
00061 }
00062 function &addTaxonPath()
00063 {
00064 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
00065
00066 $tax =& new ilMDTaxonPath($this->getRBACId(),$this->getObjId(),$this->getObjType());
00067 $tax->setParentId($this->getMetaId());
00068 $tax->setParentType('meta_classification');
00069
00070 return $tax;
00071 }
00072
00073 function &getKeywordIds()
00074 {
00075 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
00076
00077 return ilMDKeyword::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_classification');
00078 }
00079 function &getKeyword($a_keyword_id)
00080 {
00081 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
00082
00083 if(!$a_keyword_id)
00084 {
00085 return false;
00086 }
00087 $key =& new ilMDKeyword();
00088 $key->setMetaId($a_keyword_id);
00089
00090 return $key;
00091 }
00092 function &addKeyword()
00093 {
00094 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
00095
00096 $key =& new ilMDKeyword($this->getRBACId(),$this->getObjId(),$this->getObjType());
00097 $key->setParentId($this->getMetaId());
00098 $key->setParentType('meta_classification');
00099
00100 return $key;
00101 }
00102
00103
00104 function setPurpose($a_purpose)
00105 {
00106 switch($a_purpose)
00107 {
00108 case 'Discipline':
00109 case 'Idea':
00110 case 'Prerequisite':
00111 case 'EducationalObjective':
00112 case 'AccessibilityRestrictions':
00113 case 'EducationalLevel':
00114 case 'SkillLevel':
00115 case 'SecurityLevel':
00116 case 'Competency':
00117 $this->purpose = $a_purpose;
00118 return true;
00119
00120 default:
00121 return false;
00122 }
00123 }
00124 function getPurpose()
00125 {
00126 return $this->purpose;
00127 }
00128 function setDescription($a_description)
00129 {
00130 $this->description = $a_description;
00131 }
00132 function getDescription()
00133 {
00134 return $this->description;
00135 }
00136 function setDescriptionLanguage(&$lng_obj)
00137 {
00138 if(is_object($lng_obj))
00139 {
00140 $this->description_language = $lng_obj;
00141 }
00142 }
00143 function &getDescriptionLanguage()
00144 {
00145 return is_object($this->description_language) ? $this->description_language : false;
00146 }
00147 function getDescriptionLanguageCode()
00148 {
00149 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
00150 }
00151
00152
00153 function save()
00154 {
00155 if($this->db->autoExecute('il_meta_classification',
00156 $this->__getFields(),
00157 DB_AUTOQUERY_INSERT))
00158 {
00159 $this->setMetaId($this->db->getLastInsertId());
00160
00161 return $this->getMetaId();
00162 }
00163 return false;
00164 }
00165
00166 function update()
00167 {
00168 if($this->getMetaId())
00169 {
00170 if($this->db->autoExecute('il_meta_classification',
00171 $this->__getFields(),
00172 DB_AUTOQUERY_UPDATE,
00173 "meta_classification_id = '".$this->getMetaId()."'"))
00174 {
00175 return true;
00176 }
00177 }
00178 return false;
00179 }
00180
00181 function delete()
00182 {
00183 if($this->getMetaId())
00184 {
00185 $query = "DELETE FROM il_meta_classification ".
00186 "WHERE meta_classification_id = '".$this->getMetaId()."'";
00187
00188 $this->db->query($query);
00189
00190 foreach($this->getTaxonPathIds() as $id)
00191 {
00192 $tax = $this->getTaxonPath($id);
00193 $tax->delete();
00194 }
00195 foreach($this->getKeywordIds() as $id)
00196 {
00197 $key = $this->getKeyword($id);
00198 $key->delete();
00199 }
00200
00201 return true;
00202 }
00203 return false;
00204 }
00205
00206
00207 function __getFields()
00208 {
00209 return array('rbac_id' => $this->getRBACId(),
00210 'obj_id' => $this->getObjId(),
00211 'obj_type' => $this->getObjType(),
00212 'purpose' => $this->getPurpose(),
00213 'description' => $this->getDescription(),
00214 'description_language' => $this->getDescriptionLanguageCode());
00215 }
00216
00217 function read()
00218 {
00219 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00220
00221 if($this->getMetaId())
00222 {
00223 $query = "SELECT * FROM il_meta_classification ".
00224 "WHERE meta_classification_id = '".$this->getMetaId()."'";
00225
00226 $res = $this->db->query($query);
00227 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00228 {
00229 $this->setRBACId($row->rbac_id);
00230 $this->setObjId($row->obj_id);
00231 $this->setObjType($row->obj_type);
00232 $this->setPurpose($row->purpose);
00233 $this->setDescription($row->description);
00234 $this->description_language = new ilMDLanguageItem($row->description_language);
00235 }
00236 }
00237 return true;
00238 }
00239
00240
00241
00242
00243
00244
00245 function toXML(&$writer)
00246 {
00247 $writer->xmlStartTag('Classification',array('Purpose' => $this->getPurpose()
00248 ? $this->getPurpose()
00249 : 'Idea'));
00250
00251
00252 $taxs = $this->getTaxonPathIds();
00253 foreach($taxs as $id)
00254 {
00255 $tax =& $this->getTaxonPath($id);
00256 $tax->toXML($writer);
00257 }
00258 if(!count($taxs))
00259 {
00260 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
00261 $tax = new ilMDTaxonPath($this->getRBACId(),$this->getObjId());
00262 $tax->toXML($writer);
00263 }
00264
00265
00266 $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()
00267 ? $this->getDescriptionLanguageCode()
00268 : 'en'),
00269 $this->getDescription());
00270
00271
00272 $keys = $this->getKeywordIds();
00273 foreach($keys as $id)
00274 {
00275 $key =& $this->getKeyword($id);
00276 $key->toXML($writer);
00277 }
00278 if(!count($keys))
00279 {
00280 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
00281 $key = new ilMDKeyword($this->getRBACId(),$this->getObjId());
00282 $key->toXML($writer);
00283 }
00284 $writer->xmlEndTag('Classification');
00285 }
00286
00287
00288
00289
00290 function _getIds($a_rbac_id,$a_obj_id)
00291 {
00292 global $ilDB;
00293
00294 $query = "SELECT meta_classification_id FROM il_meta_classification ".
00295 "WHERE rbac_id = '".$a_rbac_id."' ".
00296 "AND obj_id = '".$a_obj_id."'";
00297
00298
00299 $res = $ilDB->query($query);
00300 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00301 {
00302 $ids[] = $row->meta_classification_id;
00303 }
00304 return $ids ? $ids : array();
00305 }
00306 }
00307 ?>