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