ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 // METHODS OF CLIENT OBJECTS (TaxonPath, Keyword)
36 function &getTaxonPathIds()
37 {
38 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
39
40 return ilMDTaxonPath::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_classification');
41 }
42 function &getTaxonPath($a_taxon_path_id)
43 {
44 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
45
46 if(!$a_taxon_path_id)
47 {
48 return false;
49 }
50 $tax = new ilMDTaxonPath();
51 $tax->setMetaId($a_taxon_path_id);
52
53 return $tax;
54 }
55 function &addTaxonPath()
56 {
57 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
58
59 $tax = new ilMDTaxonPath($this->getRBACId(),$this->getObjId(),$this->getObjType());
60 $tax->setParentId($this->getMetaId());
61 $tax->setParentType('meta_classification');
62
63 return $tax;
64 }
65
66 function &getKeywordIds()
67 {
68 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
69
70 return ilMDKeyword::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_classification');
71 }
72 function &getKeyword($a_keyword_id)
73 {
74 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
75
76 if(!$a_keyword_id)
77 {
78 return false;
79 }
80 $key = new ilMDKeyword();
81 $key->setMetaId($a_keyword_id);
82
83 return $key;
84 }
85 function &addKeyword()
86 {
87 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
88
89 $key = new ilMDKeyword($this->getRBACId(),$this->getObjId(),$this->getObjType());
90 $key->setParentId($this->getMetaId());
91 $key->setParentType('meta_classification');
92
93 return $key;
94 }
95
96 // SET/GET
97 function setPurpose($a_purpose)
98 {
99 switch($a_purpose)
100 {
101 case 'Discipline':
102 case 'Idea':
103 case 'Prerequisite':
104 case 'EducationalObjective':
105 case 'AccessibilityRestrictions':
106 case 'EducationalLevel':
107 case 'SkillLevel':
108 case 'SecurityLevel':
109 case 'Competency':
110 $this->purpose = $a_purpose;
111 return true;
112
113 default:
114 return false;
115 }
116 }
117 function getPurpose()
118 {
119 return $this->purpose;
120 }
121 function setDescription($a_description)
122 {
123 $this->description = $a_description;
124 }
125 function getDescription()
126 {
127 return $this->description;
128 }
129 function setDescriptionLanguage(&$lng_obj)
130 {
131 if(is_object($lng_obj))
132 {
133 $this->description_language = $lng_obj;
134 }
135 }
137 {
138 return is_object($this->description_language) ? $this->description_language : false;
139 }
141 {
142 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
143 }
144
145
146 function save()
147 {
148 global $ilDB;
149
150 $fields = $this->__getFields();
151 $fields['meta_classification_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_classification'));
152
153 if($this->db->insert('il_meta_classification',$fields))
154 {
155 $this->setMetaId($next_id);
156 return $this->getMetaId();
157 }
158 return false;
159 }
160
161 function update()
162 {
163 global $ilDB;
164
165 if($this->getMetaId())
166 {
167 if($this->db->update('il_meta_classification',
168 $this->__getFields(),
169 array("meta_classification_id" => array('integer',$this->getMetaId()))))
170 {
171 return true;
172 }
173 }
174 return false;
175 }
176
177 function delete()
178 {
179 global $ilDB;
180
181 if($this->getMetaId())
182 {
183 $query = "DELETE FROM il_meta_classification ".
184 "WHERE meta_classification_id = ".$ilDB->quote($this->getMetaId() ,'integer');
185 $res = $ilDB->manipulate($query);
186
187 foreach($this->getTaxonPathIds() as $id)
188 {
189 $tax = $this->getTaxonPath($id);
190 $tax->delete();
191 }
192 foreach($this->getKeywordIds() as $id)
193 {
194 $key = $this->getKeyword($id);
195 $key->delete();
196 }
197
198 return true;
199 }
200 return false;
201 }
202
203
204 function __getFields()
205 {
206 return array('rbac_id' => array('integer',$this->getRBACId()),
207 'obj_id' => array('integer',$this->getObjId()),
208 'obj_type' => array('text',$this->getObjType()),
209 'purpose' => array('text',$this->getPurpose()),
210 'description' => array('text',$this->getDescription()),
211 'description_language' => array('text',$this->getDescriptionLanguageCode()));
212 }
213
214 function read()
215 {
216 global $ilDB;
217
218 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
219
220 if($this->getMetaId())
221 {
222 $query = "SELECT * FROM il_meta_classification ".
223 "WHERE meta_classification_id = ".$ilDB->quote($this->getMetaId() ,'integer');
224
225 $res = $this->db->query($query);
226 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
227 {
228 $this->setRBACId($row->rbac_id);
229 $this->setObjId($row->obj_id);
230 $this->setObjType($row->obj_type);
231 $this->setPurpose($row->purpose);
232 $this->setDescription($row->description);
233 $this->description_language = new ilMDLanguageItem($row->description_language);
234 }
235 }
236 return true;
237 }
238
239 /*
240 * XML Export of all meta data
241 * @param object (xml writer) see class.ilMD2XML.php
242 *
243 */
244 function toXML(&$writer)
245 {
246 $writer->xmlStartTag('Classification',array('Purpose' => $this->getPurpose()
247 ? $this->getPurpose()
248 : 'Idea'));
249
250 // Taxon Path
251 $taxs = $this->getTaxonPathIds();
252 foreach($taxs as $id)
253 {
254 $tax =& $this->getTaxonPath($id);
255 $tax->toXML($writer);
256 }
257 if(!count($taxs))
258 {
259 include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
260 $tax = new ilMDTaxonPath($this->getRBACId(),$this->getObjId());
261 $tax->toXML($writer);
262 }
263
264 // Description
265 $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()
267 : 'en'),
268 $this->getDescription());
269
270 // Keyword
271 $keys = $this->getKeywordIds();
272 foreach($keys as $id)
273 {
274 $key =& $this->getKeyword($id);
275 $key->toXML($writer);
276 }
277 if(!count($keys))
278 {
279 include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
280 $key = new ilMDKeyword($this->getRBACId(),$this->getObjId());
281 $key->toXML($writer);
282 }
283 $writer->xmlEndTag('Classification');
284 }
285
286
287
288 // STATIC
289 static function _getIds($a_rbac_id,$a_obj_id)
290 {
291 global $ilDB;
292
293 $query = "SELECT meta_classification_id FROM il_meta_classification ".
294 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
295 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
296
297
298 $res = $ilDB->query($query);
299 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
300 {
301 $ids[] = $row->meta_classification_id;
302 }
303 return $ids ? $ids : array();
304 }
305}
306?>
An exception for terminatinating execution or to throw for unit testing.
setObjId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
& getTaxonPath($a_taxon_path_id)
static _getIds($a_rbac_id, $a_obj_id)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
global $ilDB