ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMDEducational.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 ilMDEducational($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 for child objects (TypicalAgeRange, Description, Language)
44 {
45 include_once 'Services/MetaData/classes/class.ilMDTypicalAgeRange.php';
46
47 return ilMDTypicalAgeRange::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_educational');
48 }
49 function &getTypicalAgeRange($a_typical_age_range_id)
50 {
51 include_once 'Services/MetaData/classes/class.ilMDTypicalAgeRange.php';
52
53 if(!$a_typical_age_range_id)
54 {
55 return false;
56 }
57 $typ =& new ilMDTypicalAgeRange();
58 $typ->setMetaId($a_typical_age_range_id);
59
60 return $typ;
61 }
63 {
64 include_once 'Services/MetaData/classes/class.ilMDTypicalAgeRange.php';
65
66 $typ =& new ilMDTypicalAgeRange($this->getRBACId(),$this->getObjId(),$this->getObjType());
67 $typ->setParentId($this->getMetaId());
68 $typ->setParentType('meta_educational');
69
70 return $typ;
71 }
73 {
74 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
75
76 return ilMDDescription::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_educational');
77 }
78 function &getDescription($a_description_id)
79 {
80 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
81
82 if(!$a_description_id)
83 {
84 return false;
85 }
86 $des =& new ilMDDescription();
87 $des->setMetaId($a_description_id);
88
89 return $des;
90 }
91 function &addDescription()
92 {
93 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
94
95 $des =& new ilMDDescription($this->getRBACId(),$this->getObjId(),$this->getObjType());
96 $des->setParentId($this->getMetaId());
97 $des->setParentType('meta_educational');
98
99 return $des;
100 }
101 function &getLanguageIds()
102 {
103 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
104
105 return ilMDLanguage::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_educational');
106 }
107 function &getLanguage($a_language_id)
108 {
109 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
110
111 if(!$a_language_id)
112 {
113 return false;
114 }
115 $lan =& new ilMDLanguage();
116 $lan->setMetaId($a_language_id);
117
118 return $lan;
119 }
120 function &addLanguage()
121 {
122 include_once 'Services/MetaData/classes/class.ilMDLanguage.php';
123
124 $lan =& new ilMDLanguage($this->getRBACId(),$this->getObjId(),$this->getObjType());
125 $lan->setParentId($this->getMetaId());
126 $lan->setParentType('meta_educational');
127
128 return $lan;
129 }
130
131 // SET/GET
132 function setInteractivityType($a_iat)
133 {
134 switch($a_iat)
135 {
136 case 'Active':
137 case 'Expositive':
138 case 'Mixed':
139 $this->interactivity_type = $a_iat;
140 return true;
141
142 default:
143 return false;
144 }
145 }
147 {
148 return $this->interactivity_type;
149 }
150 function setLearningResourceType($a_lrt)
151 {
152 switch($a_lrt)
153 {
154 case 'Exercise':
155 case 'Simulation':
156 case 'Questionnaire':
157 case 'Diagram':
158 case 'Figure':
159 case 'Graph':
160 case 'Index':
161 case 'Slide':
162 case 'Table':
163 case 'NarrativeText':
164 case 'Exam':
165 case 'Experiment':
166 case 'ProblemStatement':
167 case 'SelfAssessment':
168 case 'Lecture':
169 $this->learning_resource_type = $a_lrt;
170 return true;
171
172 default:
173 return false;
174 }
175 }
177 {
178 return $this->learning_resource_type;
179 }
180 function setInteractivityLevel($a_iat)
181 {
182 switch($a_iat)
183 {
184 case 'VeryLow':
185 case 'Low':
186 case 'Medium':
187 case 'High':
188 case 'VeryHigh':
189 $this->interactivity_level = $a_iat;
190 return true;
191
192 default:
193 return false;
194 }
195 }
197 {
198 return $this->interactivity_level;
199 }
200 function setSemanticDensity($a_sd)
201 {
202 switch($a_sd)
203 {
204 case 'VeryLow':
205 case 'Low':
206 case 'Medium':
207 case 'High':
208 case 'VeryHigh':
209 $this->semantic_density = $a_sd;
210 return true;
211
212 default:
213 return false;
214 }
215 }
217 {
218 return $this->semantic_density;
219 }
220 function setIntendedEndUserRole($a_ieur)
221 {
222 switch($a_ieur)
223 {
224 case 'Teacher':
225 case 'Author':
226 case 'Learner':
227 case 'Manager':
228 $this->intended_end_user_role = $a_ieur;
229 return true;
230
231 default:
232 return false;
233 }
234 }
236 {
237 return $this->intended_end_user_role;
238 }
239 function setContext($a_context)
240 {
241 switch($a_context)
242 {
243 case 'School':
244 case 'HigherEducation':
245 case 'Training':
246 case 'Other':
247 $this->context = $a_context;
248 return true;
249
250 default:
251 return false;
252 }
253 }
254 function getContext()
255 {
256 return $this->context;
257 }
258 function setDifficulty($a_difficulty)
259 {
260 switch($a_difficulty)
261 {
262 case 'VeryEasy':
263 case 'Easy':
264 case 'Medium':
265 case 'Difficult':
266 case 'VeryDifficult':
267 $this->difficulty = $a_difficulty;
268 return true;
269
270 default:
271 return false;
272 }
273 }
274 function getDifficulty()
275 {
276 return $this->difficulty;
277 }
278
279 function setPhysicalTypicalLearningTime($months,$days,$hours,$minutes,$seconds)
280 {
281 if(!$months and !$days and !$hours and !$minutes and !$seconds)
282 {
283 $this->setTypicalLearningTime('PT00H00M');
284 return true;
285 }
286 $tlt = 'P';
287 if($months)
288 {
289 $tlt .= ($months.'M');
290 }
291 if($days)
292 {
293 $tlt .= ($days.'D');
294 }
295 if($hours or $minutes or $seconds)
296 {
297 $tlt .= 'T';
298 }
299 if($hours)
300 {
301 $tlt .= ($hours.'H');
302 }
303 if($minutes)
304 {
305 $tlt .= ($minutes.'M');
306 }
307 if($seconds)
308 {
309 $tlt .= ($seconds.'S');
310 }
311 $this->setTypicalLearningTime($tlt);
312 return true;
313 }
314
315
316 function setTypicalLearningTime($a_tlt)
317 {
318 $this->typical_learning_time = $a_tlt;
319 }
321 {
322 return $this->typical_learning_time;
323 }
324
326 {
327 include_once './Services/MetaData/classes/class.ilMDUtils.php';
328
330
331 return 60 * 60 * 24 * 30 * $time_arr[0] + 60 * 60 * 24 * $time_arr[1] + 60 * 60 * $time_arr[2] + 60 * $time_arr[3] + $time_arr[4];
332 }
333
334 function save()
335 {
336 global $ilDB;
337
338 $fields = $this->__getFields();
339 $fields['meta_educational_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_educational'));
340
341 if($this->db->insert('il_meta_educational',$fields))
342 {
343 $this->setMetaId($next_id);
344 return $this->getMetaId();
345 }
346 return false;
347 }
348
349 function update()
350 {
351 global $ilDB;
352
353 if($this->getMetaId())
354 {
355 if($this->db->update('il_meta_educational',
356 $this->__getFields(),
357 array("meta_educational_id" => array('integer',$this->getMetaId()))))
358 {
359 return true;
360 }
361 }
362 return false;
363 }
364
365 function delete()
366 {
367 global $ilDB;
368
369 if($this->getMetaId())
370 {
371 $query = "DELETE FROM il_meta_educational ".
372 "WHERE meta_educational_id = ".$ilDB->quote($this->getMetaId());
373 $res = $ilDB->manipulate($query);
374
375 foreach($this->getTypicalAgeRangeIds() as $id)
376 {
377 $typ = $this->getTypicalAgeRange($id);
378 $typ->delete();
379 }
380 foreach($this->getDescriptionIds() as $id)
381 {
382 $des = $this->getDescription($id);
383 $des->delete();
384 }
385 foreach($this->getLanguageIds() as $id)
386 {
387 $lan = $this->getLanguage($id);
388 $lan->delete();
389 }
390
391
392 return true;
393 }
394 return false;
395 }
396
397
398 function __getFields()
399 {
400 return array('rbac_id' => array('integer',$this->getRBACId()),
401 'obj_id' => array('integer',$this->getObjId()),
402 'obj_type' => array('text',$this->getObjType()),
403 'interactivity_type' => array('text',$this->getInteractivityType()),
404 'learning_resource_type' => array('text',$this->getLearningResourceType()),
405 'interactivity_level' => array('text',$this->getInteractivityLevel()),
406 'semantic_density' => array('text',$this->getSemanticDensity()),
407 'intended_end_user_role' => array('text',$this->getIntendedEndUserRole()),
408 'context' => array('text',$this->getContext()),
409 'difficulty' => array('text',$this->getDifficulty()),
410 'typical_learning_time' => array('text',$this->getTypicalLearningTime()));
411 }
412
413 function read()
414 {
415 global $ilDB;
416
417 if($this->getMetaId())
418 {
419
420 $query = "SELECT * FROM il_meta_educational ".
421 "WHERE meta_educational_id = ".$ilDB->quote($this->getMetaId() ,'integer');
422
423
424 $res = $this->db->query($query);
425 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
426 {
427 $this->setRBACId($row->rbac_id);
428 $this->setObjId($row->obj_id);
429 $this->setObjType($row->obj_type);
430 $this->setInteractivityType($row->interactivity_type);
431 $this->setLearningResourceType($row->learning_resource_type);
432 $this->setInteractivityLevel($row->interactivity_level);
433 $this->setSemanticDensity($row->semantic_density);
434 $this->setIntendedEndUserRole($row->intended_end_user_role);
435 $this->setContext($row->context);
436 $this->setDifficulty($row->difficulty);
437 $this->setTypicalLearningTime($row->typical_learning_time);
438 }
439 return true;
440 }
441 return false;
442 }
443
444 /*
445 * XML Export of all meta data
446 * @param object (xml writer) see class.ilMD2XML.php
447 *
448 */
449 function toXML(&$writer)
450 {
451 $writer->xmlStartTag('Educational',
452 array('InteractivityType' => $this->getInteractivityType()
453 ? $this->getInteractivityType()
454 : 'Active',
455 'LearningResourceType' => $this->getLearningResourceType()
456 ? $this->getLearningResourceType()
457 : 'Exercise',
458 'InteractivityLevel' => $this->getInteractivityLevel()
459 ? $this->getInteractivityLevel()
460 : 'Medium',
461 'SemanticDensity' => $this->getSemanticDensity()
462 ? $this->getSemanticDensity()
463 : 'Medium',
464 'IntendedEndUserRole' => $this->getIntendedEndUserRole()
465 ? $this->getIntendedEndUserRole()
466 : 'Learner',
467 'Context' => $this->getContext()
468 ? $this->getContext()
469 : 'Other',
470 'Difficulty' => $this->getDifficulty()
471 ? $this->getDifficulty()
472 : 'Medium'));
473
474 // TypicalAgeRange
475 $typ_ages = $this->getTypicalAgeRangeIds();
476 foreach($typ_ages as $id)
477 {
478 $key =& $this->getTypicalAgeRange($id);
479
480 // extra test due to bug 5316 (may be due to eLaix import)
481 if (is_object($key))
482 {
483 $key->toXML($writer);
484 }
485 }
486 if(!count($typ_ages))
487 {
488 include_once 'Services/MetaData/classes/class.ilMDTypicalAgeRange.php';
489 $typ = new ilMDTypicalAgeRange($this->getRBACId(),$this->getObjId());
490 $typ->toXML($writer);
491 }
492
493 // TypicalLearningTime
494 $writer->xmlElement('TypicalLearningTime',null,$this->getTypicalLearningTime());
495
496 // Description
497 foreach($this->getDescriptionIds() as $id)
498 {
499 $key =& $this->getDescription($id);
500 $key->toXML($writer);
501 }
502 // Language
503 foreach($this->getLanguageIds() as $id)
504 {
505 $lang =& $this->getLanguage($id);
506 $lang->toXML($writer);
507 }
508 $writer->xmlEndTag('Educational');
509 }
510 // STATIC
511 function _getId($a_rbac_id,$a_obj_id)
512 {
513 global $ilDB;
514
515 $query = "SELECT meta_educational_id FROM il_meta_educational ".
516 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
517 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
518
519 $res = $ilDB->query($query);
520 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
521 {
522 return $row->meta_educational_id;
523 }
524 return false;
525 }
526
527 function _getTypicalLearningTimeSeconds($a_rbac_id,$a_obj_id = 0)
528 {
529 global $ilDB;
530
531 $a_obj_id = $a_obj_id ? $a_obj_id : $a_rbac_id;
532
533 $query = "SELECT typical_learning_time FROM il_meta_educational ".
534 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
535 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
536 $res = $ilDB->query($query);
537 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
538 {
539 include_once './Services/MetaData/classes/class.ilMDUtils.php';
540
541 $time_arr = ilMDUtils::_LOMDurationToArray($row->typical_learning_time);
542
543 return 60 * 60 * 24 * 30 * $time_arr[0] +
544 60 * 60 * 24 * $time_arr[1] +
545 60 * 60 * $time_arr[2] +
546 60 * $time_arr[3] +
547 $time_arr[4];
548 }
549 return 0;
550 }
551
552}
553?>
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)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
_getId($a_rbac_id, $a_obj_id)
setPhysicalTypicalLearningTime($months, $days, $hours, $minutes, $seconds)
& getTypicalAgeRange($a_typical_age_range_id)
ilMDEducational($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
& getDescription($a_description_id)
setDifficulty($a_difficulty)
& getLanguage($a_language_id)
_getTypicalLearningTimeSeconds($a_rbac_id, $a_obj_id=0)
_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)
_LOMDurationToArray($a_string)
LOM datatype duration is a string like P2M4DT7H18M2S (2 months 4 days 7 hours 18 minutes 2 seconds) T...
global $ilDB