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