Public Member Functions

ASS_MatchingQuestionGUI Class Reference

Matching question GUI representation. More...

Inheritance diagram for ASS_MatchingQuestionGUI:
Collaboration diagram for ASS_MatchingQuestionGUI:

Public Member Functions

 ASS_MatchingQuestionGUI ($id=-1)
 ASS_MatchingQuestionGUI constructor.
 getQuestionType ()
 Returns the question type string.
 getCommand ($cmd)
 editQuestion ($has_error=0, $delete=false)
 Creates an output of the edit form for the question.
 outOtherQuestionData ()
 Sets the extra fields i.e.
 addPair ()
 add matching pair
 upload ()
 upload matching picture or material
 delete ()
 delete matching pair
 writePostData ()
 Evaluates a posted edit form and writes the form data in the question object.
 outWorkingForm ($test_id="", $is_postponed=false, $showsolution=0, $show_question_page=true, $show_solution_only=false, $ilUser=NULL, $pass=NULL, $mixpass=false, $user_post_solution=false)
 Creates the question output form for the learner.
 checkInput ()
 check input fields
 addSuggestedSolution ()

Detailed Description

Matching question GUI representation.

The ASS_MatchingQuestionGUI class encapsulates the GUI representation for matching questions.

Author:
Helmut Schottmüller <helmut.schottmueller@mac.com>
Version:
Id:
class.assMatchingQuestionGUI.php 13763 2007-05-02 15:02:42Z hschottm

class.assMatchingQuestionGUI.php Assessment

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


Member Function Documentation

ASS_MatchingQuestionGUI::addPair (  ) 

add matching pair

Definition at line 347 of file class.assMatchingQuestionGUI.php.

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

        {
                $result = $this->writePostData();
                $this->editQuestion($result);
        }

Here is the call graph for this function:

ASS_MatchingQuestionGUI::addSuggestedSolution (  ) 

Reimplemented from ASS_QuestionGUI.

Definition at line 736 of file class.assMatchingQuestionGUI.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());
                $this->getQuestionTemplate("qt_matching");
                parent::addSuggestedSolution();
        }       

Here is the call graph for this function:

ASS_MatchingQuestionGUI::ASS_MatchingQuestionGUI ( id = -1  ) 

ASS_MatchingQuestionGUI constructor.

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

Parameters:
integer $id The database id of a image map question object public

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

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

        {
                $this->ASS_QuestionGUI();
                include_once "./assessment/classes/class.assMatchingQuestion.php";
                $this->object = new ASS_MatchingQuestion();
                if ($id >= 0)
                {
                        $this->object->loadFromDb($id);
                }
        }

Here is the call graph for this function:

ASS_MatchingQuestionGUI::checkInput (  ) 

check input fields

Definition at line 726 of file class.assMatchingQuestionGUI.php.

References $_POST.

Referenced by addSuggestedSolution(), and writePostData().

        {
                if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
                {
                        return false;
                }
                return true;
        }

Here is the caller graph for this function:

ASS_MatchingQuestionGUI::delete (  ) 

delete matching pair

Definition at line 366 of file class.assMatchingQuestionGUI.php.

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

        {
                $this->writePostData();
                if (is_array($_POST["chb_answer"]))
                {
                        $deleteanswers = $_POST["chb_answer"];
                        rsort($deleteanswers);
                        foreach ($deleteanswers as $value)
                        {
                                $this->object->delete_matchingpair($value);
                        }
                }
                $this->editQuestion(0, true);
        }

Here is the call graph for this function:

ASS_MatchingQuestionGUI::editQuestion ( has_error = 0,
delete = false 
)

Creates an output of the edit form for the question.

Creates an output of the edit form for the question

public

Definition at line 95 of file class.assMatchingQuestionGUI.php.

References $_POST, $key, ASS_Question::_getInternalLinkHref(), ilUtil::getImagePath(), ASS_QuestionGUI::getQuestionTemplate(), outOtherQuestionData(), and sendInfo().

Referenced by addPair(), addSuggestedSolution(), delete(), and upload().

        {
                //$this->tpl->setVariable("HEADER", $this->object->getTitle());
                $this->getQuestionTemplate("qt_matching");
                $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_matching.html", true);

                $tblrow = array("tblrow1top", "tblrow2top");
                // Vorhandene Anworten ausgeben
                for ($i = 0; $i < $this->object->get_matchingpair_count(); $i++)
                {
                        $thispair = $this->object->get_matchingpair($i);
                        if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                        {
                                $this->tpl->setCurrentBlock("pictures");
                                $this->tpl->setVariable("ANSWER_ORDER", $i);
                                $this->tpl->setVariable("PICTURE_ID", $thispair->getPictureId());
                                $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
                                $filename = $thispair->getPicture();
                                if ($filename)
                                {
                                        $imagepath = $this->object->getImagePathWeb() . $thispair->getPicture();
                                        $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $this->lng->txt("qpl_display_fullsize_image") . "\" title=\"" . $this->lng->txt("qpl_display_fullsize_image") . "\" border=\"\" />");
                                        $this->tpl->setVariable("IMAGE_FILENAME", $thispair->getPicture());
                                        $this->tpl->setVariable("VALUE_PICTURE", $thispair->getPicture());
                                }
                                $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
                        }
                        elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
                        {
                                $this->tpl->setCurrentBlock("definitions");
                                $this->tpl->setVariable("ANSWER_ORDER", $i);
                                $this->tpl->setVariable("DEFINITION_ID", $thispair->getDefinitionId());
                                $this->tpl->setVariable("VALUE_DEFINITION", htmlspecialchars($thispair->getDefinition()));
                                $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
                        }
                        $this->tpl->parseCurrentBlock();
                        $this->tpl->setCurrentBlock("answers");
                        $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $i + 1);
                        $this->tpl->setVariable("ANSWER_ORDER", $i);
                        $this->tpl->setVariable("TERM_ID", $thispair->getTermId());
                        $this->tpl->setVariable("VALUE_TERM", htmlspecialchars($thispair->getTerm()));
                        $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
                        $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%d", $thispair->getPoints()));
                        $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
                        $this->tpl->parseCurrentBlock();
                }
                if ($this->object->get_matchingpair_count())
                {
                        $this->tpl->setCurrentBlock("answerhead");
                        $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
                        $this->tpl->setVariable("TERM", $this->lng->txt("term"));
                        if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                        {
                                $this->tpl->setVariable("PICTURE_OR_DEFINITION", $this->lng->txt("picture"));
                        }
                        else
                        {
                                $this->tpl->setVariable("PICTURE_OR_DEFINITION", $this->lng->txt("definition"));
                        }
                        $this->tpl->parseCurrentBlock();
                        $this->tpl->setCurrentBlock("selectall");
                        $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
                        $i++;
                        $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
                        $this->tpl->parseCurrentBlock();
                        $this->tpl->setCurrentBlock("QFooter");
                        $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\"/>");
                        $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
                        $this->tpl->parseCurrentBlock();
                }
                // call to other question data i.e. estimated working time block
                $this->outOtherQuestionData();

                // Check the creation of new answer text fields
                $allow_add_pair = 1;
                foreach ($_POST as $key => $value)
                {
                        if (preg_match("/(term|picture|definition)_(\d+)_(\d+)/", $key, $matches))
                        {
                                if (!$value)
                                {
                                        $allow_add_pair = 0;
                                }
                        }
                }
                $add_random_id = "";
                if (($this->ctrl->getCmd() == "addPair") and $allow_add_pair and (!$has_error))
                {
                        $i++;
                        // Template für neue Antwort erzeugen
                        if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                        {
                                $this->tpl->setCurrentBlock("pictures");
                                $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
                                $this->tpl->setVariable("PICTURE_ID", $this->object->get_random_id());
                                $this->tpl->setVariable("VALUE_PICTURE", "");
                                $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
                        }
                        elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
                        {
                                $this->tpl->setCurrentBlock("definitions");
                                $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
                                $this->tpl->setVariable("DEFINITION_ID", $this->object->get_random_id());
                                $this->tpl->setVariable("VALUE_DEFINITION", "");
                        }
                        $this->tpl->parseCurrentBlock();
                        $this->tpl->setCurrentBlock("answers");
                        $this->tpl->setVariable("TEXT_MATCHING_PAIR", $this->lng->txt("matching_pair"));
                        $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_matchingpair_count() + 1);
                        $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
                        $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
                        $add_random_id = $this->object->get_random_id();
                        $this->tpl->setVariable("TERM_ID", $add_random_id);
                        $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%d", 0));
                        $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
                        $this->tpl->parseCurrentBlock();
                }
                else if ($this->ctrl->getCmd() == "addPair")
                {
                        $this->error .= $this->lng->txt("fill_out_all_matching_pairs") . "<br />";
                }

                $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");
                $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
                if ($delete)
                {
                        if ($this->object->get_matchingpair_count() > 0)
                        {
                                $thispair = $this->object->get_matchingpair($this->object->get_matchingpair_count()-1);
                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.term_".($this->object->get_matchingpair_count()-1)."_" . $thispair->getTermId().".focus(); document.frm_matching.term_".($this->object->get_matchingpair_count()-1)."_" . $thispair->getTermId().".scrollIntoView(\"true\");"));
                        }
                        else
                        {
                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
                        }
                }
                else
                {
                        switch ($this->ctrl->getCmd())
                        {
                                case "addPair":
                                        $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.term_".($this->object->get_matchingpair_count())."_" . $add_random_id.".focus(); document.frm_matching.term_".($this->object->get_matchingpair_count())."_" . $add_random_id.".scrollIntoView(\"true\");"));
                                        break;
                                default:
                                        $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.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("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("MATCHING_ID", $this->object->getId());
                $this->tpl->setVariable("VALUE_MATCHING_TITLE", htmlspecialchars($this->object->getTitle()));
                $this->tpl->setVariable("VALUE_MATCHING_COMMENT", htmlspecialchars($this->object->getComment()));
                $this->tpl->setVariable("VALUE_MATCHING_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_matching_pair"));
                $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
                $this->tpl->setVariable("TEXT_TYPE_TERMS_PICTURES", $this->lng->txt("match_terms_and_pictures"));
                $this->tpl->setVariable("TEXT_TYPE_TERMS_DEFINITIONS", $this->lng->txt("match_terms_and_definitions"));
                if ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
                {
                        $this->tpl->setVariable("SELECTED_DEFINITIONS", " selected=\"selected\"");
                }
                elseif ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                {
                        $this->tpl->setVariable("SELECTED_PICTURES", " 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);
                        include_once "./assessment/classes/class.assQuestion.php";
                        $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_matching");
                $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_matching"));
                $this->tpl->setVariable("ACTION_MATCHING_QUESTION",     $this->ctrl->getFormAction($this));

                $this->tpl->parseCurrentBlock();
                if ($this->error)
                {
                        sendInfo($this->error);
                }
                $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_MatchingQuestionGUI::getCommand ( cmd  ) 

Reimplemented from ASS_QuestionGUI.

Definition at line 74 of file class.assMatchingQuestionGUI.php.

References $cmd.

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

                return $cmd;
        }

ASS_MatchingQuestionGUI::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 69 of file class.assMatchingQuestionGUI.php.

        {
                return "qt_matching";
        }

ASS_MatchingQuestionGUI::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 333 of file class.assMatchingQuestionGUI.php.

References ilUtil::makeTimeSelect().

Referenced by editQuestion().

        {
                $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_MatchingQuestionGUI::outWorkingForm ( test_id = "",
is_postponed = false,
showsolution = 0,
show_question_page = true,
show_solution_only = false,
ilUser = NULL,
pass = NULL,
mixpass = false,
user_post_solution = false 
)

Creates the question output form for the learner.

Creates the question output form for the learner

Parameters:
integer $test_id Database ID of a test which contains the question
boolean $is_postponed True if the question is a postponed question ("Postponed" added to the title)
boolean $showsolution Forces the output of the users solution if set to true
boolean $show_question_page Forces the output of the question only (without the surrounding page) when set to false. Default is true.
boolean $show_solution_only Forces the output of the correct question solution only when set to true. Default is false
object $ilUser The user object of the user who answered the question
integer $pass The pass of the question which should be displayed
boolean $mixpass Mixes test passes (takes the last pass of the question) when set to true. Default is false. public

Definition at line 529 of file class.assMatchingQuestionGUI.php.

References $id, $idx, $ilUser, $key, $output, $size, ilObjTest::_getHidePreviousResults(), ilObjTest::_getPass(), ASS_QuestionGUI::outQuestionPage(), ASS_QuestionGUI::removeFormElements(), and ASS_QuestionGUI::replaceSelectElements().

        {
                if (!is_object($ilUser)) 
                {
                        global $ilUser;
                }
                $output = $this->outQuestionPage(($show_solution_only)?"":"MATCHING_QUESTION", $is_postponed, $test_id);
                $output = preg_replace("/&#123;/", "{", $output);
                $output = preg_replace("/&#125;/", "}", $output);

                if ($showsolution && !$show_solution_only)
                {
                        $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
                        $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
                }
                if ($this->object->getOutputType() == OUTPUT_HTML)
                {
                        $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
                        $solutionoutput = preg_replace("/\"match/", "\"solution_match", $solutionoutput);
                        $solutionoutput = preg_replace("/name\=\"sel_matching/", "name=\"solution_sel_matching", $solutionoutput);
                }
                else
                {
                        $solutionoutput = "<table border=\"0\">\n";
                }
                
                if (!$show_question_page)
                        $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
                        
                // if wants solution only then strip the question element from output
                if ($show_solution_only) {
                        $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
                }
                        
                
                // set solutions
                $solution_script = "";
                if ($test_id)
                {
                        $solutions = NULL;
                        include_once "./assessment/classes/class.ilObjTest.php";
                        if ((!$showsolution) && ilObjTest::_getHidePreviousResults($test_id, true))
                        {
                                if ($show_question_page)
                                {
                                        if (is_null($pass)) $pass = ilObjTest::_getPass($ilUser->id, $test_id);
                                }
                        }
                        if ($mixpass) $pass = NULL;
                        if (is_array($user_post_solution)) 
                        { 
                                $solutions = array();
                                foreach ($user_post_solution as $key => $value)
                                {
                                        if (preg_match("/sel_matching_(\d+)/", $key, $matches))
                                        {
                                                array_push($solutions, array("value1" => $value, "value2" => $matches[1]));
                                        }
                                }
                        }
                        else
                        { 
                                $solutions =& $this->object->getSolutionValues($test_id, $ilUser, $pass);
                        }
                        $solution_script .= "";//"resetValues();\n";
                        foreach ($solutions as $idx => $solution_value)
                        {
                                if ($this->object->getOutputType() == OUTPUT_HTML || !$show_question_page)
                                {                                       
                                        $repl_str = "dummy=\"match".$solution_value["value2"]."_".$solution_value["value1"]."\"";
                                        
                                        if (!$show_question_page) {
                                                $output = $this->replaceSelectElements ("sel_matching_".$solution_value["value2"],$repl_str,$output,"[","]");
                                        }
                                        else 
                                                $output = str_replace($repl_str, $repl_str." selected=\"selected\"", $output);
                                                
                                }
                                else
                                {
                                        if (($solution_value["value2"] > 1) && ($solution_value["value1"] > 1))
                                        {
                                                $solution_script .= "addSolution(" . $solution_value["value1"] . "," . $solution_value["value2"] . ");\n";
                                        }
                                }
                        }
                        if (!$show_question_page) 
                        {
                                // remove all selects which don't have a solution
                                $output = $this->removeFormElements($output);                           
                        }
                        
                }
                if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
                {
                        $output = str_replace("// solution_script", "", $output);
                        $this->tpl->setVariable("JS_INITIALIZE", "<script type=\"text/javascript\">\nfunction show_solution() {\n$solution_script\n}\n</script>\n");
                        $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"setDragelementPositions();show_solution();\"");
                }

                if ($this->object->getOutputType() == OUTPUT_HTML)
                {
                        foreach ($this->object->matchingpairs as $idx => $answer)
                        {
                                $id = $answer->getDefinitionId()."_".$answer->getTermId();
                                $repl_str = "dummy=\"solution_match".$id."\"";
                                $solutionoutput = str_replace($repl_str, $repl_str." selected=\"selected\"", $solutionoutput);                          
                                $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_match$id" . "[^\d].*?)<\/tr>/", "\\1<td>" . "<em>(" . $answer->getPoints() . " " . $this->lng->txt("points") . ")</em>" . "</td></tr>", $solutionoutput);
                                                                                                
                                if ($show_solution_only) {
                                        //$regexp = "/<select name=\"solution_match_$idx\">.*?<option[^>]*dummy=\"solution_match$id\">(.*?)<\/option>.*?<\/select>/";
                                        //                                      preg_match ($regexp, $solutionoutput, $matches);
                                                                                //$sol_points [] = $matches[1]." (".$answer->getPoints()." ".$this->lng->txt("points").")";                                     
                                        $solutionoutput = $this->replaceSelectElements("solution_sel_matching_".$answer->getDefinitionId(),$repl_str, $solutionoutput,"[","]" );
                                }                                                               
                        }
                                                                //print_r($sol_points);
                                                                //$solutionoutput = preg_replace ("/<select[^>]*name=\"solution_gap_$idx\">.*?<\/select>/i","[".join($sol_points,", ")."]",$solutionoutput); 
                }
                else
                {
                        foreach ($this->object->matchingpairs as $idx => $answer)
                        {
                                if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                                {
                                        $imagepath = $this->object->getImagePathWeb() . $answer->getPicture();
                                        $solutionoutput .= "<tr><td><div class=\"textbox\">" . $answer->getTerm() . "</div></td><td width=\"10\"></td><td><div class=\"imagebox\"><img src=\"" . $imagepath . ".thumb.jpg\" alt=\"".$this->lng->txt("thumbnail")."\"/></div></td></tr>\n";
                                        $size = GetImageSize ($this->object->getImagePath() . $answer->getPicture() . ".thumb.jpg");
                                        $sizeorig = GetImageSize ($this->object->getImagePath() . $answer->getPicture());
                                        if ($size[0] >= $sizeorig[0])
                                        {
                                                // thumbnail is larger than original -> remove enlarge image
                                                $output = preg_replace("/<a[^>]*?id\=\"enlarge_" . $answer->getDefinitionId() . "[^>]*?>.*?<\/a>/", "", $output);
                                        }
                                        // add the image size to the thumbnails
                                        $output = preg_replace("/(id\=\"thumb_" . $answer->getDefinitionId() . "\")/", "\\1 " . $size[3], $output);
                                }
                                else
                                {
                                        $solutionoutput .= "<tr><td><div class=\"textbox\">" . $answer->getTerm() . "</div></td><td width=\"10\"></td><td><div class=\"textbox\"><strong>" . $answer->getDefinition() . "</strong></div></td></tr>\n";
                                }
                        }
                        $solutionoutput .= "</table>";
                }
                if (!$show_solution_only)
                {
                        $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
                }
                if ($test_id) 
                {
                        $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
                        $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
                        $count_comment = "";
                        if ($reached_points == 0)
                        {
                                $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
                                if (strlen($count_comment))
                                {
                                        if (strlen($mc_comment) == 0)
                                        {
                                                $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
                                        }
                                        else
                                        {
                                                $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
                                        }
                                }
                        }
                        $received_points .= $count_comment;
                        $received_points .= "</p>";
                }
                if (!$showsolution)
                {
                        $solutionoutput = "";
                        $received_points = "";
                }
                if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                {
                        $output = str_replace("textbox", "textboximage", $output);
                        $solutionoutput = str_replace("textbox", "textboximage", $solutionoutput);
                }
                $this->tpl->setVariable("MATCHING_QUESTION", $output.$solutionoutput.$received_points);
        }

Here is the call graph for this function:

ASS_MatchingQuestionGUI::upload (  ) 

upload matching picture or material

Definition at line 356 of file class.assMatchingQuestionGUI.php.

References editQuestion(), and writePostData().

        {
                $this->writePostData();
                $this->editQuestion();
        }

Here is the call graph for this function:

ASS_MatchingQuestionGUI::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 389 of file class.assMatchingQuestionGUI.php.

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

Referenced by addPair(), addSuggestedSolution(), delete(), and upload().

        {
                $saved = false;
                $result = 0;

                if (!$this->checkInput())
                {
                        $result = 1;
                }

                if (($result) and ($_POST["cmd"]["addPair"]))
                {
                        // You cannot add matching pairs before you enter the required data
                        $this->error .= $this->lng->txt("fill_out_all_required_fields_add_matching") . "<br />";
                }

                $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"]);
                // adding estimated working time
                $saved = $saved | $this->writeOtherPostData($result);
                $this->object->set_matching_type($_POST["matching_type"]);

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

                // Add all answers from the form into the object
                $postvalues = $_POST;
                foreach ($postvalues as $key => $value)
                {
                        $matching_text = "";
                        if (preg_match("/term_(\d+)_(\d+)/", $key, $matches))
                        {
                                // find out random id for term
                                foreach ($_POST as $key2 => $value2)
                                {
                                        if (preg_match("/(definition|picture)_$matches[1]_(\d+)/", $key2, $matches2))
                                        {
                                                $matchingtext_id = $matches2[2];
                                                if (strcmp($matches2[1], "definition") == 0)
                                                {
                                                        $matching_text = $_POST["definition_$matches[1]_$matches2[2]"];
                                                }
                                                else
                                                {
                                                        $matching_text = $_POST["picture_$matches[1]_$matches2[2]"];
                                                }
                                        }
                                }
                                
                                // save picture file if matching terms and pictures
                                if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
                                {
                                        foreach ($_FILES as $key2 => $value2)
                                        {
                                                if (preg_match("/picture_$matches[1]_(\d+)/", $key2, $matches2))
                                                {
                                                        if ($value2["tmp_name"])
                                                        {
                                                                // upload the matching picture
                                                                if ($this->object->getId() <= 0)
                                                                {
                                                                        $this->object->saveToDb();
                                                                        $saved = true;
                                                                        $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
                                                                }
                                                                $upload_result = $this->object->set_image_file($value2['name'], $value2['tmp_name']);
                                                                switch ($upload_result)
                                                                {
                                                                        case 0:
                                                                                $_POST["picture_$matches[1]_".$matches2[1]] = $value2['name'];
                                                                                $matching_text = $value2['name'];
                                                                                break;
                                                                        case 1:
                                                                                $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
                                                                                break;
                                                                        case 2:
                                                                                $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
                                                                                break;
                                                                }
                                                        }
                                                }
                                        }
                                }
                                $points = $_POST["points_$matches[1]"];
                                if (preg_match("/\d+/", $points))
                                {
                                        if ($points < 0)
                                        {
                                                $points = 0.0;
                                                $this->error .= $this->lng->txt("negative_points_not_allowed") . "<br />";
                                        }
                                }
                                else
                                {
                                        $points = 0.0;
                                }
                                $this->object->add_matchingpair(
                                        ilUtil::stripSlashes($_POST["$key"]),
                                        ilUtil::stripSlashes($matching_text),
                                        ilUtil::stripSlashes($points),
                                        ilUtil::stripSlashes($matches[2]),
                                        ilUtil::stripSlashes($matchingtext_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: