ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTestExpressPageObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php";
5 include_once 'Modules/Test/classes/class.ilTestExpressPage.php';
6 
25 {
26  public function nextQuestion()
27  {
28  $obj = new ilObjTest($_REQUEST['ref_id']);
29  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
30 
31  $pos = array_search($_REQUEST['q_id'], $questions);
32 
33  if( $pos !== false )
34  {
35  $next = $questions[$pos + 1];
36  }
37  else
38  {
39  $next = $questions[0];
40  }
41 
42  $this->ctrl->setParameter($this, 'q_id', $next);
43  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
44 
45  ilUtil::redirect($link);
46  }
47 
48  public function prevQuestion()
49  {
50  $obj = new ilObjTest($_REQUEST['ref_id']);
51  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
52 
53  $pos = array_search($_REQUEST['q_id'], $questions);
54 
55  if( $pos !== false )
56  {
57  $next = $questions[$pos - 1];
58  }
59  else
60  {
61  $next = $questions[0];
62  }
63 
64  $this->ctrl->setParameter($this, 'q_id', $next);
65  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
66 
67  ilUtil::redirect($link);
68  }
69 
70  public function __construct($a_id = 0, $a_old_nr = 0) {
71  parent::__construct($a_id, $a_old_nr);
72  }
73 
74  function &executeCommand()
75  {
76  global $ilCtrl, $ilTabs, $ilUser, $lng;
77 
78  $next_class = $this->ctrl->getNextClass($this);
79  $cmd = $this->ctrl->getCmd();
80 
81  switch ($next_class)
82  {
83  case 'ilobjquestionpoolgui':
84 
85  $nodeParts = explode(':', $_GET['cmdNode']);
86 
87  $params = array(
88  'ref_id' => $_GET['ref_id'],
89  'calling_test' => $_GET['ref_id'],
90  'q_id' => $_GET['q_id'],
91  'cmd' => $_GET['cmd'],
92  'cmdClass' => $_GET['cmdClass'],
93  'cmdNode' => $nodeParts[count($nodeParts) - 2] . ':' . $nodeParts[count($nodeParts) - 1],
94  'baseClass' => 'ilObjQuestionPoolGUI',
95  'test_express_mode' => '1'
96  );
97 
98  ilUtil::redirect('ilias.php?' . http_build_query($params, null, '&'));
99 
100  break;
101 
102  case "ilpageeditorgui":
103 
104  if (!$this->getEnableEditing())
105  {
106  ilUtil::sendFailure($lng->txt("permission_denied"), true);
107  $ilCtrl->redirect($this, "preview");
108  }
109 
110  $page_editor = & new ilPageEditorGUI($this->getPageObject(), $this);
111  $page_editor->setLocator($this->locator);
112  $page_editor->setHeader($this->getHeader());
113  $page_editor->setPageBackTitle($this->page_back_title);
114  $page_editor->setIntLinkReturn($this->int_link_return);
115 
116  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
117 
118  $ret = & $this->ctrl->forwardCommand($page_editor);
119 
120  break;
121 
122  case '':
123  case 'iltestexpresspageobjectgui':
124 
125  include_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
126 
127  if( $cmd == 'view' )
128  {
129  $cmd = 'showPage';
130  $ilCtrl->setCmd($cmd);
131  }
132 
133  $q_gui = & assQuestionGUI::_getQuestionGUI('', $_REQUEST["q_id"]);
134 
135  if ($q_gui->object)
136  {
138  $q_gui->object->setObjId($obj->getId());
139  }
140 
141  $cmds = array(
142  'handleToolbarCommand',
143  'addQuestion',
144  'questions',
145  'insertQuestions',
146  'browseForQuestions',
147  'filterAvailableQuestions',
148  'resetfilterAvailableQuestions'
149  );
150 
151  if( in_array($cmd, $cmds) )
152  {
153  return $this->$cmd();
154  }
155  elseif( $q_gui->object )
156  {
157  $total = $this->test_object->evalTotalPersons();
158 
160 
161  if( $total != 0 )
162  {
163  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', "participants");
164  $link = "<a href=\"".$link."\">".$lng->txt("test_has_datasets_warning_page_view_link")."</a>";
165  ilUtil::sendInfo($lng->txt("test_has_datasets_warning_page_view")." ".$link);
166  }
167 
168  if( (in_array($cmd, array('view', 'showPage')) || $cmd == 'edit') && $this->test_object->evalTotalPersons() )
169  {
170  return $this->showPage();
171  }
172 
173  return parent::executeCommand();
174  }
175 
176  break;
177 
178  default:
179 
180  $qtype = $_REQUEST['qtype'];
182 
183  if( !$_GET['q_id'] )
184  {
185  $q_gui = $this->addPageOfQuestions(preg_replace('/(.*?)gui/i', '$1', $_GET['sel_question_types']));
186  $q_gui->setQuestionTabs();
187 
188  $ret = $this->ctrl->forwardCommand($q_gui);
189 
190  break;
191  }
192 
193  $this->ctrl->setReturn($this, "questions");
194 
195  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
196  $q_gui = & assQuestionGUI::_getQuestionGUI($type, $_GET["q_id"]);
197 
198  if( $q_gui->object )
199  {
201  $q_gui->object->setObjId($obj->getId());
202  }
203 
204  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_id');
205  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
206 
207  $q_gui->setQuestionTabs();
208  $ret = & $this->ctrl->forwardCommand($q_gui);
209 
210  break;
211  }
212  }
213 
214  public function addPageOfQuestions($type = '')
215  {
216  global $ilCtrl;
217 
218  if( !$type )
219  {
220  $qtype = $_REQUEST['qtype'];
221  $pool = new ilObjQuestionPool();
223  }
224 
225  $this->ctrl->setReturn($this, "questions");
226 
227  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
228  $q_gui = & assQuestionGUI::_getQuestionGUI($type);
229 
231 
232  $q_gui->object->setObjId($obj->getId());
233 
234  return $q_gui;
235  }
236 
237  public function handleToolbarCommand()
238  {
239  global $ilCtrl;
240 
241  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
242 
243  if( $_REQUEST['qtype'] )
244  {
245  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
246  $questionType = ilObjQuestionPool::getQuestionTypeByTypeId($_REQUEST['qtype']);
247  }
248  elseif( $_REQUEST['sel_question_types'] )
249  {
250  $questionType = $_REQUEST['sel_question_types'];
251  }
252 
253  include_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
255  {
256  $addContEditMode = $_REQUEST['add_quest_cont_edit_mode'];
257  }
258  else
259  {
261  }
262 
263  $q_gui =& assQuestionGUI::_getQuestionGUI($questionType);
264 
265  // CHECK THIS !!! --> obj or ref id ???
266  $q_gui->object->setObjId($_GET['ref_id']);
267  $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
268 
269  $q_gui->object->createNewQuestion();
270 
271  $previousQuestionId = $_REQUEST['position'];
272 
273  switch( $_REQUEST['usage'] )
274  {
275  case 3: // existing pool
276 
277  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $_REQUEST['sel_qpl']);
278  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
279  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
280  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
281 
282  if ($_REQUEST['test_express_mode'])
283  {
284  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
285  }
286 
287  if( isset($_REQUEST['add_quest_cont_edit_mode']) )
288  {
289  $ilCtrl->setParameterByClass(
290  'ilobjtestgui', 'add_quest_cont_edit_mode', $_REQUEST['add_quest_cont_edit_mode']
291  );
292  }
293 
294  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 3);
295  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
296 
297  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
298 
299  ilUtil::redirect($link);
300 
301  break;
302 
303  case 2: // new pool
304 
305  $ilCtrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $_REQUEST['txt_qpl']);
306  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
307  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
308  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
309 
310  if ($_REQUEST['test_express_mode'])
311  {
312  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
313  }
314 
315  if( isset($_REQUEST['add_quest_cont_edit_mode']) )
316  {
317  $ilCtrl->setParameterByClass(
318  'ilobjtestgui', 'add_quest_cont_edit_mode', $_REQUEST['add_quest_cont_edit_mode']
319  );
320  }
321 
322  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 2);
323  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
324 
325  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
326  ilUtil::redirect($link);
327 
328  break;
329 
330  case 1: // no pool
331  default:
332 
333  $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
334 
335  break;
336  }
337  }
338 
339  public function addQuestion()
340  {
341  global $lng, $ilCtrl, $tpl;
342 
343  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
344 
345  $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
346 
347  $form = new ilPropertyFormGUI();
348 
349  $ilCtrl->setParameter($this, 'test_express_mode', 1);
350 
351  $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
352  $form->setTitle($lng->txt("ass_create_question"));
353  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
354 
355  $pool = new ilObjQuestionPool();
356  $questionTypes = $pool->getQuestionTypes(false, true);
357  $options = array();
358 
359  // question type
360  foreach($questionTypes as $label => $data)
361  {
362  $options[$data['question_type_id']] = $label;
363  }
364 
365  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
366  $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
367  $si->setOptions($options);
368  $form->addItem($si, true);
369 
370  // position
371  $questions = $this->test_object->getQuestionTitlesAndIndexes();
372  if($questions)
373  {
374  $si = new ilSelectInputGUI($lng->txt("position"), "position");
375  $options = array('0' => $lng->txt('first'));
376  foreach($questions as $key => $title)
377  {
378  $options[$key] = $lng->txt('behind') . ' '. $title . ' ['.$this->lng->txt('question_id_short') . ': '. $key .']';
379  }
380  $si->setOptions($options);
381  $si->setValue($_REQUEST['q_id']);
382  $form->addItem($si, true);
383  }
384 
385  // content editing mode
387  {
388  $ri = new ilRadioGroupInputGUI($lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
389 
390  $ri->addOption(new ilRadioOption(
391  $lng->txt('tst_add_quest_cont_edit_mode_default'),
393  ));
394 
395  $ri->addOption(new ilRadioOption(
396  $lng->txt('tst_add_quest_cont_edit_mode_page_object'),
398  ));
399 
401 
402  $form->addItem($ri, true);
403  }
404  else
405  {
406  $hi = new ilHiddenInputGUI("question_content_editing_type");
408  $form->addItem($hi, true);
409  }
410 
411  if($this->test_object->getPoolUsage())
412  {
413  // use pool
414  $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
415  $usage->setRequired(true);
416  $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
417  $usage->addOption($no_pool);
418  $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
419  $usage->addOption($existing_pool);
420  $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
421  $usage->addOption($new_pool);
422  $form->addItem($usage);
423 
424  $usage->setValue(1);
425 
426  $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
427  $pools_data = array();
428  foreach($questionpools as $key => $p)
429  {
430  $pools_data[$key] = $p['title'];
431  }
432  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
433  $pools->setOptions($pools_data);
434  $existing_pool->addSubItem($pools);
435 
436  $name = new ilTextInputGUI($this->lng->txt("name"), "txt_qpl");
437  $name->setSize(50);
438  $name->setMaxLength(50);
439  $new_pool->addSubItem($name);
440  }
441 
442  $form->addCommandButton("handleToolbarCommand", $lng->txt("create"));
443  $form->addCommandButton("questions", $lng->txt("cancel"));
444 
445  return $tpl->setContent($form->getHTML());
446  }
447 
448  public function questions()
449  {
450  global $ilCtrl;
451 
452  $ilCtrl->saveParameterByClass('ilobjtestgui', 'q_id');
453 
454  $ilCtrl->redirectByClass('ilobjtestgui', 'showPage');
455  }
456 
457  private function redirectToQuestionEditPage($questionType, $qid, $prev_qid)
458  {
459  $cmdClass = $questionType.'GUI';
460 
461  $this->ctrl->setParameterByClass($cmdClass, 'ref_id', $_GET['ref_id']);
462  $this->ctrl->setParameterByClass($cmdClass, 'sel_question_types', $questionType);
463  $this->ctrl->setParameterByClass($cmdClass, 'test_ref_id', $_GET['ref_id']);
464  $this->ctrl->setParameterByClass($cmdClass, 'calling_test', $_GET['ref_id']);
465  $this->ctrl->setParameterByClass($cmdClass, 'q_id', $qid);
466  $this->ctrl->setParameterByClass($cmdClass, 'prev_qid', $prev_qid);
467 
468  if ($_REQUEST['test_express_mode'])
469  {
470  $this->ctrl->setParameterByClass($cmdClass, 'test_express_mode', 1);
471  }
472 
473  $this->ctrl->redirectByClass(
474  array('ilRepositoryGUI', 'ilObjTestGUI', $questionType."GUI"), 'editQuestion'
475  );
476  }
477 
478  private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
479  {
480  $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $_REQUEST['ref_id']);
481  $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
482  $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
483  $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
484  $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
485 
486  ilUtil::redirect($redir);
487  }
488 
489  function insertQuestions()
490  {
491  $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : array();
492  if (!count($selected_array))
493  {
494  ilUtil::sendInfo($this->lng->txt("tst_insert_missing_question"), true);
495  $this->ctrl->redirect($this, "browseForQuestions");
496  }
497  else
498  {
499  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
500  $manscoring = FALSE;
501 
502  global $tree, $ilDB, $ilPluginAdmin;
503 
504  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
505  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $this->test_object);
506  $testQuestionSetConfig = $testQuestionSetConfigFactory->getQuestionSetConfig();
507 
508  foreach ($selected_array as $key => $value)
509  {
510  $last_question_id = $this->test_object->insertQuestion( $testQuestionSetConfig, $value );
511 
512  if (!$manscoring)
513  {
514  $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
515  }
516  }
517  $this->test_object->saveCompleteStatus( $testQuestionSetConfig );
518  if ($manscoring)
519  {
520  ilUtil::sendInfo($this->lng->txt("manscoring_hint"), TRUE);
521  }
522  else
523  {
524  ilUtil::sendSuccess($this->lng->txt("tst_questions_inserted"), TRUE);
525  }
526 
527  $this->ctrl->setParameter($this, 'q_id', $last_question_id);
528  $this->ctrl->redirect($this, "showPage");
529  return;
530  }
531  }
532 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
const IL_PAGE_PREVIEW
$_POST['username']
Definition: cron.php:12
getPageObject()
Get Page Object.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
This class represents a selection list property in a property form.
This class represents a property form user interface.
const ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT
constant for additional content editing mode "pageobject"
$_GET["client_id"]
static getQuestionTypeByTypeId($type_id)
$cmd
Definition: sahs_server.php:35
Question page GUI class.
Page Editor GUI class.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
This class represents a property in a property form.
addOption($a_option)
Add Option.
$data
setValue($a_value)
Set Value.
if(!is_array($argv)) $options
getEnableEditing()
Get Enable Editing.
setSize($a_size)
Set Size.
& _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
This class represents a text property in a property form.
const IL_PAGE_EDIT
setOptions($a_options)
Set Options.
_needsManualScoring($question_id)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
global $ilUser
Definition: imgupload.php:15
redirectToQuestionEditPage($questionType, $qid, $prev_qid)
global $ilDB
static isAdditionalQuestionContentEditingModePageObjectEnabled()
returns the fact wether content editing with ilias page editor is enabled for questions or not ...
& _getAvailableQuestionpools($use_object_id=FALSE, $equal_points=FALSE, $could_be_offline=FALSE, $showPath=FALSE, $with_questioncount=FALSE, $permission="read", $usr_id="")
Returns the available question pools for the active user.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
static redirect($a_script)
http redirect to other script
ilTestExpressPageObjectGUI: assMultipleChoiceGUI, assClozeTestGUI, assMatchingQuestionGUI ilTestExpr...
$params
Definition: example_049.php:96
setRequired($a_required)
Set Required.
setOutputMode($a_mode=IL_PAGE_PRESENTATION)
Set Output Mode.