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';
 
   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();
 
  184            foreach (
$_POST as $key => $value) {
 
  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]);
 
  195                $this->
object->setLifecycle($lifecycle);
 
  205            if (!$this->object->checkForDuplicateResults()) {
 
  210            foreach ($found_vars as $variable) {
 
  211                if ($this->object->getVariable($variable) != 
null) {
 
  213                    $varObj->setRangeMinTxt(
$_POST[
"range_min_$variable"]);
 
  214                    $varObj->setRangeMaxTxt(
$_POST[
"range_max_$variable"]);
 
  215                    $this->
object->addVariable($varObj);
 
  219            $tmp_form_vars = array();
 
  220            $tmp_quest_vars = array();
 
  221            foreach ($found_results as 
$result) {
 
  222                $tmp_res_match = preg_match_all(
"/([$][v][0-9]*)/", 
$_POST[
"formula_$result"], $form_vars);
 
  223                $tmp_form_vars = array_merge($tmp_form_vars, $form_vars[0]);
 
  225                $tmp_que_match = preg_match_all(
"/([$][v][0-9]*)/", 
$_POST[
'question'], $quest_vars);
 
  226                $tmp_quest_vars = array_merge($tmp_quest_vars, $quest_vars[0]);
 
  228            $result_has_undefined_vars = array_diff($tmp_form_vars, $found_vars);
 
  229            $question_has_unused_vars = array_diff($tmp_quest_vars, $tmp_form_vars);
 
  231            if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
 
  233                if (count($result_has_undefined_vars) > 0) {
 
  234                    $error_message .= $this->lng->txt(
"res_contains_undef_var") . 
'<br>';
 
  236                if (count($question_has_unused_vars) > 0) {
 
  237                    $error_message .= $this->lng->txt(
"que_contains_unused_var");
 
  244            foreach ($found_results as 
$result) {
 
  245                if (is_object($this->object->getUnitrepository()->getUnit(
$_POST[
"unit_$result"]))) {
 
  246                    $tmp_result_unit = $this->
object->getUnitrepository()->getUnit(
$_POST[
"unit_$result"]);
 
  248                    $tmp_result_unit = 
null;
 
  251                if ($this->object->getResult(
$result) != 
null) {
 
  252                    $use_simple_rating = (
$_POST[
"rating_advanced_$result"] == 1) ? 
false : 
true;
 
  255                        $_POST[
"range_min_$result"],
 
  256                        $_POST[
"range_max_$result"],
 
  257                        $_POST[
"tolerance_$result"],
 
  259                        $_POST[
"formula_$result"],
 
  261                        $_POST[
"precision_$result"],
 
  263                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_sign_$result"] : 
"",
 
  264                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_value_$result"] : 
"",
 
  265                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_unit_$result"] : 
"",
 
  266                        $_POST[
"result_type_$result"] != 0 ? 
$_POST[
"result_type_$result"] : 0
 
  268                    $resObj->setRangeMinTxt(
$_POST[
"range_min_$result"]);
 
  269                    $resObj->setRangeMaxTxt(
$_POST[
"range_max_$result"]);
 
  270                    $this->
object->addResult($resObj);
 
  271                    $this->
object->addResultUnits($resObj, 
$_POST[
"units_$result"]);
 
  274            if ($checked == 
false) {
 
  290        $question_id = $this->
object->getId();
 
  291        require_once 
'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
 
  293        $ilAssQuestionPreviewSession->setParticipantsSolution(array());
 
  298        return in_array($this->ctrl->getCmd(), array(
'saveFQ', 
'saveEdit', 
'saveReturnFQ'));
 
  306    public function editQuestion($checkonly = 
false)
 
  312        include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
 
  314        $this->editForm = $form;
 
  316        $form->setFormAction($this->ctrl->getFormAction($this));
 
  318        $form->setMultipart(
false);
 
  319        $form->setTableWidth(
'100%');
 
  320        $form->setId(
'assformulaquestion');
 
  326        $question = $form->getItemByPostVar(
'question');
 
  327        $question->setInfo($this->lng->txt(
'fq_question_desc'));
 
  329        $variables = $this->
object->getVariables();
 
  330        $categorized_units = $this->
object->getUnitrepository()->getCategorizedUnits();
 
  331        $result_units = $this->
object->__get(
'resultunits');
 
  333        $unit_options = array();
 
  335        $new_category = 
false;
 
  336        foreach ((array) $categorized_units as $item) {
 
  341                if ($category_name != $item->getDisplayString()) {
 
  342                    $new_category = 
true;
 
  343                    $category_name = $item->getDisplayString();
 
  347            $unit_options[$item->getId()] = $item->getDisplayString() . ($new_category ? 
' (' . $category_name . 
')' : 
'');
 
  348            $new_category = 
false;
 
  351        if (count($variables)) {
 
  355                if ($num_v1 > $num_v2) {
 
  357                } elseif ($num_v1 < $num_v2) {
 
  364            foreach ($variables as $variable) {
 
  369                $variable_header->setTitle(sprintf($this->lng->txt(
'variable_x'), $variable->getVariable()));
 
  371                $range_min = 
new ilNumberInputGUI($this->lng->txt(
'range_min'), 
'range_min_' . $variable->getVariable());
 
  372                $range_min->allowDecimals(
true);
 
  373                $range_min->setSize(3);
 
  374                $range_min->setRequired(
true);
 
  375                $range_min->setValue($variable->getRangeMin());
 
  377                $range_max = 
new ilNumberInputGUI($this->lng->txt(
'range_max'), 
'range_max_' . $variable->getVariable());
 
  378                $range_max->allowDecimals(
true);
 
  379                $range_max->setSize(3);
 
  380                $range_max->setRequired(
true);
 
  381                $range_max->setValue($variable->getRangeMax());
 
  383                $units = 
new ilSelectInputGUI($this->lng->txt(
'unit'), 
'unit_' . $variable->getVariable());
 
  384                $units->setOptions(array(0 => $this->lng->txt(
'no_selection')) + $unit_options);
 
  385                if (is_object($variable->getUnit())) {
 
  386                    $units->setValue($variable->getUnit()->getId());
 
  389                $precision = 
new ilNumberInputGUI($this->lng->txt(
'precision'), 
'precision_' . $variable->getVariable());
 
  390                $precision->setRequired(
true);
 
  391                $precision->setSize(3);
 
  392                $precision->setMinValue(0);
 
  393                $precision->setValue($variable->getPrecision());
 
  394                $precision->setInfo($this->lng->txt(
'fq_precision_info'));
 
  396                $intprecision = 
new ilNumberInputGUI($this->lng->txt(
'intprecision'), 
'intprecision_' . $variable->getVariable());
 
  397                $intprecision->setSize(3);
 
  398                $intprecision->setMinValue(1);
 
  399                $intprecision->setValue($variable->getIntprecision());
 
  400                $intprecision->setInfo($this->lng->txt(
'intprecision_info'));
 
  402                $form->addItem($variable_header);
 
  403                $form->addItem($range_min);
 
  404                $form->addItem($range_max);
 
  405                $form->addItem($units);
 
  406                $form->addItem($precision);
 
  407                $form->addItem($intprecision);
 
  411        $results = $this->
object->getResults();
 
  413            require_once 
'Services/Form/classes/class.ilMultiSelectInputGUI.php';
 
  416                $num_r1 = (int) substr($r1->
getResult(), 2);
 
  417                $num_r2 = (int) substr($r2->
getResult(), 2);
 
  418                if ($num_r1 > $num_r2) {
 
  420                } elseif ($num_r1 < $num_r2) {
 
  432                $result_header->setTitle(sprintf($this->lng->txt(
'result_x'), 
$result->getResult()));
 
  435                $formula->setInfo($this->lng->txt(
'fq_formula_desc'));
 
  436                $formula->setRequired(
true);
 
  437                $formula->setSize(50);
 
  438                $formula->setValue(
$result->getFormula());
 
  439                $formula->setSuffix(
' = ' . 
$result->getResult());
 
  442                    preg_match(
"/suggestrange_(.*)/", $this->ctrl->getCmd(), $matches) &&
 
  443                    strcmp($matches[1], 
$result->getResult()) == 0
 
  452                $range_min->allowDecimals(
true);
 
  453                $range_min->setSize(3);
 
  454                $range_min->setRequired(
true);
 
  455                $range_min->setValue(
$result->getRangeMin());
 
  458                $range_max->allowDecimals(
true);
 
  459                $range_max->setSize(3);
 
  460                $range_max->setRequired(
true);
 
  461                $range_max->setValue(
$result->getRangeMax());
 
  466                $precision->setRequired(
true);
 
  467                $precision->setSize(3);
 
  468                $precision->setMinValue(0);
 
  469                $precision->setInfo($this->lng->txt(
'fq_precision_info'));
 
  470                $precision->setValue(
$result->getPrecision());
 
  473                $tolerance->setSize(3);
 
  474                $tolerance->setMinValue(0);
 
  475                $tolerance->setMaxValue(100);
 
  476                $tolerance->allowDecimals(
true);
 
  477                $tolerance->setInfo($this->lng->txt(
'tolerance_info'));
 
  478                $tolerance->setValue(
$result->getTolerance());
 
  481                $suggest_range_button->setHtml(
'<input type="submit" class="btn btn-default" name="cmd[suggestrange_' . 
$result->getResult() . 
']" value="' . $this->lng->txt(
"suggest_range") . 
'" />');
 
  484                $sel_result_units->setOptions(array(0 => $this->lng->txt(
'no_selection')) + $unit_options);
 
  485                $sel_result_units->setInfo($this->lng->txt(
'result_unit_info'));
 
  486                if (is_object(
$result->getUnit())) {
 
  487                    $sel_result_units->setValue(
$result->getUnit()->getId());
 
  491                $mc_result_units->setOptions($unit_options);
 
  492                $mc_result_units->setInfo($this->lng->txt(
'result_units_info'));
 
  493                $selectedvalues = array();
 
  494                foreach ($unit_options as $unit_id => 
$txt) {
 
  495                    if ($this->
hasResultUnit($result, $unit_id, $result_units)) {
 
  496                        $selectedvalues[] = $unit_id;
 
  499                $mc_result_units->setValue($selectedvalues);
 
  502                $result_type->setRequired(
true);
 
  504                $no_type = 
new ilRadioOption($this->lng->txt(
'no_result_type'), 0);
 
  505                $no_type->setInfo($this->lng->txt(
'fq_no_restriction_info'));
 
  507                $result_dec = 
new ilRadioOption($this->lng->txt(
'result_dec'), 1);
 
  508                $result_dec->setInfo($this->lng->txt(
'result_dec_info'));
 
  510                $result_frac = 
new ilRadioOption($this->lng->txt(
'result_frac'), 2);
 
  511                $result_frac->setInfo($this->lng->txt(
'result_frac_info'));
 
  513                $result_co_frac = 
new ilRadioOption($this->lng->txt(
'result_co_frac'), 3);
 
  514                $result_co_frac->setInfo($this->lng->txt(
'result_co_frac_info'));
 
  516                $result_type->addOption($no_type);
 
  517                $result_type->addOption($result_dec);
 
  518                $result_type->addOption($result_frac);
 
  519                $result_type->addOption($result_co_frac);
 
  520                $result_type->setValue(strlen(
$result->getResultType()) ? 
$result->getResultType() : 0);
 
  523                $points->allowDecimals(
true);
 
  524                $points->setRequired(
true);
 
  526                $points->setMinValue(0);
 
  527                $points->setValue(strlen(
$result->getPoints()) ? 
$result->getPoints() : 1);
 
  530                $rating_type->setValue(1);
 
  531                $rating_type->setInfo($this->lng->txt(
'advanced_rating_info'));
 
  535                    if (!$advanced_rating) {
 
  536                        $rating_type->setDisabled(
true);
 
  537                        $rating_type->setChecked(
false);
 
  539                        $rating_type->setChecked(strlen(
$result->getRatingSimple()) && 
$result->getRatingSimple() ? 
false : 
true);
 
  544                $sign->setRequired(
true);
 
  546                $sign->setMinValue(0);
 
  547                $sign->setValue(
$result->getRatingSign());
 
  548                $rating_type->addSubItem($sign);
 
  551                $value->setRequired(
true);
 
  553                $value->setMinValue(0);
 
  554                $value->setValue(
$result->getRatingValue());
 
  555                $rating_type->addSubItem($value);
 
  558                $unit->setRequired(
true);
 
  560                $unit->setMinValue(0);
 
  561                $unit->setValue(
$result->getRatingUnit());
 
  562                $rating_type->addSubItem($unit);
 
  565                $rating_type->addSubItem($info_text);
 
  567                $form->addItem($result_header);
 
  568                $form->addItem($formula);
 
  569                $form->addItem($range_min);
 
  570                $form->addItem($range_max);
 
  571                $form->addItem($suggest_range_button);
 
  572                $form->addItem($precision);
 
  573                $form->addItem($tolerance);
 
  574                $form->addItem($sel_result_units);
 
  575                $form->addItem($mc_result_units);
 
  576                $form->addItem($result_type);
 
  577                $form->addItem($points);
 
  578                $form->addItem($rating_type);
 
  581            $defined_result_vars = array();
 
  582            $quest_vars = array();
 
  584            $defined_result_res = array();
 
  585            $result_vars = array();
 
  587            foreach ($variables as $key => 
$object) {
 
  588                $quest_vars[$key] = $key;
 
  592                $result_vars[$key] = $key;
 
  599                $formula = $tmp_result->getFormula();
 
  601                preg_match_all(
"/([$][v][0-9]*)/", $formula, $form_vars);
 
  602                preg_match_all(
"/([$][r][0-9]*)/", $formula, $form_res);
 
  603                foreach ($form_vars[0] as $res_var) {
 
  604                    $defined_result_vars[$res_var] = $res_var;
 
  607                foreach ($form_res[0] as $res_res) {
 
  608                    $defined_result_res[$res_res] = $res_res;
 
  613        $result_has_undefined_vars = [];
 
  614        $question_has_unused_vars = [];
 
  615        $result_has_undefined_res = [];
 
  617        if (is_array($quest_vars) && count($quest_vars) > 0) {
 
  618            $result_has_undefined_vars = array_diff($defined_result_vars, $quest_vars);
 
  619            $question_has_unused_vars = array_diff($quest_vars, $defined_result_vars);
 
  622        if (is_array($result_vars) && count($result_vars) > 0) {
 
  623            $result_has_undefined_res = array_diff($defined_result_res, $result_vars);
 
  627        if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
 
  628            if (count($result_has_undefined_vars) > 0) {
 
  629                $error_message .= $this->lng->txt(
"res_contains_undef_var") . 
'<br>';
 
  631            if (count($question_has_unused_vars) > 0) {
 
  632                $error_message .= $this->lng->txt(
"que_contains_unused_var") . 
'<br>';
 
  641        if (is_array($result_has_undefined_res) && count($result_has_undefined_res) > 0) {
 
  642            $error_message .= $this->lng->txt(
"res_contains_undef_res") . 
'<br>';
 
  646        if ($save && !$checked) {
 
  650        if ($this->object->getId()) {
 
  652            $hidden->setValue($this->object->getId());
 
  653            $form->addItem($hidden);
 
  658        $form->addCommandButton(
'parseQuestion', $this->lng->txt(
"parseQuestion"));
 
  659        $form->addCommandButton(
'saveReturnFQ', $this->lng->txt(
"save_return"));
 
  660        $form->addCommandButton(
'saveFQ', $this->lng->txt(
"save"));
 
  665            $found_vars = array();
 
  666            $found_results = array();
 
  667            foreach ((array) 
$_POST as $key => $value) {
 
  668                if (preg_match(
"/^unit_(\\\$v\d+)$/", $key, $matches)) {
 
  669                    array_push($found_vars, $matches[1]);
 
  671                if (preg_match(
"/^unit_(\\\$r\d+)$/", $key, $matches)) {
 
  672                    array_push($found_results, $matches[1]);
 
  676            $form->setValuesByPost();
 
  677            $errors = !$form->checkInput();
 
  679            $custom_errors = 
false;
 
  680            if (count($variables)) {
 
  681                foreach ($variables as $variable) {
 
  685                    $min_range = $form->getItemByPostVar(
'range_min_' . $variable->getVariable());
 
  686                    $max_range = $form->getItemByPostVar(
'range_max_' . $variable->getVariable());
 
  687                    if ($min_range->getValue() > $max_range->getValue()) {
 
  688                        $min_range->setAlert($this->lng->txt(
'err_range'));
 
  689                        $max_range->setAlert($this->lng->txt(
'err_range'));
 
  690                        $custom_errors = 
true;
 
  692                    $intPrecision = $form->getItemByPostVar(
'intprecision_' . $variable->getVariable());
 
  693                    if ($intPrecision->getValue() > $max_range->getValue()) {
 
  694                        $intPrecision->setAlert($this->lng->txt(
'err_division'));
 
  695                        $custom_errors = 
true;
 
  705                    $min_range = $form->getItemByPostVar(
'range_min_' . 
$result->getResult());
 
  706                    $max_range = $form->getItemByPostVar(
'range_max_' . 
$result->getResult());
 
  707                    if ($min_range->getValue() > $max_range->getValue()) {
 
  708                        $min_range->setAlert($this->lng->txt(
'err_range'));
 
  709                        $max_range->setAlert($this->lng->txt(
'err_range'));
 
  710                        $custom_errors = 
true;
 
  714                    $formula = $form->getItemByPostVar(
'formula_' . 
$result->getResult());
 
  715                    if (strpos($formula->getValue(), 
$result->getResult()) !== 
false) {
 
  716                        $formula->setAlert($this->lng->txt(
'errRecursionInResult'));
 
  717                        $custom_errors = 
true;
 
  720                    $result_unit = $form->getItemByPostVar(
'unit_' . 
$result->getResult());
 
  721                    $rating_advanced = $form->getItemByPostVar(
'rating_advanced_' . 
$result->getResult());
 
  722                    if (((
int) $result_unit->getValue() <= 0) && $rating_advanced->getChecked()) {
 
  724                        $rating_advanced->setDisabled(
true);
 
  725                        $rating_advanced->setChecked(
false);
 
  726                        $rating_advanced->setAlert($this->lng->txt(
'err_rating_advanced_not_allowed'));
 
  727                        $custom_errors = 
true;
 
  728                    } elseif ($rating_advanced->getChecked()) {
 
  729                        $rating_sign = $form->getItemByPostVar(
'rating_sign_' . 
$result->getResult());
 
  730                        $rating_value = $form->getItemByPostVar(
'rating_value_' . 
$result->getResult());
 
  731                        $rating_unit = $form->getItemByPostVar(
'rating_unit_' . 
$result->getResult());
 
  733                        $percentage = $rating_sign->getValue() + $rating_value->getValue() + $rating_unit->getValue();
 
  734                        if ($percentage != 100) {
 
  735                            $rating_advanced->setAlert($this->lng->txt(
'err_wrong_rating_advanced'));
 
  736                            $custom_errors = 
true;
 
  740                    preg_match_all(
"/([$][v][0-9]*)/", $formula->getValue(), $form_vars);
 
  741                    $result_has_undefined_vars = array_diff($form_vars[0], (array) $found_vars);
 
  742                    if (count($result_has_undefined_vars)) {
 
  749            if ($custom_errors && !
$errors) {
 
  753            $form->setValuesByPost(); 
 
  760            $this->tpl->setVariable(
'QUESTION_DATA', $form->getHTML());
 
  767        if (array_key_exists(
$result->getResult(), $resultunits)) {
 
  768            if (array_key_exists($unit_id, $resultunits[
$result->getResult()])) {
 
  784        $resultunit = 
$result->getUnit();
 
  792        if (is_object($resultunit)) {
 
  802        $this->editQuestion();
 
  809        $old_id = 
$_GET[
"q_id"];
 
  812            $ilUser->setPref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  813            $ilUser->writePref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  815            $this->
object->saveToDb();
 
  816            $originalexists = $this->
object->_questionExistsInPool($this->object->original_id);
 
  817            include_once 
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
 
  819                $this->ctrl->redirect($this, 
"originalSyncForm");
 
  821            } elseif (
$_GET[
"calling_test"]) {
 
  822                require_once 
'Modules/Test/classes/class.ilObjTest.php';
 
  824                #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId())); 
  825                $q_id = $this->
object->getId();
 
  828                    $tree = 
$DIC[
'tree'];
 
  830                    $ilPluginAdmin = 
$DIC[
'ilPluginAdmin'];
 
  832                    include_once(
"./Modules/Test/classes/class.ilObjTest.php");
 
  836                    require_once 
'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
 
  839                    $new_id = 
$test->insertQuestion(
 
  840                        $testQuestionSetConfigFactory->getQuestionSetConfig(),
 
  841                        $this->object->getId()
 
  845                    if (isset($_REQUEST[
'prev_qid'])) {
 
  846                        $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST[
'prev_qid']);
 
  849                    $this->ctrl->setParameter($this, 
'q_id', $new_id);
 
  850                    $this->ctrl->setParameter($this, 
'calling_test', 
$_GET[
'calling_test']);
 
  851                    #$this->ctrl->setParameter($this, 'test_ref_id', false); 
  853                ilUtil::sendSuccess($this->lng->txt(
"msg_obj_modified"), 
true);
 
  854                if ($_REQUEST[
'test_express_mode']) {
 
  860                if ($this->object->getId() != $old_id) {
 
  862                    ilUtil::sendSuccess($this->lng->txt(
"msg_obj_modified"), 
true);
 
  863                    $this->ctrl->redirectByClass(
"ilobjquestionpoolgui", 
"questions");
 
  865                if (strcmp(
$_SESSION[
"info"], 
"") != 0) {
 
  866                    ilUtil::sendSuccess(
$_SESSION[
"info"] . 
"<br />" . $this->lng->txt(
"msg_obj_modified"), 
true);
 
  868                    ilUtil::sendSuccess($this->lng->txt(
"msg_obj_modified"), 
true);
 
  870                $this->ctrl->redirectByClass(
"ilobjquestionpoolgui", 
"questions");
 
  873            $ilUser->setPref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  874            $ilUser->writePref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  875            $this->
object->saveToDb();
 
  876            $this->editQuestion();
 
  885            $this->editQuestion();
 
  897            $this->
addErrorMessage($this->lng->txt(
"fill_out_all_required_fields"));
 
  931        $graphicalOutput = 
false,
 
  932        $result_output = 
false,
 
  933        $show_question_only = 
true,
 
  934        $show_feedback = 
false,
 
  935        $show_correct_solution = 
false,
 
  936        $show_manual_scoring = 
false,
 
  937        $show_question_text = 
true 
  940        $user_solution = array();
 
  941        if (($active_id > 0) && (!$show_correct_solution)) {
 
  942            $solutions = array();
 
  943            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  945                if (is_null(
$pass)) {
 
  949            $user_solution[
"active_id"] = $active_id;
 
  950            $user_solution[
"pass"] = 
$pass;
 
  952            foreach ($solutions as $idx => $solution_value) {
 
  953                if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
  954                    $user_solution[$matches[1]] = $solution_value[
"value2"];
 
  955                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
 
  956                    if (!array_key_exists($matches[1], $user_solution)) {
 
  957                        $user_solution[$matches[1]] = array();
 
  959                    $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
 
  960                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
 
  961                    if (!array_key_exists($matches[1], $user_solution)) {
 
  962                        $user_solution[$matches[1]] = array();
 
  964                    $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
 
  967        } elseif ($active_id) {
 
  969            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  971                if (is_null(
$pass)) {
 
  975            $user_solution = (array) $this->object->getBestSolution($this->object->getSolutionValues($active_id, 
$pass));
 
  977            $solutionValues = array();
 
  980            if (is_array($participantsSolution)) {
 
  981                foreach ($participantsSolution as $val1 => $val2) {
 
  982                    $solutionValues[] = array(
'value1' => $val1, 
'value2' => $val2);
 
  986            $user_solution = (array) $this->object->getBestSolution($solutionValues);
 
  989        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
  990        $questiontext = $this->
object->substituteVariables($user_solution, $graphicalOutput, 
true, $result_output);
 
  992        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
  993        $questionoutput = $template->get();
 
  994        $solutiontemplate = 
new ilTemplate(
"tpl.il_as_tst_solution_output.html", 
true, 
true, 
"Modules/TestQuestionPool");
 
  996        if (strlen($feedback)) {
 
 1002            $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
 
 1003            $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, 
true));
 
 1005        $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
 
 1007        $solutionoutput = $solutiontemplate->get();
 
 1008        if (!$show_question_only) {
 
 1010            $solutionoutput = $this->
getILIASPage($solutionoutput);
 
 1012        return $solutionoutput;
 
 1015    public function getPreview($show_question_only = 
false, $showInlineFeedback = 
false)
 
 1017        $user_solution = array();
 
 1022            foreach ($solutions as $val1 => $val2) {
 
 1023                if (preg_match(
"/^(\\\$v\\d+)$/", $val1, $matches)) {
 
 1024                    $user_solution[$matches[1]] = $val2;
 
 1025                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $val1, $matches)) {
 
 1026                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1027                        $user_solution[$matches[1]] = array();
 
 1029                    $user_solution[$matches[1]][
"value"] = $val2;
 
 1030                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $val1, $matches)) {
 
 1031                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1032                        $user_solution[$matches[1]] = array();
 
 1034                    $user_solution[$matches[1]][
"unit"] = $val2;
 
 1037                if (preg_match(
"/^(\\\$r\\d+)/", $val1, $matches) && $user_solution[$matches[1]][
"result_type"] == 0) {
 
 1043        if (!$this->object->hasRequiredVariableSolutionValues($user_solution)) {
 
 1044            $user_solution = $this->
object->getInitialVariableSolutionValues();
 
 1051        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
 1053            $questiontext = $this->
object->substituteVariables($user_solution, 
false, 
false, 
false);
 
 1055            $questiontext = $this->
object->substituteVariables(array());
 
 1057        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
 1058        $questionoutput = $template->get();
 
 1059        if (!$show_question_only) {
 
 1061            $questionoutput = $this->
getILIASPage($questionoutput);
 
 1063        return $questionoutput;
 
 1067    public function getTestOutput($active_id, 
$pass, $is_postponed = 
false, $use_post_solutions = 
false, $show_feedback = 
false)
 
 1072        $user_solution = array();
 
 1074            $solutions = (array) $this->object->getTestOutputSolutions($active_id, 
$pass);
 
 1076            $actualPassIndex = 
null;
 
 1077            if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
 
 1078                require_once 
'Modules/Test/classes/class.ilObjTest.php';
 
 1082            foreach ($solutions as $idx => $solution_value) {
 
 1083                if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1084                    if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
 
 1085                        $this->
object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value[
"value2"], 
true);
 
 1088                    $user_solution[$matches[1]] = $solution_value[
"value2"];
 
 1089                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1090                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1091                        $user_solution[$matches[1]] = array();
 
 1093                    $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
 
 1094                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
 
 1095                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1096                        $user_solution[$matches[1]] = array();
 
 1098                    $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
 
 1101                if (preg_match(
"/^(\\\$r\\d+)/", $solution_value[
"value1"], $matches) && $user_solution[$matches[1]][
"result_type"] == 0) {
 
 1108        $solutions = $this->
object->getSolutionValues($active_id, 
$pass, 
true);
 
 1109        foreach ($solutions as $idx => $solution_value) {
 
 1110            if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1111                $user_solution[$matches[1]] = $solution_value[
"value2"];
 
 1116        if (!$this->object->hasRequiredVariableSolutionValues($user_solution)) {
 
 1117            foreach ($this->object->getInitialVariableSolutionValues() as $val1 => $val2) {
 
 1118                $this->
object->saveCurrentSolution($active_id, 
$pass, $val1, $val2, 
true);
 
 1123        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
 1125        $questiontext = $this->
object->substituteVariables($user_solution);
 
 1127        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
 1129        $questionoutput = $template->get();
 
 1130        $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
static getInstance($identifier)
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.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc