Public Member Functions

assJavaAppletImport Class Reference
[Modules/TestQuestionPool]

Class for java applet question imports. More...

Inheritance diagram for assJavaAppletImport:
Collaboration diagram for assJavaAppletImport:

Public Member Functions

 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file.

Detailed Description

Class for java applet question imports.

assJavaAppletImport is a class for java applet question imports

Author:
Helmut Schottmüller <helmut.schottmueller@mac.com>
Version:
$Id$

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


Member Function Documentation

assJavaAppletImport::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 $item The QTI item object
integer $questionpool_id The id of the parent questionpool
integer $tst_id The id of the parent test if the question is part of a test
object $tst_object A reference to the parent test object
integer $question_counter A reference to a question counter to count the questions of an imported question pool
array $import_mapping An array containing references to included ILIAS objects public

Reimplemented from assQuestionImport.

Definition at line 50 of file class.assJavaAppletImport.php.

References $_SESSION, ilObjQuestionPool::_getImportDirectory(), ilObjTest::_getImportDirectory(), ilRTE::_replaceMediaObjectImageSrc(), ilObjMediaObject::_saveTempFileAsMediaObject(), ilObjMediaObject::_saveUsage(), getContent(), and ilUtil::makeDirParents().

        {
                global $ilUser;

                // empty session variable for imported xhtml mobs
                unset($_SESSION["import_mob_xhtml"]);
                $presentation = $item->getPresentation(); 
                $duration = $item->getDuration();
                $now = getdate();
                $applet = NULL;
                $maxpoints = 0;
                $javacode = "";
                $javacodebase = "";
                $javaarchive = "";
                $params = array();
                $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
                $answers = array();
                foreach ($presentation->order as $entry)
                {
                        switch ($entry["type"])
                        {
                                case "material":
                                        $material = $presentation->material[$entry["index"]];
                                        for ($i = 0; $i < $material->getMaterialCount(); $i++)
                                        {
                                                $mat = $material->getMaterial($i);
                                                if (strcmp($mat["type"], "mattext") == 0)
                                                {
                                                        $mattext = $mat["material"];
                                                        if ((strlen($mattext->getLabel()) == 0) && (strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0))
                                                        {
                                                                $item->setQuestiontext($mattext->getContent());
                                                        }
                                                        if (strcmp($mattext->getLabel(), "points") == 0)
                                                        {
                                                                $maxpoints = $mattext->getContent();
                                                        }
                                                        else if (strcmp($mattext->getLabel(), "java_code") == 0)
                                                        {
                                                                $javacode = $mattext->getContent();
                                                        }
                                                        else if (strcmp($mattext->getLabel(), "java_codebase") == 0)
                                                        {
                                                                $javacodebase = $mattext->getContent();
                                                        }
                                                        else if (strcmp($mattext->getLabel(), "java_archive") == 0)
                                                        {
                                                                $javaarchive = $mattext->getContent();
                                                        }
                                                        else if (strlen($mattext->getLabel()) > 0)
                                                        {
                                                                array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
                                                        }
                                                }
                                                elseif (strcmp($mat["type"], "matapplet") == 0)
                                                {
                                                        $applet = $mat["material"];
                                                }
                                        }
                                        break;
                        }
                }

                $feedbacksgeneric = array();
                foreach ($item->resprocessing as $resprocessing)
                {
                        foreach ($resprocessing->respcondition as $respcondition)
                        {
                                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;
                                                                                        }
                                                                                }
                                                                        }
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }

                $this->object->setTitle($item->getTitle());
                $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"]);
                $this->object->setJavaAppletFilename($applet->getUri());
                $this->object->setJavaWidth($applet->getWidth());
                $this->object->setJavaHeight($applet->getHeight());
                $this->object->setJavaCode($javacode);
                $this->object->setJavaCodebase($javacodebase);
                $this->object->setJavaArchive($javaarchive);
                $this->object->setPoints($maxpoints);
                foreach ($params as $pair)
                {
                        $this->object->addParameter($pair["key"], $pair["value"]);
                }
                $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();
                }
                $javaapplet =& base64_decode($applet->getContent());
                $javapath = $this->object->getJavaPath();
                if (!file_exists($javapath))
                {
                        include_once "./Services/Utilities/classes/class.ilUtil.php";
                        ilUtil::makeDirParents($javapath);
                }
                $javapath .=  $this->object->getJavaAppletFilename();
                $fh = fopen($javapath, "wb");
                if ($fh == false)
                {
//                                                                      global $ilErr;
//                                                                      $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
//                                                                      return;
                }
                else
                {
                        $javafile = fwrite($fh, $javaapplet);
                        fclose($fh);
                }
                // handle the import of media objects in XHTML code
                foreach ($feedbacksgeneric as $correctness => $material)
                {
                        $m = $this->object->QTIMaterialToString($material);
                        $feedbacksgeneric[$correctness] = $m;
                }
                $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() . "/" . $_SESSION["tst_import_subdir"] . "/" . $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);
                }
        }

Here is the call graph for this function:


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