ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjSAHSLearningModule.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21//require_once "components/ILIAS/MetaData/classes/class.ilMDLanguageItem.php";
33{
34 private string $api_func_prefix = 'LMS';
35 private string $lesson_mode = 'normal';
36 private int $style_id = 0;
37 private string $auto_review = 'n';
38 private int $max_attempt = 0;
39 private int $module_version = 1;
40 private int $assigned_glossary = 0;
41 private bool $session = false;
42 private bool $no_menu = false;
43 private bool $hide_navig = false;
44 private bool $ie_force_render = false;
45 private bool $fourth_edition = false;
46 private bool $interactions = true;
47 private bool $objectives = true;
48 private bool $comments = true;
49 private bool $time_from_lms = false;
50 private bool $check_values = true;
51 private bool $debug = false;
52 private bool $auto_continue = false;
53 private bool $auto_last_visited = true;
54 private bool $auto_suspend = false;
55 private int $open_mode = 0;
56 private int $width = 950;
57 private int $height = 650;
58 private ?int $mastery_score = null;
59 private int $id_setting = 0;
60 private int $name_setting = 0;
61 private string $sub_type = 'scorm';
62 protected bool $sequencing = false;
63
64 protected string $localization = "";
65
66 protected string $mastery_score_values = "";
67
68 protected int $tries = 0;
69
70 protected string $api_adapter = 'API';
71
72 protected \ILIAS\DI\UIServices $ui;
73
79 public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
80 {
81 global $DIC;
82 $this->ui = $DIC->ui();
83 $this->type = "sahs";
84 parent::__construct($a_id, $a_call_by_reference);
85 }
86
90 public function create(bool $upload = false): int
91 {
92 global $DIC;
93 $ilDB = $DIC->database();
94
95 $id = parent::create();
96 if (!$upload) {
97 $this->createMetaData();
98 }
99
100 $this->createDataDirectory();
101 $ilDB->manipulateF(
102 '
103 INSERT INTO sahs_lm (id, api_adapter, c_type, editable, seq_exp_mode,localization)
104 VALUES (%s,%s,%s,%s,%s,%s)',
105 array('integer', 'text', 'text', 'integer','integer','text'),
106 array($this->getId(),'API', $this->getSubType(),(int) $this->getEditable(),
107 0, $this->getLocalization()
108 )
109 );
110 return $id;
111 }
112
119 public function read(): void
120 {
121 global $DIC;
122 $ilDB = $DIC->database();
123
124 parent::read();
125
126 $lm_set = $ilDB->queryF(
127 'SELECT * FROM sahs_lm WHERE id = %s',
128 array('integer'),
129 array($this->getId())
130 );
131
132 while ($lm_rec = $ilDB->fetchAssoc($lm_set)) {
133 $this->setAutoReviewChar((string) $lm_rec["auto_review"]);
134 $this->setAPIAdapterName((string) $lm_rec["api_adapter"]);
135 $this->setDefaultLessonMode((string) $lm_rec["default_lesson_mode"]);
136 $this->setAPIFunctionsPrefix((string) $lm_rec["api_func_prefix"]);
137 $this->setSubType((string) $lm_rec["c_type"]);
138 // $this->setEditable(false);
139 $this->setStyleSheetId((int) $lm_rec["stylesheet"]);
140 $this->setMaxAttempt((int) $lm_rec["max_attempt"]);
141 $this->setModuleVersion((int) $lm_rec["module_version"]);
142 $this->setAssignedGlossary((int) $lm_rec["glossary"]);
143 $this->setTries((int) $lm_rec["question_tries"]);
144 $this->setLocalization((string) $lm_rec["localization"]);
145 $this->setSession(ilUtil::yn2tf($lm_rec["unlimited_session"]));
146 $this->setNoMenu(ilUtil::yn2tf($lm_rec["no_menu"] ?? "n"));
147 $this->setHideNavig(ilUtil::yn2tf($lm_rec["hide_navig"]));
148 $this->setFourth_edition(ilUtil::yn2tf($lm_rec["fourth_edition"]));
149 $this->setSequencing(ilUtil::yn2tf($lm_rec["sequencing"]));
150 $this->setInteractions(ilUtil::yn2tf($lm_rec["interactions"]));
151 $this->setObjectives(ilUtil::yn2tf($lm_rec["objectives"]));
152 $this->setComments(ilUtil::yn2tf($lm_rec["comments"]));
153 $this->setTime_from_lms(ilUtil::yn2tf($lm_rec["time_from_lms"]));
154 $this->setDebug(ilUtil::yn2tf($lm_rec["debug"]));
155 // $this->setDebugPw($lm_rec["debugpw"]);
156 // $this->setSequencingExpertMode(bool $lm_rec["seq_exp_mode"]);
157 $this->setOpenMode((int) $lm_rec["open_mode"]);
158 $this->setWidth((int) $lm_rec["width"]);
159 $this->setHeight((int) $lm_rec["height"]);
160 $this->setAutoContinue(ilUtil::yn2tf($lm_rec["auto_continue"]));
161 $this->setAuto_last_visited(ilUtil::yn2tf($lm_rec["auto_last_visited"]));
162 $this->setCheck_values(ilUtil::yn2tf($lm_rec["check_values"]));
163 // $this->setOfflineMode(ilUtil::yn2tf($lm_rec["offline_mode"]));
164 $this->setAutoSuspend(ilUtil::yn2tf($lm_rec["auto_suspend"]));
165 $this->setIe_force_render(ilUtil::yn2tf($lm_rec["ie_force_render"]));
166 if ($lm_rec["mastery_score"] != null) {
167 $this->setMasteryScore((int) $lm_rec["mastery_score"]);
168 }
169 $this->setIdSetting((int) $lm_rec["id_setting"]);
170 $this->setNameSetting((int) $lm_rec["name_setting"]);
171 if (ilObject::_lookupType($this->getStyleSheetId()) !== "sty") {
172 $this->setStyleSheetId(0);
173 }
174 }
175 }
176
180 public static function getAffectiveLocalization(int $a_id): string
181 {
182 global $DIC;
183 $ilDB = $DIC->database();
184 $lng = $DIC->language();
185
186 $lm_set = $ilDB->queryF(
187 'SELECT localization FROM sahs_lm WHERE id = %s',
188 array('integer'),
189 array($a_id)
190 );
191 $lm_rec = $ilDB->fetchAssoc($lm_set);
192 $inst_lang = $lng->getInstalledLanguages();
193 if ($lm_rec["localization"] != "" && in_array($lm_rec["localization"], $inst_lang)) {
194 return $lm_rec["localization"];
195 }
196 return $lng->getLangKey();
197 }
198
202 public static function _lookupSubType(int $a_obj_id): string
203 {
204 global $DIC;
205 $ilDB = $DIC->database();
206
207 $obj_set = $ilDB->queryF(
208 'SELECT c_type FROM sahs_lm WHERE id = %s',
209 array('integer'),
210 array($a_obj_id)
211 );
212 $obj_rec = $ilDB->fetchAssoc($obj_set);
213 if ($obj_rec == null || $obj_rec["c_type"] == null) {
214 return '';
215 }
216 return $obj_rec["c_type"];
217 }
218
219 // /**
220 // * Set Editable.
221 // *
222 // * @param boolean $a_editable Editable
223 // */
224 // public function setEditable(bool $a_editable) : void
225 // {
226 // $this->editable = $a_editable;
227 // }
228
229 public function getEditable(): bool
230 {
231 return false;
232 }
233
237 public function setTries(int $a_tries): void
238 {
239 $this->tries = $a_tries;
240 }
241
242 public function getTries(): int
243 {
244 return $this->tries;
245 }
246
247 public function setLocalization(string $a_val): void
248 {
249 $this->localization = $a_val;
250 }
251
252 public function getLocalization(): string
253 {
254 return $this->localization;
255 }
256
260 public static function _getTries(int $a_id): int
261 {
262 global $DIC;
263 $ilDB = $DIC->database();
264
265 $lm_set = $ilDB->queryF(
266 'SELECT question_tries FROM sahs_lm WHERE id = %s',
267 array('integer'),
268 array($a_id)
269 );
270 $lm_rec = $ilDB->fetchAssoc($lm_set);
271
272 return (int) $lm_rec['question_tries'];
273 }
274
280 public function getDiskUsage(): int
281 {
283 }
284
285
290 public function createDataDirectory(): void
291 {
292 $lm_data_dir = ilFileUtils::getWebspaceDir() . "/lm_data";
293 ilFileUtils::makeDir($lm_data_dir);
295 }
296
300 public function getDataDirectory(?string $mode = "filesystem"): string
301 {
302 $lm_data_dir = ilFileUtils::getWebspaceDir($mode) . "/lm_data";
303 return $lm_data_dir . "/lm_" . $this->getId();
304 }
305
309 public function getAPIAdapterName(): string
310 {
311 return $this->api_adapter;
312 }
313
317 public function setAPIAdapterName(string $a_api): void
318 {
319 $this->api_adapter = $a_api;
320 }
321
326 public function getAPIFunctionsPrefix(): string
327 {
329 }
330
334 public function setAPIFunctionsPrefix(string $a_prefix): void
335 {
336 $this->api_func_prefix = $a_prefix;
337 }
338
342 public function getCreditMode(): string
343 {
344 $learningProgress = ilObjectLP::getInstance($this->getID());
345 $currentMode = $learningProgress->getCurrentMode();
346 if ($currentMode === ilLPObjSettings::LP_MODE_SCORM || $currentMode === ilLPObjSettings::LP_MODE_SCORM_PACKAGE) {
347 return "credit";
348 } else {
349 return "no-credit";
350 }
351 }
352
356 public function setDefaultLessonMode(string $a_lesson_mode): void
357 {
358 $this->lesson_mode = $a_lesson_mode;
359 }
360
364 public function getDefaultLessonMode(): string
365 {
366 global $DIC;
367 if ($DIC->user()->getId() == 13) {
368 return "browse";
369 }
370 return $this->lesson_mode;
371 }
372
376 public function getStyleSheetId(): int
377 {
378 return $this->style_id;
379 }
380
384 public function setStyleSheetId(int $a_style_id): void
385 {
386 $this->style_id = $a_style_id;
387 }
388
392 public function setAutoReview(bool $a_auto_review): void
393 {
394 $this->auto_review = ilUtil::tf2yn($a_auto_review);
395 }
396
400 public function getAutoReview(): bool
401 {
402 return ilUtil::yn2tf($this->auto_review);
403 }
404
408 public function setAutoReviewChar(?string $a_auto_review): void
409 {
410 if ($a_auto_review == null) {
411 $this->auto_review = 'n';
412 } else {
413 $this->auto_review = $a_auto_review;
414 }
415 }
416
420 public function getAutoReviewChar(): string
421 {
422 return $this->auto_review;
423 }
424
425 public function getMaxAttempt(): int
426 {
427 return $this->max_attempt;
428 }
429
430 public function setMaxAttempt(int $a_max_attempt): void
431 {
432 $this->max_attempt = $a_max_attempt;
433 }
434
435 public function getModuleVersion(): int
436 {
438 }
439
440 public function getAssignedGlossary(): int
441 {
443 }
444
445 public function setAssignedGlossary(int $a_assigned_glossary): void
446 {
447 $this->assigned_glossary = $a_assigned_glossary;
448 }
449
450 public function setModuleVersion(int $a_module_version): void
451 {
452 $this->module_version = $a_module_version;
453 }
454
455 public function getSession(): bool
456 {
457 return $this->session;
458 }
459
460 public function setSession(bool $a_session): void
461 {
462 $this->session = $a_session;
463 }
464
468 public function getNoMenu(): bool
469 {
470 return $this->no_menu;
471 }
472
476 public function setNoMenu(bool $a_no_menu): void
477 {
478 $this->no_menu = $a_no_menu;
479 }
480
484 public function getHideNavig(): bool
485 {
486 return $this->hide_navig;
487 }
488
492 public function setHideNavig(bool $a_hide_navig): void
493 {
494 $this->hide_navig = $a_hide_navig;
495 }
496
500 public function getCacheDeactivated(): bool
501 {
502 global $DIC;
503 $ilSetting = $DIC->settings();
504 $lm_set = new ilSetting("lm");
505 return $lm_set->get("scormdebug_disable_cache") == "1";
506 }
507
511 public function getSessionDeactivated(): bool
512 {
513 global $DIC;
514 $ilSetting = $DIC->settings();
515 $lm_set = new ilSetting("lm");
516 return $lm_set->get("scorm_without_session") == "1";
517 }
518
522 public function getDebugActivated(): bool
523 {
524 global $DIC;
525 $ilSetting = $DIC->settings();
526 $lm_set = new ilSetting("lm");
527 return $lm_set->get("scormdebug_global_activate") === "1";
528 }
529
533 public function getIe_force_render(): bool
534 {
536 }
537
538 public function setIe_force_render(bool $a_ie_force_render): void
539 {
540 $this->ie_force_render = $a_ie_force_render;
541 }
542
546 public function getFourth_Edition(): bool
547 {
549 }
550
551 public function setFourth_edition(bool $a_fourth_edition): void
552 {
553 $this->fourth_edition = $a_fourth_edition;
554 }
555
556 public function getSequencing(): bool
557 {
558 return $this->sequencing;
559 }
560
561 public function setSequencing(bool $a_sequencing): void
562 {
563 $this->sequencing = $a_sequencing;
564 }
565
566 public function getInteractions(): bool
567 {
568 return $this->interactions;
569 }
570
571 public function setInteractions(bool $a_interactions): void
572 {
573 $this->interactions = $a_interactions;
574 }
575
576 public function getObjectives(): bool
577 {
578 return $this->objectives;
579 }
580
581 public function setObjectives(bool $a_objectives): void
582 {
583 $this->objectives = $a_objectives;
584 }
585
586 public function getComments(): bool
587 {
588 return $this->comments;
589 }
590
591 public function setComments(bool $a_comments): void
592 {
593 $this->comments = $a_comments;
594 }
595
596 public function getTime_from_lms(): bool
597 {
599 }
600
601 public function setTime_from_lms(bool $a_time_from_lms): void
602 {
603 $this->time_from_lms = $a_time_from_lms;
604 }
605
606 public function getCheck_values(): bool
607 {
608 return $this->check_values;
609 }
610
611 public function setCheck_values(bool $a_check_values): void
612 {
613 $this->check_values = $a_check_values;
614 }
615
616 // /**
617 // * offlineMode
618 // */
619 // public function getOfflineMode()
620 // {
621 // return $this->offline_mode;
622 // }
623 //
624 // public function setOfflineMode($a_offline_mode)
625 // {
626 // $this->offline_mode = $a_offline_mode;
627 // }
628
629 public function getDebug(): bool
630 {
631 return $this->debug;
632 }
633
634 public function setDebug(bool $a_debug): void
635 {
636 $this->debug = $a_debug;
637 }
638
639 // /**
640 // * debug pw
641 // */
642 // public function getDebugPw()
643 // {
644 // return $this->debug_pw;
645 // }
646 //
647 // /**
648 // * debug pw
649 // */
650 // public function setDebugPw($a_debug_pw)
651 // {
652 // $this->debug_pw = $a_debug_pw;
653 // }
654
655 public function setAutoContinue(bool $a_auto_continue): void
656 {
657 $this->auto_continue = $a_auto_continue;
658 }
659
660 public function getAutoContinue(): bool
661 {
663 }
664
665 public function getAuto_last_visited(): bool
666 {
668 }
669
670 public function setAuto_last_visited(bool $a_auto_last_visited): void
671 {
672 $this->auto_last_visited = $a_auto_last_visited;
673 }
674
675
676 // /**
677 // * Set sequencing expert mode
678 // *
679 // * @param boolean $a_val sequencing expert mode
680 // */
681 // public function setSequencingExpertMode(bool $a_val)
682 // {
683 // $this->seq_exp_mode = $a_val;
684 // }
685 //
686 // /**
687 // * Get sequencing expert mode
688 // *
689 // * @return boolean sequencing expert mode
690 // */
691 // public function getSequencingExpertMode()
692 // {
693 // return $this->seq_exp_mode;
694 // }
695
696 public function setAutoSuspend(bool $a_auto_suspend): void
697 {
698 $this->auto_suspend = $a_auto_suspend;
699 }
700
701 public function getAutoSuspend(): bool
702 {
703 return $this->auto_suspend;
704 }
705
716 public function getOpenMode(): int
717 {
718 return $this->open_mode;
719 }
720
721 public function setOpenMode(int $a_open_mode): void
722 {
723 $this->open_mode = $a_open_mode;
724 }
725
726 public function getWidth(): int
727 {
728 return $this->width;
729 }
730
731 public function setWidth(int $a_width): void
732 {
733 $this->width = $a_width;
734 }
735
736 public function getHeight(): int
737 {
738 return $this->height;
739 }
740
741 public function setHeight(int $a_height): void
742 {
743 $this->height = $a_height;
744 }
745
746 public function getMasteryScore(): ?int
747 {
749 }
750
751 public function setMasteryScore(?int $a_mastery_score): void
752 {
753 $this->mastery_score = $a_mastery_score;
754 }
755
759 public function checkMasteryScoreValues(): void
760 {
761 global $DIC;
762 $ilDB = $DIC->database();
763 $s_result = "";
764 $a_result = array();
765 $type = self::_lookupSubType($this->getID());
766
767 if ($type === "scorm2004") {
768 $set = $ilDB->query("SELECT minnormalmeasure FROM cp_objective, cp_node" .
769 " WHERE satisfiedbymeasure=1 AND minnormalmeasure is not null AND cp_objective.cp_node_id=cp_node.cp_node_id AND" .
770 " slm_id = " . $ilDB->quote($this->getID(), "integer"));
771 while ($rec = $ilDB->fetchAssoc($set)) {
772 $tmpval = $rec["minnormalmeasure"] * 100;
773 if (!in_array($tmpval, $a_result)) {
774 $a_result[] = $tmpval;
775 }
776 }
777 } else {
778 $set = $ilDB->query("SELECT masteryscore FROM sc_item,scorm_object" .
779 " WHERE sc_item.masteryscore is not null AND sc_item.obj_id=scorm_object.obj_id AND" .
780 " slm_id = " . $ilDB->quote($this->getID(), "integer"));
781 while ($rec = $ilDB->fetchAssoc($set)) {
782 if (!in_array($rec["masteryscore"], $a_result)) {
783 $a_result[] = $rec["masteryscore"];
784 }
785 }
786 }
787 $s_result = implode(", ", $a_result);
788 $this->mastery_score_values = $s_result;
789 }
790
791 public function getMasteryScoreValues(): string
792 {
794 }
795
796 public function getIdSetting(): int
797 {
798 return $this->id_setting;
799 }
800
801 public function setIdSetting(int $a_id_setting): void
802 {
803 $this->id_setting = $a_id_setting;
804 }
805
806 public function getNameSetting(): int
807 {
808 return $this->name_setting;
809 }
810
811 public function setNameSetting(int $a_name_setting): void
812 {
813 $this->name_setting = $a_name_setting;
814 }
815
816 public function update(): bool
817 {
818 global $DIC;
819 $ilDB = $DIC->database();
820
821 $this->updateMetaData();
822 parent::update();
823
824 $statement = $ilDB->manipulateF(
825 '
826 UPDATE sahs_lm
827 SET api_adapter = %s,
828 api_func_prefix = %s,
829 auto_review = %s,
830 default_lesson_mode = %s,
831 c_type = %s,
832 stylesheet = %s,
833 editable = %s,
834 max_attempt = %s,
835 module_version = %s,
836 credit = %s,
837 glossary = %s,
838 question_tries = %s,
839 unlimited_session = %s,
840 no_menu = %s,
841 hide_navig = %s,
842 fourth_edition =%s,
843 sequencing = %s,
844 interactions = %s,
845 objectives = %s,
846 comments = %s,
847 time_from_lms = %s,
848 debug = %s,
849 localization = %s,
850 seq_exp_mode = %s,
851 open_mode = %s,
852 width = %s,
853 height = %s,
854 auto_continue = %s,
855 auto_last_visited = %s,
856 check_values = %s,
857 auto_suspend = %s,
858 ie_force_render = %s,
859 mastery_score = %s,
860 id_setting = %s,
861 name_setting = %s
862 WHERE id = %s',
863 array( 'text',
864 'text',
865 'text',
866 'text',
867 'text',
868 'integer',
869 'integer',
870 'integer',
871 'integer',
872 'text',
873 'integer',
874 'integer',
875 'text',
876 'text',
877 'text',
878 'text',
879 'text',
880 'text',
881 'text',
882 'text',
883 'text',
884 'text',
885 'text',
886 'integer',
887 'integer',
888 'integer',
889 'integer',
890 'text',
891 'text',
892 'text',
893 'text',
894 'text',
895 'integer',
896 'integer',
897 'integer',
898 'integer'
899 ),
900 array( $this->getAPIAdapterName(),
901 $this->getAPIFunctionsPrefix(),
902 $this->getAutoReviewChar(),
903 $this->getDefaultLessonMode(),
904 $this->getSubType(),
905 $this->getStyleSheetId(),
906 $this->getEditable(),
907 $this->getMaxAttempt(),
908 $this->getModuleVersion(),
909 $this->getCreditMode(),
910 $this->getAssignedGlossary(),
911 $this->getTries(),
912 ilUtil::tf2yn($this->getSession()),
913 ilUtil::tf2yn($this->getNoMenu()),
914 ilUtil::tf2yn($this->getHideNavig()),
915 ilUtil::tf2yn($this->getFourth_edition()),
919 ilUtil::tf2yn($this->getComments()),
921 ilUtil::tf2yn($this->getDebug()),
922 $this->getLocalization(),
923 0,//$this->getSequencingExpertMode(),
924 $this->getOpenMode(),
925 $this->getWidth(),
926 $this->getHeight(),
932 $this->getMasteryScore(),
933 $this->getIdSetting(),
934 $this->getNameSetting(),
935 $this->getId())
936 );
937
938 return true;
939 }
940
944 public static function getScormModulesForGlossary(int $a_glo_id): array
945 {
946 global $DIC;
947 $ilDB = $DIC->database();
948
949 $set = $ilDB->query("SELECT DISTINCT id FROM sahs_lm WHERE " .
950 " glossary = " . $ilDB->quote($a_glo_id, "integer"));
951 $sms = array();
952 while ($rec = $ilDB->fetchAssoc($set)) {
953 if (ilObject::_hasUntrashedReference((int) $rec["id"])) {
954 $sms[] = $rec["id"];
955 }
956 }
957 return $sms;
958 }
959
963 public static function lookupAssignedGlossary(int $a_slm_id): int
964 {
965 global $DIC;
966 $ilDB = $DIC->database();
967
968 $set = $ilDB->query("SELECT DISTINCT glossary FROM sahs_lm WHERE " .
969 " id = " . $ilDB->quote($a_slm_id, "integer"));
970 $rec = $ilDB->fetchAssoc($set);
971 $glo_id = $rec["glossary"];
972 if (ilObject::_lookupType($glo_id) === "glo") {
973 return $glo_id;
974 }
975 return 0;
976 }
977
978 public function setSubType(string $a_sub_type): void
979 {
980 $this->sub_type = $a_sub_type;
981 }
982
983 public function getSubType(): string
984 {
985 return $this->sub_type;
986 }
987
998 public function delete(): bool
999 {
1000 global $DIC;
1001 $ilDB = $DIC->database();
1002 $ilLog = ilLoggerFactory::getLogger('sahs');
1003
1004 // always call parent delete function first!!
1005 if (!parent::delete()) {
1006 return false;
1007 }
1008
1009 // delete meta data of scorm content object
1010 $this->deleteMetaData();
1011
1012 // delete data directory
1014
1015 // delete scorm learning module record
1016 $ilDB->manipulateF(
1017 'DELETE FROM sahs_lm WHERE id = %s',
1018 array('integer'),
1019 array($this->getId())
1020 );
1021
1022 $ilLog->debug("SAHS Delete(SAHSLM), Subtype: " . $this->getSubType());
1023
1024 if ($this->getSubType() === "scorm") {
1025 $sc_tree = new ilSCORMTree($this->getId());
1026 $r_id = $sc_tree->readRootId();
1027 if ($r_id > 0) {
1028 $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
1029 foreach ($items as $item) {
1030 $sc_object = ilSCORMObject::_getInstance((int) $item["obj_id"], $this->getId());
1031 if (is_object($sc_object)) {
1032 $sc_object->delete();
1033 }
1034 }
1035 $sc_tree->removeTree($sc_tree->getTreeId());
1036 }
1037 }
1038
1039 if ($this->getSubType() !== "scorm") {
1040 // delete aicc data
1041 $res = $ilDB->queryF(
1042 '
1043 SELECT aicc_object.obj_id FROM aicc_object, aicc_units
1044 WHERE aicc_object.obj_id = aicc_units.obj_id
1045 AND aicc_object.slm_id = %s',
1046 array('integer'),
1047 array($this->getId())
1048 );
1049
1050 while ($row = $ilDB->fetchAssoc($res)) {
1051 $obj_id = $row['obj_id'];
1052 $ilDB->manipulateF(
1053 '
1054 DELETE FROM aicc_units WHERE obj_id = %s',
1055 array('integer'),
1056 array($obj_id)
1057 );
1058 }
1059
1060 $res = $ilDB->queryF(
1061 '
1062 SELECT aicc_object.obj_id FROM aicc_object, aicc_course
1063 WHERE aicc_object.obj_id = aicc_course.obj_id
1064 AND aicc_object.slm_id = %s',
1065 array('integer'),
1066 array($this->getId())
1067 );
1068
1069 while ($row = $ilDB->fetchAssoc($res)) {
1070 $obj_id = $row['obj_id'];
1071 $ilDB->manipulateF(
1072 '
1073 DELETE FROM aicc_course WHERE obj_id = %s',
1074 array('integer'),
1075 array($obj_id)
1076 );
1077 }
1078
1079 $ilDB->manipulateF(
1080 '
1081 DELETE FROM aicc_object WHERE slm_id = %s',
1082 array('integer'),
1083 array($this->getId())
1084 );
1085 }
1086
1087 $q_log = "DELETE FROM scorm_tracking WHERE obj_id = " . $ilDB->quote($this->getId());
1088 $ilLog->write("SAHS Delete(SAHSLM): " . $q_log);
1089
1090 $ilDB->manipulateF(
1091 'DELETE FROM scorm_tracking WHERE obj_id = %s',
1092 array('integer'),
1093 array($this->getId())
1094 );
1095
1096 $q_log = "DELETE FROM sahs_user WHERE obj_id = " . $ilDB->quote($this->getId());
1097 $ilLog->write("SAHS Delete(SAHSLM): " . $q_log);
1098
1099 $ilDB->manipulateF(
1100 'DELETE FROM sahs_user WHERE obj_id = %s',
1101 array('integer'),
1102 array($this->getId())
1103 );
1104
1105 // always call parent delete function at the end!!
1106 return true;
1107 }
1108
1114 public function getPointsInPercent(): ?float
1115 {
1116 global $DIC;
1117 $ilUser = $DIC->user();
1118 if (strcmp($this->getSubType(), "scorm2004") == 0) {
1120 if (!is_null($res)) {
1121 return $res * 100.0;
1122 }
1123
1124 return $res;
1125 }
1126
1127 return null;
1128 }
1129
1135 public function getMaxPoints(): ?float
1136 {
1137 global $DIC;
1138 $ilUser = $DIC->user();
1139
1140 if (strcmp($this->getSubType(), 'scorm2004') == 0) {
1141 $res = ilObjSCORM2004LearningModule::_getMaxScoreForUser($this->getId(), $ilUser->getId());
1142 return $res;
1143 }
1144
1145 return null;
1146 }
1147
1157 public function populateByDirectoy(string $a_dir, string $a_filename = ""): void
1158 {
1159 /*preg_match("/.*sahs_([0-9]*)\.zip/", $a_filename, $match);
1160 if (is_dir($a_dir."/sahs_".$match[1]))
1161 {
1162 $a_dir = $a_dir."/sahs_".$match[1];
1163 }*/
1164 ilFileUtils::rCopy($a_dir, $this->getDataDirectory());
1166 }
1167
1175 public function cloneObject(int $a_target_id, int $a_copy_id = 0, bool $a_omit_tree = false): ?ilObject
1176 {
1177 global $DIC;
1178 $ilDB = $DIC->database();
1179 $ilUser = $DIC->user();
1180 $lng = $DIC->language();
1181
1182 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
1183 if ($new_obj !== null) {
1184 $this->cloneMetaData($new_obj);
1185
1186 $new_obj->setOfflineStatus($this->getOfflineStatus());
1187 //copy online status if object is not the root copy object
1188 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1189 if ($cp_options->isRootNode($this->getRefId())) {
1190 $new_obj->setOfflineStatus(true);
1191 }
1192
1193 // copy properties
1194 // $new_obj->setTitle($this->getTitle() . ' ' . $lng->txt('copy_of_suffix'));
1195 $new_obj->setDescription($this->getDescription());
1196 $new_obj->setSubType($this->getSubType());
1197 $new_obj->setAPIAdapterName($this->getAPIAdapterName());
1198 $new_obj->setAPIFunctionsPrefix($this->getAPIFunctionsPrefix());
1199 $new_obj->setAutoReviewChar($this->getAutoReviewChar());
1200 $new_obj->setDefaultLessonMode($this->getDefaultLessonMode());
1201 // $new_obj->setEditable($this->getEditable());
1202 $new_obj->setMaxAttempt($this->getMaxAttempt());
1203 $new_obj->setModuleVersion($this->getModuleVersion());
1204 $new_obj->setModuleVersion(1);
1205 $new_obj->setAssignedGlossary($this->getAssignedGlossary());
1206 $new_obj->setTries($this->getTries());
1207 $new_obj->setSession($this->getSession());
1208 $new_obj->setNoMenu($this->getNoMenu());
1209 $new_obj->setHideNavig($this->getHideNavig());
1210 $new_obj->setFourth_edition($this->getFourth_edition());
1211 $new_obj->setSequencing($this->getSequencing());
1212 $new_obj->setInteractions($this->getInteractions());
1213 $new_obj->setObjectives($this->getObjectives());
1214 $new_obj->setComments($this->getComments());
1215 $new_obj->setTime_from_lms($this->getTime_from_lms());
1216 $new_obj->setDebug($this->getDebug());
1217 $new_obj->setLocalization($this->getLocalization());
1218 // $new_obj->setSequencingExpertMode(0); //$this->getSequencingExpertMode()
1219 // $new_obj->setDebugPw($this->getDebugPw());
1220 $new_obj->setOpenMode($this->getOpenMode());
1221 $new_obj->setWidth($this->getWidth());
1222 $new_obj->setHeight($this->getHeight());
1223 $new_obj->setAutoContinue($this->getAutoContinue());
1224 $new_obj->setAuto_last_visited($this->getAuto_last_visited());
1225 $new_obj->setCheck_values($this->getCheck_values());
1226 // $new_obj->setOfflineMode($this->getOfflineMode());
1227 $new_obj->setAutoSuspend($this->getAutoSuspend());
1228 $new_obj->setIe_force_render($this->getIe_force_render());
1229 $new_obj->setStyleSheetId($this->getStyleSheetId());
1230 $new_obj->update();
1231
1232
1233 // set/copy stylesheet
1234 /* include_once("../components/ILIAS/Style/Content/classes/class.ilObjStyleSheet.php");
1235 $style_id = $this->getStyleSheetId();
1236 if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
1237 {
1238 $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
1239 $new_id = $style_obj->ilClone();
1240 $new_obj->setStyleSheetId($new_id);
1241 $new_obj->update();
1242 }*/
1243
1244 // up to this point $new_obj is of type ilobjsahslearning module
1245
1246 // create instance of correct subtype and call forward it to
1247 // cloneIntoNewObject method
1248 switch ($this->getSubType()) {
1249 case "scorm":
1250 $source_obj = new ilObjSCORMLearningModule($this->getRefId());
1251 $new_obj = new ilObjSCORMLearningModule($new_obj->getRefId());
1252 break;
1253
1254 case "scorm2004":
1255 $source_obj = new ilObjSCORM2004LearningModule($this->getRefId());
1256 $new_obj = new ilObjSCORM2004LearningModule($new_obj->getRefId());
1257 break;
1258 }
1259
1260 // copy data directory
1261 $new_obj->populateByDirectoy($source_obj->getDataDirectory());
1262
1263 // // copy authored content ...
1264 // if ($new_obj->getEditable()) {
1265 // $source_obj->copyAuthoredContent($new_obj);
1266 // } else {
1267 // ... or read manifest file
1268 $new_obj->readObject();
1269 // }
1270 $obj_settings = new ilLPObjSettings($this->getId());
1271 $obj_settings->cloneSettings($new_obj->getId());
1273 $olp = ilObjectLP::getInstance($this->getId());
1274 $collection = $olp->getCollectionInstance();
1275 if ($collection) {
1276 $collection->cloneCollection($new_obj->getRefId(), $cp_options->getCopyId());
1277 }
1278 }
1279 return $new_obj;
1280 }
1281
1282
1286 public function getApiStudentId(): string
1287 {
1288 global $DIC;
1289 $usr = $DIC->user();
1290 $idSetting = $this->getIdSetting();
1291 $studentId = (string) $usr->getId();
1292 if ($idSetting % 2 == 1) {
1293 $studentId = $usr->getLogin();
1294 }
1295 if ($idSetting > 3) {
1296 $studentId .= '_o_' . $this->getId();
1297 } elseif ($idSetting > 1) {
1298 $studentId .= '_r_' . $this->getRefId();
1299 }
1300 return $studentId;
1301 }
1302
1307 public function getApiStudentName(): string
1308 {
1309 global $DIC;
1310 $lng = $DIC->language();
1311 $usr = $DIC->user();
1312 $studentName = " ";
1313 switch ($this->getNameSetting()) {
1314 case 0:
1315 $studentName = $usr->getLastname() . ', ' . $usr->getFirstname();
1316 break;
1317 case 1:
1318 $studentName = $usr->getFirstname() . ' ' . $usr->getLastname();
1319 break;
1320 case 2:
1321 $studentName = $usr->getFullname();
1322 break;
1323 case 3:
1324 switch ($usr->getGender()) {
1325 case 'f':
1326 $studentName = $lng->txt('salutation_f') . ' ';
1327 break;
1328
1329 case 'm':
1330 $studentName = $lng->txt('salutation_m') . ' ';
1331 break;
1332
1333 case 'n':
1334 $studentName = '';//$lng->txt('salutation_n');
1335 break;
1336
1337 default:
1338 $studentName = $lng->txt('salutation') . ' ';
1339 }
1340 $studentName .= $usr->getLastname();
1341 break;
1342 case 4:
1343 $studentName = $usr->getFirstname();
1344 break;
1345 }
1346 return $studentName;
1347 }
1348
1349 //todo : replace LinkButton
1350
1354 public function getViewButton(): ilLinkButton //\ILIAS\UI\Component\Button\Primary
1355 {
1356 $setUrl = "ilias.php?baseClass=ilSAHSPresentationGUI&amp;ref_id=" . $this->getRefID();
1357 // $setUrl = $this->getLinkTargetByClass("ilsahspresentationgui", "")."&amp;ref_id=".$this->getRefID();
1358 $setTarget = "ilContObj" . $this->getId();
1359 $om = $this->getOpenMode();
1360 $width = $this->getWidth();
1361 $height = $this->getHeight();
1362 if (($om == 5 || $om == 1) && $width > 0 && $height > 0) {
1363 $om++;
1364 }
1365 if ($om != 0) {
1366 $setUrl = "javascript:void(0); onclick=startSAHS('" . $setUrl . "','ilContObj" . $this->getId() . "'," . $om . "," . $width . "," . $height . ");";
1367 $setTarget = "";
1368 }
1369
1370
1371 //todo : replace LinkButton - but target needed
1372 // $button = $this->ui->factory()->button()->primary(
1373 // $this->lng->txt("view"),
1374 // $setUrl
1375 // );
1376
1377 $button = ilLinkButton::getInstance();
1378 $button->setCaption("start_lm");//view
1379 $button->setPrimary(true);
1380 $button->setUrl($setUrl);
1381 $button->setTarget($setTarget);
1382 return $button;
1383 }
1384}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getInstance(int $a_copy_id)
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static renameExecutables(string $a_dir)
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
getLangKey()
Return lang key.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getInstalledLanguages()
Get installed languages.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
static _lookupDiskUsage(int $a_id)
Returns the number of bytes used on the harddisk by the learning module with the specified object id.
Class ilObjSCORMLearningModule.
getAPIFunctionsPrefix()
get api functions prefix
getDefaultLessonMode()
get default lesson mode
getMaxPoints()
Returns score.max for the learning module, refered to the last sco where score.max is set.
setDefaultLessonMode(string $a_lesson_mode)
set default lesson mode
setAssignedGlossary(int $a_assigned_glossary)
getApiStudentId()
Get cmi.core.student_id / cmi.learner_id for API.
createDataDirectory()
creates data directory for package files ("./public/data/lm_data/lm_<id>")
setTries(int $a_tries)
Set default tries for questions.
getApiStudentName()
Get cmi.core.student_name / cmi.learner_name for API note: 'lastname, firstname' is required for SCOR...
getDiskUsage()
Gets the disk usage of the object in bytes.
static getScormModulesForGlossary(int $a_glo_id)
Get SCORM modules that assign a certain glossary.
setNoMenu(bool $a_no_menu)
disable menu
getFourth_Edition()
SCORM 2004 4th edition features.
getIe_force_render()
force Internet Explorer to render again after some Milliseconds - useful for learning Modules with a ...
getDataDirectory(?string $mode="filesystem")
get data directory of lm
setAutoReview(bool $a_auto_review)
set auto review as true/false for SCORM 1.2
setStyleSheetId(int $a_style_id)
set ID of assigned style sheet object
setFourth_edition(bool $a_fourth_edition)
getAutoReviewChar()
get auto review as Char for SCORM 2004
getPointsInPercent()
Returns the points in percent for the learning module This is called by the certificate generator if ...
getOpenMode()
open_mode 0: in Tab/new Window like in previous versions 1: in iFrame with width=100% and heigth=100%...
setIe_force_render(bool $a_ie_force_render)
static lookupAssignedGlossary(int $a_slm_id)
Get SCORM modules that assign a certain glossary.
setAPIAdapterName(string $a_api)
set api adapter name
setHideNavig(bool $a_hide_navig)
disable menu
getCacheDeactivated()
BrowserCacheDisabled for SCORM 2004 / ENABLE_JS_DEBUG.
create(bool $upload=false)
create file based lm
setAPIFunctionsPrefix(string $a_prefix)
set api functions prefix
__construct(int $a_id=0, bool $a_call_by_reference=true)
Constructor.
getAutoReview()
get auto review as true/false for SCORM 1.2
checkMasteryScoreValues()
check mastery_score / min_normalized_measure of SCOs (SCORM 1.2) / objectives (SCORM 2004)
populateByDirectoy(string $a_dir, string $a_filename="")
Populate by directory.
getStyleSheetId()
get ID of assigned style sheet object
getSessionDeactivated()
sessionDisabled for SCORM 2004
setAutoReviewChar(?string $a_auto_review)
set auto review as Char for SCORM 2004
setAuto_last_visited(bool $a_auto_last_visited)
static getAffectiveLocalization(int $a_id)
Get affective localization.
static _lookupSubType(int $a_obj_id)
lookup subtype id (scorm, )
static _getTries(int $a_id)
obsolet?
Class ilObjSCORM2004LearningModule.
static _getUniqueScaledScoreForUser(int $a_id, int $a_user)
Get the Unique Scaled Score of a course Conditions: Only one SCO may set cmi.score....
static _getMaxScoreForUser(int $a_id, int $a_user)
Returns score.max for the learning module, refered to the last sco where score.max is set.
Class ilObjSCORMLearningModule.
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
cloneMetaData(ilObject $target_obj)
Copy meta data.
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
ilLanguage $lng
string $type
static & _getInstance(int $a_id, int $a_slm_id)
SCORM Object Tree.
ILIAS Setting Class.
static tf2yn(bool $a_tf)
static yn2tf(string $a_yn)
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$lm_set