Public Member Functions | Data Fields

ASS_ClozeTest Class Reference

Class for cloze tests. More...

Inheritance diagram for ASS_ClozeTest:
Collaboration diagram for ASS_ClozeTest:

Public Member Functions

 ASS_ClozeTest ($title="", $comment="", $author="", $owner=-1, $cloze_text="")
 ASS_ClozeTest constructor.
 isComplete ()
 Returns true, if a cloze test is complete for use.
createCloseTextArray ()
 Creates an associative array from the close text.
 createCloseTextFromArray ($assoc_array)
 Re-creates the close text from an an associative array.
 saveToDb ($original_id="")
 Saves a ASS_ClozeTest object to a database.
 loadFromDb ($question_id)
 Loads a ASS_ClozeTest object from a database.
 duplicate ($for_test=true, $title="", $author="", $owner="")
 Duplicates an ASS_ClozeTest.
 from_xml ($xml_text)
 Imports a question from XML.
 to_xml ($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false)
 Returns a QTI xml representation of the question.
 set_cloze_text ($cloze_text="")
 Evaluates the text gap solutions from the cloze text.
 get_cloze_text ()
 Returns the cloze text.
 get_start_tag ()
 Returns the start tag of a cloze gap.
 get_end_tag ()
 Returns the end tag of a cloze gap.
 set_start_tag ($start_tag="<gap>")
 Sets the start tag of a cloze gap.
 set_end_tag ($end_tag="</gap>")
 Sets the end tag of a cloze gap.
 rebuild_cloze_text ()
 Replaces the gap values with the values of the gaps array.
 get_gap ($index=0)
 Returns an array of gap answers.
 get_gap_count ()
 Returns the number of gaps.
 get_gap_text_list ($index=0, $separator=",")
 Returns a separated string of all answers for a given text gap.
 get_gap_text_count ($index=0)
 Returns a count of all answers of a gap.
 delete_gap ($index=0)
 Deletes a gap.
 flush_gaps ()
 Deletes all gaps without changing the cloze text.
 delete_answertext_by_index ($gap_index=0, $answertext_index=0)
 Deletes an answer text of a gap.
 set_answertext ($index=0, $answertext_index=0, $answertext="", $add_gaptext=0)
 Sets an answer text of a gap.
 update_all_gap_params ()
 Updates the cloze text setting the cloze type for every gap.
 set_cloze_type ($index, $cloze_type=CLOZE_TEXT)
 Sets the cloze type of the gap.
 set_gap_points ($index=0, $points=0.0)
 Sets the points of a gap.
 set_gap_shuffle ($index=0, $shuffle=1)
 Sets the shuffle state of a gap.
 set_single_answer_points ($index_gaps=0, $index_answerobject=0, $points=0.0)
 Sets the points of a gap answer.
 set_single_answer_state ($index_gaps=0, $index_answerobject=0, $state=0)
 Sets the state of a gap answer.
 getReachedPoints ($user_id, $test_id)
 Returns the points, a learner has reached answering the question.
 getReachedInformation ($user_id, $test_id)
 Returns the evaluation data, a learner has entered to answer the question.
 getMaximumPoints ()
 Returns the maximum points, a learner can reach answering the question.
 saveWorkingData ($test_id, $limit_to=LIMIT_NO_LIMIT)
 Saves the learners input of the question to the database.
 syncWithOriginal ()
 getQuestionType ()
 Returns the question type of the question.

Data Fields

 $cloze_text
 $gaps
 $start_tag
 $end_tag

Detailed Description

Class for cloze tests.

ASS_ClozeText is a class for cloze tests using text or select gaps.

Author:
Helmut Schottmüller <hschottm@tzi.de>
Version:
Id:
class.assClozeTest.php 8266 2005-08-04 07:10:58Z hschottm

class.assClozeTest.php Assessment

Definition at line 42 of file class.assClozeTest.php.


Member Function Documentation

ASS_ClozeTest::ASS_ClozeTest ( title = "",
comment = "",
author = "",
owner = -1,
cloze_text = "" 
)

ASS_ClozeTest constructor.

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

Parameters:
string $title A title string to describe the question
string $comment A comment string to describe the question
string $author A string containing the name of the questions author
integer $owner A numerical ID to identify the owner/creator
string $cloze_text The question string of the cloze test public

Definition at line 92 of file class.assClozeTest.php.

References ASS_Question::$author, $cloze_text, ASS_Question::$comment, ASS_Question::$owner, ASS_Question::$title, ASS_Question::ASS_Question(), and set_cloze_text().

        {
                $this->start_tag = "<gap>";
                $this->end_tag = "</gap>";
                $this->ASS_Question($title, $comment, $author, $owner);
                $this->gaps = array();
                $this->set_cloze_text($cloze_text);
        }

Here is the call graph for this function:

& ASS_ClozeTest::createCloseTextArray (  ) 

Creates an associative array from the close text.

Creates an associative array from the close text

Returns:
array Associative array containing all separated close text parts public

Definition at line 135 of file class.assClozeTest.php.

References $gaps, $params, and $result.

Referenced by delete_answertext_by_index(), delete_gap(), rebuild_cloze_text(), set_cloze_text(), set_cloze_type(), and update_all_gap_params().

        {
                $result = array();
                $search_pattern = "|<gap([^>]*?)>(.*?)</gap>|i";
                preg_match_all($search_pattern, $this->cloze_text, $gaps);
                if (count($gaps[0]))
                {
                        // found at least one gap
                        $delimiters = preg_split($search_pattern, $this->cloze_text, -1, PREG_SPLIT_OFFSET_CAPTURE);
                        $result["gaps"] = array();
                        foreach ($gaps[0] as $index => $gap)
                        {
                                $result["gaps"][$index] = array();
                                $result["gaps"][$index]["gap"] = $gap;
                                $result["gaps"][$index]["params"] = array();
                                $result["gaps"][$index]["params"]["text"] = $gaps[1][$index];
                                // separate gap params
                                if (preg_match("/name\=\"([^\"]*?)\"/", $gaps[1][$index], $params))
                                {
                                        $result["gaps"][$index]["params"]["name"] = $params[1];
                                }
                                else
                                {
                                        $result["gaps"][$index]["params"]["name"] = $this->lng->txt("gap") . " " . ($index+1);
                                }
                                if (preg_match("/type\=\"([^\"]*?)\"/", $gaps[1][$index], $params))
                                {
                                        $result["gaps"][$index]["params"]["type"] = $params[1];
                                }
                                else
                                {
                                        $result["gaps"][$index]["params"]["type"] = "text";
                                }
                                if (preg_match("/shuffle\=\"([^\"]*?)\"/", $gaps[1][$index], $params))
                                {
                                        $result["gaps"][$index]["params"]["shuffle"] = $params[1];
                                }
                                else
                                {
                                        if (strcmp(strtolower($result["gaps"][$index]["params"]["type"]), "select") == 0)
                                        {
                                                $result["gaps"][$index]["params"]["shuffle"] = "yes";
                                        }
                                }
                                $result["gaps"][$index]["text"] = array();
                                $result["gaps"][$index]["text"]["text"] = $gaps[2][$index];
                                $textparams = preg_split("/(?<!\\\\),/", $gaps[2][$index]);
                                foreach ($textparams as $key => $value)
                                {
                                        $result["gaps"][$index]["text"][$key] = $value;
                                }
                        }
                        $result["delimiters"] = $delimiters;
                }
                //echo str_replace("\n", "<br />", str_replace(" ", "&nbsp;", ilUtil::prepareFormOutput(print_r($result, true))));
                return $result;         
        }

Here is the caller graph for this function:

ASS_ClozeTest::createCloseTextFromArray ( assoc_array  ) 

Re-creates the close text from an an associative array.

Re-creates the close text from an an associative array

Parameters:
array $assoc_array Associative array containing all separated close text parts public

Definition at line 201 of file class.assClozeTest.php.

References ASS_Question::$shuffle.

Referenced by delete_answertext_by_index(), delete_gap(), rebuild_cloze_text(), set_cloze_type(), and update_all_gap_params().

        {
                $this->cloze_text = "";
                if (count($assoc_array))
                {
                        $gap = 0;
                        foreach ($assoc_array["delimiters"] as $key => $value)
                        {
                                if (($key > 0) && ($key < count($assoc_array["delimiters"])))
                                {
                                        if (strcmp($assoc_array["gaps"][$gap]["params"]["shuffle"], "") == 0)
                                        {
                                                $shuffle = "";
                                        }
                                        else
                                        {
                                                $shuffle = " shuffle=\"" . $assoc_array["gaps"][$gap]["params"]["shuffle"] . "\"";
                                        }
                                        $textarray = array();
                                        foreach ($assoc_array["gaps"][$gap]["text"] as $textindex => $textvalue)
                                        {
                                                if (preg_match("/\d+/", $textindex))
                                                {
                                                        array_push($textarray, $textvalue);
                                                }
                                        }
                                        $this->cloze_text .= sprintf("<gap name=\"%s\" type=\"%s\"%s>%s</gap>",
                                                $assoc_array["gaps"][$gap]["params"]["name"],
                                                $assoc_array["gaps"][$gap]["params"]["type"],
                                                $shuffle,
                                                join(",", $textarray)
                                        );
                                        $gap++;
                                }
                                $this->cloze_text .= $value[0];
                        }
                }
        }

Here is the caller graph for this function:

ASS_ClozeTest::delete_answertext_by_index ( gap_index = 0,
answertext_index = 0 
)

Deletes an answer text of a gap.

Deletes an answer text of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap
string $answertext The answer text that should be deleted public
See also:
$gaps

Definition at line 1328 of file class.assClozeTest.php.

References createCloseTextArray(), createCloseTextFromArray(), delete_gap(), and get_gap_text_list().

                                                                             {
    if ($gap_index < 0) return;
    if (count($this->gaps) < 1) return;
    if ($gap_index >= count($this->gaps)) return;
    $old_text = $this->get_gap_text_list($gap_index);
                if (count($this->gaps[$gap_index]) == 1) {
                        $this->delete_gap($gap_index);
                } else {
                        $close = $this->createCloseTextArray();
                        unset($this->gaps[$gap_index][$answertext_index]);
      $this->gaps[$gap_index] = array_values($this->gaps[$gap_index]);
                        unset($close["gaps"][$gap_index]["text"][$answertext_index]);
                        $this->createCloseTextFromArray($close);
                }
  }

Here is the call graph for this function:

ASS_ClozeTest::delete_gap ( index = 0  ) 

Deletes a gap.

Deletes a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap public
See also:
$gaps

Definition at line 1294 of file class.assClozeTest.php.

References createCloseTextArray(), and createCloseTextFromArray().

Referenced by delete_answertext_by_index().

                                  {
    if ($index < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index >= count($this->gaps)) return;
                $close = $this->createCloseTextArray();
                unset($close["gaps"][$index]);
                $this->createCloseTextFromArray($close);
    unset($this->gaps[$index]);
    $this->gaps = array_values($this->gaps);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

ASS_ClozeTest::duplicate ( for_test = true,
title = "",
author = "",
owner = "" 
)

Duplicates an ASS_ClozeTest.

Duplicates an ASS_ClozeTest

public

Definition at line 429 of file class.assClozeTest.php.

References ASS_Question::$author, ASS_Question::$owner, ASS_Question::$title, and ASS_Question::_getOriginalId().

        {
                if ($this->id <= 0)
                {
                        // The question has not been saved. It cannot be duplicated
                        return;
                }
                // duplicate the question in database
                $clone = $this;
                include_once ("./assessment/classes/class.assQuestion.php");
                $original_id = ASS_Question::_getOriginalId($this->id);
                $clone->id = -1;
                if ($title)
                {
                        $clone->setTitle($title);
                }
                if ($author)
                {
                        $clone->setAuthor($author);
                }
                if ($owner)
                {
                        $clone->setOwner($owner);
                }
                if ($for_test)
                {
                        $clone->saveToDb($original_id);
                }
                else
                {
                        $clone->saveToDb();
                }

                // copy question page content
                $clone->copyPageOfQuestion($original_id);

                return $clone->id;
        }

Here is the call graph for this function:

ASS_ClozeTest::flush_gaps (  ) 

Deletes all gaps without changing the cloze text.

Deletes all gaps without changing the cloze text

public

See also:
$gaps

Definition at line 1313 of file class.assClozeTest.php.

                        {
    $this->gaps = array();
  }

ASS_ClozeTest::from_xml ( xml_text  ) 

Imports a question from XML.

Sets the attributes of the question from the XML text passed as argument

Returns:
boolean True, if the import succeeds, false otherwise public

Definition at line 477 of file class.assClozeTest.php.

References ASS_Question::$comment, $result, ASS_Question::$shuffle, $type, ilQTIUtils::_getRespcondition(), domxml_open_mem(), get_gap_text_list(), ASS_Question::getId(), saveToDb(), ASS_Question::setAuthor(), ASS_Question::setComment(), ASS_Question::setEstimatedWorkingTime(), ASS_Question::setSuggestedSolution(), and ASS_Question::setTitle().

        {
                $result = false;
                if (!empty($this->domxml))
                {
                        $this->domxml->free();
                }
                $xml_text = preg_replace("/>\s*?</", "><", $xml_text);
                $this->domxml = domxml_open_mem($xml_text);
                if (!empty($this->domxml))
                {
                        $root = $this->domxml->document_element();
                        $item = $root->first_child();
                        $this->setTitle($item->get_attribute("title"));
                        $this->gaps = array();
                        $itemnodes = $item->child_nodes();
                        $materials = array();
                        $gapcounter = 0;
                        foreach ($itemnodes as $index => $node)
                        {
                                switch ($node->node_name())
                                {
                                        case "qticomment":
                                                $comment = $node->get_content();
                                                if (strpos($comment, "ILIAS Version=") !== false)
                                                {
                                                }
                                                elseif (strpos($comment, "Questiontype=") !== false)
                                                {
                                                }
                                                elseif (strpos($comment, "Author=") !== false)
                                                {
                                                        $comment = str_replace("Author=", "", $comment);
                                                        $this->setAuthor($comment);
                                                }
                                                else
                                                {
                                                        $this->setComment($comment);
                                                }
                                                break;
                                        case "itemmetadata":
                                                $md_array = array();
                                                $metanodes = $node->child_nodes();
                                                foreach ($metanodes as $metanode)
                                                {
                                                        switch ($metanode->node_name())
                                                        {
                                                                case "qtimetadata":
                                                                        $metafields = $metanode->child_nodes();
                                                                        foreach ($metafields as $metafield)
                                                                        {
                                                                                switch ($metafield->node_name())
                                                                                {
                                                                                        case "qtimetadatafield":
                                                                                                $metafieldlist = $metafield->child_nodes();
                                                                                                $md = array("label" => "", "entry" => "");
                                                                                                foreach ($metafieldlist as $attr)
                                                                                                {
                                                                                                        switch ($attr->node_name())
                                                                                                        {
                                                                                                                case "fieldlabel":
                                                                                                                        $md["label"] = $attr->get_content();
                                                                                                                        break;
                                                                                                                case "fieldentry":
                                                                                                                        $md["entry"] = $attr->get_content();
                                                                                                                        break;
                                                                                                        }
                                                                                                }
                                                                                                array_push($md_array, $md);
                                                                                                break;
                                                                                }
                                                                        }
                                                                        break;
                                                        }
                                                }
                                                foreach ($md_array as $md)
                                                {
                                                        switch ($md["label"])
                                                        {
                                                                case "ILIAS_VERSION":
                                                                        break;
                                                                case "QUESTIONTYPE":
                                                                        break;
                                                                case "AUTHOR":
                                                                        $this->setAuthor($md["entry"]);
                                                                        break;
                                                        }
                                                }
                                                break;
                                        case "duration":
                                                $iso8601period = $node->get_content();
                                                if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $iso8601period, $matches))
                                                {
                                                        $this->setEstimatedWorkingTime($matches[4], $matches[5], $matches[6]);
                                                }
                                                break;
                                        case "presentation":
                                                $flow = $node->first_child();
                                                $flownodes = $flow->child_nodes();
                                                foreach ($flownodes as $idx => $flownode)
                                                {
                                                        if (strcmp($flownode->node_name(), "material") == 0)
                                                        {
                                                                $mattext = $flownode->first_child();
                                                                array_push($materials, $mattext->get_content());
                                                        }
                                                        elseif (strcmp($flownode->node_name(), "response_str") == 0)
                                                        {
                                                                $ident = $flownode->get_attribute("ident");
                                                                $this->gaps["$ident"] = array();
                                                                $shuffle = "";
                                                                $subnodes = $flownode->child_nodes();
                                                                foreach ($subnodes as $node_type)
                                                                {
                                                                        switch ($node_type->node_name())
                                                                        {
                                                                                case "render_choice":
                                                                                        $render_type = $node_type;
                                                                                        if (strcmp($render_type->node_name(), "render_choice") == 0)
                                                                                        {
                                                                                                // select gap
                                                                                                $shuffle = $render_type->get_attribute("shuffle");
                                                                                                $labels = $render_type->child_nodes();
                                                                                                foreach ($labels as $lidx => $response_label)
                                                                                                {
                                                                                                        $material = $response_label->first_child();
                                                                                                        $mattext = $material->first_child();
                                                                                                        $shuf = 0;
                                                                                                        if (strcmp(strtolower($shuffle), "yes") == 0)
                                                                                                        {
                                                                                                                $shuf = 1;
                                                                                                        }
                                                                                                        array_push($this->gaps["$ident"], new ASS_AnswerCloze($mattext->get_content(), 0, count($this->gaps["$ident"]), 0, CLOZE_SELECT, $ident, $shuf));
                                                                                                }
                                                                                        }
                                                                                        break;
                                                                                case "render_fib":
                                                                                        break;
                                                                                case "material":
                                                                                        $matlabel = $node_type->get_attribute("label");
                                                                                        if (strcmp($matlabel, "suggested_solution") == 0)
                                                                                        {
                                                                                                $mattype = $node_type->first_child();
                                                                                                if (strcmp($mattype->node_name(), "mattext") == 0)
                                                                                                {
                                                                                                        $suggested_solution = $mattype->get_content();
                                                                                                        if ($suggested_solution)
                                                                                                        {
                                                                                                                if ($this->getId() < 1)
                                                                                                                {
                                                                                                                        $this->saveToDb();
                                                                                                                }
                                                                                                                if (preg_match("/gap_(\d+)/", $ident, $matches))
                                                                                                                {
                                                                                                                        $this->setSuggestedSolution($suggested_solution, $matches[1], true);
                                                                                                                }
                                                                                                        }
                                                                                                }
                                                                                        }
                                                                                        break;
                                                                        }
                                                                }
                                                        }
                                                }
                                                break;
                                        case "resprocessing":
                                                $resproc_nodes = $node->child_nodes();
                                                foreach ($resproc_nodes as $index => $respcondition)
                                                {
                                                        if (strcmp($respcondition->node_name(), "respcondition") == 0)
                                                        {
                                                                $respcondition_array =& ilQTIUtils::_getRespcondition($respcondition);
                                                                $found_answer = 0;
                                                                foreach ($this->gaps[$respcondition_array["conditionvar"]["respident"]] as $key => $value)
                                                                {
                                                                        if (strcmp($value->get_answertext(), $respcondition_array["conditionvar"]["value"]) == 0)
                                                                        {
                                                                                $found_answer = 1;
                                                                                $this->gaps[$respcondition_array["conditionvar"]["respident"]][$key]->set_points($respcondition_array["setvar"]["points"]);
                                                                                if ($respcondition_array["conditionvar"]["selected"])
                                                                                {
                                                                                        $this->gaps[$respcondition_array["conditionvar"]["respident"]][$key]->setChecked();
                                                                                }
                                                                        }
                                                                }
                                                                if (!$found_answer)
                                                                {
                                                                        // text gap
                                                                        array_push($this->gaps[$respcondition_array["conditionvar"]["respident"]], new ASS_AnswerCloze($respcondition_array["conditionvar"]["value"], $respcondition_array["setvar"]["points"], count($this->gaps[$respcondition_array["conditionvar"]["respident"]]), 1, CLOZE_TEXT, $respcondition_array["conditionvar"]["respident"], 0));
                                                                }
                                                        }
                                                }
                                                break;
                                }
                        }
                        $this->gaps = array_values($this->gaps);
                        $i = 0;
                        foreach ($materials as $key => $value)
                        {
                                $this->cloze_text .= $value;
                                $gaptext = $this->get_gap_text_list($i);
                                if ($gaptext)
                                {
                                        $type = " type=\"select\"";
                                        if ($this->gaps[$i][0]->get_cloze_type() == CLOZE_TEXT)
                                        {
                                                $type = " type=\"text\"";
                                        }
                                        $shuffle = " shuffle=\"yes\"";
                                        if (!$this->gaps[$i][0]->get_shuffle())
                                        {
                                                $shuffle = " shuffle=\"no\"";
                                        }
                                        $this->cloze_text .= "<gap$type$shuffle>$gaptext</gap>";
                                }
                                $i++;
                        }
                        $result = true;
                }
                return $result;
        }

Here is the call graph for this function:

ASS_ClozeTest::get_cloze_text (  ) 

Returns the cloze text.

Returns the cloze text

Returns:
string The cloze text string public
See also:
$cloze_text

Definition at line 1131 of file class.assClozeTest.php.

Referenced by to_xml().

                            {
    return $this->cloze_text;
  }

Here is the caller graph for this function:

ASS_ClozeTest::get_end_tag (  ) 

Returns the end tag of a cloze gap.

Returns the end tag of a cloze gap

Returns:
string The end tag of a cloze gap public
See also:
$end_tag

Definition at line 1157 of file class.assClozeTest.php.

                         {
    return $this->end_tag;
  }

ASS_ClozeTest::get_gap ( index = 0  ) 

Returns an array of gap answers.

Returns the array of gap answers with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap
Returns:
array Array of ASS_AnswerCloze-Objects containing the gap gaps public
See also:
$gaps

Definition at line 1227 of file class.assClozeTest.php.

Referenced by to_xml().

                               {
    if ($index < 0) return array();
    if (count($this->gaps) < 1) return array();
    if ($index >= count($this->gaps)) return array();
    return $this->gaps[$index];
  }

Here is the caller graph for this function:

ASS_ClozeTest::get_gap_count (  ) 

Returns the number of gaps.

Returns the number of gaps

Returns:
integer The number of gaps in the question text public
See also:
$gaps

Definition at line 1243 of file class.assClozeTest.php.

Referenced by to_xml(), and update_all_gap_params().

                           {
    return count($this->gaps);
  }

Here is the caller graph for this function:

ASS_ClozeTest::get_gap_text_count ( index = 0  ) 

Returns a count of all answers of a gap.

Returns a count of all answers of a gap

Parameters:
integer $index A nonnegative index of the n-th gap public
See also:
$gaps

Definition at line 1278 of file class.assClozeTest.php.

                                          {
    if ($index < 0) return 0;
    if (count($this->gaps) < 1) return 0;
    if ($index >= count($this->gaps)) return 0;
    return count($this->gaps[$index]);
  }

ASS_ClozeTest::get_gap_text_list ( index = 0,
separator = "," 
)

Returns a separated string of all answers for a given text gap.

Returns a separated string of all answers for a given gap. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap
string $separator A string that separates the answer strings
Returns:
string Separated string containing the answer strings public
See also:
$gaps

Definition at line 1259 of file class.assClozeTest.php.

References $result, and $separator.

Referenced by delete_answertext_by_index(), from_xml(), rebuild_cloze_text(), and update_all_gap_params().

                                                           {
    if ($index < 0) return "";
    if (count($this->gaps) < 1) return "";
    if ($index >= count($this->gaps)) return "";
    $result = array();
    foreach ($this->gaps[$index] as $key => $value) {
                        array_push($result, str_replace(",", "\,", $value->get_answertext()));
    }
    return join($separator, $result);
  }

Here is the caller graph for this function:

ASS_ClozeTest::get_start_tag (  ) 

Returns the start tag of a cloze gap.

Returns the start tag of a cloze gap

Returns:
string The start tag of a cloze gap public
See also:
$start_tag

Definition at line 1144 of file class.assClozeTest.php.

                           {
    return $this->start_tag;
  }

ASS_ClozeTest::getMaximumPoints (  ) 

Returns the maximum points, a learner can reach answering the question.

Returns the maximum points, a learner can reach answering the question

public

See also:
$points

Reimplemented from ASS_Question.

Definition at line 1679 of file class.assClozeTest.php.

                              {
    $points = 0;
    foreach ($this->gaps as $key => $value) {
      if ($value[0]->get_cloze_type() == CLOZE_TEXT) {
        $points += $value[0]->get_points();
      } else {
                                $points_arr = array("set" => 0, "unset" => 0);
        foreach ($value as $key2 => $value2) {
                                        if ($value2->get_points() > $points_arr["set"])
                                        {
                                                $points_arr["set"] = $value2->get_points();
                                        }
                                }
                                $points += $points_arr["set"];
      }
    }
    return $points;
  }

ASS_ClozeTest::getQuestionType (  ) 

Returns the question type of the question.

Returns the question type of the question

Returns:
integer The question type of the question public

Definition at line 1804 of file class.assClozeTest.php.

        {
                return 3;
        }

ASS_ClozeTest::getReachedInformation ( user_id,
test_id 
)

Returns the evaluation data, a learner has entered to answer the question.

Returns the evaluation data, a learner has entered to answer the question

Parameters:
integer $user_id The database ID of the learner
integer $test_id The database Id of the test containing the question public

Definition at line 1617 of file class.assClozeTest.php.

References $counter, $data, $query, $result, ASS_Question::$test_id, $user_id, and ASS_Question::getId().

                                                     {
    $found_value1 = array();
    $found_value2 = array();
    $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
      $this->ilias->db->quote($user_id),
      $this->ilias->db->quote($test_id),
      $this->ilias->db->quote($this->getId())
    );
    $result = $this->ilias->db->query($query);
    while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
      array_push($found_value1, $data->value1);
      array_push($found_value2, $data->value2);
    }
    $counter = 1;
                $user_result = array();
    foreach ($found_value1 as $key => $value) {
      if ($this->gaps[$value][0]->get_cloze_type() == CLOZE_TEXT) 
                        {
                                $solution = array(
                                        "gap" => "$counter",
                                        "points" => 0,
                                        "true" => 0,
                                        "value" => $found_value2[$key]
                                );
        foreach ($this->gaps[$value] as $k => $v) {
          if (strcmp(strtolower($v->get_answertext()), strtolower($found_value2[$key])) == 0) {
                                                $solution = array(
                                                        "gap" => "$counter",
                                                        "points" => $v->get_points(),
                                                        "true" => 1,
                                                        "value" => $found_value2[$key]
                                                );
          }
        }
      } 
                        else 
                        {
                                $solution = array(
                                        "gap" => "$counter",
                                        "points" => 0,
                                        "true" => 0,
                                        "value" => $found_value2[$key]
                                );
        if ($this->gaps[$value][$found_value1[$key]]->isStateSet()) {
                                        $solution["points"] = $this->gaps[$value][$found_value1[$key]]->get_points();
                                        $solution["true"] = 1;
        }
      }
                        $counter++;
                        $user_result[$value] = $solution;
    }
    return $user_result;
  }

Here is the call graph for this function:

ASS_ClozeTest::getReachedPoints ( user_id,
test_id 
)

Returns the points, a learner has reached answering the question.

Returns the points, a learner has reached answering the question

Parameters:
integer $user_id The database ID of the learner
integer $test_id The database Id of the test containing the question public

Reimplemented from ASS_Question.

Definition at line 1559 of file class.assClozeTest.php.

References $counter, $data, $query, $result, ASS_Question::$test_id, $user_id, and ASS_Question::getId().

                                                {
    $found_value1 = array();
    $found_value2 = array();
    $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
      $this->ilias->db->quote($user_id),
      $this->ilias->db->quote($test_id),
      $this->ilias->db->quote($this->getId())
    );
    $result = $this->ilias->db->query($query);
                $user_result = array();
    while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
                        if (strcmp($data->value2, "") != 0)
                        {
                                $user_result[$data->value1] = array(
                                        "gap_id" => $data->value1,
                                        "value" => $data->value2
                                );
                        }
    }
    $points = 0;
    $counter = 0;
                foreach ($user_result as $gap_id => $value) {
                        if ($this->gaps[$gap_id][0]->get_cloze_type() == CLOZE_TEXT) 
                        {
                                $foundsolution = 0;
                                foreach ($this->gaps[$gap_id] as $k => $v) {
                                        if ((strcmp(strtolower($v->get_answertext()), strtolower($value["value"])) == 0) && (!$foundsolution)) {
                                                $points += $v->get_points();
                                                $foundsolution = 1;
                                        }
                                }
                        } 
                        else 
                        {
                                if ($value["value"] >= 0)
                                {
                                        foreach ($this->gaps[$gap_id] as $answerkey => $answer)
                                        {
                                                if ($value["value"] == $answerkey)
                                                {
                                                        $points += $answer->get_points();
                                                }
                                        }
                                }
                        }
    }
    return $points;
  }

Here is the call graph for this function:

ASS_ClozeTest::isComplete (  ) 

Returns true, if a cloze test is complete for use.

Returns true, if a cloze test is complete for use

Returns:
boolean True, if the cloze test is complete for use, otherwise false public

Reimplemented from ASS_Question.

Definition at line 115 of file class.assClozeTest.php.

Referenced by saveToDb(), and syncWithOriginal().

        {
                if (($this->title) and ($this->author) and ($this->cloze_text) and (count($this->gaps)))
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }

Here is the caller graph for this function:

ASS_ClozeTest::loadFromDb ( question_id  ) 

Loads a ASS_ClozeTest object from a database.

Loads a ASS_ClozeTest object from a database

Parameters:
object $db A pear DB object
integer $question_id A unique key which defines the cloze test in the database public

Reimplemented from ASS_Question.

Definition at line 369 of file class.assClozeTest.php.

References $counter, $data, ASS_Question::$ilias, $query, $result, and ASS_Question::setEstimatedWorkingTime().

  {
    global $ilias;
    $db =& $ilias->db;

    $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
      $db->quote($question_id)
    );
    $result = $db->query($query);
    if (strcmp(strtolower(get_class($result)), db_result) == 0) {
      if ($result->numRows() == 1) {
        $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
        $this->id = $question_id;
        $this->obj_id = $data->obj_fi;
        $this->title = $data->title;
        $this->comment = $data->comment;
                                $this->solution_hint = $data->solution_hint;
                                $this->original_id = $data->original_id;
        $this->author = $data->author;
        $this->owner = $data->owner;
        $this->cloze_text = $data->question_text;
                                $this->shuffle = $data->shuffle;
        $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
      }

      $query = sprintf("SELECT * FROM qpl_answers WHERE question_fi = %s ORDER BY gap_id, aorder ASC",
        $db->quote($question_id)
      );
      $result = $db->query($query);
      if (strcmp(strtolower(get_class($result)), db_result) == 0) {
        $counter = -1;
        while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
          if ($data->gap_id != $counter) {
            $answer_array = array();
            array_push($this->gaps, $answer_array);
            $counter = $data->gap_id;
          }
                                        if ($data->cloze_type == CLOZE_SELECT)
                                        {
                                                if ($data->correctness == 0)
                                                {
                                                        // fix for older single response answers where points could be given for unchecked answers
                                                        $data->correctness = 1;
                                                        $data->points = 0;
                                                }
                                        }
          array_push($this->gaps[$counter], new ASS_AnswerCloze($data->answertext, $data->points, $data->aorder, $data->correctness, $data->cloze_type, $data->name, $data->shuffle, $data->answer_id));
        }
      }
    }
                parent::loadFromDb($question_id);
  }

Here is the call graph for this function:

ASS_ClozeTest::rebuild_cloze_text (  ) 

Replaces the gap values with the values of the gaps array.

Replaces the gap values with the values of the gaps array

public

See also:
$cloze_text

Definition at line 1196 of file class.assClozeTest.php.

References createCloseTextArray(), createCloseTextFromArray(), and get_gap_text_list().

Referenced by set_answertext().

        {
                $close =& $this->createCloseTextArray();
                if (count($close))
                {
                        for ($i = 0; $i < count($this->gaps); $i++)
                        {
                                $gaptext = $this->get_gap_text_list($i);
                                $textparams = preg_split("/(?<!\\\\),/", $gaptext);
                                $close["gaps"][$i]["text"] = array();
                                $close["gaps"][$i]["text"]["text"] = $gaptext;
                                foreach ($textparams as $key => $value)
                                {
                                        $close["gaps"][$i]["text"][$key] = $value;
                                }
                        }
                }
                $this->createCloseTextFromArray($close);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

ASS_ClozeTest::saveToDb ( original_id = ""  ) 

Saves a ASS_ClozeTest object to a database.

Saves a ASS_ClozeTest object to a database (experimental)

Parameters:
object $db A pear DB object public

Reimplemented from ASS_Question.

Definition at line 248 of file class.assClozeTest.php.

References ASS_Question::$ilias, $query, $result, ASS_Question::$shuffle, ASS_Question::createPageObject(), ASS_Question::getEstimatedWorkingTime(), ASS_Question::getTestId(), ASS_Question::insertIntoTest(), and isComplete().

Referenced by from_xml().

        {
                global $ilias;

                $db =& $ilias->db;
                $complete = 0;
                if ($this->isComplete())
                {
                        $complete = 1;
                }

                $estw_time = $this->getEstimatedWorkingTime();
                $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
                $shuffle = 1;

                if (!$this->shuffle)
                {
                        $shuffle = 0;
                }

                if ($original_id)
                {
                        $original_id = $db->quote($original_id);
                }
                else
                {
                        $original_id = "NULL";
                }

                if ($this->id == -1)
                {
                        // Neuen Datensatz schreiben
                        $now = getdate();
                        $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
                        $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, working_time, shuffle, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
                                $db->quote($this->getQuestionType()),
                                $db->quote($this->obj_id),
                                $db->quote($this->title),
                                $db->quote($this->comment),
                                $db->quote($this->author),
                                $db->quote($this->owner),
                                $db->quote($this->cloze_text),
                                $db->quote($estw_time),
                                $db->quote("$this->shuffle"),
                                $db->quote("$complete"),
                                $db->quote($created),
                                $original_id
                        );
                        $result = $db->query($query);
                        if ($result == DB_OK)
                        {
                                $this->id = $this->ilias->db->getLastInsertId();

                                // create page object of question
                                $this->createPageObject();

                                // Falls die Frage in einen Test eingef�gt werden soll, auch diese Verbindung erstellen
                                if ($this->getTestId() > 0)
                                {
                                        $this->insertIntoTest($this->getTestId());
                                }
                        }
                }
                else
                {
                        // Vorhandenen Datensatz aktualisieren
                        $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time = %s, shuffle = %s, complete = %s WHERE question_id = %s",
                                $db->quote($this->obj_id. ""),
                                $db->quote($this->title),
                                $db->quote($this->comment),
                                $db->quote($this->author),
                                $db->quote($this->cloze_text),
                                $db->quote($estw_time),
                                $db->quote("$this->shuffle"),
                                $db->quote("$complete"),
                                $db->quote($this->id)
                                );
                        $result = $db->query($query);
                }

                if ($result == DB_OK)
                {
                        // Antworten schreiben

                        // delete old answers
                        $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
                                $db->quote($this->id)
                        );
                        $result = $db->query($query);
                        // Anworten wegschreiben
                        foreach ($this->gaps as $key => $value)
                        {
                                foreach ($value as $answer_id => $answer_obj)
                                {
                                        $query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, name, shuffle, correctness, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
                                                $db->quote($this->id),
                                                $db->quote($key),
                                                $db->quote($answer_obj->get_answertext() . ""),
                                                $db->quote($answer_obj->get_points() . ""),
                                                $db->quote($answer_obj->get_order() . ""),
                                                $db->quote($answer_obj->get_cloze_type() . ""),
                                                $db->quote($answer_obj->get_name() . ""),
                                                $db->quote($answer_obj->get_shuffle() . ""),
                                                $db->quote($answer_obj->getState() . "")
                                                );
                                        $answer_result = $db->query($query);
                                }
                        }
                }
                parent::saveToDb($original_id);
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ASS_ClozeTest::saveWorkingData ( test_id,
limit_to = LIMIT_NO_LIMIT 
)

Saves the learners input of the question to the database.

Saves the learners input of the question to the database

Parameters:
integer $test_id The database id of the test containing this question
Returns:
boolean Indicates the save status (true if saved successful, false otherwise) public
See also:
$answers

Definition at line 1708 of file class.assClozeTest.php.

References $_POST, $ilUser, $query, $result, ASS_Question::$test_id, ASS_Question::getId(), and ilUtil::stripSlashes().

                                                                 {
    global $ilDB;
                global $ilUser;
    $db =& $ilDB->db;

    $query = sprintf("DELETE FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
      $db->quote($ilUser->id),
      $db->quote($test_id),
      $db->quote($this->getId())
    );
    $result = $db->query($query);

    foreach ($_POST as $key => $value) {
      if (preg_match("/^gap_(\d+)/", $key, $matches)) {
        $query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
                                        $db->quote($ilUser->id),
                                        $db->quote($test_id),
          $db->quote($this->getId()),
          $db->quote($matches[1]),
          $db->quote(ilUtil::stripSlashes($value))
        );
        $result = $db->query($query);
      }
    }
    //parent::saveWorkingData($limit_to);
                return true;
  }

Here is the call graph for this function:

ASS_ClozeTest::set_answertext ( index = 0,
answertext_index = 0,
answertext = "",
add_gaptext = 0 
)

Sets an answer text of a gap.

Sets an answer text of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap
integer $answertext_index A nonnegative index of the n-th answertext
string $answertext The answer text that should be deleted public
See also:
$gaps

Definition at line 1356 of file class.assClozeTest.php.

References rebuild_cloze_text().

                                                                                               {
                $answertext = str_replace("\,", ",", $answertext);
        if ($add_gaptext == 1)    {
        $arr = $this->gaps[$index][0];
        if (strlen($this->gaps[$index][count($this->gaps[$index])-1]->get_answertext()) != 0) {
                                $default_state = 0;
                                if ($arr->get_cloze_type() == CLOZE_TEXT)
                                {
                                        $default_state = 1;
                                }
                array_push($this->gaps[$index], new ASS_AnswerCloze($answertext, 0, count($this->gaps[$index]),
                        $default_state, $arr->get_cloze_type(),
                        $arr->get_name(), $arr->get_shuffle()));
                $this->rebuild_cloze_text();
        }
        return;
    }
    if ($index < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index >= count($this->gaps)) return;
    if ($answertext_index < 0) return;
    if (count($this->gaps[$index]) < 1) return;
    if ($answertext_index >= count($this->gaps[$index])) return;


    if (strlen($answertext) == 0) {
      // delete the answertext
      $this->delete_answertext($index, $this->gaps[$index][$answertext_index]->get_answertext());
    } else {
      $this->gaps[$index][$answertext_index]->set_answertext($answertext);
      $this->rebuild_cloze_text();
    }
  }

Here is the call graph for this function:

ASS_ClozeTest::set_cloze_text ( cloze_text = ""  ) 

Evaluates the text gap solutions from the cloze text.

Evaluates the text gap solutions from the cloze text. A single or multiple text gap solutions could be entered using the following syntax in the cloze text: solution1 [, solution2, ..., solutionN] enclosed in the text gap selector *[]

Parameters:
string $cloze_text The cloze text with all gaps and gap gaps public
See also:
$cloze_text

Definition at line 1074 of file class.assClozeTest.php.

References $cloze_text, ASS_Question::$shuffle, $type, and createCloseTextArray().

Referenced by ASS_ClozeTest().

        {
                $this->gaps = array();
                $this->cloze_text =& $cloze_text;
                $close = $this->createCloseTextArray();
                if (count($close))
                {
                        foreach ($close["gaps"] as $key => $value)
                        {
                                if (strcmp(strtolower($value["params"]["type"]), "select") == 0)
                                {
                                        $type = CLOZE_SELECT;
                                }
                                        else
                                {
                                        $type = CLOZE_TEXT;
                                }
                                if ($type == CLOZE_TEXT)
                                {
                                        $default_state = 1;
                                }
                                else
                                {
                                        $default_state = 0;
                                }
                                $name = $value["params"]["name"];
                                if (strcmp(strtolower($value["params"]["shuffle"]), "no") == 0)
                                {
                                        $shuffle = 0;
                                }
                                        else
                                {
                                        $shuffle = 1;
                                }
                                $answer_array = array();
                                foreach ($value["text"] as $index => $textvalue)
                                {
                                        if (preg_match("/\d+/", $index))
                                        {
                                                $textvalue = str_replace("\,", ",", $textvalue);
                                                array_push($answer_array, new ASS_AnswerCloze($textvalue, 0, $index, $default_state, $type, $name, $shuffle));
                                        }
                                }
                                array_push($this->gaps, $answer_array);
                        }
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ASS_ClozeTest::set_cloze_type ( index,
cloze_type = CLOZE_TEXT 
)

Sets the cloze type of the gap.

Sets the cloze type of the gap

Parameters:
integer $index The index of the chosen gap
integer $cloze_type The cloze type of the gap public
See also:
$gaps

Definition at line 1444 of file class.assClozeTest.php.

References $type, createCloseTextArray(), and createCloseTextFromArray().

                                                                  {
    if ($index < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index >= count($this->gaps)) return;
                $close = $this->createCloseTextArray();
                foreach ($this->gaps[$index] as $key => $value) {
                        $this->gaps[$index][$key]->set_cloze_type($cloze_type);
                        $this->gaps[$index][$key]->setState(1);
                }
                if ($cloze_type == CLOZE_TEXT)
                {
                        $type = "text";
                }
                else
                {
                        $type = "select";
                }
                $close["gaps"][$index]["type"] = $type;
                $this->createCloseTextFromArray($close);
        }

Here is the call graph for this function:

ASS_ClozeTest::set_end_tag ( end_tag = "</gap>"  ) 

Sets the end tag of a cloze gap.

Sets the end tag of a cloze gap

Parameters:
string $end_tag The end tag for a cloze gap public
See also:
$end_tag

Definition at line 1184 of file class.assClozeTest.php.

References $end_tag.

                                            {
    $this->end_tag = $end_tag;
  }

ASS_ClozeTest::set_gap_points ( index = 0,
points = 0.0 
)

Sets the points of a gap.

Sets the points of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap
double $points The points for the correct solution of the gap public
See also:
$gaps

Definition at line 1476 of file class.assClozeTest.php.

                                                     {
    if ($index < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index >= count($this->gaps)) return;
    foreach ($this->gaps[$index] as $key => $value) {
      $this->gaps[$index][$key]->set_points($points);
    }
  }

ASS_ClozeTest::set_gap_shuffle ( index = 0,
shuffle = 1 
)

Sets the shuffle state of a gap.

Sets the shuffle state of a gap with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index A nonnegative index of the n-th gap
integer $shuffle Turn shuffle on (=1) or off (=0) public
See also:
$gaps

Definition at line 1496 of file class.assClozeTest.php.

References ASS_Question::$shuffle.

                                                     {
    if ($index < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index >= count($this->gaps)) return;
    foreach ($this->gaps[$index] as $key => $value) {
      $this->gaps[$index][$key]->set_shuffle($shuffle);
    }
  }

ASS_ClozeTest::set_single_answer_points ( index_gaps = 0,
index_answerobject = 0,
points = 0.0 
)

Sets the points of a gap answer.

Sets the points of a gap answer with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index_gaps A nonnegative index of the n-th gap
integer $index_answerobject A nonnegative index of the n-th answer in the specified gap
double $points The points for the correct solution of the answer public
See also:
$gaps

Definition at line 1518 of file class.assClozeTest.php.

                                                                                             {
    if ($index_gaps < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index_gaps >= count($this->gaps)) return;
    if ($index_answerobject < 0) return;
    if (count($this->gaps[$index_gaps]) < 1) return;
    if ($index_answerobject >= count($this->gaps[$index_gaps])) return;
    $this->gaps[$index_gaps][$index_answerobject]->set_points($points);
  }

ASS_ClozeTest::set_single_answer_state ( index_gaps = 0,
index_answerobject = 0,
state = 0 
)

Sets the state of a gap answer.

Sets the state of a gap answer with a given index. The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters:
integer $index_gaps A nonnegative index of the n-th gap
integer $index_answerobject A nonnegative index of the n-th answer in the specified gap
boolean $state The state of the answer public
See also:
$gaps

Definition at line 1540 of file class.assClozeTest.php.

                                                                                         {
    if ($index_gaps < 0) return;
    if (count($this->gaps) < 1) return;
    if ($index_gaps >= count($this->gaps)) return;
    if ($index_answerobject < 0) return;
    if (count($this->gaps[$index_gaps]) < 1) return;
    if ($index_answerobject >= count($this->gaps[$index_gaps])) return;
    $this->gaps[$index_gaps][$index_answerobject]->setState($state);
  }

ASS_ClozeTest::set_start_tag ( start_tag = "<gap>"  ) 

Sets the start tag of a cloze gap.

Sets the start tag of a cloze gap

Parameters:
string $start_tag The start tag for a cloze gap public
See also:
$start_tag

Definition at line 1170 of file class.assClozeTest.php.

References $start_tag.

                                               {
    $this->start_tag = $start_tag;
  }

ASS_ClozeTest::syncWithOriginal (  ) 

Reimplemented from ASS_Question.

Definition at line 1736 of file class.assClozeTest.php.

References ASS_Question::$ilias, $query, $result, ASS_Question::getEstimatedWorkingTime(), and isComplete().

        {
                global $ilias;
                if ($this->original_id)
                {
                        $complete = 0;
                        if ($this->isComplete())
                        {
                                $complete = 1;
                        }
                        $db = & $ilias->db;
        
                        $estw_time = $this->getEstimatedWorkingTime();
                        $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
        
                        $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time = %s, shuffle = %s, complete = %s WHERE question_id = %s",
                                $db->quote($this->obj_id. ""),
                                $db->quote($this->title . ""),
                                $db->quote($this->comment . ""),
                                $db->quote($this->author . ""),
                                $db->quote($this->cloze_text . ""),
                                $db->quote($estw_time . ""),
                                $db->quote($this->shuffle . ""),
                                $db->quote($complete . ""),
                                $db->quote($this->original_id . "")
                                );
                        $result = $db->query($query);

                        if ($result == DB_OK)
                        {
                                // write answers
                                // delete old answers
                                $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
                                        $db->quote($this->original_id)
                                );
                                $result = $db->query($query);
        
                                foreach ($this->gaps as $key => $value)
                                {
                                        foreach ($value as $answer_id => $answer_obj)
                                        {
                                                $query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, name, shuffle, correctness, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
                                                        $db->quote($this->original_id . ""),
                                                        $db->quote($key . ""),
                                                        $db->quote($answer_obj->get_answertext() . ""),
                                                        $db->quote($answer_obj->get_points() . ""),
                                                        $db->quote($answer_obj->get_order() . ""),
                                                        $db->quote($answer_obj->get_cloze_type() . ""),
                                                        $db->quote($answer_obj->get_name() . ""),
                                                        $db->quote($answer_obj->get_shuffle() . ""),
                                                        $db->quote($answer_obj->getState() . "")
                                                        );
                                                $answer_result = $db->query($query);
                                        }
                                }
                        }
                        parent::syncWithOriginal();
                }
        }

Here is the call graph for this function:

ASS_ClozeTest::to_xml ( a_include_header = true,
a_include_binary = true,
a_shuffle = false,
test_output = false 
)

Returns a QTI xml representation of the question.

Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation

Returns:
string The QTI xml representation of the question public

Definition at line 708 of file class.assClozeTest.php.

References $pos, $xml, domxml_open_mem(), get_cloze_text(), get_gap(), get_gap_count(), ASS_Question::getAuthor(), ASS_Question::getComment(), ASS_Question::getEstimatedWorkingTime(), ASS_Question::getSuggestedSolution(), ASS_Question::getTitle(), and ASS_Question::pcArrayShuffle().

        {
                if (!empty($this->domxml))
                {
                        $this->domxml->free();
                }
                $xml_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<questestinterop></questestinterop>\n";
                $this->domxml = domxml_open_mem($xml_header);
                $root = $this->domxml->document_element();
                // qti ident
                $qtiIdent = $this->domxml->create_element("item");
                $qtiIdent->set_attribute("ident", "il_".IL_INST_ID."_qst_".$this->getId());
                $qtiIdent->set_attribute("title", $this->getTitle());
                $root->append_child($qtiIdent);
        // add question description
                $qtiComment = $this->domxml->create_element("qticomment");
                $qtiCommentText = $this->domxml->create_text_node($this->getComment());
                $qtiComment->append_child($qtiCommentText);
                $qtiIdent->append_child($qtiComment);
                // add estimated working time
                $qtiDuration = $this->domxml->create_element("duration");
                $workingtime = $this->getEstimatedWorkingTime();
                $qtiDurationText = $this->domxml->create_text_node(sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]));
                $qtiDuration->append_child($qtiDurationText);
                $qtiIdent->append_child($qtiDuration);

                // add ILIAS specific metadata
                $qtiItemmetadata = $this->domxml->create_element("itemmetadata");
                $qtiMetadata = $this->domxml->create_element("qtimetadata");
                
                $qtiMetadatafield = $this->domxml->create_element("qtimetadatafield");
                $qtiFieldlabel = $this->domxml->create_element("fieldlabel");
                $qtiFieldlabelText = $this->domxml->create_text_node("ILIAS_VERSION");
                $qtiFieldlabel->append_child($qtiFieldlabelText);
                $qtiFieldentry = $this->domxml->create_element("fieldentry");
                $qtiFieldentryText = $this->domxml->create_text_node($this->ilias->getSetting("ilias_version"));
                $qtiFieldentry->append_child($qtiFieldentryText);
                $qtiMetadatafield->append_child($qtiFieldlabel);
                $qtiMetadatafield->append_child($qtiFieldentry);
                $qtiMetadata->append_child($qtiMetadatafield);

                $qtiMetadatafield = $this->domxml->create_element("qtimetadatafield");
                $qtiFieldlabel = $this->domxml->create_element("fieldlabel");
                $qtiFieldlabelText = $this->domxml->create_text_node("QUESTIONTYPE");
                $qtiFieldlabel->append_child($qtiFieldlabelText);
                $qtiFieldentry = $this->domxml->create_element("fieldentry");
                $qtiFieldentryText = $this->domxml->create_text_node(CLOZE_TEST_IDENTIFIER);
                $qtiFieldentry->append_child($qtiFieldentryText);
                $qtiMetadatafield->append_child($qtiFieldlabel);
                $qtiMetadatafield->append_child($qtiFieldentry);
                $qtiMetadata->append_child($qtiMetadatafield);
                
                $qtiMetadatafield = $this->domxml->create_element("qtimetadatafield");
                $qtiFieldlabel = $this->domxml->create_element("fieldlabel");
                $qtiFieldlabelText = $this->domxml->create_text_node("AUTHOR");
                $qtiFieldlabel->append_child($qtiFieldlabelText);
                $qtiFieldentry = $this->domxml->create_element("fieldentry");
                $qtiFieldentryText = $this->domxml->create_text_node($this->getAuthor());
                $qtiFieldentry->append_child($qtiFieldentryText);
                $qtiMetadatafield->append_child($qtiFieldlabel);
                $qtiMetadatafield->append_child($qtiFieldentry);
                $qtiMetadata->append_child($qtiMetadatafield);
                
                $qtiItemmetadata->append_child($qtiMetadata);
                $qtiIdent->append_child($qtiItemmetadata);
                
                // PART I: qti presentation
                $qtiPresentation = $this->domxml->create_element("presentation");
                $qtiPresentation->set_attribute("label", $this->getTitle());
                // add flow to presentation
                $qtiFlow = $this->domxml->create_element("flow");

                $text_parts = preg_split("/<gap.*?<\/gap>/", $this->get_cloze_text());
                // add material with question text to presentation
                for ($i = 0; $i <= $this->get_gap_count(); $i++)
                {
                        // n-th text part
                        $qtiMaterial = $this->domxml->create_element("material");
                        $qtiMatText = $this->domxml->create_element("mattext");
                        $qtiMatTextText = $this->domxml->create_text_node($text_parts[$i]);
                        $qtiMatText->append_child($qtiMatTextText);
                        $qtiMaterial->append_child($qtiMatText);
                        $qtiFlow->append_child($qtiMaterial);

                        if ($i < $this->get_gap_count())
                        {
                                // add gap
                                $gap = $this->get_gap($i);
                                if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
                                {
                                        // comboboxes
                                        $qtiResponseStr = $this->domxml->create_element("response_str");
                                        $qtiResponseStr->set_attribute("ident", "gap_$i");
                                        $qtiResponseStr->set_attribute("rcardinality", "Single");
                                        $solution = $this->getSuggestedSolution($i);
                                        if (count($solution))
                                        {
                                                if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
                                                {
                                                        $qtiMaterial = $this->domxml->create_element("material");
                                                        $qtiMaterial->set_attribute("label", "suggested_solution");
                                                        $qtiMatText = $this->domxml->create_element("mattext");
                                                        $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
                                                        if (strcmp($matches[1], "") != 0)
                                                        {
                                                                $intlink = $solution["internal_link"];
                                                        }
                                                        $qtiMatTextText = $this->domxml->create_text_node($intlink);
                                                        $qtiMatText->append_child($qtiMatTextText);
                                                        $qtiMaterial->append_child($qtiMatText);
                                                        $qtiResponseStr->append_child($qtiMaterial);
                                                }
                                        }
                                        
                                        $qtiRenderChoice = $this->domxml->create_element("render_choice");
                                        // shuffle output
                                        if ($gap[0]->get_shuffle())
                                        {
                                                $qtiRenderChoice->set_attribute("shuffle", "Yes");
                                        }
                                        else
                                        {
                                                $qtiRenderChoice->set_attribute("shuffle", "No");
                                        }

                                        $gkeys = array_keys($gap);
                                        if ($this->getshuffle() && $a_shuffle)
                                        {
                                                $gkeys = $this->pcArrayShuffle($gkeys);
                                        }

                                        // add answers
                                        foreach ($gkeys as $key)
                                        {
                                                $value = $gap[$key];
                                                $qtiResponseLabel = $this->domxml->create_element("response_label");
                                                $qtiResponseLabel->set_attribute("ident", $key);
                                                $qtiMaterial = $this->domxml->create_element("material");
                                                $qtiMatText = $this->domxml->create_element("mattext");
                                                $tmpvalue = $value->get_answertext();
                                                $qtiMatTextText = $this->domxml->create_text_node($tmpvalue);
                                                $qtiMatText->append_child($qtiMatTextText);
                                                $qtiMaterial->append_child($qtiMatText);
                                                $qtiResponseLabel->append_child($qtiMaterial);
                                                $qtiRenderChoice->append_child($qtiResponseLabel);
                                        }
                                        $qtiResponseStr->append_child($qtiRenderChoice);
                                        $qtiFlow->append_child($qtiResponseStr);
                                }
                                else
                                {
                                        // text fields
                                        $qtiResponseStr = $this->domxml->create_element("response_str");
                                        $qtiResponseStr->set_attribute("ident", "gap_$i");
                                        $qtiResponseStr->set_attribute("rcardinality", "Single");
                                        $solution = $this->getSuggestedSolution($i);
                                        if (count($solution))
                                        {
                                                if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
                                                {
                                                        $qtiMaterial = $this->domxml->create_element("material");
                                                        $qtiMaterial->set_attribute("label", "suggested_solution");
                                                        $qtiMatText = $this->domxml->create_element("mattext");
                                                        $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
                                                        if (strcmp($matches[1], "") != 0)
                                                        {
                                                                $intlink = $solution["internal_link"];
                                                        }
                                                        $qtiMatTextText = $this->domxml->create_text_node($intlink);
                                                        $qtiMatText->append_child($qtiMatTextText);
                                                        $qtiMaterial->append_child($qtiMatText);
                                                        $qtiResponseStr->append_child($qtiMaterial);
                                                }
                                        }
                                        $qtiRenderFib = $this->domxml->create_element("render_fib");
                                        $qtiRenderFib->set_attribute("fibtype", "String");
                                        $qtiRenderFib->set_attribute("prompt", "Box");
                                        $qtiResponseLabel = $this->domxml->create_element("response_label");
                                        $qtiResponseLabel->set_attribute("ident", $i);
                                        $qtiRenderFib->append_child($qtiResponseLabel);
                                        $qtiResponseStr->append_child($qtiRenderFib);
                                        $qtiFlow->append_child($qtiResponseStr);
                                }
                        }
                }
                $qtiPresentation->append_child($qtiFlow);
                $qtiIdent->append_child($qtiPresentation);

                // PART II: qti resprocessing
                $qtiResprocessing = $this->domxml->create_element("resprocessing");
                $qtiOutcomes = $this->domxml->create_element("outcomes");
                $qtiDecvar = $this->domxml->create_element("decvar");
                $qtiOutcomes->append_child($qtiDecvar);
                $qtiResprocessing->append_child($qtiOutcomes);
                // add response conditions
                for ($i = 0; $i < $this->get_gap_count(); $i++)
                {
                        $gap = $this->get_gap($i);
                        if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
                        {
                                foreach ($gap as $index => $answer)
                                {
                                        $qtiRespcondition = $this->domxml->create_element("respcondition");
                                        $qtiRespcondition->set_attribute("continue", "Yes");
                                        // qti conditionvar
                                        $qtiConditionvar = $this->domxml->create_element("conditionvar");

                                        if (!$answer->isStateSet())
                                        {
                                                $qtinot = $this->domxml->create_element("not");
                                        }
                                        
                                        $qtiVarequal = $this->domxml->create_element("varequal");
                                        $qtiVarequal->set_attribute("respident", "gap_$i");
                                        $qtiVarequalText = $this->domxml->create_text_node($answer->get_answertext());
                                        $qtiVarequal->append_child($qtiVarequalText);
                                        if (!$answer->isStateSet())
                                        {
                                                $qtiConditionvar->append_child($qtinot);
                                                $qtinot->append_child($qtiVarequal);
                                        }
                                        else
                                        {
                                                $qtiConditionvar->append_child($qtiVarequal);
                                        }
                                        // qti setvar
                                        $qtiSetvar = $this->domxml->create_element("setvar");
                                        $qtiSetvar->set_attribute("action", "Add");
                                        $qtiSetvarText = $this->domxml->create_text_node($answer->get_points());
                                        $qtiSetvar->append_child($qtiSetvarText);
                                        // qti displayfeedback
                                        $qtiDisplayfeedback = $this->domxml->create_element("displayfeedback");
                                        $qtiDisplayfeedback->set_attribute("feedbacktype", "Response");
                                        $linkrefid = "";
                                        if ($answer->isStateSet())
                                        {
                                                $linkrefid = "$i" . "_True";
                                        }
                                                else
                                        {
                                                $linkrefid = "$i" . "_False_$index";
                                        }
                                        $qtiDisplayfeedback->set_attribute("linkrefid", $linkrefid);
                                        $qtiRespcondition->append_child($qtiConditionvar);
                                        $qtiRespcondition->append_child($qtiSetvar);
                                        $qtiRespcondition->append_child($qtiDisplayfeedback);
                                        $qtiResprocessing->append_child($qtiRespcondition);
                                }
                        }
                        else
                        {
                                foreach ($gap as $index => $answer)
                                {
                                        $qtiRespcondition = $this->domxml->create_element("respcondition");
                                        $qtiRespcondition->set_attribute("continue", "Yes");
                                        // qti conditionvar
                                        $qtiConditionvar = $this->domxml->create_element("conditionvar");
                                        $qtiVarequal = $this->domxml->create_element("varequal");
                                        $qtiVarequal->set_attribute("respident", "gap_$i");
                                        $qtiVarequalText = $this->domxml->create_text_node($answer->get_answertext());
                                        $qtiVarequal->append_child($qtiVarequalText);
                                        $qtiConditionvar->append_child($qtiVarequal);
                                        // qti setvar
                                        $qtiSetvar = $this->domxml->create_element("setvar");
                                        $qtiSetvar->set_attribute("action", "Add");
                                        $qtiSetvarText = $this->domxml->create_text_node($answer->get_points());
                                        $qtiSetvar->append_child($qtiSetvarText);
                                        // qti displayfeedback
                                        $qtiDisplayfeedback = $this->domxml->create_element("displayfeedback");
                                        $qtiDisplayfeedback->set_attribute("feedbacktype", "Response");
                                        $qtiDisplayfeedback->set_attribute("linkrefid", "$i" . "_True_$index");
                                        $qtiRespcondition->append_child($qtiConditionvar);
                                        $qtiRespcondition->append_child($qtiSetvar);
                                        $qtiRespcondition->append_child($qtiDisplayfeedback);
                                        $qtiResprocessing->append_child($qtiRespcondition);
                                }
                        }
                }
                $qtiIdent->append_child($qtiResprocessing);

                // PART III: qti itemfeedback
                for ($i = 0; $i < $this->get_gap_count(); $i++)
                {
                        $gap = $this->get_gap($i);
                        if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
                        {
                                foreach ($gap as $index => $answer)
                                {
                                        $qtiItemfeedback = $this->domxml->create_element("itemfeedback");
                                        $linkrefid = "";
                                        if ($answer->isStateSet())
                                        {
                                                $linkrefid = "$i" . "_True";
                                        }
                                                else
                                        {
                                                $linkrefid = "$i" . "_False_$index";
                                        }
                                        $qtiItemfeedback->set_attribute("ident", $linkrefid);
                                        $qtiItemfeedback->set_attribute("view", "All");
                                        // qti flow_mat
                                        $qtiFlowmat = $this->domxml->create_element("flow_mat");
                                        $qtiMaterial = $this->domxml->create_element("material");
                                        $qtiMattext = $this->domxml->create_element("mattext");
                                        // Insert response text for right/wrong answers here!!!
                                        $qtiMattextText = $this->domxml->create_text_node("");
                                        $qtiMattext->append_child($qtiMattextText);
                                        $qtiMaterial->append_child($qtiMattext);
                                        $qtiFlowmat->append_child($qtiMaterial);
                                        $qtiItemfeedback->append_child($qtiFlowmat);
                                        $qtiIdent->append_child($qtiItemfeedback);
                                }
                        }
                        else
                        {
                                foreach ($gap as $index => $answer)
                                {
                                        $qtiItemfeedback = $this->domxml->create_element("itemfeedback");
                                        $linkrefid = "";
                                        if ($answer->isStateSet())
                                        {
                                                $linkrefid = "$i" . "_True_$index";
                                        }
                                                else
                                        {
                                                $linkrefid = "$i" . "_False_$index";
                                        }
                                        $qtiItemfeedback->set_attribute("ident", $linkrefid);
                                        $qtiItemfeedback->set_attribute("view", "All");
                                        // qti flow_mat
                                        $qtiFlowmat = $this->domxml->create_element("flow_mat");
                                        $qtiMaterial = $this->domxml->create_element("material");
                                        $qtiMattext = $this->domxml->create_element("mattext");
                                        // Insert response text for right/wrong answers here!!!
                                        $qtiMattextText = $this->domxml->create_text_node("");
                                        $qtiMattext->append_child($qtiMattextText);
                                        $qtiMaterial->append_child($qtiMattext);
                                        $qtiFlowmat->append_child($qtiMaterial);
                                        $qtiItemfeedback->append_child($qtiFlowmat);
                                        $qtiIdent->append_child($qtiItemfeedback);
                                }
                        }
                }

                $xml = $this->domxml->dump_mem(true);
                if (!$a_include_header)
                {
                        $pos = strpos($xml, "?>");
                        $xml = substr($xml, $pos + 2);
                }
//echo htmlentities($xml);
                return $xml;

        }

Here is the call graph for this function:

ASS_ClozeTest::update_all_gap_params (  ) 

Updates the cloze text setting the cloze type for every gap.

Updates the cloze text setting the cloze type for every gap

public

See also:
$cloze_text

Definition at line 1398 of file class.assClozeTest.php.

References ASS_Question::$lng, createCloseTextArray(), createCloseTextFromArray(), get_gap_count(), and get_gap_text_list().

                                         {
                global $lng;
                $close = $this->createCloseTextArray();
                for ($i = 0; $i < $this->get_gap_count(); $i++)
                {
                        $gaptext = $this->get_gap_text_list($i);
                        if ($this->gaps[$i][0]->get_cloze_type() == CLOZE_TEXT)
                        {
                                $close["gaps"][$i]["params"]["type"] = "text";
                                if (array_key_exists("shuffle", $close["gaps"][$i]["params"]))
                                {
                                        unset($close["gaps"][$i]["params"]["shuffle"]);
                                }
                        }
                                else
                        {
                                $close["gaps"][$i]["params"]["type"] = "select";
                                if ($this->gaps[$i][0]->get_shuffle() == 0)
                                {
                                        $close["gaps"][$i]["params"]["shuffle"] = "no";
                                }
                                        else
                                {
                                        $close["gaps"][$i]["params"]["shuffle"] = "yes";
                                }
                        }
                        $name = $this->gaps[$i][0]->get_name();
                        if (!$name)
                        {
                                $name = $this->lng->txt("gap") . " " . ($i+1);
                        }
                        $close["gaps"][$i]["params"]["name"] = $name;
                }
                $this->createCloseTextFromArray($close);
        }

Here is the call graph for this function:


Field Documentation

ASS_ClozeTest::$cloze_text

Definition at line 52 of file class.assClozeTest.php.

Referenced by ASS_ClozeTest(), and set_cloze_text().

ASS_ClozeTest::$end_tag

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

Referenced by set_end_tag().

ASS_ClozeTest::$gaps

Definition at line 61 of file class.assClozeTest.php.

Referenced by createCloseTextArray().

ASS_ClozeTest::$start_tag

Definition at line 70 of file class.assClozeTest.php.

Referenced by set_start_tag().


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