ILIAS  release_8 Revision v8.24
class.ilLOTestAssignmentForm.php
Go to the documentation of this file.
1<?php
2
3declare(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
98 $assignable = $this->getAssignableTests();
99
100 $cr_mode = new ilRadioGroupInputGUI($this->lng->txt('crs_loc_form_assign_it'), 'mode');
101 $cr_mode->setRequired(true);
102 $cr_mode->setValue((string) self::TEST_NEW);
103
104 $new = new ilRadioOption($this->lng->txt('crs_loc_form_tst_new'), (string) self::TEST_NEW);
105
106 switch ($this->getTestType()) {
108 $new->setInfo($this->lng->txt("crs_loc_form_tst_new_initial_info"));
109 break;
110
112 $new->setInfo($this->lng->txt("crs_loc_form_tst_new_qualified_info"));
113 break;
114 }
115
116 // title
117 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
118 $ti->setMaxLength(128);
119 $ti->setSize(40);
120 $ti->setRequired(true);
121 $new->addSubItem($ti);
122
123 // description
124 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
125 $ta->setCols(40);
126 $ta->setRows(2);
127 $new->addSubItem($ta);
128
129 // Question assignment type
130 $this->lng->loadLanguageModule('assessment');
131 $qst = new ilRadioGroupInputGUI($this->lng->txt('tst_question_set_type'), 'qtype');
132 $qst->setRequired(true);
133
134 $random = new ilRadioOption(
135 $this->lng->txt('tst_question_set_type_random'),
137 );
138 $qst->addOption($random);
139
140 $fixed = new ilRadioOption(
141 $this->lng->txt('tst_question_set_type_fixed'),
143 );
144 $qst->addOption($fixed);
145 $new->addSubItem($qst);
146 $cr_mode->addOption($new);
147
148 // assign existing
149 $existing = new ilRadioOption($this->lng->txt('crs_loc_form_assign'), (string) self::TEST_ASSIGN);
150
151 switch ($this->getTestType()) {
153 $existing->setInfo($this->lng->txt("crs_loc_form_assign_initial_info"));
154 break;
155
157 $existing->setInfo($this->lng->txt("crs_loc_form_assign_qualified_info"));
158 break;
159 }
160
161 if ($assignable === []) {
162 $existing->setDisabled(true);
163 }
164 $cr_mode->addOption($existing);
165
166 $options = array();
167 $options[''] = $this->lng->txt('select_one');
168 foreach ($assignable as $tst_ref_id) {
169 $tst_obj_id = ilObject::_lookupObjId($tst_ref_id);
170 $options[$tst_ref_id] = ilObject::_lookupTitle($tst_obj_id);
171 }
172 $selectable = new ilSelectInputGUI($this->lng->txt('crs_loc_form_available_tsts'), 'tst');
173 $selectable->setRequired(true);
174 $selectable->setOptions($options);
175 $existing->addSubItem($selectable);
176 $form->addItem($cr_mode);
177 if ($a_as_multi_assignment) {
178 $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
179
180 $objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainer()->getId(), false);
181
182 $options = array();
183 $options[''] = $this->lng->txt('select_one');
184 foreach ($objective_ids as $oid) {
185 $already_assigned_tst = $assignments->getTestByObjective($oid, $this->getTestType());
186 if (!$already_assigned_tst) {
187 $options[$oid] = ilCourseObjective::lookupObjectiveTitle($oid);
188 }
189 }
190
191 $objective = new ilSelectInputGUI($this->lng->txt('crs_objectives'), 'objective');
192 $objective->setRequired(true);
193 $objective->setOptions($options);
194 $form->addItem($objective);
195 }
196 return $form;
197 }
198
199 protected function getAssignableTests(): array
200 {
201 $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
202
203 $tests = array();
204 foreach ($this->tree->getChildsByType($this->getContainer()->getRefId(), 'tst') as $tree_node) {
205 if (!in_array($tree_node['child'], $assignments->getTests())) {
206 $tests[] = $tree_node['child'];
207 }
208 }
209 return $tests;
210 }
211}
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...