ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLOTestAssignmentForm.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
26{
27 public const TEST_NEW = 1;
28 public const TEST_ASSIGN = 2;
29
32 private ilTree $tree;
33
35 private object $gui;
37 private int $type = 0;
38
42 public function __construct(object $gui, ilObject $a_container_obj, int $a_type)
43 {
44 global $DIC;
45
46 $this->lng = $DIC->language();
47 $this->ctrl = $DIC->ctrl();
48 $this->tree = $DIC->repositoryTree();
49 $this->gui = $gui;
50 $this->container = $a_container_obj;
52 $this->type = $a_type;
53 }
54
55 public function getContainer(): ilObject
56 {
57 return $this->container;
58 }
59
60 public function getGUI(): object
61 {
62 return $this->gui;
63 }
64
65 public function getSettings(): ilLOSettings
66 {
67 return $this->settings;
68 }
69
70 public function getTestType(): int
71 {
72 return $this->type;
73 }
74
75 public function initForm(bool $a_as_multi_assignment = false): ilPropertyFormGUI
76 {
77 $form = new ilPropertyFormGUI();
78 $form->setTitle($this->lng->txt('crs_loc_tst_assignment'));
79 $form->setFormAction($this->ctrl->getFormAction($this->getGUI()));
80
81 if ($a_as_multi_assignment) {
82 $form->addCommandButton('saveMultiTestAssignment', $this->lng->txt('save'));
83 } else {
84 $form->addCommandButton('saveTest', $this->lng->txt('save'));
85 }
86
87 switch ($this->getTestType()) {
89 $form->setTitle($this->lng->txt('crs_loc_settings_itest_tbl'));
90 break;
91
93 $form->setTitle($this->lng->txt('crs_loc_settings_qtest_tbl'));
94 break;
95 }
96
97 $assignable = $this->getAssignableTests();
98
99 $cr_mode = new ilRadioGroupInputGUI($this->lng->txt('crs_loc_form_assign_it'), 'mode');
100 $cr_mode->setRequired(true);
101 $cr_mode->setValue((string) self::TEST_NEW);
102
103 $new = new ilRadioOption($this->lng->txt('crs_loc_form_tst_new'), (string) self::TEST_NEW);
104
105 switch ($this->getTestType()) {
107 $new->setInfo($this->lng->txt("crs_loc_form_tst_new_initial_info"));
108 break;
109
111 $new->setInfo($this->lng->txt("crs_loc_form_tst_new_qualified_info"));
112 break;
113 }
114
115 // title
116 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
117 $ti->setMaxLength(128);
118 $ti->setSize(40);
119 $ti->setRequired(true);
120 $new->addSubItem($ti);
121
122 // description
123 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
124 $ta->setCols(40);
125 $ta->setRows(2);
126 $new->addSubItem($ta);
127
128 // Question assignment type
129 $this->lng->loadLanguageModule('assessment');
130 $qst = new ilRadioGroupInputGUI($this->lng->txt('tst_question_set_type'), 'qtype');
131 $qst->setRequired(true);
132
133 $random = new ilRadioOption(
134 $this->lng->txt('tst_question_set_type_random'),
136 );
137 $qst->addOption($random);
138
139 $fixed = new ilRadioOption(
140 $this->lng->txt('tst_question_set_type_fixed'),
142 );
143 $qst->addOption($fixed);
144 $new->addSubItem($qst);
145 $cr_mode->addOption($new);
146
147 // assign existing
148 $existing = new ilRadioOption($this->lng->txt('crs_loc_form_assign'), (string) self::TEST_ASSIGN);
149
150 switch ($this->getTestType()) {
152 $existing->setInfo($this->lng->txt("crs_loc_form_assign_initial_info"));
153 break;
154
156 $existing->setInfo($this->lng->txt("crs_loc_form_assign_qualified_info"));
157 break;
158 }
159
160 if ($assignable === []) {
161 $existing->setDisabled(true);
162 }
163 $cr_mode->addOption($existing);
164
165 $options = array();
166 $options[''] = $this->lng->txt('select_one');
167 foreach ($assignable as $tst_ref_id) {
168 $tst_obj_id = ilObject::_lookupObjId($tst_ref_id);
169 $options[$tst_ref_id] = ilObject::_lookupTitle($tst_obj_id);
170 }
171 $selectable = new ilSelectInputGUI($this->lng->txt('crs_loc_form_available_tsts'), 'tst');
172 $selectable->setRequired(true);
173 $selectable->setOptions($options);
174 $existing->addSubItem($selectable);
175 $form->addItem($cr_mode);
176 if ($a_as_multi_assignment) {
177 $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
178
179 $objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainer()->getId(), false);
180
181 $options = array();
182 $options[''] = $this->lng->txt('select_one');
183 foreach ($objective_ids as $oid) {
184 $already_assigned_tst = $assignments->getTestByObjective($oid, $this->getTestType());
185 if (!$already_assigned_tst) {
186 $options[$oid] = ilCourseObjective::lookupObjectiveTitle($oid);
187 }
188 }
189
190 $objective = new ilSelectInputGUI($this->lng->txt('crs_objectives'), 'objective');
191 $objective->setRequired(true);
192 $objective->setOptions($options);
193 $form->addItem($objective);
194 }
195 return $form;
196 }
197
198 protected function getAssignableTests(): array
199 {
200 $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
201
202 $tests = array();
203 foreach ($this->tree->getChildsByType($this->getContainer()->getRefId(), 'tst') as $tree_node) {
204 if (!in_array($tree_node['child'], $assignments->getTests())) {
205 $tests[] = $tree_node['child'];
206 }
207 }
208 return $tests;
209 }
210}
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
Settings for LO courses.
static getInstanceByObjId(int $a_obj_id)
initForm(bool $a_as_multi_assignment=false)
__construct(object $gui, ilObject $a_container_obj, int $a_type)
Constructor.
static getInstance(int $a_container_id)
language handling
const QUESTION_SET_TYPE_RANDOM
const QUESTION_SET_TYPE_FIXED
Class ilObject Basic functions for all objects.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
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...
global $DIC
Definition: shib_login.php:26