ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_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['lng'];
33  $this->ctrl = $GLOBALS['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) {
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['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 }
static getInstanceByObjId($a_obj_id)
get singleton instance
This class represents an option in a radio group.
static getInstance($a_container_id)
Get instance by container id.
static lookupObjectiveTitle($a_objective_id, $a_add_description=false)
This class represents a selection list property in a property form.
This class represents a property form user interface.
const QUESTION_SET_TYPE_RANDOM
type setting value for random question set
__construct($gui, ilObject $a_container_obj, $a_type)
Constructor.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static _getObjectiveIds($course_id, $a_activated_only=false)
initForm($a_as_multi_assignment=false)
static _lookupTitle($a_id)
lookup object title
$a_type
Definition: workflow.php:92
This class represents a property in a property form.
if(isset($_POST['submit'])) $form
static _lookupObjId($a_id)
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
Create styles array
The data for the language used.
getAssignableTests()
Get assignable tests.
settings()
Definition: settings.php:2
This class represents a text area property in a property form.
const QUESTION_SET_TYPE_FIXED
type setting value for fixed question set
setRequired($a_required)
Set Required.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20