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);
 
   47        global $rbacsystem, $ilTabs;
 
   49        $ilTabs->clearTargets();
 
   51        $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI", 
"q_id", 
$_GET[
"q_id"]);
 
   52        include_once 
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
 
   53        $q_type = $this->
object->getQuestionType();
 
   55        if (strlen($q_type)) {
 
   56            $classname = $q_type . 
"GUI";
 
   57            $this->ctrl->setParameterByClass(strtolower($classname), 
"sel_question_types", $q_type);
 
   58            $this->ctrl->setParameterByClass(strtolower($classname), 
"q_id", 
$_GET[
"q_id"]);
 
   62            if ($rbacsystem->checkAccess(
'write', 
$_GET[
"ref_id"])) {
 
   66                    $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI", 
"edit"),
 
   67                    array(
"edit", 
"insert", 
"exec_pg"),
 
   77        $force_active = 
false;
 
   78        if ($rbacsystem->checkAccess(
'write', 
$_GET[
"ref_id"])) {
 
   82                $url = $this->ctrl->getLinkTargetByClass($classname, 
"editQuestion");
 
   85            if (is_array($commands)) {
 
   86                foreach ($commands as 
$key => $value) {
 
   87                    if (preg_match(
"/^suggestrange_.*/", 
$key, $matches)) {
 
   97                    "editQuestion", 
"save", 
"cancel", 
"addSuggestedSolution",
 
   98                    "cancelExplorer", 
"linkChilds", 
"removeSuggestedSolution",
 
   99                    "parseQuestion", 
"saveEdit", 
"suggestRange" 
  120            $this->addTab_Units($ilTabs);
 
  127                $this->ctrl->getLinkTargetByClass($classname, 
"assessment"),
 
  139        if (preg_match(
"/suggestrange_(.*?)/", $cmd, $matches)) {
 
  140            $cmd = 
"suggestRange";
 
  154        $this->editQuestion();
 
  162        $hasErrors = (!$always) ? $this->editQuestion(
true) : 
false;
 
  165            $this->
object->setTitle(
$_POST[
"title"]);
 
  166            $this->
object->setAuthor(
$_POST[
"author"]);
 
  167            $this->
object->setComment(
$_POST[
"comment"]);
 
  168            include_once 
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
 
  170            $this->
object->setQuestion($questiontext);
 
  171            $this->
object->setEstimatedWorkingTime(
 
  172                $_POST[
"Estimated"][
"hh"],
 
  173                $_POST[
"Estimated"][
"mm"],
 
  177            $this->
object->parseQuestionText();
 
  178            $found_vars    = array();
 
  179            $found_results = array();
 
  183                if (preg_match(
"/^unit_(\\\$v\d+)$/", 
$key, $matches)) {
 
  184                    array_push($found_vars, $matches[1]);
 
  186                if (preg_match(
"/^unit_(\\\$r\d+)$/", 
$key, $matches)) {
 
  187                    array_push($found_results, $matches[1]);
 
  197            if (!$this->object->checkForDuplicateResults()) {
 
  202            foreach ($found_vars as $variable) {
 
  203                if ($this->object->getVariable($variable) != 
null) {
 
  205                    $varObj->setRangeMinTxt(
$_POST[
"range_min_$variable"]);
 
  206                    $varObj->setRangeMaxTxt(
$_POST[
"range_max_$variable"]);
 
  207                    $this->
object->addVariable($varObj);
 
  211            $tmp_form_vars = array();
 
  212            $tmp_quest_vars = array();
 
  213            foreach ($found_results as 
$result) {
 
  214                $tmp_res_match = preg_match_all(
"/([$][v][0-9]*)/", 
$_POST[
"formula_$result"], $form_vars);
 
  215                $tmp_form_vars = array_merge($tmp_form_vars, $form_vars[0]);
 
  217                $tmp_que_match = preg_match_all(
"/([$][v][0-9]*)/", 
$_POST[
'question'], $quest_vars);
 
  218                $tmp_quest_vars= array_merge($tmp_quest_vars, $quest_vars[0]);
 
  220            $result_has_undefined_vars = array_diff($tmp_form_vars, $found_vars);
 
  221            $question_has_unused_vars =  array_diff($tmp_quest_vars, $tmp_form_vars);
 
  223            if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
 
  225                if (count($result_has_undefined_vars) > 0) {
 
  226                    $error_message .= $this->lng->txt(
"res_contains_undef_var") . 
'<br>';
 
  228                if (count($question_has_unused_vars) > 0) {
 
  229                    $error_message .= $this->lng->txt(
"que_contains_unused_var");
 
  236            foreach ($found_results as 
$result) {
 
  237                if (is_object($this->object->getUnitrepository()->getUnit(
$_POST[
"unit_$result"]))) {
 
  238                    $tmp_result_unit = $this->
object->getUnitrepository()->getUnit(
$_POST[
"unit_$result"]);
 
  240                    $tmp_result_unit = 
null;
 
  243                if ($this->object->getResult(
$result) != 
null) {
 
  244                    $use_simple_rating = (
$_POST[
"rating_advanced_$result"] == 1) ? 
false : 
true;
 
  247                        $_POST[
"range_min_$result"],
 
  248                        $_POST[
"range_max_$result"],
 
  249                        $_POST[
"tolerance_$result"],
 
  251                        $_POST[
"formula_$result"],
 
  253                        $_POST[
"precision_$result"],
 
  255                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_sign_$result"] : 
"",
 
  256                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_value_$result"] : 
"",
 
  257                        (
$_POST[
"rating_advanced_$result"] == 1) ? 
$_POST[
"rating_unit_$result"] : 
"",
 
  258                        $_POST[
"result_type_$result"] != 0 ? 
$_POST[
"result_type_$result"] : 0
 
  260                    $resObj->setRangeMinTxt(
$_POST[
"range_min_$result"]);
 
  261                    $resObj->setRangeMaxTxt(
$_POST[
"range_max_$result"]);
 
  262                    $this->
object->addResult($resObj);
 
  263                    $this->
object->addResultUnits($resObj, 
$_POST[
"units_$result"]);
 
  266            if ($checked == 
false) {
 
  281        $question_id            = $this->
object->getId();
 
  282        require_once 
'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
 
  284        $ilAssQuestionPreviewSession->setParticipantsSolution(array());
 
  289        return in_array($this->ctrl->getCmd(), array(
'saveFQ', 
'saveEdit', 
'saveReturnFQ'));
 
  297    public function editQuestion($checkonly = 
false)
 
  303        include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
 
  305        $this->editForm = 
$form;
 
  307        $form->setFormAction($this->ctrl->getFormAction($this));
 
  309        $form->setMultipart(
false);
 
  310        $form->setTableWidth(
'100%');
 
  311        $form->setId(
'assformulaquestion');
 
  317        $question = 
$form->getItemByPostVar(
'question');
 
  318        $question->setInfo($this->lng->txt(
'fq_question_desc'));
 
  320        $variables         = $this->
object->getVariables();
 
  321        $categorized_units = $this->
object->getUnitrepository()->getCategorizedUnits();
 
  322        $result_units      = $this->
object->__get(
'resultunits');
 
  324        $unit_options  = array();
 
  326        $new_category  = 
false;
 
  327        foreach ((array) $categorized_units as $item) {
 
  332                if ($category_name != $item->getDisplayString()) {
 
  333                    $new_category  = 
true;
 
  334                    $category_name = $item->getDisplayString();
 
  338            $unit_options[$item->getId()] = $item->getDisplayString() . ($new_category ? 
' (' . $category_name . 
')' : 
'');
 
  339            $new_category                 = 
false;
 
  342        if (count($variables)) {
 
  346                if ($num_v1 > $num_v2) {
 
  348                } elseif ($num_v1 < $num_v2) {
 
  355            foreach ($variables as $variable) {
 
  360                $variable_header->setTitle(
sprintf($this->lng->txt(
'variable_x'), $variable->getVariable()));
 
  362                $range_min = 
new ilNumberInputGUI($this->lng->txt(
'range_min'), 
'range_min_' . $variable->getVariable());
 
  363                $range_min->allowDecimals(
true);
 
  364                $range_min->setSize(3);
 
  365                $range_min->setRequired(
true);
 
  366                $range_min->setValue($variable->getRangeMin());
 
  368                $range_max = 
new ilNumberInputGUI($this->lng->txt(
'range_max'), 
'range_max_' . $variable->getVariable());
 
  369                $range_max->allowDecimals(
true);
 
  370                $range_max->setSize(3);
 
  371                $range_max->setRequired(
true);
 
  372                $range_max->setValue($variable->getRangeMax());
 
  374                $units = 
new ilSelectInputGUI($this->lng->txt(
'unit'), 
'unit_' . $variable->getVariable());
 
  375                $units->setOptions(array(0 => $this->lng->txt(
'no_selection')) + $unit_options);
 
  376                if (is_object($variable->getUnit())) {
 
  377                    $units->setValue($variable->getUnit()->getId());
 
  380                $precision = 
new ilNumberInputGUI($this->lng->txt(
'precision'), 
'precision_' . $variable->getVariable());
 
  381                $precision->setRequired(
true);
 
  382                $precision->setSize(3);
 
  383                $precision->setMinValue(0);
 
  384                $precision->setValue($variable->getPrecision());
 
  385                $precision->setInfo($this->lng->txt(
'fq_precision_info'));
 
  387                $intprecision = 
new ilNumberInputGUI($this->lng->txt(
'intprecision'), 
'intprecision_' . $variable->getVariable());
 
  388                $intprecision->setSize(3);
 
  389                $intprecision->setMinValue(1);
 
  390                $intprecision->setValue($variable->getIntprecision());
 
  391                $intprecision->setInfo($this->lng->txt(
'intprecision_info'));
 
  393                $form->addItem($variable_header);
 
  394                $form->addItem($range_min);
 
  395                $form->addItem($range_max);
 
  396                $form->addItem($units);
 
  397                $form->addItem($precision);
 
  398                $form->addItem($intprecision);
 
  402        $results = $this->
object->getResults();
 
  404            require_once 
'Services/Form/classes/class.ilMultiSelectInputGUI.php';
 
  407                $num_r1 = (int) substr($r1->
getResult(), 2);
 
  408                $num_r2 = (int) substr($r2->
getResult(), 2);
 
  409                if ($num_r1 > $num_r2) {
 
  411                } elseif ($num_r1 < $num_r2) {
 
  423                $result_header->setTitle(
sprintf($this->lng->txt(
'result_x'), 
$result->getResult()));
 
  426                $formula->setInfo($this->lng->txt(
'fq_formula_desc'));
 
  427                $formula->setRequired(
true);
 
  428                $formula->setSize(50);
 
  429                $formula->setValue(
$result->getFormula());
 
  430                $formula->setSuffix(
' = ' . 
$result->getResult());
 
  433                    preg_match(
"/suggestrange_(.*)/", $this->ctrl->getCmd(), $matches) &&
 
  434                    strcmp($matches[1], 
$result->getResult()) == 0
 
  443                $range_min->allowDecimals(
true);
 
  444                $range_min->setSize(3);
 
  445                $range_min->setRequired(
true);
 
  446                $range_min->setValue(
$result->getRangeMin());
 
  449                $range_max->allowDecimals(
true);
 
  450                $range_max->setSize(3);
 
  451                $range_max->setRequired(
true);
 
  452                $range_max->setValue(
$result->getRangeMax());
 
  457                $precision->setRequired(
true);
 
  458                $precision->setSize(3);
 
  459                $precision->setMinValue(0);
 
  460                $precision->setInfo($this->lng->txt(
'fq_precision_info'));
 
  461                $precision->setValue(
$result->getPrecision());
 
  464                $tolerance->setSize(3);
 
  465                $tolerance->setMinValue(0);
 
  466                $tolerance->setMaxValue(100);
 
  467                $tolerance->allowDecimals(
false);
 
  468                $tolerance->setInfo($this->lng->txt(
'tolerance_info'));
 
  469                $tolerance->setValue(
$result->getTolerance());
 
  472                $suggest_range_button->setHtml(
'<input type="submit" class="btn btn-default" name="cmd[suggestrange_' . 
$result->getResult() . 
']" value="' . $this->lng->txt(
"suggest_range") . 
'" />');
 
  475                $sel_result_units->setOptions(array(0 => $this->lng->txt(
'no_selection')) + $unit_options);
 
  476                $sel_result_units->setInfo($this->lng->txt(
'result_unit_info'));
 
  477                if (is_object(
$result->getUnit())) {
 
  478                    $sel_result_units->setValue(
$result->getUnit()->getId());
 
  482                $mc_result_units->setOptions($unit_options);
 
  483                $mc_result_units->setInfo($this->lng->txt(
'result_units_info'));
 
  484                $selectedvalues = array();
 
  485                foreach ($unit_options as $unit_id => 
$txt) {
 
  486                    if ($this->
hasResultUnit($result, $unit_id, $result_units)) {
 
  487                        $selectedvalues[] = $unit_id;
 
  490                $mc_result_units->setValue($selectedvalues);
 
  493                $result_type->setRequired(
true);
 
  495                $no_type = 
new ilRadioOption($this->lng->txt(
'no_result_type'), 0);
 
  496                $no_type->setInfo($this->lng->txt(
'fq_no_restriction_info'));
 
  498                $result_dec = 
new ilRadioOption($this->lng->txt(
'result_dec'), 1);
 
  499                $result_dec->setInfo($this->lng->txt(
'result_dec_info'));
 
  501                $result_frac = 
new ilRadioOption($this->lng->txt(
'result_frac'), 2);
 
  502                $result_frac->setInfo($this->lng->txt(
'result_frac_info'));
 
  504                $result_co_frac = 
new ilRadioOption($this->lng->txt(
'result_co_frac'), 3);
 
  505                $result_co_frac->setInfo($this->lng->txt(
'result_co_frac_info'));
 
  507                $result_type->addOption($no_type);
 
  508                $result_type->addOption($result_dec);
 
  509                $result_type->addOption($result_frac);
 
  510                $result_type->addOption($result_co_frac);
 
  511                $result_type->setValue(strlen(
$result->getResultType()) ? 
$result->getResultType() : 0);
 
  514                $points->allowDecimals(
true);
 
  515                $points->setRequired(
true);
 
  517                $points->setMinValue(0);
 
  518                $points->setValue(strlen(
$result->getPoints()) ? 
$result->getPoints() : 1);
 
  521                $rating_type->setValue(1);
 
  522                $rating_type->setInfo($this->lng->txt(
'advanced_rating_info'));
 
  526                    if (!$advanced_rating) {
 
  527                        $rating_type->setDisabled(
true);
 
  528                        $rating_type->setChecked(
false);
 
  530                        $rating_type->setChecked(strlen(
$result->getRatingSimple()) && 
$result->getRatingSimple() ? 
false : 
true);
 
  535                $sign->setRequired(
true);
 
  537                $sign->setMinValue(0);
 
  538                $sign->setValue(
$result->getRatingSign());
 
  539                $rating_type->addSubItem($sign);
 
  542                $value->setRequired(
true);
 
  544                $value->setMinValue(0);
 
  545                $value->setValue(
$result->getRatingValue());
 
  546                $rating_type->addSubItem($value);
 
  549                $unit->setRequired(
true);
 
  551                $unit->setMinValue(0);
 
  552                $unit->setValue(
$result->getRatingUnit());
 
  553                $rating_type->addSubItem($unit);
 
  556                $rating_type->addSubItem($info_text);
 
  558                $form->addItem($result_header);
 
  559                $form->addItem($formula);
 
  560                $form->addItem($range_min);
 
  561                $form->addItem($range_max);
 
  562                $form->addItem($suggest_range_button);
 
  563                $form->addItem($precision);
 
  564                $form->addItem($tolerance);
 
  565                $form->addItem($sel_result_units);
 
  566                $form->addItem($mc_result_units);
 
  567                $form->addItem($result_type);
 
  568                $form->addItem($points);
 
  569                $form->addItem($rating_type);
 
  572            $defined_result_vars = array();
 
  573            $quest_vars = array();
 
  575            $defined_result_res = array();
 
  576            $result_vars = array();
 
  590                $formula = $tmp_result->getFormula();
 
  592                preg_match_all(
"/([$][v][0-9]*)/", $formula, $form_vars);
 
  593                preg_match_all(
"/([$][r][0-9]*)/", $formula, $form_res);
 
  594                foreach ($form_vars[0] as $res_var) {
 
  595                    $defined_result_vars[$res_var] = $res_var;
 
  598                foreach ($form_res[0] as $res_res) {
 
  599                    $defined_result_res[$res_res] = $res_res;
 
  604        $result_has_undefined_vars = array();
 
  605        $question_has_unused_vars = array();
 
  607        if (is_array($quest_vars) && count($quest_vars) > 0) {
 
  608            $result_has_undefined_vars = array_diff($defined_result_vars, $quest_vars);
 
  609            $question_has_unused_vars = array_diff($quest_vars, $defined_result_vars);
 
  612        if (is_array($result_vars) && count($result_vars) > 0) {
 
  613            $result_has_undefined_res = array_diff($defined_result_res, $result_vars);
 
  617        if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
 
  618            if (count($result_has_undefined_vars) > 0) {
 
  619                $error_message .= $this->lng->txt(
"res_contains_undef_var") . 
'<br>';
 
  621            if (count($question_has_unused_vars) > 0) {
 
  622                $error_message .= $this->lng->txt(
"que_contains_unused_var") . 
'<br>';
 
  631        if (is_array($result_has_undefined_res) && count($result_has_undefined_res) > 0) {
 
  632            $error_message .= $this->lng->txt(
"res_contains_undef_res") . 
'<br>';
 
  636        if ($save && !$checked) {
 
  640        if ($this->object->getId()) {
 
  642            $hidden->setValue($this->object->getId());
 
  643            $form->addItem($hidden);
 
  648        $form->addCommandButton(
'parseQuestion', $this->lng->txt(
"parseQuestion"));
 
  649        $form->addCommandButton(
'saveReturnFQ', $this->lng->txt(
"save_return"));
 
  650        $form->addCommandButton(
'saveFQ', $this->lng->txt(
"save"));
 
  655            $found_vars    = array();
 
  656            $found_results = array();
 
  658                if (preg_match(
"/^unit_(\\\$v\d+)$/", 
$key, $matches)) {
 
  659                    array_push($found_vars, $matches[1]);
 
  661                if (preg_match(
"/^unit_(\\\$r\d+)$/", 
$key, $matches)) {
 
  662                    array_push($found_results, $matches[1]);
 
  666            $form->setValuesByPost();
 
  669            $custom_errors = 
false;
 
  670            if (count($variables)) {
 
  671                foreach ($variables as $variable) {
 
  675                    $min_range = 
$form->getItemByPostVar(
'range_min_' . $variable->getVariable());
 
  676                    $max_range = 
$form->getItemByPostVar(
'range_max_' . $variable->getVariable());
 
  677                    if ($min_range->getValue() > $max_range->getValue()) {
 
  678                        $min_range->setAlert($this->lng->txt(
'err_range'));
 
  679                        $max_range->setAlert($this->lng->txt(
'err_range'));
 
  680                        $custom_errors = 
true;
 
  690                    $min_range = 
$form->getItemByPostVar(
'range_min_' . 
$result->getResult());
 
  691                    $max_range = 
$form->getItemByPostVar(
'range_max_' . 
$result->getResult());
 
  692                    if ($min_range->getValue() > $max_range->getValue()) {
 
  693                        $min_range->setAlert($this->lng->txt(
'err_range'));
 
  694                        $max_range->setAlert($this->lng->txt(
'err_range'));
 
  695                        $custom_errors = 
true;
 
  699                    $formula = 
$form->getItemByPostVar(
'formula_' . 
$result->getResult());
 
  700                    if (strpos($formula->getValue(), 
$result->getResult()) !== 
false) {
 
  701                        $formula->setAlert($this->lng->txt(
'errRecursionInResult'));
 
  702                        $custom_errors = 
true;
 
  705                    $result_unit    = 
$form->getItemByPostVar(
'unit_' . 
$result->getResult());
 
  706                    $rating_advanced = 
$form->getItemByPostVar(
'rating_advanced_' . 
$result->getResult());
 
  707                    if (((
int) $result_unit->getValue() <= 0) && $rating_advanced->getChecked()) {
 
  709                        $rating_advanced->setDisabled(
true);
 
  710                        $rating_advanced->setChecked(
false);
 
  711                        $rating_advanced->setAlert($this->lng->txt(
'err_rating_advanced_not_allowed'));
 
  712                        $custom_errors = 
true;
 
  713                    } elseif ($rating_advanced->getChecked()) {
 
  714                        $rating_sign  = 
$form->getItemByPostVar(
'rating_sign_' . 
$result->getResult());
 
  715                        $rating_value = 
$form->getItemByPostVar(
'rating_value_' . 
$result->getResult());
 
  716                        $rating_unit  = 
$form->getItemByPostVar(
'rating_unit_' . 
$result->getResult());
 
  718                        $percentage = $rating_sign->getValue() + $rating_value->getValue() + $rating_unit->getValue();
 
  719                        if ($percentage != 100) {
 
  720                            $rating_advanced->setAlert($this->lng->txt(
'err_wrong_rating_advanced'));
 
  721                            $custom_errors = 
true;
 
  725                    preg_match_all(
"/([$][v][0-9]*)/", $formula->getValue(), $form_vars);
 
  726                    $result_has_undefined_vars = array_diff($form_vars[0], (array) $found_vars);
 
  727                    if (count($result_has_undefined_vars)) {
 
  734            if ($custom_errors && !
$errors) {
 
  738            $form->setValuesByPost(); 
 
  745            $this->tpl->setVariable(
'QUESTION_DATA', 
$form->getHTML());
 
  752        if (array_key_exists(
$result->getResult(), $resultunits)) {
 
  753            if (array_key_exists($unit_id, $resultunits[
$result->getResult()])) {
 
  769        $resultunit = 
$result->getUnit();
 
  777        if (is_object($resultunit)) {
 
  787        $this->editQuestion();
 
  793        $old_id = 
$_GET[
"q_id"];
 
  796            $ilUser->setPref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  797            $ilUser->writePref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  799            $this->
object->saveToDb();
 
  800            $originalexists = $this->
object->_questionExistsInPool($this->object->original_id);
 
  801            include_once 
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
 
  803                $this->ctrl->redirect($this, 
"originalSyncForm");
 
  805            } elseif (
$_GET[
"calling_test"]) {
 
  806                require_once 
'Modules/Test/classes/class.ilObjTest.php';
 
  808                #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId())); 
  809                $q_id = $this->
object->getId();
 
  811                    global $tree, 
$ilDB, $ilPluginAdmin;
 
  813                    include_once(
"./Modules/Test/classes/class.ilObjTest.php");
 
  817                    require_once 
'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
 
  820                    $new_id = 
$test->insertQuestion(
 
  821                        $testQuestionSetConfigFactory->getQuestionSetConfig(),
 
  822                        $this->object->getId()
 
  826                    if (isset($_REQUEST[
'prev_qid'])) {
 
  827                        $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST[
'prev_qid']);
 
  830                    $this->ctrl->setParameter($this, 
'q_id', $new_id);
 
  831                    $this->ctrl->setParameter($this, 
'calling_test', 
$_GET[
'calling_test']);
 
  832                    #$this->ctrl->setParameter($this, 'test_ref_id', false); 
  835                if ($_REQUEST[
'test_express_mode']) {
 
  841                if ($this->object->getId() !=  $old_id) {
 
  844                    $this->ctrl->redirectByClass(
"ilobjquestionpoolgui", 
"questions");
 
  846                if (strcmp(
$_SESSION[
"info"], 
"") != 0) {
 
  851                $this->ctrl->redirectByClass(
"ilobjquestionpoolgui", 
"questions");
 
  854            $ilUser->setPref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  855            $ilUser->writePref(
"tst_lastquestiontype", $this->object->getQuestionType());
 
  856            $this->
object->saveToDb();
 
  857            $this->editQuestion();
 
  866            $this->editQuestion();
 
  878            $this->
addErrorMessage($this->lng->txt(
"fill_out_all_required_fields"));
 
  901        $graphicalOutput = 
false,
 
  902        $result_output = 
false,
 
  903        $show_question_only = 
true,
 
  904        $show_feedback = 
false,
 
  905        $show_correct_solution = 
false,
 
  906        $show_manual_scoring = 
false,
 
  907        $show_question_text = 
true 
  910        $user_solution = array();
 
  911        if (($active_id > 0) && (!$show_correct_solution)) {
 
  912            $solutions = array();
 
  913            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  915                if (is_null(
$pass)) {
 
  919            $user_solution[
"active_id"] = $active_id;
 
  920            $user_solution[
"pass"]      = 
$pass;
 
  921            $solutions                  =&$this->
object->getSolutionValues($active_id, 
$pass);
 
  922            foreach ($solutions as $idx => $solution_value) {
 
  923                if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
  924                    $user_solution[$matches[1]] = $solution_value[
"value2"];
 
  925                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
 
  926                    if (!array_key_exists($matches[1], $user_solution)) {
 
  927                        $user_solution[$matches[1]] = array();
 
  929                    $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
 
  930                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
 
  931                    if (!array_key_exists($matches[1], $user_solution)) {
 
  932                        $user_solution[$matches[1]] = array();
 
  934                    $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
 
  937        } elseif ($active_id) {
 
  939            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  941                if (is_null(
$pass)) {
 
  945            $user_solution = (array) $this->object->getBestSolution($this->object->getSolutionValues($active_id, 
$pass));
 
  947            $solutionValues = array();
 
  949            foreach ($this->
getPreviewSession()->getParticipantsSolution() as $val1 => $val2) {
 
  950                $solutionValues[] = array(
'value1' => $val1, 
'value2' => $val2);
 
  953            $user_solution = (array) $this->object->getBestSolution($solutionValues);
 
  956        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
  957        $questiontext = $this->
object->substituteVariables($user_solution, $graphicalOutput, 
true, $result_output);
 
  959        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
  961        $solutiontemplate = 
new ilTemplate(
"tpl.il_as_tst_solution_output.html", 
true, 
true, 
"Modules/TestQuestionPool");
 
  963        if (strlen($feedback)) {
 
  969            $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
 
  970            $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, 
true));
 
  972        $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
 
  974        $solutionoutput = $solutiontemplate->get();
 
  975        if (!$show_question_only) {
 
  979        return $solutionoutput;
 
  982    public function getPreview($show_question_only = 
false, $showInlineFeedback = 
false)
 
  984        $user_solution = array();
 
  989            foreach ($solutions as $val1 => $val2) {
 
  990                if (preg_match(
"/^(\\\$v\\d+)$/", $val1, $matches)) {
 
  991                    $user_solution[$matches[1]] = $val2;
 
  992                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $val1, $matches)) {
 
  993                    if (!array_key_exists($matches[1], $user_solution)) {
 
  994                        $user_solution[$matches[1]] = array();
 
  996                    $user_solution[$matches[1]][
"value"] = $val2;
 
  997                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $val1, $matches)) {
 
  998                    if (!array_key_exists($matches[1], $user_solution)) {
 
  999                        $user_solution[$matches[1]] = array();
 
 1001                    $user_solution[$matches[1]][
"unit"] = $val2;
 
 1004                if (preg_match(
"/^(\\\$r\\d+)/", $val1, $matches) && $user_solution[$matches[1]][
"result_type"] == 0) {
 
 1010        if (!$this->object->hasRequiredVariableSolutionValues($user_solution)) {
 
 1011            $user_solution = $this->
object->getInitialVariableSolutionValues();
 
 1018        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
 1020            $questiontext = $this->
object->substituteVariables($user_solution, 
false, 
false, 
false);
 
 1022            $questiontext = $this->
object->substituteVariables(array());
 
 1024        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
 1026        if (!$show_question_only) {
 
 1028            $questionoutput = $this->
getILIASPage($questionoutput);
 
 1030        return $questionoutput;
 
 1034    public function getTestOutput($active_id, 
$pass, $is_postponed = 
false, $use_post_solutions = 
false, $show_feedback = 
false)
 
 1039        $user_solution = array();
 
 1041            $solutions = (array) $this->object->getTestOutputSolutions($active_id, 
$pass);
 
 1043            $actualPassIndex = 
null;
 
 1044            if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
 
 1045                require_once 
'Modules/Test/classes/class.ilObjTest.php';
 
 1049            foreach ($solutions as $idx => $solution_value) {
 
 1050                if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1051                    if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
 
 1052                        $this->
object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value[
"value2"], 
true);
 
 1055                    $user_solution[$matches[1]] = $solution_value[
"value2"];
 
 1056                } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1057                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1058                        $user_solution[$matches[1]] = array();
 
 1060                    $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
 
 1061                } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
 
 1062                    if (!array_key_exists($matches[1], $user_solution)) {
 
 1063                        $user_solution[$matches[1]] = array();
 
 1065                    $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
 
 1068                if (preg_match(
"/^(\\\$r\\d+)/", $solution_value[
"value1"], $matches) && $user_solution[$matches[1]][
"result_type"] == 0) {
 
 1075        $solutions = $this->
object->getSolutionValues($active_id, 
$pass, 
true);
 
 1076        foreach ($solutions as $idx => $solution_value) {
 
 1077            if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
 
 1078                $user_solution[$matches[1]] = $solution_value[
"value2"];
 
 1083        if (!$this->object->hasRequiredVariableSolutionValues($user_solution)) {
 
 1084            foreach ($this->object->getInitialVariableSolutionValues() as $val1 => $val2) {
 
 1085                $this->
object->saveCurrentSolution($active_id, 
$pass, $val1, $val2, 
true);
 
 1090        $template = 
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html", 
true, 
true, 
'Modules/TestQuestionPool');
 
 1092        $questiontext = $this->
object->substituteVariables($user_solution);
 
 1094        $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, 
true));
 
 1097        $pageoutput     = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
 
sprintf('%.4f', $callTime)
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
saveTaxonomyAssignments()
addErrorMessage($errormessage)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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