Public Member Functions

ASS_MultipleChoiceGUI Class Reference

Multiple choice question GUI representation. More...

Inheritance diagram for ASS_MultipleChoiceGUI:
Collaboration diagram for ASS_MultipleChoiceGUI:

Public Member Functions

 ASS_MultipleChoiceGUI ($id=-1)
 ASS_MultipleChoiceGUI constructor.
 getCommand ($cmd)
 getQuestionType ()
 Returns the question type string.
 editQuestion ()
 Creates an output of the edit form for the question.
 outOtherQuestionData ()
 Sets the extra fields i.e.
 addYesNo ()
 add yes no answer
 addTrueFalse ()
 add true/false answer
 add ()
 add an answer
 delete ()
 delete an answer
 checkInput ()
 check input fields
 writePostData ()
 Evaluates a posted edit form and writes the form data in the question object.
 outWorkingForm ($test_id="", $is_postponed=false, $showsolution=0)
 Creates the question output form for the learner.
 outUserSolution ($user_id, $test_id)
 Creates an output of the user's solution.
 addSuggestedSolution ()

Detailed Description

Multiple choice question GUI representation.

The ASS_MultipleChoiceGUI class encapsulates the GUI representation for multiple choice questions.

Author:
Helmut Schottmüller <hschottm@tzi.de>
Version:
Id:
class.assMultipleChoiceGUI.php 6746 2005-02-20 09:32:47Z hschottm

class.assMultipleChoiceGUI.php Assessment

Definition at line 38 of file class.assMultipleChoiceGUI.php.


Member Function Documentation

ASS_MultipleChoiceGUI::add (  ) 

add an answer

Definition at line 437 of file class.assMultipleChoiceGUI.php.

References checkInput(), editQuestion(), sendInfo(), and writePostData().

        {
                //$this->setObjectData();
                $this->writePostData();

                if (!$this->checkInput())
                {
                        sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
                }
                else
                {
                        // add an answer template
                        $this->object->add_answer(
                                $this->lng->txt(""),
                                0,
                                0,
                                count($this->object->answers)
                        );
                }

                $this->editQuestion();
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::addSuggestedSolution (  ) 

Reimplemented from ASS_QuestionGUI.

Definition at line 844 of file class.assMultipleChoiceGUI.php.

References $_GET, $_POST, $_SESSION, checkInput(), editQuestion(), ASS_QuestionGUI::getQuestionTemplate(), sendInfo(), and writePostData().

        {
                $_SESSION["subquestion_index"] = 0;
                if ($_POST["cmd"]["addSuggestedSolution"])
                {
                        $this->writePostData();
                        if (!$this->checkInput())
                        {
                                sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
                                $this->editQuestion();
                                return;
                        }
                }
                $this->object->saveToDb();
                $_GET["q_id"] = $this->object->getId();
                $this->tpl->setVariable("HEADER", $this->object->getTitle());
                if ($this->object->get_response() == RESPONSE_SINGLE)
                {
                        $this->getQuestionTemplate("qt_multiple_choice_sr");
                }
                else
                {
                        $this->getQuestionTemplate("qt_multiple_choice_mr");
                }
                parent::addSuggestedSolution();
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::addTrueFalse (  ) 

add true/false answer

Definition at line 405 of file class.assMultipleChoiceGUI.php.

References checkInput(), editQuestion(), sendInfo(), and writePostData().

        {
                //$this->setObjectData();
                $this->writePostData();

                if (!$this->checkInput())
                {
                        sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
                }
                else
                {
                        // add a true/false answer template
                        $this->object->add_answer(
                                $this->lng->txt("true"),
                                0,
                                0,
                                count($this->object->answers)
                        );
                        $this->object->add_answer(
                                $this->lng->txt("false"),
                                0,
                                0,
                                count($this->object->answers)
                        );
                }

                $this->editQuestion();
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::addYesNo (  ) 

add yes no answer

Definition at line 373 of file class.assMultipleChoiceGUI.php.

References checkInput(), editQuestion(), sendInfo(), and writePostData().

        {
                $this->writePostData();
                //$this->setObjectData();

                if (!$this->checkInput())
                {
                        sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
                }
                else
                {
                        // add a yes/no answer template
                        $this->object->add_answer(
                                $this->lng->txt("yes"),
                                0,
                                0,
                                count($this->object->answers)
                        );
                        $this->object->add_answer(
                                $this->lng->txt("no"),
                                0,
                                0,
                                count($this->object->answers)
                        );
                }

                $this->editQuestion();
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::ASS_MultipleChoiceGUI ( id = -1  ) 

ASS_MultipleChoiceGUI constructor.

The constructor takes possible arguments an creates an instance of the ASS_MultipleChoiceGUI object.

Parameters:
integer $id The database id of a multiple choice question object public

Definition at line 48 of file class.assMultipleChoiceGUI.php.

References $id, and ASS_QuestionGUI::ASS_QuestionGUI().

        {
                $this->ASS_QuestionGUI();
                $this->object = new ASS_MultipleChoice();
                if ($id >= 0)
                {
                        $this->object->loadFromDb($id);
                }
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::checkInput (  ) 

check input fields

Definition at line 483 of file class.assMultipleChoiceGUI.php.

References $_POST, and $cmd.

Referenced by add(), addSuggestedSolution(), addTrueFalse(), and addYesNo().

        {
                $cmd = $this->ctrl->getCmd();

                if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
                {
//echo "<br>checkInput1:FALSE";
                        return false;
                }
                foreach ($_POST as $key => $value)
                {
                        if (preg_match("/answer_(\d+)/", $key, $matches))
                        {
                                if (!$value)
                                {
//echo "<br>checkInput2:FALSE";
                                        return false;
                                }
                        }
                }

                return true;
        }

Here is the caller graph for this function:

ASS_MultipleChoiceGUI::delete (  ) 

delete an answer

Definition at line 463 of file class.assMultipleChoiceGUI.php.

References $_POST, editQuestion(), and writePostData().

        {
                //$this->setObjectData();
                $this->writePostData();

                foreach ($_POST["cmd"] as $key => $value)
                {
                        // was one of the answers deleted
                        if (preg_match("/delete_(\d+)/", $key, $matches))
                        {
                                $this->object->delete_answer($matches[1]);
                        }
                }

                $this->editQuestion();
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::editQuestion (  ) 

Creates an output of the edit form for the question.

Creates an output of the edit form for the question

public

Definition at line 98 of file class.assMultipleChoiceGUI.php.

References ASS_Question::_getInternalLinkHref(), ASS_QuestionGUI::getQuestionTemplate(), and outOtherQuestionData().

Referenced by add(), addSuggestedSolution(), addTrueFalse(), addYesNo(), and delete().

        {
                $this->tpl->setVariable("HEADER", $this->object->getTitle());
                $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
                // single response
                if ($this->object->get_response() == RESPONSE_SINGLE)
                {
                        $this->getQuestionTemplate("qt_multiple_choice_sr");
                        $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_mc_sr.html", true);
                        // output of existing single response answers
                        for ($i = 0; $i < $this->object->get_answer_count(); $i++)
                        {
                                $this->tpl->setCurrentBlock("deletebutton");
                                $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
                                $this->tpl->setVariable("ANSWER_ORDER", $i);
                                $this->tpl->parseCurrentBlock();
                                $this->tpl->setCurrentBlock("answers");
                                $answer = $this->object->get_answer($i);
                                $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $answer->get_order() + 1);
                                $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
                                $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
                                $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
                                $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
                                $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS", sprintf("%d", $answer->get_points()));
                                $this->tpl->setVariable("VALUE_TRUE", $this->lng->txt("true"));
                                $this->tpl->parseCurrentBlock();
                        }
                        // call to other question data i.e. estimated working time block
                        $this->outOtherQuestionData();

                        $internallinks = array(
                                "lm" => $this->lng->txt("obj_lm"),
                                "st" => $this->lng->txt("obj_st"),
                                "pg" => $this->lng->txt("obj_pg"),
                                "glo" => $this->lng->txt("glossary_term")
                        );
                        foreach ($internallinks as $key => $value)
                        {
                                $this->tpl->setCurrentBlock("internallink");
                                $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
                                $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
                                $this->tpl->parseCurrentBlock();
                        }
                        
                        $this->tpl->setCurrentBlock("HeadContent");
                        if ($this->object->get_answer_count() == 0)
                        {
                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
                        }
                        else
                        {
                                switch ($this->ctrl->getCmd())
                                {
                                        case "add":
                                        case "addTrueFalse":
                                        case "addYesNo":
                                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
                                                break;
                                        case "":
                                                if ($this->object->get_answer_count() == 0)
                                                {
                                                        $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
                                                }
                                                else
                                                {
                                                        $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
                                                }
                                                break;
                                        default:
                                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
                                                break;
                                }
                        }
                        $this->tpl->parseCurrentBlock();
                        $this->tpl->setCurrentBlock("question_data");
                        $this->tpl->setVariable("MULTIPLE_CHOICE_ID", $this->object->getId());
                        $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_TITLE", htmlspecialchars($this->object->getTitle()));
                        $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_COMMENT", htmlspecialchars($this->object->getComment()));
                        $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_AUTHOR", htmlspecialchars($this->object->getAuthor()));
                        $questiontext = $this->object->get_question();
                        $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
                        $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
                        $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
                        $this->tpl->setVariable("VALUE_ADD_ANSWER_YN", $this->lng->txt("add_answer_yn"));
                        $this->tpl->setVariable("VALUE_ADD_ANSWER_TF", $this->lng->txt("add_answer_tf"));
                        $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
                        $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
                        $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
                        $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
                        $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
                        $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
                        $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
                        if ($this->object->getShuffle())
                        {
                                $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
                        }
                        else
                        {
                                $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
                        }
                        $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
                        if (count($this->object->suggested_solutions))
                        {
                                $solution_array = $this->object->getSuggestedSolution(0);
                                $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
                                $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
                                $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
                                $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
                                $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
                        }
                        else
                        {
                                $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
                        }
                        $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
                        $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
                        $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
                        $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
                        $this->ctrl->setParameter($this, "sel_question_types", "qt_multiple_choice_sr");
                        $this->tpl->setVariable("ACTION_MULTIPLE_CHOICE_TEST", $this->ctrl->getFormAction($this));

                        $this->tpl->parseCurrentBlock();
                }
                else    // multiple response
                {
                        $this->getQuestionTemplate("qt_multiple_choice_mr");
                        $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_mc_mr.html", true);

                        // output of existing multiple response answers
                        for ($i = 0; $i < $this->object->get_answer_count(); $i++)
                        {
                                $this->tpl->setCurrentBlock("deletebutton");
                                $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
                                $this->tpl->setVariable("ANSWER_ORDER", $i);
                                $this->tpl->parseCurrentBlock();
                                $this->tpl->setCurrentBlock("answers");
                                $answer = $this->object->get_answer($i);
                                $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
                                $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $answer->get_order() + 1);
                                $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS", sprintf("%d", $answer->get_points()));
                                $this->tpl->setVariable("TEXT_WHEN", $this->lng->txt("when"));
                                $this->tpl->setVariable("TEXT_UNCHECKED", $this->lng->txt("checkbox_unchecked"));
                                $this->tpl->setVariable("TEXT_CHECKED", $this->lng->txt("checkbox_checked"));
                                $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
                                $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
                                $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
                                $this->tpl->setVariable("VALUE_TRUE", $this->lng->txt("true"));
                                if ($answer->isStateChecked())
                                {
                                        $this->tpl->setVariable("CHECKED_SELECTED", " selected=\"selected\"");
                                }
                                $this->tpl->parseCurrentBlock();
                        }

                        // call to other question data i.e. estimated working time block
                        $this->outOtherQuestionData();

                        $internallinks = array(
                                "lm" => $this->lng->txt("obj_lm"),
                                "st" => $this->lng->txt("obj_st"),
                                "pg" => $this->lng->txt("obj_pg"),
                                "glo" => $this->lng->txt("glossary_term")
                        );
                        foreach ($internallinks as $key => $value)
                        {
                                $this->tpl->setCurrentBlock("internallink");
                                $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
                                $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
                                $this->tpl->parseCurrentBlock();
                        }
                        
                        $this->tpl->setCurrentBlock("HeadContent");

                        if ($this->object->get_answer_count() == 0)
                        {
                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
                        }
                        else
                        {
                                switch ($this->ctrl->getCmd())
                                {
                                        case "add":
                                        case "addTrueFalse":
                                        case "addYesNo":
                                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
                                                break;
                                        case "":
                                                if ($this->object->get_answer_count() == 0)
                                                {
                                                        $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
                                                }
                                                else
                                                {
                                                        $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
                                                }
                                                break;
                                        default:
                                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
                                                break;
                                }
                        }
                        $this->tpl->parseCurrentBlock();
                        $this->tpl->setCurrentBlock("question_data");
                        $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
                        $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
                        $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
                        $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
                        $this->tpl->setVariable("MULTIPLE_CHOICE_ID", $this->object->getId());
                        $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_TITLE", htmlspecialchars($this->object->getTitle()));
                        $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_COMMENT", htmlspecialchars($this->object->getComment()));
                        $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_AUTHOR", htmlspecialchars($this->object->getAuthor()));
                        $questiontext = $this->object->get_question();
                        $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
                        $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
                        $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
                        $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
                        $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
                        $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
                        if ($this->object->getShuffle())
                        {
                                $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
                        }
                        else
                        {
                                $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
                        }
                        $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
                        if (count($this->object->suggested_solutions))
                        {
                                $solution_array = $this->object->getSuggestedSolution(0);
                                $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
                                $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
                                $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
                                $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
                                $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
                        }
                        else
                        {
                                $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
                        }
                        $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
                        $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
                        $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
                        $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
                        $this->ctrl->setParameter($this, "sel_question_types", "qt_multiple_choice_mr");
                        $this->tpl->setVariable("ACTION_MULTIPLE_CHOICE_TEST", $this->ctrl->getFormAction($this));
                        $this->tpl->parseCurrentBlock();
                }

                $this->tpl->setCurrentBlock("adm_content");
                $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
                $this->tpl->parseCurrentBlock();
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ASS_MultipleChoiceGUI::getCommand ( cmd  ) 

Reimplemented from ASS_QuestionGUI.

Definition at line 60 of file class.assMultipleChoiceGUI.php.

References $cmd.

        {
                if (substr($cmd, 0, 6) == "delete")
                {
                        $cmd = "delete";
                }

                return $cmd;
        }

ASS_MultipleChoiceGUI::getQuestionType (  ) 

Returns the question type string.

Returns the question type string

Returns:
string The question type string public

Reimplemented from ASS_QuestionGUI.

Definition at line 79 of file class.assMultipleChoiceGUI.php.

        {
                if ($this->object->get_response() == RESPONSE_SINGLE)
                {
                        return "qt_multiple_choice_sr";
                }
                else
                {
                        return "qt_multiple_choice_mr";
                }
        }

ASS_MultipleChoiceGUI::outOtherQuestionData (  ) 

Sets the extra fields i.e.

estimated working time of a question from a posted create/edit form

Sets the extra fields i.e. estimated working time of a question from a posted create/edit form

private

Reimplemented from ASS_QuestionGUI.

Definition at line 359 of file class.assMultipleChoiceGUI.php.

References ilUtil::makeTimeSelect().

Referenced by editQuestion().

        {
//echo "<br>ASS_MultipleChoiceGUI->outOtherQuestionData()";
                $this->tpl->setCurrentBlock("other_question_data");
                $est_working_time = $this->object->getEstimatedWorkingTime();
                $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
                $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
                $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
                $this->tpl->parseCurrentBlock();
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ASS_MultipleChoiceGUI::outUserSolution ( user_id,
test_id 
)

Creates an output of the user's solution.

Creates an output of the user's solution

public

Definition at line 779 of file class.assMultipleChoiceGUI.php.

References $right, $user_id, and ilUtil::getImagePath().

        {
                $results = $this->object->getReachedInformation($user_id, $test_id);
                foreach ($this->object->answers as $key => $answer)
                {
                        $selected = 0;
                        $this->tpl->setCurrentBlock("tablerow");
                        if ($answer->isStateChecked())
                        {
                                $right = 0;
                                foreach ($results as $reskey => $resvalue)
                                {
                                        if ($resvalue["value"] == $key)
                                        {
                                                $right = 1;
                                                $selected = 1;
                                        }
                                }
                        }
                        elseif ($answer->isStateUnchecked())
                        {
                                $right = 1;
                                foreach ($results as $reskey => $resvalue)
                                {
                                        if ($resvalue["value"] == $key)
                                        {
                                                $right = 0;
                                                $selected = 1;
                                        }
                                }
                        }
                        if ($right)
                        {
                                $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
                                $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
                        }
                        else
                        {
                                $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
                                $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
                        }
                        if ($this->object->get_response() == RESPONSE_SINGLE)
                        {
                                $state = $this->lng->txt("unselected");
                        }
                        else
                        {
                                $state = $this->lng->txt("checkbox_unchecked");
                        }
                        if ($selected)
                        {
                                if ($this->object->get_response() == RESPONSE_SINGLE)
                                {
                                        $state = $this->lng->txt("selected");
                                }
                                else
                                {
                                        $state = $this->lng->txt("checkbox_checked");
                                }
                        }
                        $this->tpl->setVariable("ANSWER_DESCRIPTION", "$state: " . "&quot;<em>" . $answer->get_answertext() . "</em>&quot;");
                        $this->tpl->parseCurrentBlock();
                }
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::outWorkingForm ( test_id = "",
is_postponed = false,
showsolution = 0 
)

Creates the question output form for the learner.

Creates the question output form for the learner

public

Definition at line 662 of file class.assMultipleChoiceGUI.php.

References $ilUser, $output, and ASS_QuestionGUI::outQuestionPage().

        {
                global $ilUser;
                $output = $this->outQuestionPage("MULTIPLE_CHOICE_QUESTION", $is_postponed);
//              preg_match("/(<div[^<]*?ilc_Question.*?<\/div>)/is", $output, $matches);
//              $solutionoutput = $matches[1];
                $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
                $solutionoutput = preg_replace("/\"mc/", "\"solution_mc", $solutionoutput);
                $solutionoutput = preg_replace("/multiple_choice_result/", "solution_multiple_choice_result", $solutionoutput);
                // set solutions
                if ($test_id)
                {
                        $solutions =& $this->object->getSolutionValues($test_id);
                        foreach ($solutions as $idx => $solution_value)
                        {
                                $repl_str = "dummy=\"mc".$solution_value->value1."\"";
//echo "<br>".htmlentities($repl_str);
                                $output = str_replace($repl_str, $repl_str." checked=\"checked\"", $output);
                        }
                }
                
                $maxpoints = 0;
                $maxindex = -1;
                foreach ($this->object->answers as $idx => $answer)
                {
                        if ($answer->get_points() > $maxpoints)
                        {
                                $maxpoints = $answer->get_points();
                                $maxindex = $idx;
                        }
                }
                foreach ($this->object->answers as $idx => $answer)
                {
                        if ($this->object->get_response() == RESPONSE_MULTIPLE)
                        {
                                if ($answer->isStateChecked() && ($answer->get_points() > 0))
                                {
                                        $repl_str = "dummy=\"solution_mc$idx\"";
                                        $solutionoutput = str_replace($repl_str, $repl_str." checked=\"checked\"", $solutionoutput);
                                }
                                $sol = '(<em>';
                                $sol .= '<input name="checkbox' . time() . $idx . '" type="checkbox" readonly="readonly" checked="checked" /> = ';
                                if ($answer->isStateChecked())
                                {
                                        $sol .= $answer->get_points();
                                }
                                else
                                {
                                        $sol .= "0";
                                }
                                $sol .= ' ' . $this->lng->txt("points") . ', ';
                                $sol .= '<input name="checkbox' . time() . $idx . '" type="checkbox" readonly="readonly" /> = ';
                                if (!$answer->isStateChecked())
                                {
                                        $sol .= $answer->get_points();
                                }
                                else
                                {
                                        $sol .= "0";
                                }
                                $sol .= ' ' . $this->lng->txt("points");
                                $sol .= '</em>)';
                                $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_mc$idx.*?)<\/tr>/", "\\1<td>" . $sol . "</td></tr>", $solutionoutput);
                        }
                        else
                        {
                                $sol = '(<em>';
                                $sol .= '<input name="radio' . time() . $idx . '" type="radio" readonly="readonly" checked="checked" /> = ';
                                if ($answer->isStateChecked())
                                {
                                        $sol .= $answer->get_points();
                                }
                                else
                                {
                                        $sol .= "0";
                                }
                                $sol .= ' ' . $this->lng->txt("points") . ', ';
                                $sol .= '<input name="radio' . time() . $idx . '" type="radio" readonly="readonly" /> = ';
                                if (!$answer->isStateChecked())
                                {
                                        $sol .= $answer->get_points();
                                }
                                else
                                {
                                        $sol .= "0";
                                }
                                $sol .= ' ' . $this->lng->txt("points");
                                $sol .= '</em>)';
                                $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_mc$idx.*?)<\/tr>/", "\\1<td>" . $sol . "</td></tr>", $solutionoutput);
                        }
                }
                if (($maxindex > -1) && ($this->object->get_response() == RESPONSE_SINGLE))
                {
                        $repl_str = "dummy=\"solution_mc$maxindex\"";
                        $solutionoutput = str_replace($repl_str, $repl_str." checked=\"checked\"", $solutionoutput);
                }

                $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
                if ($test_id) 
                {
                        $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
                }
                if (!$showsolution)
                {
                        $solutionoutput = "";
                        $received_points = "";
                }
                $this->tpl->setVariable("MULTIPLE_CHOICE_QUESTION", $output.$solutionoutput.$received_points);
        }

Here is the call graph for this function:

ASS_MultipleChoiceGUI::writePostData (  ) 

Evaluates a posted edit form and writes the form data in the question object.

Evaluates a posted edit form and writes the form data in the question object

Returns:
integer A positive value, if one of the required fields wasn't set, else 0 private

Reimplemented from ASS_QuestionGUI.

Definition at line 515 of file class.assMultipleChoiceGUI.php.

References $_GET, $_POST, $result, sendInfo(), ilUtil::stripSlashes(), and ASS_QuestionGUI::writeOtherPostData().

Referenced by add(), addSuggestedSolution(), addTrueFalse(), addYesNo(), and delete().

        {
//echo "here!"; exit;
//echo "<br>ASS_MultipleChoiceGUI->writePostData()";
                $result = 0;
                if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
                {
                        $result = 1;
                }

                if (($result) and (($_POST["cmd"]["add"]) or ($_POST["cmd"]["add_tf"]) or ($_POST["cmd"]["add_yn"])))
                {
                        // You cannot add answers before you enter the required data
                        sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
                        $_POST["cmd"]["add"] = "";
                        $_POST["cmd"]["add_yn"] = "";
                        $_POST["cmd"]["add_tf"] = "";
                }

                // Check the creation of new answer text fields
                if ($_POST["cmd"]["add"] or $_POST["cmd"]["add_yn"] or $_POST["cmd"]["add_tf"])
                {
                        foreach ($_POST as $key => $value)
                        {
                                if (preg_match("/answer_(\d+)/", $key, $matches))
                                {
                                        if (!$value)
                                        {
                                                $_POST["cmd"]["add"] = "";
                                                $_POST["cmd"]["add_yn"] = "";
                                                $_POST["cmd"]["add_tf"] = "";
                                                sendInfo($this->lng->txt("fill_out_all_answer_fields"));
                                        }
                                }
                        }
                }

                $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
                $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
                $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
                $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
                $questiontext = preg_replace("/\n/", "<br />", $questiontext);
                $this->object->set_question($questiontext);
                $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
                $this->object->setShuffle($_POST["shuffle"]);

                $saved = $this->writeOtherPostData($result);

                // Delete all existing answers and create new answers from the form data
                $this->object->flush_answers();

                // Add all answers from the form into the object
                if ($this->object->get_response() == RESPONSE_SINGLE)
                {
                        // ...for multiple choice with single response
                        foreach ($_POST as $key => $value)
                        {
                                if (preg_match("/answer_(\d+)/", $key, $matches))
                                {
                                        $points = $_POST["points_$matches[1]"];
                                        if (preg_match("/\d+/", $points))
                                        {
                                                if ($points < 0)
                                                {
                                                        $points = 0.0;
                                                        sendInfo($this->lng->txt("negative_points_not_allowed"), true);
                                                }
                                        }
                                        else
                                        {
                                                $points = 0.0;
                                        }
                                        $this->object->add_answer(
                                                ilUtil::stripSlashes($_POST["$key"]),
                                                ilUtil::stripSlashes($points),
                                                ilUtil::stripSlashes(1),
                                                ilUtil::stripSlashes($matches[1])
                                                );
                                }
                        }
                }
                else
                {
                        // ...for multiple choice with multiple response
                        foreach ($_POST as $key => $value)
                        {
                                if (preg_match("/answer_(\d+)/", $key, $matches))
                                {
                                        $points = $_POST["points_$matches[1]"];
                                        if (preg_match("/\d+/", $points))
                                        {
                                                if ($points < 0)
                                                {
                                                        $points = 0.0;
                                                        sendInfo($this->lng->txt("negative_points_not_allowed"), true);
                                                }
                                        }
                                        else
                                        {
                                                $points = 0.0;
                                        }
                                        $this->object->add_answer(
                                                ilUtil::stripSlashes($_POST["$key"]),
                                                ilUtil::stripSlashes($points),
                                                ilUtil::stripSlashes($_POST["status_$matches[1]"]),
                                                ilUtil::stripSlashes($matches[1])
                                                );
                                }
                        }
                }

                // After adding all questions from the form we have to check if the learner pressed a delete button
                foreach ($_POST as $key => $value)
                {
                        // was one of the answers deleted
                        if (preg_match("/delete_(\d+)/", $key, $matches))
                        {
                                $this->object->delete_answer($matches[1]);
                        }
                }

                // Set the question id from a hidden form parameter
                if ($_POST["multiple_choice_id"] > 0)
                {
                        $this->object->setId($_POST["multiple_choice_id"]);
                }
                
                if ($saved)
                {
                        // If the question was saved automatically before an upload, we have to make
                        // sure, that the state after the upload is saved. Otherwise the user could be
                        // irritated, if he presses cancel, because he only has the question state before
                        // the upload process.
                        $this->object->saveToDb();
                        $_GET["q_id"] = $this->object->getId();
                }

                return $result;
        }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: