ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
31 include_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 $ilDB;
313 
314  $fields = $this->__getFields();
315  $fields['meta_educational_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_educational'));
316 
317  if ($this->db->insert('il_meta_educational', $fields)) {
318  $this->setMetaId($next_id);
319  return $this->getMetaId();
320  }
321  return false;
322  }
323 
324  public function update()
325  {
326  global $ilDB;
327 
328  if ($this->getMetaId()) {
329  if ($this->db->update(
330  'il_meta_educational',
331  $this->__getFields(),
332  array("meta_educational_id" => array('integer',$this->getMetaId()))
333  )) {
334  return true;
335  }
336  }
337  return false;
338  }
339 
340  public function delete()
341  {
342  global $ilDB;
343 
344  if ($this->getMetaId()) {
345  $query = "DELETE FROM il_meta_educational " .
346  "WHERE meta_educational_id = " . $ilDB->quote($this->getMetaId());
347  $res = $ilDB->manipulate($query);
348 
349  foreach ($this->getTypicalAgeRangeIds() as $id) {
350  $typ = $this->getTypicalAgeRange($id);
351  $typ->delete();
352  }
353  foreach ($this->getDescriptionIds() as $id) {
354  $des = $this->getDescription($id);
355  $des->delete();
356  }
357  foreach ($this->getLanguageIds() as $id) {
358  $lan = $this->getLanguage($id);
359  $lan->delete();
360  }
361 
362 
363  return true;
364  }
365  return false;
366  }
367 
368 
369  public function __getFields()
370  {
371  return array('rbac_id' => array('integer',$this->getRBACId()),
372  'obj_id' => array('integer',$this->getObjId()),
373  'obj_type' => array('text',$this->getObjType()),
374  'interactivity_type' => array('text',$this->getInteractivityType()),
375  'learning_resource_type' => array('text',$this->getLearningResourceType()),
376  'interactivity_level' => array('text',$this->getInteractivityLevel()),
377  'semantic_density' => array('text',$this->getSemanticDensity()),
378  'intended_end_user_role' => array('text',$this->getIntendedEndUserRole()),
379  'context' => array('text',$this->getContext()),
380  'difficulty' => array('text',$this->getDifficulty()),
381  'typical_learning_time' => array('text',$this->getTypicalLearningTime()));
382  }
383 
384  public function read()
385  {
386  global $ilDB;
387 
388  if ($this->getMetaId()) {
389  $query = "SELECT * FROM il_meta_educational " .
390  "WHERE meta_educational_id = " . $ilDB->quote($this->getMetaId(), 'integer');
391 
392 
393  $res = $this->db->query($query);
394  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
395  $this->setRBACId($row->rbac_id);
396  $this->setObjId($row->obj_id);
397  $this->setObjType($row->obj_type);
398  $this->setInteractivityType($row->interactivity_type);
399  $this->setLearningResourceType($row->learning_resource_type);
400  $this->setInteractivityLevel($row->interactivity_level);
401  $this->setSemanticDensity($row->semantic_density);
402  $this->setIntendedEndUserRole($row->intended_end_user_role);
403  $this->setContext($row->context);
404  $this->setDifficulty($row->difficulty);
405  $this->setTypicalLearningTime($row->typical_learning_time);
406  }
407  return true;
408  }
409  return false;
410  }
411 
412  /*
413  * XML Export of all meta data
414  * @param object (xml writer) see class.ilMD2XML.php
415  *
416  */
417  public function toXML(&$writer)
418  {
419  $writer->xmlStartTag(
420  'Educational',
421  array('InteractivityType' => $this->getInteractivityType()
422  ? $this->getInteractivityType()
423  : 'Active',
424  'LearningResourceType' => $this->getLearningResourceType()
425  ? $this->getLearningResourceType()
426  : 'Exercise',
427  'InteractivityLevel' => $this->getInteractivityLevel()
428  ? $this->getInteractivityLevel()
429  : 'Medium',
430  'SemanticDensity' => $this->getSemanticDensity()
431  ? $this->getSemanticDensity()
432  : 'Medium',
433  'IntendedEndUserRole' => $this->getIntendedEndUserRole()
434  ? $this->getIntendedEndUserRole()
435  : 'Learner',
436  'Context' => $this->getContext()
437  ? $this->getContext()
438  : 'Other',
439  'Difficulty' => $this->getDifficulty()
440  ? $this->getDifficulty()
441  : 'Medium')
442  );
443 
444  // TypicalAgeRange
445  $typ_ages = $this->getTypicalAgeRangeIds();
446  foreach ($typ_ages as $id) {
447  $key =&$this->getTypicalAgeRange($id);
448 
449  // extra test due to bug 5316 (may be due to eLaix import)
450  if (is_object($key)) {
451  $key->toXML($writer);
452  }
453  }
454  if (!count($typ_ages)) {
455  include_once 'Services/MetaData/classes/class.ilMDTypicalAgeRange.php';
456  $typ = new ilMDTypicalAgeRange($this->getRBACId(), $this->getObjId());
457  $typ->toXML($writer);
458  }
459 
460  // TypicalLearningTime
461  $writer->xmlElement('TypicalLearningTime', null, $this->getTypicalLearningTime());
462 
463  // Description
464  foreach ($this->getDescriptionIds() as $id) {
465  $key =&$this->getDescription($id);
466  $key->toXML($writer);
467  }
468  // Language
469  foreach ($this->getLanguageIds() as $id) {
470  $lang =&$this->getLanguage($id);
471  $lang->toXML($writer);
472  }
473  $writer->xmlEndTag('Educational');
474  }
475  // STATIC
476  public static function _getId($a_rbac_id, $a_obj_id)
477  {
478  global $ilDB;
479 
480  $query = "SELECT meta_educational_id FROM il_meta_educational " .
481  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
482  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
483 
484  $res = $ilDB->query($query);
485  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
486  return $row->meta_educational_id;
487  }
488  return false;
489  }
490 
491  public static function _getTypicalLearningTimeSeconds($a_rbac_id, $a_obj_id = 0)
492  {
493  global $ilDB;
494 
495  $a_obj_id = $a_obj_id ? $a_obj_id : $a_rbac_id;
496 
497  $query = "SELECT typical_learning_time FROM il_meta_educational " .
498  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
499  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
500  $res = $ilDB->query($query);
501  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
502  include_once './Services/MetaData/classes/class.ilMDUtils.php';
503 
504  $time_arr = ilMDUtils::_LOMDurationToArray($row->typical_learning_time);
505 
506  return 60 * 60 * 24 * 30 * $time_arr[0] +
507  60 * 60 * 24 * $time_arr[1] +
508  60 * 60 * $time_arr[2] +
509  60 * $time_arr[3] +
510  $time_arr[4];
511  }
512  return 0;
513  }
514 }
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getLanguage($a_language_id)
setObjType($a_type)
static _getTypicalLearningTimeSeconds($a_rbac_id, $a_obj_id=0)
setDifficulty($a_difficulty)
& getDescription($a_description_id)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
if(!array_key_exists('StateId', $_REQUEST)) $id
& getTypicalAgeRange($a_typical_age_range_id)
static _LOMDurationToArray($a_string)
LOM datatype duration is a string like P2M4DT7H18M2S (2 months 4 days 7 hours 18 minutes 2 seconds) T...
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
setMetaId($a_meta_id, $a_read_data=true)
foreach($_POST as $key=> $value) $res
setObjId($a_id)
setRBACId($a_id)
static _getId($a_rbac_id, $a_obj_id)
$query
Create styles array
The data for the language used.
setPhysicalTypicalLearningTime($months, $days, $hours, $minutes, $seconds)
global $ilDB
$key
Definition: croninfo.php:18