ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLOTestAssignmentForm.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
5
14{
15 const TEST_NEW = 1;
16 const TEST_ASSIGN = 2;
17
18 private $lng = null;
19 private $ctrl = null;
20
21 private $container = null;
22 private $gui = null;
23 private $settings = null;
24
25 private $type = 0;
26
30 public function __construct($gui, ilObject $a_container_obj, $a_type)
31 {
32 $this->lng = $GLOBALS['DIC']['lng'];
33 $this->ctrl = $GLOBALS['DIC']['ilCtrl'];
34
35 $this->gui = $gui;
36 $this->container = $a_container_obj;
37 $this->settings = ilLOSettings::getInstanceByObjId($this->getContainer()->getId());
38
39 $this->type = $a_type;
40 }
41
45 public function getContainer()
46 {
47 return $this->container;
48 }
49
50 public function getGUI()
51 {
52 return $this->gui;
53 }
54
59 public function getSettings()
60 {
61 return $this->settings;
62 }
63
64 public function getTestType()
65 {
66 return $this->type;
67 }
68
69 public function initForm($a_as_multi_assignment = false)
70 {
71 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
72 $form = new ilPropertyFormGUI();
73 $form->setTitle($this->lng->txt('crs_loc_tst_assignment'));
74 $form->setFormAction($this->ctrl->getFormAction($this->getGUI()));
75
76 if ($a_as_multi_assignment) {
77 $form->addCommandButton('saveMultiTestAssignment', $this->lng->txt('save'));
78 } else {
79 $form->addCommandButton('saveTest', $this->lng->txt('save'));
80 }
81
82 switch ($this->getTestType()) {
84 $form->setTitle($this->lng->txt('crs_loc_settings_itest_tbl'));
85 break;
86
88 $form->setTitle($this->lng->txt('crs_loc_settings_qtest_tbl'));
89 break;
90
91 }
92
93 $assignable = $this->getAssignableTests();
94
95 $cr_mode = new ilRadioGroupInputGUI($this->lng->txt('crs_loc_form_assign_it'), 'mode');
96 $cr_mode->setRequired(true);
97 $cr_mode->setValue(self::TEST_NEW);
98
99 $new = new ilRadioOption($this->lng->txt('crs_loc_form_tst_new'), self::TEST_NEW);
100
101 switch ($this->getTestType()) {
103 $new->setInfo($this->lng->txt("crs_loc_form_tst_new_initial_info"));
104 break;
105
107 $new->setInfo($this->lng->txt("crs_loc_form_tst_new_qualified_info"));
108 break;
109 }
110
111 // title
112 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
113 $ti->setMaxLength(128);
114 $ti->setSize(40);
115 $ti->setRequired(true);
116 $new->addSubItem($ti);
117
118 // description
119 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
120 $ta->setCols(40);
121 $ta->setRows(2);
122 $new->addSubItem($ta);
123
124 // Question assignment type
125 include_once './Modules/Test/classes/class.ilObjTest.php';
126 $this->lng->loadLanguageModule('assessment');
127 $qst = new ilRadioGroupInputGUI($this->lng->txt('tst_question_set_type'), 'qtype');
128 $qst->setRequired(true);
129
130 $random = new ilRadioOption(
131 $this->lng->txt('tst_question_set_type_random'),
133 );
134 $qst->addOption($random);
135
136 $fixed = new ilRadioOption(
137 $this->lng->txt('tst_question_set_type_fixed'),
139 );
140 $qst->addOption($fixed);
141 $new->addSubItem($qst);
142 $cr_mode->addOption($new);
143
144 // assign existing
145 $existing = new ilRadioOption($this->lng->txt('crs_loc_form_assign'), self::TEST_ASSIGN);
146
147 switch ($this->getTestType()) {
149 $existing->setInfo($this->lng->txt("crs_loc_form_assign_initial_info"));
150 break;
151
153 $existing->setInfo($this->lng->txt("crs_loc_form_assign_qualified_info"));
154 break;
155 }
156
157 if (!$assignable) {
158 $existing->setDisabled(true);
159 }
160 $cr_mode->addOption($existing);
161
162 $options = array();
163 $options[''] = $this->lng->txt('select_one');
164 foreach ((array) $assignable as $tst_ref_id) {
165 $tst_obj_id = ilObject::_lookupObjId($tst_ref_id);
166 $options[$tst_ref_id] = ilObject::_lookupTitle($tst_obj_id);
167 }
168 $selectable = new ilSelectInputGUI($this->lng->txt('crs_loc_form_available_tsts'), 'tst');
169 $selectable->setRequired(true);
170 $selectable->setOptions($options);
171 $existing->addSubItem($selectable);
172
173 $form->addItem($cr_mode);
174
175
176 if ($a_as_multi_assignment) {
177 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
178 $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
179
180 include_once './Modules/Course/classes/class.ilCourseObjective.php';
181 $objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainer()->getId(), false);
182
183 $options = array();
184 $options[''] = $this->lng->txt('select_one');
185 foreach ($objective_ids as $oid) {
186 $already_assigned_tst = $assignments->getTestByObjective($oid, $this->getTestType());
187 if (!$already_assigned_tst) {
188 $options[$oid] = ilCourseObjective::lookupObjectiveTitle($oid);
189 }
190 }
191
192 $objective = new ilSelectInputGUI($this->lng->txt('crs_objectives'), 'objective');
193 $objective->setRequired(true);
194 $objective->setOptions($options);
195 $form->addItem($objective);
196 }
197
198 return $form;
199 }
200
205 protected function getAssignableTests()
206 {
207 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
208 $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
209
210 $tests = array();
211 foreach ($GLOBALS['DIC']['tree']->getChildsByType($this->getContainer()->getRefId(), 'tst') as $tree_node) {
212 if (!in_array($tree_node['child'], $assignments->getTests())) {
213 $tests[] = $tree_node['child'];
214 }
215 }
216 return $tests;
217 }
218}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static lookupObjectiveTitle($a_objective_id, $a_add_description=false)
static _getObjectiveIds($course_id, $a_activated_only=false)
static getInstanceByObjId($a_obj_id)
get singleton instance
getAssignableTests()
Get assignable tests.
initForm($a_as_multi_assignment=false)
__construct($gui, ilObject $a_container_obj, $a_type)
Constructor.
static getInstance($a_container_id)
Get instance by container id.
const QUESTION_SET_TYPE_RANDOM
type setting value for random question set
const QUESTION_SET_TYPE_FIXED
type setting value for fixed question set
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
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.
settings()
Definition: settings.php:2
$a_type
Definition: workflow.php:92