ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMDClassification.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
31include_once 'class.ilMDBase.php';
32
34{
35 function ilMDClassification($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
36 {
37 parent::ilMDBase($a_rbac_id,
38 $a_obj_id,
39 $a_obj_type);
40 }
41
42 // METHODS OF CLIENT OBJECTS (TaxonPath, Keyword)
43 function &getTaxonPathIds()
44 {
45 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
46
47 return ilMDTaxonPath::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_classification');
48 }
49 function &getTaxonPath($a_taxon_path_id)
50 {
51 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
52
53 if(!$a_taxon_path_id)
54 {
55 return false;
56 }
57 $tax =& new ilMDTaxonPath();
58 $tax->setMetaId($a_taxon_path_id);
59
60 return $tax;
61 }
62 function &addTaxonPath()
63 {
64 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
65
66 $tax =& new ilMDTaxonPath($this->getRBACId(),$this->getObjId(),$this->getObjType());
67 $tax->setParentId($this->getMetaId());
68 $tax->setParentType('meta_classification');
69
70 return $tax;
71 }
72
73 function &getKeywordIds()
74 {
75 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
76
77 return ilMDKeyword::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_classification');
78 }
79 function &getKeyword($a_keyword_id)
80 {
81 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
82
83 if(!$a_keyword_id)
84 {
85 return false;
86 }
87 $key =& new ilMDKeyword();
88 $key->setMetaId($a_keyword_id);
89
90 return $key;
91 }
92 function &addKeyword()
93 {
94 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
95
96 $key =& new ilMDKeyword($this->getRBACId(),$this->getObjId(),$this->getObjType());
97 $key->setParentId($this->getMetaId());
98 $key->setParentType('meta_classification');
99
100 return $key;
101 }
102
103 // SET/GET
104 function setPurpose($a_purpose)
105 {
106 switch($a_purpose)
107 {
108 case 'Discipline':
109 case 'Idea':
110 case 'Prerequisite':
111 case 'EducationalObjective':
112 case 'AccessibilityRestrictions':
113 case 'EducationalLevel':
114 case 'SkillLevel':
115 case 'SecurityLevel':
116 case 'Competency':
117 $this->purpose = $a_purpose;
118 return true;
119
120 default:
121 return false;
122 }
123 }
124 function getPurpose()
125 {
126 return $this->purpose;
127 }
128 function setDescription($a_description)
129 {
130 $this->description = $a_description;
131 }
132 function getDescription()
133 {
134 return $this->description;
135 }
136 function setDescriptionLanguage(&$lng_obj)
137 {
138 if(is_object($lng_obj))
139 {
140 $this->description_language = $lng_obj;
141 }
142 }
144 {
145 return is_object($this->description_language) ? $this->description_language : false;
146 }
148 {
149 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
150 }
151
152
153 function save()
154 {
155 global $ilDB;
156
157 $fields = $this->__getFields();
158 $fields['meta_classification_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_classification'));
159
160 if($this->db->insert('il_meta_classification',$fields))
161 {
162 $this->setMetaId($next_id);
163 return $this->getMetaId();
164 }
165 return false;
166 }
167
168 function update()
169 {
170 global $ilDB;
171
172 if($this->getMetaId())
173 {
174 if($this->db->update('il_meta_classification',
175 $this->__getFields(),
176 array("meta_classification_id" => array('integer',$this->getMetaId()))))
177 {
178 return true;
179 }
180 }
181 return false;
182 }
183
184 function delete()
185 {
186 global $ilDB;
187
188 if($this->getMetaId())
189 {
190 $query = "DELETE FROM il_meta_classification ".
191 "WHERE meta_classification_id = ".$ilDB->quote($this->getMetaId() ,'integer');
192 $res = $ilDB->manipulate($query);
193
194 foreach($this->getTaxonPathIds() as $id)
195 {
196 $tax = $this->getTaxonPath($id);
197 $tax->delete();
198 }
199 foreach($this->getKeywordIds() as $id)
200 {
201 $key = $this->getKeyword($id);
202 $key->delete();
203 }
204
205 return true;
206 }
207 return false;
208 }
209
210
211 function __getFields()
212 {
213 return array('rbac_id' => array('integer',$this->getRBACId()),
214 'obj_id' => array('integer',$this->getObjId()),
215 'obj_type' => array('text',$this->getObjType()),
216 'purpose' => array('text',$this->getPurpose()),
217 'description' => array('text',$this->getDescription()),
218 'description_language' => array('text',$this->getDescriptionLanguageCode()));
219 }
220
221 function read()
222 {
223 global $ilDB;
224
225 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
226
227 if($this->getMetaId())
228 {
229 $query = "SELECT * FROM il_meta_classification ".
230 "WHERE meta_classification_id = ".$ilDB->quote($this->getMetaId() ,'integer');
231
232 $res = $this->db->query($query);
233 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
234 {
235 $this->setRBACId($row->rbac_id);
236 $this->setObjId($row->obj_id);
237 $this->setObjType($row->obj_type);
238 $this->setPurpose($row->purpose);
239 $this->setDescription($row->description);
240 $this->description_language = new ilMDLanguageItem($row->description_language);
241 }
242 }
243 return true;
244 }
245
246 /*
247 * XML Export of all meta data
248 * @param object (xml writer) see class.ilMD2XML.php
249 *
250 */
251 function toXML(&$writer)
252 {
253 $writer->xmlStartTag('Classification',array('Purpose' => $this->getPurpose()
254 ? $this->getPurpose()
255 : 'Idea'));
256
257 // Taxon Path
258 $taxs = $this->getTaxonPathIds();
259 foreach($taxs as $id)
260 {
261 $tax =& $this->getTaxonPath($id);
262 $tax->toXML($writer);
263 }
264 if(!count($taxs))
265 {
266 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
267 $tax = new ilMDTaxonPath($this->getRBACId(),$this->getObjId());
268 $tax->toXML($writer);
269 }
270
271 // Description
272 $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()
274 : 'en'),
275 $this->getDescription());
276
277 // Keyword
278 $keys = $this->getKeywordIds();
279 foreach($keys as $id)
280 {
281 $key =& $this->getKeyword($id);
282 $key->toXML($writer);
283 }
284 if(!count($keys))
285 {
286 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
287 $key = new ilMDKeyword($this->getRBACId(),$this->getObjId());
288 $key->toXML($writer);
289 }
290 $writer->xmlEndTag('Classification');
291 }
292
293
294
295 // STATIC
296 function _getIds($a_rbac_id,$a_obj_id)
297 {
298 global $ilDB;
299
300 $query = "SELECT meta_classification_id FROM il_meta_classification ".
301 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
302 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
303
304
305 $res = $ilDB->query($query);
306 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
307 {
308 $ids[] = $row->meta_classification_id;
309 }
310 return $ids ? $ids : array();
311 }
312}
313?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setObjId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
& getTaxonPath($a_taxon_path_id)
ilMDClassification($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
_getIds($a_rbac_id, $a_obj_id)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
global $ilDB