ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
assMatchingQuestionImport Class Reference

Class for matching question imports. More...

+ Inheritance diagram for assMatchingQuestionImport:
+ Collaboration diagram for assMatchingQuestionImport:

Public Member Functions

 saveImage ($data, $filename)
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file.
- Public Member Functions inherited from assQuestionImport
 assQuestionImport (&$a_object)
 assQuestionImport constructor
 getFeedbackGeneric ($item)

Private Member Functions

 safeTempToDB ()

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object

Detailed Description

Class for matching question imports.

assMatchingQuestionImport is a class for matching question imports

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 35 of file class.assMatchingQuestionImport.php.

Member Function Documentation

assMatchingQuestionImport::fromXML ( $item,
  $questionpool_id,
$tst_id,
$tst_object,
$question_counter,
$import_mapping 
)

Creates a question from a QTI file.

Receives parameters from a QTI parser and creates a valid ILIAS question object

Parameters
object$itemThe QTI item object
integer$questionpool_idThe id of the parent questionpool
integer$tst_idThe id of the parent test if the question is part of a test
object$tst_objectA reference to the parent test object
integer$question_counterA reference to a question counter to count the questions of an imported question pool
array$import_mappingAn array containing references to included ILIAS objects public

Reimplemented from assQuestionImport.

Definition at line 71 of file class.assMatchingQuestionImport.php.

References $_SESSION, ilObjQuestionPool\_getImportDirectory(), ilObjTest\_getImportDirectory(), ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), safeTempToDB(), and saveImage().

{
global $ilUser;
// empty session variable for imported xhtml mobs
unset($_SESSION["import_mob_xhtml"]);
$presentation = $item->getPresentation();
$duration = $item->getDuration();
$shuffle = 0;
$now = getdate();
$created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
$definitions = array();
$terms = array();
$foundimage = FALSE;
foreach ($presentation->order as $entry)
{
switch ($entry["type"])
{
case "response":
$response = $presentation->response[$entry["index"]];
$rendertype = $response->getRenderType();
switch (strtolower(get_class($rendertype)))
{
case "ilqtirenderchoice":
$shuffle = $rendertype->getShuffle();
$answerorder = 0;
foreach ($rendertype->response_labels as $response_label)
{
$ident = $response_label->getIdent();
$answertext = "";
$answerimage = array();
foreach ($response_label->material as $mat)
{
for ($m = 0; $m < $mat->getMaterialCount(); $m++)
{
$foundmat = $mat->getMaterial($m);
if (strcmp($foundmat["type"], "mattext") == 0)
{
$answertext .= $foundmat["material"]->getContent();
}
if (strcmp($foundmat["type"], "matimage") == 0)
{
$foundimage = TRUE;
$answerimage = array(
"imagetype" => $foundmat["material"]->getImageType(),
"label" => $foundmat["material"]->getLabel(),
"content" => $foundmat["material"]->getContent()
);
}
}
}
if (($response_label->getMatchMax() == 1) && (strlen($response_label->getMatchGroup())))
{
$definitions[$ident] = array(
"answertext" => $answertext,
"answerimage" => $answerimage,
"points" => 0,
"answerorder" => $ident,
"action" => ""
);
}
else
{
$terms[$ident] = array(
"term" => $answertext,
"answerimage" => $answerimage,
"points" => 0,
"ident" => $ident,
"action" => ""
);
}
}
break;
}
break;
}
}
$responses = array();
$feedbacksgeneric = array();
foreach ($item->resprocessing as $resprocessing)
{
foreach ($resprocessing->respcondition as $respcondition)
{
$subset = array();
$correctness = 1;
$conditionvar = $respcondition->getConditionvar();
foreach ($conditionvar->order as $order)
{
switch ($order["field"])
{
case "varsubset":
$subset = split(",", $conditionvar->varsubset[$order["index"]]->getContent());
break;
}
}
foreach ($respcondition->setvar as $setvar)
{
array_push($responses, array("subset" => $subset, "action" => $setvar->getAction(), "points" => $setvar->getContent()));
}
if (count($respcondition->displayfeedback))
{
foreach ($respcondition->displayfeedback as $feedbackpointer)
{
if (strlen($feedbackpointer->getLinkrefid()))
{
foreach ($item->itemfeedback as $ifb)
{
if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
{
// found a feedback for the identifier
if (count($ifb->material))
{
foreach ($ifb->material as $material)
{
$feedbacksgeneric[1] = $material;
}
}
if ((count($ifb->flow_mat) > 0))
{
foreach ($ifb->flow_mat as $fmat)
{
if (count($fmat->material))
{
foreach ($fmat->material as $material)
{
$feedbacksgeneric[1] = $material;
}
}
}
}
}
else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
{
// found a feedback for the identifier
if (count($ifb->material))
{
foreach ($ifb->material as $material)
{
$feedbacksgeneric[0] = $material;
}
}
if ((count($ifb->flow_mat) > 0))
{
foreach ($ifb->flow_mat as $fmat)
{
if (count($fmat->material))
{
foreach ($fmat->material as $material)
{
$feedbacksgeneric[0] = $material;
}
}
}
}
}
}
}
}
}
}
}
include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
$this->object->createNewQuestion();
$this->object->setTitle($item->getTitle());
$this->object->setExternalID($item->getIdent());
$this->object->setNrOfTries($item->getMaxattempts());
$this->object->setComment($item->getComment());
$this->object->setAuthor($item->getAuthor());
$this->object->setOwner($ilUser->getId());
$this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
$this->object->setObjId($questionpool_id);
$this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
$extended_shuffle = $item->getMetadataEntry("shuffle");
$this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
$this->object->setElementHeight($item->getMetadataEntry("element_height"));
// save images
foreach ($terms as $term)
{
if (count($term['answerimage'])) $this->saveImage($term['answerimage']['content'], $term['answerimage']['label']);
}
foreach ($definitions as $definition)
{
if (count($definition['answerimage'])) $this->saveImage($definition['answerimage']['content'], $definition['answerimage']['label']);
}
foreach ($terms as $termindex => $term)
{
$this->object->addTerm(new assAnswerMatchingTerm($term["term"], $term['answerimage']['label'], $term["ident"]));
}
foreach ($definitions as $definitionindex => $definition)
{
$this->object->addDefinition(new assAnswerMatchingDefinition($definition["answertext"], $definition['answerimage']['label'], $definition["answerorder"]));
}
if (strlen($extended_shuffle) > 0)
{
$shuffle = $extended_shuffle;
}
$this->object->setShuffle($shuffle);
foreach ($responses as $response)
{
$subset = $response["subset"];
foreach ($subset as $ident)
{
if (array_key_exists($ident, $definitions))
{
$definition = $definitions[$ident];
}
if (array_key_exists($ident, $terms))
{
$term = $terms[$ident];
}
}
$this->object->addMatchingPair(new assAnswerMatchingTerm('', '', $term["ident"]), new assAnswerMatchingDefinition('', '', $definition["answerorder"]), $response['points']);
}
$this->object->saveToDb();
if (count($item->suggested_solutions))
{
foreach ($item->suggested_solutions as $suggested_solution)
{
$this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
}
$this->object->saveToDb();
}
foreach ($responses as $response)
{
$subset = $response["subset"];
foreach ($subset as $ident)
{
if (array_key_exists($ident, $definitions))
{
$definition = $definitions[$ident];
}
if (array_key_exists($ident, $terms))
{
$term = $terms[$ident];
}
}
}
foreach ($feedbacksgeneric as $correctness => $material)
{
$m = $this->object->QTIMaterialToString($material);
$feedbacksgeneric[$correctness] = $m;
}
// handle the import of media objects in XHTML code
$questiontext = $this->object->getQuestion();
if (is_array($_SESSION["import_mob_xhtml"]))
{
include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
include_once "./Services/RTE/classes/class.ilRTE.php";
foreach ($_SESSION["import_mob_xhtml"] as $mob)
{
if ($tst_id > 0)
{
include_once "./Modules/Test/classes/class.ilObjTest.php";
$importfile = ilObjTest::_getImportDirectory() . "/" . $mob["uri"];
}
else
{
include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
$importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
}
$media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
$questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
foreach ($feedbacksgeneric as $correctness => $material)
{
$feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
}
}
}
$this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
foreach ($feedbacksgeneric as $correctness => $material)
{
$this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
}
$this->object->saveToDb();
if ($tst_id > 0)
{
$q_1_id = $this->object->getId();
$question_id = $this->object->duplicate(true);
$tst_object->questions[$question_counter++] = $question_id;
$import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
}
else
{
$import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
}
$this->safeTempToDB();
}

+ Here is the call graph for this function:

assMatchingQuestionImport::safeTempToDB ( )
private

Definition at line 375 of file class.assMatchingQuestionImport.php.

References $data, and $ilDB.

Referenced by fromXML().

{
global $ilDB;
$oldIDExists = false;
//Get the columns of qpl_a_mterm an check if the column 'old_id' already exists
$checkResult = $ilDB->query("SHOW COLUMNS FROM qpl_a_mterm");
if ($checkResult->numRows() > 0)
{
while ($data = $ilDB->fetchAssoc($checkResult))
{
if($data['field']=='old_id')
{
$oldIDExists=true;
}
}
}
// If it does exist, get rid of it!
// if($oldIDExists)
// {
// $ilDB->dropTableColumn("qpl_a_mterm", "old_id");
// }
//Now we create the temporal column to hold the old Term-IDs
if(!$oldIDExists)
{
$ilDB->addTableColumn("qpl_a_mterm", "old_id",
array("type" => "integer", "length" => 4));
}
//Get the data stored within the table for the current question
$changeResult = $ilDB->queryF("SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
array('integer'),
array($this->object->id)
);
//Write for each retrieved row the corresponding old ID from the masterTermIDs Array into the new column
$newTerms=array();
if ($changeResult->numRows() > 0)
{
while ($data = $ilDB->fetchAssoc($changeResult))
{
$data['old_id']=array_search($data['term_id'], $this->object->masterTermIDs);
array_push($newTerms, $data);
}
foreach ($newTerms as $singleTerm)
{
$ilDB->update("qpl_a_mterm", array(
"old_id" =>array("integer", $singleTerm['old_id'])),
array(
"term_id" =>array("integer", $singleTerm['term_id']),
"question_fi" =>array("integer", $singleTerm['question_fi'])
));
}
}
}

+ Here is the caller graph for this function:

assMatchingQuestionImport::saveImage (   $data,
  $filename 
)

Definition at line 37 of file class.assMatchingQuestionImport.php.

References $data, $filename, and ilUtil\makeDirParents().

Referenced by fromXML().

{
$image =& base64_decode($data);
$imagepath = $this->object->getImagePath();
include_once "./Services/Utilities/classes/class.ilUtil.php";
if (!file_exists($imagepath))
{
}
$imagepath .= $filename;
$fh = fopen($imagepath, "wb");
if ($fh == false)
{
}
else
{
$imagefile = fwrite($fh, $image);
fclose($fh);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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