ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseLPBadgeGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected int $parent_ref_id = 0;
28
29 protected ilTree $tree;
31 protected ilLanguage $lng;
32
33 public function __construct()
34 {
35 global $DIC;
36
37 $this->tree = $DIC->repositoryTree();
38 $this->ctrl = $DIC->ctrl();
39 $this->lng = $DIC->language();
40 $this->lng->loadLanguageModule('trac');
41 }
42
43 public function initConfigForm(ilPropertyFormGUI $a_form, int $a_parent_ref_id): void
44 {
45 $this->parent_ref_id = $a_parent_ref_id;
46
47 $subitems = new ilRepositorySelector2InputGUI($this->lng->txt("objects"), "subitems", true);
48
49 $exp = $subitems->getExplorerGUI();
50 $exp->setSkipRootNode(true);
51 $exp->setRootId($this->parent_ref_id);
52 $white = $this->getLPTypes($this->parent_ref_id);
53 $exp->setSelectableTypes($white);
54 if (!in_array("fold", $white)) {
55 $white[] = "fold";
56 }
57 $exp->setTypeWhiteList($white);
58 $subitems->setTitleModifier(function ($a_id): string {
59 $obj_id = ilObject::_lookupObjId((int) $a_id);
60 $olp = ilObjectLP::getInstance((int) $obj_id);
62 $mode = $olp->getModeText($olp->getCurrentMode());
63 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
64 $mode = "<strong>$mode</strong>";
65 }
66 return ilObject::_lookupTitle(ilObject::_lookupObjId((int) $a_id)) . " (" . $mode . ")";
67 });
68
69 $subitems->setRequired(true);
70 $a_form->addItem($subitems);
71 }
72
73 protected function getLPTypes(int $a_parent_ref_id): array
74 {
75 $res = [];
76 $root = $this->tree->getNodeData($a_parent_ref_id);
77 $sub_items = $this->tree->getSubTree($root);
78 array_shift($sub_items); // remove root
79
80 foreach ($sub_items as $node) {
81 if (ilObjectLP::isSupportedObjectType($node["type"])) {
82 $class = ilObjectLP::getTypeClass($node["type"]);
84 $modes = $class::getDefaultModes(ilObjUserTracking::_enabledLearningProgress());
85 if (count($modes) > 1) {
86 $res[] = $node["type"];
87 }
88 }
89 }
90 return $res;
91 }
92
93 public function importConfigToForm(ilPropertyFormGUI $a_form, array $a_config): void
94 {
95 if (is_array($a_config["subitems"])) {
96 $items = $a_form->getItemByPostVar("subitems");
97 $items->setValue($a_config["subitems"]);
98 }
99 }
100
101 public function getConfigFromForm(ilPropertyFormGUI $a_form): array
102 {
103 return ["subitems" => $a_form->getInput("subitems")];
104 }
105
106 public static function getInvalidLPModes(): array
107 {
108 /* supported modes
109 LP_MODE_TLT
110 LP_MODE_OBJECTIVES
111 LP_MODE_TEST_FINISHED
112 LP_MODE_TEST_PASSED
113 LP_MODE_EXERCISE_RETURNED
114 LP_MODE_EVENT
115 LP_MODE_SCORM_PACKAGE
116 LP_MODE_PLUGIN
117 LP_MODE_QUESTIONS
118 LP_MODE_SURVEY_FINISHED
119 LP_MODE_VISITED_PAGES
120 LP_MODE_DOWNLOADED
121 LP_MODE_STUDY_PROGRAMME ?!
122 */
123
124 $invalid_modes = array(ilLPObjSettings::LP_MODE_DEACTIVATED,
126 );
127
128 // without active LP the following modes cannot be supported
130 // status cannot be set without active LP
131 //$invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
134
135 // mode cannot be configured without active LP
136 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
139 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
140 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
141 }
142 return $invalid_modes;
143 }
144
145 public function validateForm(ilPropertyFormGUI $a_form): bool
146 {
147 $invalid = array();
148 $invalid_modes = self::getInvalidLPModes();
149 foreach ($a_form->getInput("subitems") as $ref_id) {
150 $obj_id = ilObject::_lookupObjId((int) $ref_id);
151 $olp = ilObjectLP::getInstance((int) $obj_id);
152 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
153 $invalid[] = ilObject::_lookupTitle((int) $obj_id);
154 }
155 }
156 if ($invalid !== []) {
157 $mess = sprintf($this->lng->txt("badge_course_lp_invalid"), implode(", ", $invalid));
158 $a_form->getItemByPostVar("subitems")->setAlert($mess);
159 return false;
160 }
161 return true;
162 }
163}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getConfigFromForm(ilPropertyFormGUI $a_form)
Export values to DB.
importConfigToForm(ilPropertyFormGUI $a_form, array $a_config)
Set form values.
getLPTypes(int $a_parent_ref_id)
validateForm(ilPropertyFormGUI $a_form)
Custom form validation.
initConfigForm(ilPropertyFormGUI $a_form, int $a_parent_ref_id)
Add custom fields to form.
language handling
static isSupportedObjectType(string $type)
static getTypeClass(string $type)
static getInstance(int $obj_id)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26