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
33class ilMDClassification extends ilMDBase
34{
35 // METHODS OF CLIENT OBJECTS (TaxonPath, Keyword)
36 function &getTaxonPathIds()
37 {
38 include_once 'Services/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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 if($this->db->autoExecute('il_meta_classification',
149 $this->__getFields(),
151 {
152 $this->setMetaId($this->db->getLastInsertId());
153
154 return $this->getMetaId();
155 }
156 return false;
157 }
158
159 function update()
160 {
161 global $ilDB;
162
163 if($this->getMetaId())
164 {
165 if($this->db->autoExecute('il_meta_classification',
166 $this->__getFields(),
168 "meta_classification_id = ".$ilDB->quote($this->getMetaId())))
169 {
170 return true;
171 }
172 }
173 return false;
174 }
175
176 function delete()
177 {
178 global $ilDB;
179
180 if($this->getMetaId())
181 {
182 $query = "DELETE FROM il_meta_classification ".
183 "WHERE meta_classification_id = ".$ilDB->quote($this->getMetaId());
184
185 $this->db->query($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' => $this->getRBACId(),
207 'obj_id' => $this->getObjId(),
208 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
209 'purpose' => ilUtil::prepareDBString($this->getPurpose()),
210 'description' => ilUtil::prepareDBString($this->getDescription()),
211 'description_language' => ilUtil::prepareDBString($this->getDescriptionLanguageCode()));
212 }
213
214 function read()
215 {
216 global $ilDB;
217
218 include_once 'Services/Migration/DBUpdate_426/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());
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(ilUtil::stripSlashes($row->purpose));
232 $this->setDescription(ilUtil::stripSlashes($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
248 // Taxon Path
249 foreach($this->getTaxonPathIds() as $id)
250 {
251 $tax =& $this->getTaxonPath($id);
252 $tax->toXML($writer);
253 }
254 // Description
255 $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()),$this->getDescription());
256
257 // Keyword
258 foreach($this->getKeywordIds() as $id)
259 {
260 $key =& $this->getKeyword($id);
261 $key->toXML($writer);
262 }
263 $writer->xmlEndTag('Classification');
264 }
265
266
267
268 // STATIC
269 function _getIds($a_rbac_id,$a_obj_id)
270 {
271 global $ilDB;
272
273 $query = "SELECT meta_classification_id FROM il_meta_classification ".
274 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
275 "AND obj_id = ".$ilDB->quote($a_obj_id);
276
277
278 $res = $ilDB->query($query);
279 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
280 {
281 $ids[] = $row->meta_classification_id;
282 }
283 return $ids ? $ids : array();
284 }
285}
286?>
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)
_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)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilDB