Public Member Functions

ASS_OrderingQuestionGUI Class Reference

Ordering question GUI representation. More...

Inheritance diagram for ASS_OrderingQuestionGUI:
Collaboration diagram for ASS_OrderingQuestionGUI:

Public Member Functions

 ASS_OrderingQuestionGUI ($id=-1)
 ASS_OrderingQuestionGUI constructor.
 getQuestionType ()
 Returns the question type string.
 getCommand ($cmd)
 editQuestion ($ok=true)
 Creates an output of the edit form for the question.
 addItem ()
 delete ()
 delete matching pair
 upload ()
 upload matching picture
 outOtherQuestionData ()
 Sets the extra fields i.e.
 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

Ordering question GUI representation.

The ASS_OrderingQuestionGUI class encapsulates the GUI representation for ordering questions.

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

class.assOrderingQuestionGUI.php Assessment

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


Member Function Documentation

ASS_OrderingQuestionGUI::addItem (  ) 

Definition at line 290 of file class.assOrderingQuestionGUI.php.

References $_POST, $key, $ok, checkInput(), editQuestion(), and writePostData().

        {
                $ok = true;
                if (!$this->checkInput())
                {
                        // You cannot add answers before you enter the required data
                        $this->error .= $this->lng->txt("fill_out_all_required_fields_add_answer") . "<br />";
                        $ok = false;
                }
                else
                {
                        foreach ($_POST as $key => $value)
                        {
                                if (preg_match("/answer_(\d+)/", $key, $matches))
                                {
                                        if (!$value)
                                        {
                                                $ok = false;
                                        }
                                }
                        }
                }
                if (!$ok)
                {
                        $this->error .= $this->lng->txt("fill_out_all_answer_fields") . "<br />";
                }

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

Here is the call graph for this function:

ASS_OrderingQuestionGUI::addSuggestedSolution (  ) 

Reimplemented from ASS_QuestionGUI.

Definition at line 686 of file class.assOrderingQuestionGUI.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_ordering");
                parent::addSuggestedSolution();
        }

Here is the call graph for this function:

ASS_OrderingQuestionGUI::ASS_OrderingQuestionGUI ( id = -1  ) 

ASS_OrderingQuestionGUI constructor.

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

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

Definition at line 49 of file class.assOrderingQuestionGUI.php.

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

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

Here is the call graph for this function:

ASS_OrderingQuestionGUI::checkInput (  ) 

check input fields

Definition at line 677 of file class.assOrderingQuestionGUI.php.

References $_POST.

Referenced by addItem(), and addSuggestedSolution().

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

Here is the caller graph for this function:

ASS_OrderingQuestionGUI::delete (  ) 

delete matching pair

Definition at line 324 of file class.assOrderingQuestionGUI.php.

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

        {
                $this->writePostData();

                // Delete an answer if the delete button was pressed
                foreach ($_POST[cmd] as $key => $value)
                {
                        if (preg_match("/delete_(\d+)/", $key, $matches))
                        {
                                $this->object->delete_answer($matches[1]);
                        }
                }
                //$this->ctrl->redirect($this, "editQuestion"); works only on save
                $this->editQuestion();
        }

Here is the call graph for this function:

ASS_OrderingQuestionGUI::editQuestion ( ok = true  ) 

Creates an output of the edit form for the question.

Creates an output of the edit form for the question

public

Definition at line 97 of file class.assOrderingQuestionGUI.php.

References $key, $ok, ASS_Question::_getInternalLinkHref(), ASS_QuestionGUI::getQuestionTemplate(), outOtherQuestionData(), and sendInfo().

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

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

                // Output of existing 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();

                        $thisanswer = $this->object->get_answer($i);
                        if ($this->object->get_ordering_type() == OQ_PICTURES)
                        {
                                $this->tpl->setCurrentBlock("order_pictures");
                                $this->tpl->setVariable("ANSWER_ORDER", $i);
                                $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->get_order() + 1);
                                $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));

                                $filename = $thisanswer->get_answertext();
                                $extension = "jpg";
                                if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $filename, $matches))
                                {
                                        $extension = $matches[1];
                                }
                                if ($filename)
                                {
                                        $imagepath = $this->object->getImagePathWeb() . $thisanswer->get_answertext();
                                        $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $thisanswer->get_answertext() . "\" border=\"\" />");
                                        $this->tpl->setVariable("IMAGE_FILENAME", htmlspecialchars($thisanswer->get_answertext()));
                                        $this->tpl->setVariable("VALUE_ANSWER", "");
                                        //$thisanswer->get_answertext()
                                }
                                $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
                        }
                        elseif ($this->object->get_ordering_type() == OQ_TERMS)
                        {
                                $this->tpl->setCurrentBlock("order_terms");
                                $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->get_order() + 1);
                                $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
                                $this->tpl->setVariable("ANSWER_ORDER", $i);
                                $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($thisanswer->get_answertext()));
                        }
                        $this->tpl->parseCurrentBlock();

                        $this->tpl->setCurrentBlock("answers");
                        $anchor = "#answer_" . ($thisanswer->get_order() + 1);
                        $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
                        $this->tpl->setVariable("ANSWER_ORDER", $thisanswer->get_order());
                        $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
                        $this->tpl->setVariable("VALUE_ORDER", $thisanswer->get_solution_order());
                        $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
                        $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%d", $thisanswer->get_points()));
                        $this->tpl->parseCurrentBlock();
                }

                if (($this->ctrl->getCmd() == "addItem") and ($ok))
                {
                        if ($this->object->get_ordering_type() == OQ_PICTURES)
                        {
                                $this->tpl->setCurrentBlock("order_pictures");
                                $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
                                $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_answer_count() + 1);
                                $this->tpl->setVariable("VALUE_ANSWER", "");
                                $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
                                $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
                        }
                        elseif ($this->object->get_ordering_type() == OQ_TERMS)
                        {
                                $this->tpl->setCurrentBlock("order_terms");
                                $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
                                $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_answer_count() + 1);
                                $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
                                $this->tpl->setVariable("VALUE_ASNWER", "");
                        }
                        $this->tpl->parseCurrentBlock();

                        // Create an empty answer
                        $this->tpl->setCurrentBlock("answers");
                        //$this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
                        $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
                        $anchor = "#answer_" . ($this->object->get_answer_count() + 1);
                        $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
                        $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
                        $this->tpl->setVariable("VALUE_ORDER", $this->object->get_max_solution_order() + 1);
                        $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
                        $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%d", 0));
                        $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");
                $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
                switch ($this->ctrl->getCmd())
                {
                        case "addItem":
                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.answer_".($this->object->get_answer_count()).".focus(); document.frm_ordering.answer_".($this->object->get_answer_count()).".scrollIntoView(\"true\");"));
                                break;
                        default:
                                $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.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("ORDERING_ID", $this->object->getId());
                $this->tpl->setVariable("VALUE_ORDERING_TITLE", htmlspecialchars($this->object->getTitle()));
                $this->tpl->setVariable("VALUE_ORDERING_COMMENT", htmlspecialchars($this->object->getComment()));
                $this->tpl->setVariable("VALUE_ORDERING_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_TYPE", $this->lng->txt("type"));
                $this->tpl->setVariable("TEXT_TYPE_PICTURES", $this->lng->txt("order_pictures"));
                $this->tpl->setVariable("TEXT_TYPE_TERMS", $this->lng->txt("order_terms"));
                if ($this->object->get_ordering_type() == OQ_TERMS)
                {
                        $this->tpl->setVariable("SELECTED_TERMS", " selected=\"selected\"");
                }
                elseif ($this->object->get_ordering_type() == OQ_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->ctrl->setParameter($this, "sel_question_types", "qt_ordering");
                $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_ordering"));
                $this->tpl->setVariable("ACTION_ORDERING_QUESTION",     $this->ctrl->getFormAction($this));
                $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
                $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_OrderingQuestionGUI::getCommand ( cmd  ) 

Reimplemented from ASS_QuestionGUI.

Definition at line 75 of file class.assOrderingQuestionGUI.php.

References $cmd.

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

                return $cmd;
        }

ASS_OrderingQuestionGUI::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 70 of file class.assOrderingQuestionGUI.php.

        {
                return "qt_ordering";
        }

ASS_OrderingQuestionGUI::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 356 of file class.assOrderingQuestionGUI.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_OrderingQuestionGUI::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 477 of file class.assOrderingQuestionGUI.php.

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

        {
                if (!is_object($ilUser)) 
                {
                        global $ilUser;
                }
                
                $output = $this->outQuestionPage(($show_solution_only)?"":"ORDERING_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);
                }
                $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
                $solutionoutput = preg_replace("/\"ord/", "\"solution_ord", $solutionoutput);
                $solutionoutput = preg_replace("/name\=\"order_/", "name=\"solution_order_", $solutionoutput);
                
                
                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("/order_(\d+)/", $key, $matches))
                                        {
                                                array_push($solutions, array("value1" => $matches[1], "value2" => $value));
                                        }
                                }
                        }
                        else
                        {
                                $solutions =& $this->object->getSolutionValues($test_id, $ilUser, $pass);
                        }
                        $solution_script .= "";//"resetValues();\n";
                        $jssolutions = array();
                        foreach ($solutions as $idx => $solution_value)
                        {
                                if ($this->object->getOutputType() == OUTPUT_HTML || !$show_question_page)
                                {
                                        $repl_str = "dummy=\"ord".$solution_value["value1"]."\"";
        //echo "<br>".$repl_str;
                                        if (!$show_question_page)
                                                $output = $this->replaceInputElements($repl_str, $solution_value["value2"], $output, "[","]"); 
                                        else 
                                                $output = str_replace($repl_str, $repl_str." value=\"".$solution_value["value2"]."\"", $output);
                                }
                                else
                                {
                                        if ((strcmp($solution_value["value2"], "") != 0) && (strcmp($solution_value["value1"], "") != 0))
                                        {
                                                $jssolutions[$solution_value["value2"]] = $solution_value["value1"];
                                        }
                                }
                        }
                        if (!$show_question_page) 
                        {
                                //echo htmlentities ($output);
                                $output = $this->removeFormElements($output);
                        }
                        if (count($jssolutions))
                        {
                                ksort($jssolutions);
                                $js = "";
                                foreach ($jssolutions as $key => $value)
                                {
                                        $js .= "initialorder.push($value);";
                                }
                                $js .= "restoreInitialOrder();";
                                $output = str_replace("/*solution*/", $js, $output);
                        }
                }

                if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
                {
                        if ($this->object->get_ordering_type() == OQ_PICTURES)
                        {
                                foreach ($this->object->answers as $key => $answer)
                                {
                                        $extension = "jpg";
                                        if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $answer->get_answertext(), $matches))
                                        {
                                                $extension = $matches[1];
                                        }
                                        $sizethumb = GetImageSize ($this->object->getImagePath() . $answer->get_answertext() . ".thumb.jpg");
                                        $sizeorig = GetImageSize ($this->object->getImagePath() . $answer->get_answertext());
                                        if ($sizethumb[0] >= $sizeorig[0])
                                        {
                                                // thumbnail is larger than original -> remove enlarge image
                                                $output = preg_replace("/<a[^>]*?>\s*<img[^>]*?enlarge[^>]*?>\s*<\/a>/", "", $output);
                                        }
                                        // add the image size to the thumbnails
                                        $output = preg_replace("/(<img[^>]*?".$answer->get_answertext()."[^>]*?)(\/{0,1}\s*)?>/", "\\1 " . $sizethumb[3] . "\\2", $output);
                                }
                        }
                        // $output = str_replace("// solution_script", "", $output);

                        // BEGIN: add javascript code for javascript enabled ordering questions
                        $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_execute_ordering_javascript.html", true);
                        $this->tpl->setCurrentBlock("head_content");
                        $this->tpl->setVariable("JS_LOCATION", "./assessment/js/toolman/");
                        $this->tpl->parseCurrentBlock();
                        // END: add javascript code for javascript enabled ordering questions
                        
                        // BEGIN: add additional stylesheet for javascript enabled ordering questions
                        $this->tpl->setCurrentBlock("AdditionalStyle");
                        $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", "./assessment/templates/default/test_javascript.css");
                        $this->tpl->parseCurrentBlock();
                        // END: add additional stylesheet for javascript enabled ordering questions
                        
                        // BEGIN: onsubmit form action for javascript enabled ordering questions
                        $this->tpl->setVariable("ON_SUBMIT", "return saveOrder('orderlist');");
                        // END: onsubmit form action for javascript enabled ordering questions
                        
                        //$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=\"show_solution();\"");
                }
                
                foreach ($this->object->answers as $idx => $answer)
                {
                        $repl_str = "dummy=\"solution_ord$idx\"";
                        $solutionoutput = str_replace($repl_str, $repl_str." value=\"" . $answer->get_solution_order() . "\"", $solutionoutput);
                        $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_ord$idx" . "[^\d].*?)<\/tr>/", "\\1<td>" . "<em>(" . $answer->get_points() . " " . $this->lng->txt("points") . ")</em>" . "</td></tr>", $solutionoutput);
                        if ($show_solution_only)
                                $solutionoutput = $this->replaceInputElements($repl_str, $answer->get_solution_order(), $solutionoutput , "[" , "]");
                }

                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 = "";
                }
                $this->tpl->setVariable("ORDERING_QUESTION", $output.$solutionoutput.$received_points);
        }

Here is the call graph for this function:

ASS_OrderingQuestionGUI::upload (  ) 

upload matching picture

Definition at line 343 of file class.assOrderingQuestionGUI.php.

References editQuestion(), and writePostData().

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

Here is the call graph for this function:

ASS_OrderingQuestionGUI::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 374 of file class.assOrderingQuestionGUI.php.

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

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

        {
                $result = 0;
                $saved = false;

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

                $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_ordering_type($_POST["ordering_type"]);

                // Add answers from the form
                foreach ($_POST as $key => $value)
                {
                        if (preg_match("/answer_(\d+)/", $key, $matches))
                        {
                                if ($this->object->get_ordering_type() == OQ_PICTURES)
                                {
                                        if ($_FILES[$key]["tmp_name"])
                                        {
                                                // upload the ordering picture
                                                if ($this->object->getId() <= 0)
                                                {
                                                        $this->object->saveToDb();
                                                        $saved = true;
                                                        $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
                                                }
                                                $image_file = $_FILES[$key]["name"];
                                                $image_file = str_replace(" ", "_", $image_file);
                                                $upload_result = $this->object->set_image_file($image_file, $_FILES[$key]['tmp_name']);
                                                switch ($upload_result)
                                                {
                                                        case 0:
                                                                $_POST[$key] = $image_file;
                                                                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_answer(
                                        ilUtil::stripSlashes($_POST["$key"]),
                                        ilUtil::stripSlashes($points),
                                        ilUtil::stripSlashes($matches[1]),
                                        ilUtil::stripSlashes($_POST["order_$matches[1]"])
                                );
                        }
                }

                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: