4include_once 
"./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
 
    5include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestion.php";
 
    6include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php";
 
    7include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php";
 
    8include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnit.php";
 
    9include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnitCategory.php";
 
   10include_once 
"./Modules/Test/classes/inc.AssessmentConstants.php";
 
   11require_once 
'./Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
 
   32        parent::__construct();
 
   34        $this->newUnitId = 
null;
 
   36            $this->
object->loadFromDb(
$id);
 
   48        $rbacsystem = 
$DIC[
'rbacsystem'];
 
   49        $ilTabs = 
$DIC[
'ilTabs'];
 
   51        $ilTabs->clearTargets();
 
   53        $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI", 
"q_id", 
$_GET[
"q_id"]);
 
   54        include_once 
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
 
   55        $q_type = $this->
object->getQuestionType();
 
   57        if (strlen($q_type)) {
 
   58            $classname = $q_type . 
"GUI";
 
   59            $this->ctrl->setParameterByClass(strtolower($classname), 
"sel_question_types", $q_type);
 
   60            $this->ctrl->setParameterByClass(strtolower($classname), 
"q_id", 
$_GET[
"q_id"]);
 
   64            if ($rbacsystem->checkAccess(
'write', 
$_GET[
"ref_id"])) {
 
   68                    $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI", 
"edit"),
 
   69                    array(
"edit", 
"insert", 
"exec_pg"),
 
   79        $force_active = 
false;
 
   80        if ($rbacsystem->checkAccess(
'write', 
$_GET[
"ref_id"])) {
 
   84                $url = $this->ctrl->getLinkTargetByClass($classname, 
"editQuestion");
 
   87            if (is_array($commands)) {
 
   88                foreach ($commands as 
$key => $value) {
 
   89                    if (preg_match(
"/^suggestrange_.*/", 
$key, $matches)) {
 
   99                    "editQuestion", 
"save", 
"cancel", 
"addSuggestedSolution",
 
  100                    "cancelExplorer", 
"linkChilds", 
"removeSuggestedSolution",
 
  101                    "parseQuestion", 
"saveEdit", 
"suggestRange" 
  122            $this->addTab_Units($ilTabs);
 
  129                $this->ctrl->getLinkTargetByClass($classname, 
"assessment"),
 
  141        if (preg_match(
"/suggestrange_(.*?)/", $cmd, $matches)) {
 
  142            $cmd = 
"suggestRange";
 
  156        $this->editQuestion();
 
  164        $hasErrors = (!$always) ? $this->editQuestion(
true) : 
false;
 
  167            $this->
object->setTitle(
$_POST[
"title"]);
 
  168            $this->
object->setAuthor(
$_POST[
"author"]);
 
  169            $this->
object->setComment(
$_POST[
"comment"]);
 
  170            include_once 
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
 
  172            $this->
object->setQuestion($questiontext);
 
  173            $this->
object->setEstimatedWorkingTime(
 
  174                $_POST[
"Estimated"][
"hh"],
 
  175                $_POST[
"Estimated"][
"mm"],
 
  179            $this->
object->parseQuestionText();
 
  180            $found_vars = array();
 
  181            $found_results = array();
 
  185                if (preg_match(
"/^unit_(\\\$v\d+)$/", 
$key, $matches)) {
 
  186                    array_push($found_vars, $matches[1]);
 
  188                if (preg_match(
"/^unit_(\\\$r\d+)$/", 
$key, $matches)) {
 
  189                    array_push($found_results, $matches[1]);
 
  199            if (!$this->object->checkForDuplicateResults()) {
 
  204            foreach ($found_vars as $variable) {
 
  205                if ($this->object->getVariable($variable) != 
null) {
 
  207                    $varObj->setRangeMinTxt(
$_POST[
"range_min_$variable"]);
 
  208                    $varObj->setRangeMaxTxt(
$_POST[
"range_max_$variable"]);
 
  209                    $this->
object->addVariable($varObj);
 
  213            $tmp_form_vars = array();
 
  214            $tmp_quest_vars = array();
 
  215            foreach ($found_results as 
$result) {
 
  216                $tmp_res_match = preg_match_all(
"/([$][v][0-9]*)/", 
$_POST[
"formula_$result"], $form_vars);
 
  217                $tmp_form_vars = array_merge($tmp_form_vars, $form_vars[0]);
 
  219                $tmp_que_match = preg_match_all(
"/([$][v][0-9]*)/", 
$_POST[
'question'], $quest_vars);
 
  220                $tmp_quest_vars = array_merge($tmp_quest_vars, $quest_vars[0]);
 
  222            $result_has_undefined_vars = array_diff($tmp_form_vars, $found_vars);
 
  223            $question_has_unused_vars = array_diff($tmp_quest_vars, $tmp_form_vars);
 
  225            if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
 
  227                if (count($result_has_undefined_vars) > 0) {
 
  228                    $error_message .= $this->lng->txt(
"res_contains_undef_var") . 
'<br>';
 
  230                if (count($question_has_unused_vars) > 0) {
 
  231                    $error_message .= $this->lng->txt(
"que_contains_unused_var");
 
  238            foreach ($found_results as 
$result) {
 
  239                if (is_object($this->object->getUnitrepository()->getUnit(
$_POST[
"unit_$result"]))) {
 
  240                    $tmp_result_unit = $this->
object->getUnitrepository()->getUnit(
$_POST[
"unit_$result"]);
 
  242                    $tmp_result_unit = 
null;
 
  245                if ($this->object->getResult(
$result) != 
null) {
 
  246                    $use_simple_rating = (
$_POST[
"rating_advanced_$result"] == 1) ? 
false : 
true;
 
  249                        $_POST[
"range_min_$result"],
 
  250                        $_POST[
"range_max_$result"],
 
  251                        $_POST[
"tolerance_$result"],
 
  253                        $_POST[
"formula_$result"],
 
  255                        $_POST[
"precision_$result"],
 
  257                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_sign_$result"] : 
"",
 
  258                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_value_$result"] : 
"",
 
  259                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_unit_$result"] : 
"",
 
  260                        $_POST[
"result_type_$result"] != 0 ? 
$_POST[
"result_type_$result"] : 0
 
  262                    $resObj->setRangeMinTxt(
$_POST[
"range_min_$result"]);
 
  263                    $resObj->setRangeMaxTxt(
$_POST[
"range_max_$result"]);
 
  264                    $this->
object->addResult($resObj);
 
  265                    $this->
object->addResultUnits($resObj, 
$_POST[
"units_$result"]);
 
  268            if ($checked == 
false) {
 
  284        $question_id = $this->
object->getId();
 
  285        require_once 
'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
 
  287        $ilAssQuestionPreviewSession->setParticipantsSolution(array());
 
  292        return in_array($this->ctrl->getCmd(), array(
'saveFQ', 
'saveEdit', 
'saveReturnFQ'));
 
  300    public function editQuestion($checkonly = 
false)
 
  306        include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
 
  308        $this->editForm = 
$form;
 
  310        $form->setFormAction($this->ctrl->getFormAction($this));
 
  312        $form->setMultipart(
false);
 
  313        $form->setTableWidth(
'100%');
 
  314        $form->setId(
'assformulaquestion');
 
  320        $question = 
$form->getItemByPostVar(
'question');
 
  321        $question->setInfo($this->lng->txt(
'fq_question_desc'));
 
  323        $variables = $this->
object->getVariables();
 
  324        $categorized_units = $this->
object->getUnitrepository()->getCategorizedUnits();
 
  325        $result_units = $this->
object->__get(
'resultunits');
 
  327        $unit_options = array();
 
  329        $new_category = 
false;
 
  330        foreach ((array) $categorized_units as $item) {
 
  335                if ($category_name != $item->getDisplayString()) {
 
  336                    $new_category = 
true;
 
  337                    $category_name = $item->getDisplayString();
 
  341            $unit_options[$item->getId()] = $item->getDisplayString() . ($new_category ? 
' (' . $category_name . 
')' : 
'');
 
  342            $new_category = 
false;
 
  345        if (count($variables)) {
 
  349                if ($num_v1 > $num_v2) {
 
  351                } elseif ($num_v1 < $num_v2) {
 
  358            foreach ($variables as $variable) {
 
  363                $variable_header->setTitle(sprintf($this->lng->txt(
'variable_x'), $variable->getVariable()));
 
  365                $range_min = 
new ilNumberInputGUI($this->lng->txt(
'range_min'), 
'range_min_' . $variable->getVariable());
 
  366                $range_min->allowDecimals(
true);
 
  367                $range_min->setSize(3);
 
  368                $range_min->setRequired(
true);
 
  369                $range_min->setValue($variable->getRangeMin());
 
  371                $range_max = 
new ilNumberInputGUI($this->lng->txt(
'range_max'), 
'range_max_' . $variable->getVariable());
 
  372                $range_max->allowDecimals(
true);
 
  373                $range_max->setSize(3);
 
  374                $range_max->setRequired(
true);
 
  375                $range_max->setValue($variable->getRangeMax());
 
  377                $units = 
new ilSelectInputGUI($this->lng->txt(
'unit'), 
'unit_' . $variable->getVariable());
 
  378                $units->setOptions(array(0 => $this->lng->txt(
'no_selection')) + $unit_options);
 
  379                if (is_object($variable->getUnit())) {
 
  380                    $units->setValue($variable->getUnit()->getId());
 
  383                $precision = 
new ilNumberInputGUI($this->lng->txt(
'precision'), 
'precision_' . $variable->getVariable());
 
  384                $precision->setRequired(
true);
 
  385                $precision->setSize(3);
 
  386                $precision->setMinValue(0);
 
  387                $precision->setValue($variable->getPrecision());
 
  388                $precision->setInfo($this->lng->txt(
'fq_precision_info'));
 
  390                $intprecision = 
new ilNumberInputGUI($this->lng->txt(
'intprecision'), 
'intprecision_' . $variable->getVariable());
 
  391                $intprecision->setSize(3);
 
  392                $intprecision->setMinValue(1);
 
  393                $intprecision->setValue($variable->getIntprecision());
 
  394                $intprecision->setInfo($this->lng->txt(
'intprecision_info'));
 
  396                $form->addItem($variable_header);
 
  397                $form->addItem($range_min);
 
  398                $form->addItem($range_max);
 
  399                $form->addItem($units);
 
  400                $form->addItem($precision);
 
  401                $form->addItem($intprecision);
 
  405        $results = $this->
object->getResults();
 
  407            require_once 
'Services/Form/classes/class.ilMultiSelectInputGUI.php';
 
  410                $num_r1 = (int) substr($r1->
getResult(), 2);
 
  411                $num_r2 = (int) substr($r2->
getResult(), 2);
 
  412                if ($num_r1 > $num_r2) {
 
  414                } elseif ($num_r1 < $num_r2) {
 
  426                $result_header->setTitle(sprintf($this->lng->txt(
'result_x'), 
$result->getResult()));
 
  429                $formula->setInfo($this->lng->txt(
'fq_formula_desc'));
 
  430                $formula->setRequired(
true);
 
  431                $formula->setSize(50);
 
  432                $formula->setValue(
$result->getFormula());
 
  433                $formula->setSuffix(
' = ' . 
$result->getResult());
 
  436                    preg_match(
"/suggestrange_(.*)/", $this->ctrl->getCmd(), $matches) &&
 
  437                    strcmp($matches[1], 
$result->getResult()) == 0
 
  446                $range_min->allowDecimals(
true);
 
  447                $range_min->setSize(3);
 
  448                $range_min->setRequired(
true);
 
  449                $range_min->setValue(
$result->getRangeMin());
 
  452                $range_max->allowDecimals(
true);
 
  453                $range_max->setSize(3);
 
  454                $range_max->setRequired(
true);
 
  455                $range_max->setValue(
$result->getRangeMax());
 
  460                $precision->setRequired(
true);
 
  461                $precision->setSize(3);
 
  462                $precision->setMinValue(0);
 
  463                $precision->setInfo($this->lng->txt(
'fq_precision_info'));
 
  464                $precision->setValue(
$result->getPrecision());
 
  467                $tolerance->setSize(3);
 
  468                $tolerance->setMinValue(0);
 
  469                $tolerance->setMaxValue(100);
 
  470                $tolerance->allowDecimals(
true);
 
  471                $tolerance->setInfo($this->lng->txt(
'tolerance_info'));
 
  472                $tolerance->setValue(
$result->getTolerance());
 
  475                $suggest_range_button->setHtml(
'<input type="submit" class="btn btn-default" name="cmd[suggestrange_' . 
$result->getResult() . 
']" value="' . $this->lng->txt(
"suggest_range") . 
'" />');
 
  478                $sel_result_units->setOptions(array(0 => $this->lng->txt(
'no_selection')) + $unit_options);
 
  479                $sel_result_units->setInfo($this->lng->txt(
'result_unit_info'));
 
  480                if (is_object(
$result->getUnit())) {
 
  481                    $sel_result_units->setValue(
$result->getUnit()->getId());
 
  485                $mc_result_units->setOptions($unit_options);
 
  486                $mc_result_units->setInfo($this->lng->txt(
'result_units_info'));
 
  487                $selectedvalues = array();
 
  488                foreach ($unit_options as $unit_id => 
$txt) {
 
  489                    if ($this->
hasResultUnit($result, $unit_id, $result_units)) {
 
  490                        $selectedvalues[] = $unit_id;
 
  493                $mc_result_units->setValue($selectedvalues);
 
  496                $result_type->setRequired(
true);
 
  498                $no_type = 
new ilRadioOption($this->lng->txt(
'no_result_type'), 0);
 
  499                $no_type->setInfo($this->lng->txt(
'fq_no_restriction_info'));
 
  501                $result_dec = 
new ilRadioOption($this->lng->txt(
'result_dec'), 1);
 
  502                $result_dec->setInfo($this->lng->txt(
'result_dec_info'));
 
  504                $result_frac = 
new ilRadioOption($this->lng->txt(
'result_frac'), 2);
 
  505                $result_frac->setInfo($this->lng->txt(
'result_frac_info'));
 
  507                $result_co_frac = 
new ilRadioOption($this->lng->txt(
'result_co_frac'), 3);
 
  508                $result_co_frac->setInfo($this->lng->txt(
'result_co_frac_info'));
 
  510                $result_type->addOption($no_type);
 
  511                $result_type->addOption($result_dec);
 
  512                $result_type->addOption($result_frac);
 
  513                $result_type->addOption($result_co_frac);
 
  514                $result_type->setValue(strlen(
$result->getResultType()) ? 
$result->getResultType() : 0);
 
  517                $points->allowDecimals(
true);
 
  518                $points->setRequired(
true);
 
  520                $points->setMinValue(0);
 
  521                $points->setValue(strlen(
$result->getPoints()) ? 
$result->getPoints() : 1);
 
  524                $rating_type->setValue(1);
 
  525                $rating_type->setInfo($this->lng->txt(
'advanced_rating_info'));
 
  529                    if (!$advanced_rating) {
 
  530                        $rating_type->setDisabled(
true);
 
  531                        $rating_type->setChecked(
false);
 
  533                        $rating_type->setChecked(strlen(
$result->getRatingSimple()) && 
$result->getRatingSimple() ? 
false : 
true);
 
  538                $sign->setRequired(
true);
 
  540                $sign->setMinValue(0);
 
  541                $sign->setValue(
$result->getRatingSign());
 
  542                $rating_type->addSubItem($sign);
 
  545                $value->setRequired(
true);
 
  547                $value->setMinValue(0);
 
  548                $value->setValue(
$result->getRatingValue());
 
  549                $rating_type->addSubItem($value);
 
  552                $unit->setRequired(
true);
 
  554                $unit->setMinValue(0);
 
  555                $unit->setValue(
$result->getRatingUnit());
 
  556                $rating_type->addSubItem($unit);
 
  559                $rating_type->addSubItem($info_text);
 
  561                $form->addItem($result_header);
 
  562                $form->addItem($formula);
 
  563                $form->addItem($range_min);
 
  564                $form->addItem($range_max);
 
  565                $form->addItem($suggest_range_button);
 
  566                $form->addItem($precision);
 
  567                $form->addItem($tolerance);
 
  568                $form->addItem($sel_result_units);
 
  569                $form->addItem($mc_result_units);
 
  570                $form->addItem($result_type);
 
  571                $form->addItem($points);
 
  572                $form->addItem($rating_type);
 
  575            $defined_result_vars = array();
 
  576            $quest_vars = array();
 
  578            $defined_result_res = array();
 
  579            $result_vars = array();
 
  593                $formula = $tmp_result->getFormula();
 
  595                preg_match_all(
"/([$][v][0-9]*)/", $formula, $form_vars);
 
  596                preg_match_all(
"/([$][r][0-9]*)/", $formula, $form_res);
 
  597                foreach ($form_vars[0] as $res_var) {
 
  598                    $defined_result_vars[$res_var] = $res_var;
 
  601                foreach ($form_res[0] as $res_res) {
 
  602                    $defined_result_res[$res_res] = $res_res;
 
  607        $result_has_undefined_vars = [];
 
  608        $question_has_unused_vars = [];
 
  609        $result_has_undefined_res = [];
 
  611        if (is_array($quest_vars) && count($quest_vars) > 0) {
 
  612            $result_has_undefined_vars = array_diff($defined_result_vars, $quest_vars);
 
  613            $question_has_unused_vars = array_diff($quest_vars, $defined_result_vars);
 
  616        if (is_array($result_vars) && count($result_vars) > 0) {
 
  617            $result_has_undefined_res = array_diff($defined_result_res, $result_vars);
 
  621        if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
 
  622            if (count($result_has_undefined_vars) > 0) {
 
  623                $error_message .= $this->lng->txt(
"res_contains_undef_var") . 
'<br>';
 
  625            if (count($question_has_unused_vars) > 0) {
 
  626                $error_message .= $this->lng->txt(
"que_contains_unused_var") . 
'<br>';
 
  635        if (is_array($result_has_undefined_res) && count($result_has_undefined_res) > 0) {
 
  636            $error_message .= $this->lng->txt(
"res_contains_undef_res") . 
'<br>';
 
  640        if ($save && !$checked) {
 
  644        if ($this->object->getId()) {
 
  646            $hidden->setValue($this->object->getId());
 
  647            $form->addItem($hidden);
 
  652        $form->addCommandButton(
'parseQuestion', $this->lng->txt(
"parseQuestion"));
 
  653        $form->addCommandButton(
'saveReturnFQ', $this->lng->txt(
"save_return"));
 
  654        $form->addCommandButton(
'saveFQ', $this->lng->txt(
"save"));
 
  659            $found_vars = array();
 
  660            $found_results = array();
 
  662                if (preg_match(
"/^unit_(\\\$v\d+)$/", 
$key, $matches)) {
 
  663                    array_push($found_vars, $matches[1]);
 
  665                if (preg_match(
"/^unit_(\\\$r\d+)$/", 
$key, $matches)) {
 
  666                    array_push($found_results, $matches[1]);
 
  670            $form->setValuesByPost();
 
  673            $custom_errors = 
false;
 
  674            if (count($variables)) {
 
  675                foreach ($variables as $variable) {
 
  679                    $min_range = 
$form->getItemByPostVar(
'range_min_' . $variable->getVariable());
 
  680                    $max_range = 
$form->getItemByPostVar(
'range_max_' . $variable->getVariable());
 
  681                    if ($min_range->getValue() > $max_range->getValue()) {
 
  682                        $min_range->setAlert($this->lng->txt(
'err_range'));
 
  683                        $max_range->setAlert($this->lng->txt(
'err_range'));
 
  684                        $custom_errors = 
true;
 
  694                    $min_range = 
$form->getItemByPostVar(
'range_min_' . 
$result->getResult());
 
  695                    $max_range = 
$form->getItemByPostVar(
'range_max_' . 
$result->getResult());
 
  696                    if ($min_range->getValue() > $max_range->getValue()) {
 
  697                        $min_range->setAlert($this->lng->txt(
'err_range'));
 
  698                        $max_range->setAlert($this->lng->txt(
'err_range'));
 
  699                        $custom_errors = 
true;
 
  703                    $formula = 
$form->getItemByPostVar(
'formula_' . 
$result->getResult());
 
  704                    if (strpos($formula->getValue(), 
$result->getResult()) !== 
false) {
 
  705                        $formula->setAlert($this->lng->txt(
'errRecursionInResult'));
 
  706                        $custom_errors = 
true;
 
  709                    $result_unit = 
$form->getItemByPostVar(
'unit_' . 
$result->getResult());
 
  710                    $rating_advanced = 
$form->getItemByPostVar(
'rating_advanced_' . 
$result->getResult());
 
  711                    if (((
int) $result_unit->getValue() <= 0) && $rating_advanced->getChecked()) {
 
  713                        $rating_advanced->setDisabled(
true);
 
  714                        $rating_advanced->setChecked(
false);
 
  715                        $rating_advanced->setAlert($this->lng->txt(
'err_rating_advanced_not_allowed'));
 
  716                        $custom_errors = 
true;
 
  717                    } elseif ($rating_advanced->getChecked()) {
 
  718                        $rating_sign = 
$form->getItemByPostVar(
'rating_sign_' . 
$result->getResult());
 
  719                        $rating_value = 
$form->getItemByPostVar(
'rating_value_' . 
$result->getResult());
 
  720                        $rating_unit = 
$form->getItemByPostVar(
'rating_unit_' . 
$result->getResult());
 
  722                        $percentage = $rating_sign->getValue() + $rating_value->getValue() + $rating_unit->getValue();
 
  723                        if ($percentage != 100) {
 
  724                            $rating_advanced->setAlert($this->lng->txt(
'err_wrong_rating_advanced'));
 
  725                            $custom_errors = 
true;
 
  729                    preg_match_all(
"/([$][v][0-9]*)/", $formula->getValue(), $form_vars);
 
  730                    $result_has_undefined_vars = array_diff($form_vars[0], (array) $found_vars);
 
  731                    if (count($result_has_undefined_vars)) {
 
  738            if ($custom_errors && !
$errors) {
 
  742            $form->setValuesByPost(); 
 
  749            $this->tpl->setVariable(
'QUESTION_DATA', 
$form->getHTML());
 
  756        if (array_key_exists(
$result->getResult(), $resultunits)) {
 
  757            if (array_key_exists($unit_id, $resultunits[
$result->getResult()])) {
 
  773        $resultunit = 
$result->getUnit();
 
  781        if (is_object($resultunit)) {
 
  791        $this->editQuestion();
 
  798        $old_id = 
$_GET[
"q_id"];
 
  801            $ilUser->setPref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  802            $ilUser->writePref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  804            $this->
object->saveToDb();
 
  805            $originalexists = $this->
object->_questionExistsInPool($this->object->original_id);
 
  806            include_once 
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
 
  808                $this->ctrl->redirect($this, 
"originalSyncForm");
 
  810            } elseif (
$_GET[
"calling_test"]) {
 
  811                require_once 
'Modules/Test/classes/class.ilObjTest.php';
 
  813                #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId())); 
  814                $q_id = $this->
object->getId();
 
  819                    $ilPluginAdmin = 
$DIC[
'ilPluginAdmin'];
 
  821                    include_once(
"./Modules/Test/classes/class.ilObjTest.php");
 
  825                    require_once 
'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
 
  828                    $new_id = 
$test->insertQuestion(
 
  829                        $testQuestionSetConfigFactory->getQuestionSetConfig(),
 
  830                        $this->object->getId()
 
  834                    if (isset($_REQUEST[
'prev_qid'])) {
 
  835                        $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST[
'prev_qid']);
 
  838                    $this->ctrl->setParameter($this, 
'q_id', $new_id);
 
  839                    $this->ctrl->setParameter($this, 
'calling_test', 
$_GET[
'calling_test']);
 
  840                    #$this->ctrl->setParameter($this, 'test_ref_id', false); 
  842                ilUtil::sendSuccess($this->lng->txt(
"msg_obj_modified"), 
true);
 
  843                if ($_REQUEST[
'test_express_mode']) {
 
  849                if ($this->object->getId() != $old_id) {
 
  851                    ilUtil::sendSuccess($this->lng->txt(
"msg_obj_modified"), 
true);
 
  852                    $this->ctrl->redirectByClass(
"ilobjquestionpoolgui", 
"questions");
 
  854                if (strcmp(
$_SESSION[
"info"], 
"") != 0) {
 
  855                    ilUtil::sendSuccess(
$_SESSION[
"info"] . 
"<br />" . $this->lng->txt(
"msg_obj_modified"), 
true);
 
  857                    ilUtil::sendSuccess($this->lng->txt(
"msg_obj_modified"), 
true);
 
  859                $this->ctrl->redirectByClass(
"ilobjquestionpoolgui", 
"questions");
 
  862            $ilUser->setPref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  863            $ilUser->writePref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  864            $this->
object->saveToDb();
 
  865            $this->editQuestion();
 
  874            $this->editQuestion();
 
  886            $this->
addErrorMessage($this->lng->txt(
"fill_out_all_required_fields"));
 
  920        $graphicalOutput = 
false,
 
  921        $result_output = 
false,
 
  922        $show_question_only = 
true,
 
  923        $show_feedback = 
false,
 
  924        $show_correct_solution = 
false,
 
  925        $show_manual_scoring = 
false,
 
  926        $show_question_text = 
true 
  929        $user_solution = array();
 
  930        if (($active_id > 0) && (!$show_correct_solution)) {
 
  931            $solutions = array();
 
  932            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  934                if (is_null(
$pass)) {
 
  938            $user_solution[
"active_id"] = $active_id;
 
  939            $user_solution[
"pass"] = 
$pass;
 
  941            foreach ($solutions as $idx => $solution_value) {
 
  942                if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
  943                    $user_solution[$matches[1]] = $solution_value[
"value2"];
 
  944                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
 
  945                    if (!array_key_exists($matches[1], $user_solution)) {
 
  946                        $user_solution[$matches[1]] = array();
 
  948                    $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
 
  949                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
 
  950                    if (!array_key_exists($matches[1], $user_solution)) {
 
  951                        $user_solution[$matches[1]] = array();
 
  953                    $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
 
  956        } elseif ($active_id) {
 
  958            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  960                if (is_null(
$pass)) {
 
  964            $user_solution = (array) $this->object->getBestSolution($this->object->getSolutionValues($active_id, 
$pass));
 
  966            $solutionValues = array();
 
  969            if (is_array($participantsSolution)) {
 
  970                foreach ($participantsSolution as $val1 => $val2) {
 
  971                    $solutionValues[] = array(
'value1' => $val1, 
'value2' => $val2);
 
  975            $user_solution = (array) $this->object->getBestSolution($solutionValues);
 
  978        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
  979        $questiontext = $this->
object->substituteVariables($user_solution, $graphicalOutput, 
true, $result_output);
 
  981        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
  983        $solutiontemplate = 
new ilTemplate(
"tpl.il_as_tst_solution_output.html", 
true, 
true, 
"Modules/TestQuestionPool");
 
  985        if (strlen($feedback)) {
 
  991            $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
 
  992            $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, 
true));
 
  994        $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
 
  996        $solutionoutput = $solutiontemplate->get();
 
  997        if (!$show_question_only) {
 
 1001        return $solutionoutput;
 
 1004    public function getPreview($show_question_only = 
false, $showInlineFeedback = 
false)
 
 1006        $user_solution = array();
 
 1011            foreach ($solutions as $val1 => $val2) {
 
 1012                if (preg_match(
"/^(\\\$v\\d+)$/", $val1, $matches)) {
 
 1013                    $user_solution[$matches[1]] = $val2;
 
 1014                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $val1, $matches)) {
 
 1015                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1016                        $user_solution[$matches[1]] = array();
 
 1018                    $user_solution[$matches[1]][
"value"] = $val2;
 
 1019                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $val1, $matches)) {
 
 1020                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1021                        $user_solution[$matches[1]] = array();
 
 1023                    $user_solution[$matches[1]][
"unit"] = $val2;
 
 1026                if (preg_match(
"/^(\\\$r\\d+)/", $val1, $matches) && $user_solution[$matches[1]][
"result_type"] == 0) {
 
 1032        if (!$this->object->hasRequiredVariableSolutionValues($user_solution)) {
 
 1033            $user_solution = $this->
object->getInitialVariableSolutionValues();
 
 1040        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
 1042            $questiontext = $this->
object->substituteVariables($user_solution, 
false, 
false, 
false);
 
 1044            $questiontext = $this->
object->substituteVariables(array());
 
 1046        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
 1048        if (!$show_question_only) {
 
 1050            $questionoutput = $this->
getILIASPage($questionoutput);
 
 1052        return $questionoutput;
 
 1056    public function getTestOutput($active_id, 
$pass, $is_postponed = 
false, $use_post_solutions = 
false, $show_feedback = 
false)
 
 1061        $user_solution = array();
 
 1063            $solutions = (array) $this->object->getTestOutputSolutions($active_id, 
$pass);
 
 1065            $actualPassIndex = 
null;
 
 1066            if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
 
 1067                require_once 
'Modules/Test/classes/class.ilObjTest.php';
 
 1071            foreach ($solutions as $idx => $solution_value) {
 
 1072                if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1073                    if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
 
 1074                        $this->
object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value[
"value2"], 
true);
 
 1077                    $user_solution[$matches[1]] = $solution_value[
"value2"];
 
 1078                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1079                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1080                        $user_solution[$matches[1]] = array();
 
 1082                    $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
 
 1083                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
 
 1084                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1085                        $user_solution[$matches[1]] = array();
 
 1087                    $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
 
 1090                if (preg_match(
"/^(\\\$r\\d+)/", $solution_value[
"value1"], $matches) && $user_solution[$matches[1]][
"result_type"] == 0) {
 
 1097        $solutions = $this->
object->getSolutionValues($active_id, 
$pass, 
true);
 
 1098        foreach ($solutions as $idx => $solution_value) {
 
 1099            if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1100                $user_solution[$matches[1]] = $solution_value[
"value2"];
 
 1105        if (!$this->object->hasRequiredVariableSolutionValues($user_solution)) {
 
 1106            foreach ($this->object->getInitialVariableSolutionValues() as $val1 => $val2) {
 
 1107                $this->
object->saveCurrentSolution($active_id, 
$pass, $val1, $val2, 
true);
 
 1112        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
 1114        $questiontext = $this->
object->substituteVariables($user_solution);
 
 1116        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
 1119        $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
 
An exception for terminatinating execution or to throw for unit testing.
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
callNewIdListeners($a_new_id)
Call the new id listeners.
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
output question page
getUseIntermediateSolution()
Get if intermediate solution should be used for solution output.
saveTaxonomyAssignments()
addErrorMessage($errormessage)
addBackTab(ilTabsGUI $ilTabs)
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getGenericFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
static _questionExistsInTest($question_id, $test_id)
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
const CSS_CLASS_FEEDBACK_WRONG
const CSS_CLASS_FEEDBACK_CORRECT
This class represents a non editable value in a property form.
static _getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
static getReturnToPageLink($q_id=null)
This class represents a text property in a property form.
static stripOnlySlashes($a_str)
strip slashes if magic qoutes is enabled
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!array_key_exists('StateId', $_REQUEST)) $id
if(isset($_POST['submit'])) $form