ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
31 include_once 'class.ilMDBase.php';
32 
33 class ilMDClassification extends ilMDBase
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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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  if($this->db->autoExecute('il_meta_classification',
156  $this->__getFields(),
157  DB_AUTOQUERY_INSERT))
158  {
159  $this->setMetaId($this->db->getLastInsertId());
160 
161  return $this->getMetaId();
162  }
163  return false;
164  }
165 
166  function update()
167  {
168  global $ilDB;
169 
170  if($this->getMetaId())
171  {
172  if($this->db->autoExecute('il_meta_classification',
173  $this->__getFields(),
174  DB_AUTOQUERY_UPDATE,
175  "meta_classification_id = ".$ilDB->quote($this->getMetaId())))
176  {
177  return true;
178  }
179  }
180  return false;
181  }
182 
183  function delete()
184  {
185  global $ilDB;
186 
187  if($this->getMetaId())
188  {
189  $query = "DELETE FROM il_meta_classification ".
190  "WHERE meta_classification_id = ".$ilDB->quote($this->getMetaId());
191 
192  $this->db->query($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' => $this->getRBACId(),
214  'obj_id' => $this->getObjId(),
215  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
216  'purpose' => ilUtil::prepareDBString($this->getPurpose()),
217  'description' => ilUtil::prepareDBString($this->getDescription()),
218  'description_language' => ilUtil::prepareDBString($this->getDescriptionLanguageCode()));
219  }
220 
221  function read()
222  {
223  global $ilDB;
224 
225  include_once 'Services/Migration/DBUpdate_426/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());
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(ilUtil::stripSlashes($row->purpose));
239  $this->setDescription(ilUtil::stripSlashes($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 
255  // Taxon Path
256  foreach($this->getTaxonPathIds() as $id)
257  {
258  $tax =& $this->getTaxonPath($id);
259  $tax->toXML($writer);
260  }
261  // Description
262  $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()),$this->getDescription());
263 
264  // Keyword
265  foreach($this->getKeywordIds() as $id)
266  {
267  $key =& $this->getKeyword($id);
268  $key->toXML($writer);
269  }
270  $writer->xmlEndTag('Classification');
271  }
272 
273 
274 
275  // STATIC
276  function _getIds($a_rbac_id,$a_obj_id)
277  {
278  global $ilDB;
279 
280  $query = "SELECT meta_classification_id FROM il_meta_classification ".
281  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
282  "AND obj_id = ".$ilDB->quote($a_obj_id);
283 
284 
285  $res = $ilDB->query($query);
286  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
287  {
288  $ids[] = $row->meta_classification_id;
289  }
290  return $ids ? $ids : array();
291  }
292 }
293 ?>