ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  'baseClass' => 'ilObjQuestionPoolGUI',
94  'test_express_mode' => '1'
95  );
96 
99  '?' . http_build_query($params, null, '&'),
100  'cmdNode=' . ($nodeParts[count($nodeParts) - 2] . ':' . $nodeParts[count($nodeParts) - 1])
101  )
102  );
103 
104  break;
105 
106  case "ilpageeditorgui":
107 
108  if (!$this->getEnableEditing())
109  {
110  ilUtil::sendFailure($lng->txt("permission_denied"), true);
111  $ilCtrl->redirect($this, "preview");
112  }
113 
114  $page_editor = new ilPageEditorGUI($this->getPageObject(), $this);
115  $page_editor->setLocator($this->locator);
116  $page_editor->setHeader($this->getHeader());
117  $page_editor->setPageBackTitle($this->page_back_title);
118  $page_editor->setIntLinkReturn($this->int_link_return);
119 
120  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
121 
122  $ret = & $this->ctrl->forwardCommand($page_editor);
123 
124  break;
125 
126  case '':
127  case 'iltestexpresspageobjectgui':
128 
129  include_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
130 
131  if($cmd == 'view')
132  {
133  $cmd = 'showPage';
134  $ilCtrl->setCmd($cmd);
135  }
136 
137  $q_gui = assQuestionGUI::_getQuestionGUI('', (int)$_REQUEST["q_id"]);
138 
139  if($q_gui->object)
140  {
141  $obj = ilObjectFactory::getInstanceByRefId((int)$_REQUEST['ref_id']);
142  $q_gui->object->setObjId($obj->getId());
143  }
144 
145  $cmds = array(
146  'handleToolbarCommand',
147  'addQuestion',
148  'questions',
149  'insertQuestions',
150  'browseForQuestions',
151  'filterAvailableQuestions',
152  'resetfilterAvailableQuestions'
153  );
154 
155  if( in_array($cmd, $cmds) )
156  {
157  return $this->$cmd();
158  }
159  elseif( $q_gui->object )
160  {
161  $total = $this->test_object->evalTotalPersons();
162 
164 
165  if( $total != 0 )
166  {
167  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', "participants");
168  $link = "<a href=\"".$link."\">".$lng->txt("test_has_datasets_warning_page_view_link")."</a>";
169  ilUtil::sendInfo($lng->txt("test_has_datasets_warning_page_view")." ".$link);
170  }
171 
172  if( (in_array($cmd, array('view', 'showPage')) || $cmd == 'edit') && $this->test_object->evalTotalPersons() )
173  {
174  return $this->showPage();
175  }
176 
177  return parent::executeCommand();
178  }
179 
180  break;
181 
182  default:
183  $type = ilObjQuestionPool::getQuestionTypeByTypeId(ilUtil::stripSlashes((string)$_REQUEST['qtype']));
184 
185  if(!$_GET['q_id'])
186  {
187  $q_gui = $this->addPageOfQuestions(preg_replace('/(.*?)gui/i', '$1', $_GET['sel_question_types']));
188  $q_gui->setQuestionTabs();
189 
190  $this->ctrl->forwardCommand($q_gui);
191  break;
192  }
193 
194  $this->ctrl->setReturn($this, "questions");
195 
196  require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
197  $q_gui = assQuestionGUI::_getQuestionGUI($type, (int)$_GET['q_id']);
198  if($q_gui->object)
199  {
200  $obj = ilObjectFactory::getInstanceByRefId((int)$_GET['ref_id']);
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  $this->ctrl->forwardCommand($q_gui);
209  break;
210  }
211  }
212 
213  public function addPageOfQuestions($type = '')
214  {
215  global $ilCtrl;
216 
217  if( !$type )
218  {
219  $qtype = $_REQUEST['qtype'];
220  $pool = new ilObjQuestionPool();
222  }
223 
224  $this->ctrl->setReturn($this, "questions");
225 
226  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
227  $q_gui = & assQuestionGUI::_getQuestionGUI($type);
228 
230 
231  $q_gui->object->setObjId($obj->getId());
232 
233  return $q_gui;
234  }
235 
236  public function handleToolbarCommand()
237  {
238  global $ilCtrl;
239 
240  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
241 
242  if( $_REQUEST['qtype'] )
243  {
244  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
245  $questionType = ilObjQuestionPool::getQuestionTypeByTypeId($_REQUEST['qtype']);
246  }
247  elseif( $_REQUEST['sel_question_types'] )
248  {
249  $questionType = $_REQUEST['sel_question_types'];
250  }
251 
252  include_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
254  {
255  $addContEditMode = $_REQUEST['add_quest_cont_edit_mode'];
256  }
257  else
258  {
260  }
261 
262  $q_gui =& assQuestionGUI::_getQuestionGUI($questionType);
263 
264  $q_gui->object->setObjId(ilObject::_lookupObjectId($_GET['ref_id']));
265  $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
266 
267  $q_gui->object->createNewQuestion();
268 
269  $previousQuestionId = $_REQUEST['position'];
270 
271  switch( $_REQUEST['usage'] )
272  {
273  case 3: // existing pool
274 
275  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $_REQUEST['sel_qpl']);
276  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
277  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
278  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
279 
280  if ($_REQUEST['test_express_mode'])
281  {
282  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
283  }
284 
285  if( isset($_REQUEST['add_quest_cont_edit_mode']) )
286  {
287  $ilCtrl->setParameterByClass(
288  'ilobjtestgui', 'add_quest_cont_edit_mode', $_REQUEST['add_quest_cont_edit_mode']
289  );
290  }
291 
292  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 3);
293  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
294 
295  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
296 
297  ilUtil::redirect($link);
298 
299  break;
300 
301  case 2: // new pool
302 
303  $ilCtrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $_REQUEST['txt_qpl']);
304  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
305  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
306  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
307 
308  if ($_REQUEST['test_express_mode'])
309  {
310  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
311  }
312 
313  if( isset($_REQUEST['add_quest_cont_edit_mode']) )
314  {
315  $ilCtrl->setParameterByClass(
316  'ilobjtestgui', 'add_quest_cont_edit_mode', $_REQUEST['add_quest_cont_edit_mode']
317  );
318  }
319 
320  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 2);
321  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
322 
323  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
324  ilUtil::redirect($link);
325 
326  break;
327 
328  case 1: // no pool
329  default:
330 
331  $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
332 
333  break;
334  }
335  }
336 
337  public function addQuestion()
338  {
339  global $lng, $ilCtrl, $tpl;
340  global $DIC; /* @var \ILIAS\DI\Container $DIC */
341  $ilHelp = $DIC['ilHelp']; /* @var ilHelpGUI $ilHelp */
342 
343  $subScreenId = array('createQuestion');
344 
345  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
346 
347  $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
348 
349  $form = new ilPropertyFormGUI();
350 
351  $ilCtrl->setParameter($this, 'test_express_mode', 1);
352 
353  $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
354  $form->setTitle($lng->txt("ass_create_question"));
355  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
356 
357  $pool = new ilObjQuestionPool();
358  $questionTypes = $pool->getQuestionTypes(false, true);
359  $options = array();
360 
361  // question type
362  foreach($questionTypes as $label => $data)
363  {
364  $options[$data['question_type_id']] = $label;
365  }
366 
367  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
368  $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
369  $si->setOptions($options);
370  $form->addItem($si, true);
371 
372  // position
373  $questions = $this->test_object->getQuestionTitlesAndIndexes();
374  if($questions)
375  {
376  $si = new ilSelectInputGUI($lng->txt("position"), "position");
377  $options = array('0' => $lng->txt('first'));
378  foreach($questions as $key => $title)
379  {
380  $options[$key] = $lng->txt('behind') . ' '. $title . ' ['.$this->lng->txt('question_id_short') . ': '. $key .']';
381  }
382  $si->setOptions($options);
383  $si->setValue($_REQUEST['q_id']);
384  $form->addItem($si, true);
385  }
386 
387  // content editing mode
389  {
390  $subScreenId[] = 'editMode';
391 
392  $ri = new ilRadioGroupInputGUI($lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
393 
394  $ri->addOption(new ilRadioOption(
395  $lng->txt('tst_add_quest_cont_edit_mode_default'),
397  ));
398 
399  $ri->addOption(new ilRadioOption(
400  $lng->txt('tst_add_quest_cont_edit_mode_page_object'),
402  ));
403 
405 
406  $form->addItem($ri, true);
407  }
408  else
409  {
410  $hi = new ilHiddenInputGUI("question_content_editing_type");
412  $form->addItem($hi, true);
413  }
414 
415  if($this->test_object->getPoolUsage())
416  {
417  $subScreenId[] = 'poolSelect';
418 
419  // use pool
420  $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
421  $usage->setRequired(true);
422  $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
423  $usage->addOption($no_pool);
424  $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
425  $usage->addOption($existing_pool);
426  $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
427  $usage->addOption($new_pool);
428  $form->addItem($usage);
429 
430  $usage->setValue(1);
431 
432  $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
433  $pools_data = array();
434  foreach($questionpools as $key => $p)
435  {
436  $pools_data[$key] = $p['title'];
437  }
438  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
439  $pools->setOptions($pools_data);
440  $existing_pool->addSubItem($pools);
441 
442  $name = new ilTextInputGUI($this->lng->txt("name"), "txt_qpl");
443  $name->setSize(50);
444  $name->setMaxLength(50);
445  $new_pool->addSubItem($name);
446  }
447 
448  $form->addCommandButton("handleToolbarCommand", $lng->txt("create"));
449  $form->addCommandButton("questions", $lng->txt("cancel"));
450 
451  $ilHelp->setSubScreenId(implode('_', $subScreenId));
452 
453  return $tpl->setContent($form->getHTML());
454  }
455 
456  public function questions()
457  {
458  global $ilCtrl;
459 
460  $ilCtrl->saveParameterByClass('ilobjtestgui', 'q_id');
461 
462  $ilCtrl->redirectByClass('ilobjtestgui', 'showPage');
463  }
464 
465  private function redirectToQuestionEditPage($questionType, $qid, $prev_qid)
466  {
467  $cmdClass = $questionType.'GUI';
468 
469  $this->ctrl->setParameterByClass($cmdClass, 'ref_id', $_GET['ref_id']);
470  $this->ctrl->setParameterByClass($cmdClass, 'sel_question_types', $questionType);
471  $this->ctrl->setParameterByClass($cmdClass, 'test_ref_id', $_GET['ref_id']);
472  $this->ctrl->setParameterByClass($cmdClass, 'calling_test', $_GET['ref_id']);
473  $this->ctrl->setParameterByClass($cmdClass, 'q_id', $qid);
474  $this->ctrl->setParameterByClass($cmdClass, 'prev_qid', $prev_qid);
475 
476  if ($_REQUEST['test_express_mode'])
477  {
478  $this->ctrl->setParameterByClass($cmdClass, 'test_express_mode', 1);
479  }
480 
481  $this->ctrl->redirectByClass(
482  array('ilRepositoryGUI', 'ilObjTestGUI', $questionType."GUI"), 'editQuestion'
483  );
484  }
485 
486  private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
487  {
488  $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $_REQUEST['ref_id']);
489  $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
490  $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
491  $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
492  $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
493 
494  ilUtil::redirect($redir);
495  }
496 
497  function insertQuestions()
498  {
499  $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : array();
500  if (!count($selected_array))
501  {
502  ilUtil::sendInfo($this->lng->txt("tst_insert_missing_question"), true);
503  $this->ctrl->redirect($this, "browseForQuestions");
504  }
505  else
506  {
507  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
508  $manscoring = FALSE;
509 
510  global $tree, $ilDB, $ilPluginAdmin;
511 
512  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
513  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $this->test_object);
514  $testQuestionSetConfig = $testQuestionSetConfigFactory->getQuestionSetConfig();
515 
516  foreach ($selected_array as $key => $value)
517  {
518  $last_question_id = $this->test_object->insertQuestion( $testQuestionSetConfig, $value );
519 
520  if (!$manscoring)
521  {
522  $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
523  }
524  }
525  $this->test_object->saveCompleteStatus( $testQuestionSetConfig );
526  if ($manscoring)
527  {
528  ilUtil::sendInfo($this->lng->txt("manscoring_hint"), TRUE);
529  }
530  else
531  {
532  ilUtil::sendSuccess($this->lng->txt("tst_questions_inserted"), TRUE);
533  }
534 
535  $this->ctrl->setParameter($this, 'q_id', $last_question_id);
536  $this->ctrl->redirect($this, "showPage");
537  return;
538  }
539  }
540 }
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
getPageObject()
Get Page Object.
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 _needsManualScoring($question_id)
static getQuestionTypeByTypeId($type_id)
$cmd
Definition: sahs_server.php:35
Question page GUI class.
$total
Definition: Utf8Test.php:87
Page Editor GUI class.
static _lookupObjectId($a_ref_id)
lookup object id
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.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
This class represents a property in a property form.
addOption($a_option)
Add Option.
setValue($a_value)
Set Value.
if(!is_array($argv)) $options
static _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
getEnableEditing()
Get Enable Editing.
setSize($a_size)
Set Size.
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
const IL_PAGE_EDIT
setOptions($a_options)
Set Options.
Create styles array
The data for the language used.
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"
redirectToQuestionEditPage($questionType, $qid, $prev_qid)
global $ilDB
$ret
Definition: parser.php:6
static isAdditionalQuestionContentEditingModePageObjectEnabled()
returns the fact wether content editing with ilias page editor is enabled for questions or not ...
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
static redirect($a_script)
http redirect to other script
ilTestExpressPageObjectGUI: assMultipleChoiceGUI, assClozeTestGUI, assMatchingQuestionGUI ilTestExpr...
$_POST["username"]
static _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.
$params
Definition: example_049.php:96
setRequired($a_required)
Set Required.
setOutputMode($a_mode=IL_PAGE_PRESENTATION)
Set Output Mode.