00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 require_once "./assessment/classes/class.assQuestion.php";
00024
00025 define ("JAVAAPPLET_QUESTION_IDENTIFIER", "JAVA APPLET QUESTION");
00026
00037 class ASS_JavaApplet extends ASS_Question
00038 {
00046 var $question;
00047
00055 var $javaapplet_filename;
00056
00064 var $java_code;
00065
00073 var $java_width;
00074
00082 var $java_height;
00083
00091 var $parameters;
00092
00100 var $points;
00101
00117 function ASS_JavaApplet(
00118 $title = "",
00119 $comment = "",
00120 $author = "",
00121 $owner = -1,
00122 $question = "",
00123 $javaapplet_filename = ""
00124 )
00125 {
00126 $this->ASS_Question($title, $comment, $author, $owner);
00127 $this->question = $question;
00128 $this->javaapplet_filename = $javaapplet_filename;
00129 $this->parameters = array();
00130 }
00131
00132
00142 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false)
00143 {
00144 if (!empty($this->domxml))
00145 {
00146 $this->domxml->free();
00147 }
00148 $xml_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<questestinterop></questestinterop>\n";
00149 $this->domxml = domxml_open_mem($xml_header);
00150 $root = $this->domxml->document_element();
00151
00152
00153 $qtiComment = $this->domxml->create_element("qticomment");
00154
00155
00156 $qtiIdent = $this->domxml->create_element("item");
00157 $qtiIdent->set_attribute("ident", "il_".IL_INST_ID."_qst_".$this->getId());
00158 $qtiIdent->set_attribute("title", $this->getTitle());
00159 $root->append_child($qtiIdent);
00160
00161
00162 $qtiComment = $this->domxml->create_element("qticomment");
00163 $qtiCommentText = $this->domxml->create_text_node($this->getComment());
00164 $qtiComment->append_child($qtiCommentText);
00165 $qtiIdent->append_child($qtiComment);
00166
00167
00168 $qtiDuration = $this->domxml->create_element("duration");
00169 $workingtime = $this->getEstimatedWorkingTime();
00170 $qtiDurationText = $this->domxml->create_text_node(sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]));
00171 $qtiDuration->append_child($qtiDurationText);
00172 $qtiIdent->append_child($qtiDuration);
00173
00174
00175 $qtiItemmetadata = $this->domxml->create_element("itemmetadata");
00176 $qtiMetadata = $this->domxml->create_element("qtimetadata");
00177
00178 $qtiMetadatafield = $this->domxml->create_element("qtimetadatafield");
00179 $qtiFieldlabel = $this->domxml->create_element("fieldlabel");
00180 $qtiFieldlabelText = $this->domxml->create_text_node("ILIAS_VERSION");
00181 $qtiFieldlabel->append_child($qtiFieldlabelText);
00182 $qtiFieldentry = $this->domxml->create_element("fieldentry");
00183 $qtiFieldentryText = $this->domxml->create_text_node($this->ilias->getSetting("ilias_version"));
00184 $qtiFieldentry->append_child($qtiFieldentryText);
00185 $qtiMetadatafield->append_child($qtiFieldlabel);
00186 $qtiMetadatafield->append_child($qtiFieldentry);
00187 $qtiMetadata->append_child($qtiMetadatafield);
00188
00189 $qtiMetadatafield = $this->domxml->create_element("qtimetadatafield");
00190 $qtiFieldlabel = $this->domxml->create_element("fieldlabel");
00191 $qtiFieldlabelText = $this->domxml->create_text_node("QUESTIONTYPE");
00192 $qtiFieldlabel->append_child($qtiFieldlabelText);
00193 $qtiFieldentry = $this->domxml->create_element("fieldentry");
00194 $qtiFieldentryText = $this->domxml->create_text_node(JAVAAPPLET_QUESTION_IDENTIFIER);
00195 $qtiFieldentry->append_child($qtiFieldentryText);
00196 $qtiMetadatafield->append_child($qtiFieldlabel);
00197 $qtiMetadatafield->append_child($qtiFieldentry);
00198 $qtiMetadata->append_child($qtiMetadatafield);
00199
00200 $qtiMetadatafield = $this->domxml->create_element("qtimetadatafield");
00201 $qtiFieldlabel = $this->domxml->create_element("fieldlabel");
00202 $qtiFieldlabelText = $this->domxml->create_text_node("AUTHOR");
00203 $qtiFieldlabel->append_child($qtiFieldlabelText);
00204 $qtiFieldentry = $this->domxml->create_element("fieldentry");
00205 $qtiFieldentryText = $this->domxml->create_text_node($this->getAuthor());
00206 $qtiFieldentry->append_child($qtiFieldentryText);
00207 $qtiMetadatafield->append_child($qtiFieldlabel);
00208 $qtiMetadatafield->append_child($qtiFieldentry);
00209 $qtiMetadata->append_child($qtiMetadatafield);
00210
00211 $qtiItemmetadata->append_child($qtiMetadata);
00212 $qtiIdent->append_child($qtiItemmetadata);
00213
00214
00215 $qtiPresentation = $this->domxml->create_element("presentation");
00216 $qtiPresentation->set_attribute("label", $this->getTitle());
00217
00218
00219 $qtiFlow = $this->domxml->create_element("flow");
00220
00221
00222 $qtiMaterial = $this->domxml->create_element("material");
00223 $qtiMatText = $this->domxml->create_element("mattext");
00224 $qtiMatTextText = $this->domxml->create_text_node($this->getQuestion());
00225 $qtiMatText->append_child($qtiMatTextText);
00226 $qtiMaterial->append_child($qtiMatText);
00227 $qtiFlow->append_child($qtiMaterial);
00228
00229 $solution = $this->getSuggestedSolution(0);
00230 if (count($solution))
00231 {
00232 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00233 {
00234 $qtiMaterial = $this->domxml->create_element("material");
00235 $qtiMaterial->set_attribute("label", "suggested_solution");
00236 $qtiMatText = $this->domxml->create_element("mattext");
00237 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00238 if (strcmp($matches[1], "") != 0)
00239 {
00240 $intlink = $solution["internal_link"];
00241 }
00242 $qtiMatTextText = $this->domxml->create_text_node($intlink);
00243 $qtiMatText->append_child($qtiMatTextText);
00244 $qtiMaterial->append_child($qtiMatText);
00245 $qtiFlow->append_child($qtiMaterial);
00246 }
00247 }
00248
00249 $qtiMaterial = $this->domxml->create_element("material");
00250 $qtiMatApplet = $this->domxml->create_element("matapplet");
00251 $qtiMatApplet->set_attribute("label", "applet data");
00252 $qtiMatApplet->set_attribute("uri", $this->getJavaAppletFilename());
00253 $qtiMatApplet->set_attribute("height", $this->getJavaHeight());
00254 $qtiMatApplet->set_attribute("width", $this->getJavaWidth());
00255 $qtiMatApplet->set_attribute("embedded", "base64");
00256 $javapath = $this->getJavaPath() . $this->getJavaAppletFilename();
00257 $fh = @fopen($javapath, "rb");
00258 if ($fh == false)
00259 {
00260
00261
00262 return;
00263 }
00264 $javafile = fread($fh, filesize($javapath));
00265 fclose($fh);
00266 $base64 = base64_encode($javafile);
00267 $qtiBase64Data = $this->domxml->create_text_node($base64);
00268 $qtiMatApplet->append_child($qtiBase64Data);
00269 $qtiMaterial->append_child($qtiMatApplet);
00270 if ($this->buildParamsOnly())
00271 {
00272 if ($this->java_code)
00273 {
00274 $qtiMatText = $this->domxml->create_element("mattext");
00275 $qtiMatText->set_attribute("label", "java_code");
00276 $qtiAppletParams = $this->domxml->create_text_node($this->java_code);
00277 $qtiMatText->append_child($qtiAppletParams);
00278 $qtiMaterial->append_child($qtiMatText);
00279 }
00280 foreach ($this->parameters as $key => $value)
00281 {
00282 $qtiMatText = $this->domxml->create_element("mattext");
00283 $qtiMatText->set_attribute("label", $value["name"]);
00284 $qtiAppletParams = $this->domxml->create_text_node($value["value"]);
00285 $qtiMatText->append_child($qtiAppletParams);
00286 $qtiMaterial->append_child($qtiMatText);
00287 }
00288 if ($test_output)
00289 {
00290 require_once "./assessment/classes/class.ilObjTest.php";
00291 $qtiMatText = $this->domxml->create_element("mattext");
00292 $qtiMatText->set_attribute("label", "test_type");
00293 $qtiAppletParams = $this->domxml->create_text_node(ilObjTest::_getTestType($test_output));
00294 $qtiMatText->append_child($qtiAppletParams);
00295 $qtiMaterial->append_child($qtiMatText);
00296 $qtiMatText = $this->domxml->create_element("mattext");
00297 $qtiMatText->set_attribute("label", "test_id");
00298 $qtiAppletParams = $this->domxml->create_text_node($test_output);
00299 $qtiMatText->append_child($qtiAppletParams);
00300 $qtiMaterial->append_child($qtiMatText);
00301 $qtiMatText = $this->domxml->create_element("mattext");
00302 $qtiMatText->set_attribute("label", "question_id");
00303 $qtiAppletParams = $this->domxml->create_text_node($this->getId());
00304 $qtiMatText->append_child($qtiAppletParams);
00305 $qtiMaterial->append_child($qtiMatText);
00306 $qtiMatText = $this->domxml->create_element("mattext");
00307 $qtiMatText->set_attribute("label", "user_id");
00308 global $ilUser;
00309 $qtiAppletParams = $this->domxml->create_text_node($ilUser->id);
00310 $qtiMatText->append_child($qtiAppletParams);
00311 $qtiMaterial->append_child($qtiMatText);
00312 $qtiMatText = $this->domxml->create_element("mattext");
00313 $qtiMatText->set_attribute("label", "points_max");
00314 $qtiAppletParams = $this->domxml->create_text_node($this->getPoints());
00315 $qtiMatText->append_child($qtiAppletParams);
00316 $qtiMaterial->append_child($qtiMatText);
00317 $qtiMatText = $this->domxml->create_element("mattext");
00318 $qtiMatText->set_attribute("label", "post_url");
00319 $qtiAppletParams = $this->domxml->create_text_node(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/assessment/save_java_question_result.php");
00320 $qtiMatText->append_child($qtiAppletParams);
00321 $qtiMaterial->append_child($qtiMatText);
00322 $info = $this->getReachedInformation($ilUser->id, $test_output);
00323 foreach ($info as $kk => $infodata)
00324 {
00325 $qtiMatText->append_child($qtiAppletParams);
00326 $qtiMaterial->append_child($qtiMatText);
00327 $qtiMatText = $this->domxml->create_element("mattext");
00328 $qtiMatText->set_attribute("label", "value_" . $infodata["order"] . "_1");
00329 $qtiAppletParams = $this->domxml->create_text_node($infodata["value1"]);
00330 $qtiMatText->append_child($qtiAppletParams);
00331 $qtiMaterial->append_child($qtiMatText);
00332 $qtiMatText->append_child($qtiAppletParams);
00333 $qtiMaterial->append_child($qtiMatText);
00334 $qtiMatText = $this->domxml->create_element("mattext");
00335 $qtiMatText->set_attribute("label", "value_" . $infodata["order"] . "_2");
00336 $qtiAppletParams = $this->domxml->create_text_node($infodata["value2"]);
00337 $qtiMatText->append_child($qtiAppletParams);
00338 $qtiMaterial->append_child($qtiMatText);
00339 }
00340 }
00341 }
00342
00343 $qtiFlow->append_child($qtiMaterial);
00344
00345
00346 $qtiMaterial = $this->domxml->create_element("material");
00347 $qtiMatText = $this->domxml->create_element("mattext");
00348 $qtiMatText->set_attribute("label", "points");
00349 $qtiMatTextText = $this->domxml->create_text_node($this->getPoints());
00350 $qtiMatText->append_child($qtiMatTextText);
00351 $qtiMaterial->append_child($qtiMatText);
00352 $qtiFlow->append_child($qtiMaterial);
00353
00354 $qtiPresentation->append_child($qtiFlow);
00355 $qtiIdent->append_child($qtiPresentation);
00356
00357 $xml = $this->domxml->dump_mem(true);
00358 if (!$a_include_header)
00359 {
00360 $pos = strpos($xml, "?>");
00361 $xml = substr($xml, $pos + 2);
00362 }
00363
00364 return $xml;
00365
00366 }
00367
00377 function from_xml($xml_text)
00378 {
00379 $result = false;
00380 if (!empty($this->domxml))
00381 {
00382 $this->domxml->free();
00383 }
00384 $xml_text = preg_replace("/>\s*?</", "><", $xml_text);
00385 $this->domxml = domxml_open_mem($xml_text);
00386 if (!empty($this->domxml))
00387 {
00388 $root = $this->domxml->document_element();
00389 $item = $root->first_child();
00390 $this->setTitle($item->get_attribute("title"));
00391 $this->gaps = array();
00392 $itemnodes = $item->child_nodes();
00393 $materials = array();
00394 $images = array();
00395 $shuffle = "";
00396 foreach ($itemnodes as $index => $node)
00397 {
00398 switch ($node->node_name())
00399 {
00400 case "qticomment":
00401 $comment = $node->get_content();
00402 if (strpos($comment, "ILIAS Version=") !== false)
00403 {
00404 }
00405 elseif (strpos($comment, "Questiontype=") !== false)
00406 {
00407 }
00408 elseif (strpos($comment, "Author=") !== false)
00409 {
00410 $comment = str_replace("Author=", "", $comment);
00411 $this->setAuthor($comment);
00412 }
00413 else
00414 {
00415 $this->setComment($comment);
00416 }
00417 break;
00418 case "itemmetadata":
00419 $md_array = array();
00420 $metanodes = $node->child_nodes();
00421 foreach ($metanodes as $metanode)
00422 {
00423 switch ($metanode->node_name())
00424 {
00425 case "qtimetadata":
00426 $metafields = $metanode->child_nodes();
00427 foreach ($metafields as $metafield)
00428 {
00429 switch ($metafield->node_name())
00430 {
00431 case "qtimetadatafield":
00432 $metafieldlist = $metafield->child_nodes();
00433 $md = array("label" => "", "entry" => "");
00434 foreach ($metafieldlist as $attr)
00435 {
00436 switch ($attr->node_name())
00437 {
00438 case "fieldlabel":
00439 $md["label"] = $attr->get_content();
00440 break;
00441 case "fieldentry":
00442 $md["entry"] = $attr->get_content();
00443 break;
00444 }
00445 }
00446 array_push($md_array, $md);
00447 break;
00448 }
00449 }
00450 break;
00451 }
00452 }
00453 foreach ($md_array as $md)
00454 {
00455 switch ($md["label"])
00456 {
00457 case "ILIAS_VERSION":
00458 break;
00459 case "QUESTIONTYPE":
00460 break;
00461 case "AUTHOR":
00462 $this->setAuthor($md["entry"]);
00463 break;
00464 }
00465 }
00466 break;
00467 case "duration":
00468 $iso8601period = $node->get_content();
00469 if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $iso8601period, $matches))
00470 {
00471 $this->setEstimatedWorkingTime($matches[4], $matches[5], $matches[6]);
00472 }
00473 break;
00474 case "presentation":
00475 $flow = $node->first_child();
00476 $flownodes = $flow->child_nodes();
00477 foreach ($flownodes as $idx => $flownode)
00478 {
00479 if (strcmp($flownode->node_name(), "material") == 0)
00480 {
00481 $childnodes = $flownode->child_nodes();
00482 foreach ($childnodes as $childnodeindex => $childnode)
00483 {
00484 if (strcmp($childnode->get_attribute("label"), "suggested_solution") == 0)
00485 {
00486 $mattype = $childnode->first_child();
00487 if (strcmp($mattype->node_name(), "mattext") == 0)
00488 {
00489 $suggested_solution = $mattype->get_content();
00490 if ($suggested_solution)
00491 {
00492 if ($this->getId() < 1)
00493 {
00494 $this->saveToDb();
00495 }
00496 $this->setSuggestedSolution($suggested_solution, 0, true);
00497 }
00498 }
00499 }
00500 elseif (strcmp($childnode->node_name(), "mattext") == 0)
00501 {
00502 if (!$childnode->has_attribute("label"))
00503 {
00504 $this->setQuestion($childnode->get_content());
00505 }
00506 elseif (strcmp($childnode->get_attribute("label"), "points") == 0)
00507 {
00508 $this->setPoints($childnode->get_content());
00509 }
00510 elseif (strcmp($childnode->get_attribute("label"), "java_code") == 0)
00511 {
00512 $this->java_code = $childnode->get_content();
00513 }
00514 elseif (strcmp($childnode->get_attribute("label"), "") != 0)
00515 {
00516 $this->addParameter($childnode->get_attribute("label"), $childnode->get_content());
00517 }
00518 }
00519 elseif (strcmp($childnode->node_name(), "matapplet") == 0)
00520 {
00521 if (strcmp($childnode->get_attribute("label"), "applet data") == 0)
00522 {
00523 $this->javaapplet_filename = $childnode->get_attribute("uri");
00524 $this->java_height = $childnode->get_attribute("height");
00525 $this->java_width = $childnode->get_attribute("width");
00526 $java = base64_decode($childnode->get_content());
00527 }
00528 }
00529 }
00530 }
00531 }
00532 break;
00533 }
00534 }
00535 if ($this->javaapplet_filename)
00536 {
00537 $this->saveToDb();
00538 $javapath = $this->getJavaPath();
00539 if (!file_exists($javapath))
00540 {
00541 ilUtil::makeDirParents($javapath);
00542 }
00543 $javapath .= $this->javaapplet_filename;
00544 $fh = fopen($javapath, "wb");
00545 if ($fh == false)
00546 {
00547 global $ilErr;
00548 $ilErr->raiseError($this->lng->txt("error_save_java_file") . ": $php_errormsg", $ilErr->MESSAGE);
00549 return;
00550 }
00551 $javafile = fwrite($fh, $java);
00552 fclose($fh);
00553 }
00554 $result = true;
00555 }
00556 return $result;
00557 }
00558
00559
00568 function splitParams($params = "")
00569 {
00570 $params_array = split("<separator>", $params);
00571 foreach ($params_array as $pair)
00572 {
00573 if (preg_match("/(.*?)\=(.*)/", $pair, $matches))
00574 {
00575 switch ($matches[1])
00576 {
00577 case "java_code" :
00578 $this->java_code = $matches[2];
00579 break;
00580 case "java_width" :
00581 $this->java_width = $matches[2];
00582 break;
00583 case "java_height" :
00584 $this->java_height = $matches[2];
00585 break;
00586 }
00587 if (preg_match("/param_name_(\d+)/", $matches[1], $found_key))
00588 {
00589 $this->parameters[$found_key[1]]["name"] = $matches[2];
00590 }
00591 if (preg_match("/param_value_(\d+)/", $matches[1], $found_key))
00592 {
00593 $this->parameters[$found_key[1]]["value"] = $matches[2];
00594 }
00595 }
00596 }
00597 }
00598
00607 function buildParams()
00608 {
00609 $params_array = array();
00610 if ($this->java_code)
00611 {
00612 array_push($params_array, "java_code=$this->java_code");
00613 }
00614 if ($this->java_width)
00615 {
00616 array_push($params_array, "java_width=$this->java_width");
00617 }
00618 if ($this->java_height)
00619 {
00620 array_push($params_array, "java_height=$this->java_height");
00621 }
00622 foreach ($this->parameters as $key => $value)
00623 {
00624 array_push($params_array, "param_name_$key=" . $value["name"]);
00625 array_push($params_array, "param_value_$key=" . $value["value"]);
00626 }
00627 return join($params_array, "<separator>");
00628 }
00629
00638 function buildParamsOnly()
00639 {
00640 $params_array = array();
00641 if ($this->java_code)
00642 {
00643 array_push($params_array, "java_code=$this->java_code");
00644 }
00645 foreach ($this->parameters as $key => $value)
00646 {
00647 array_push($params_array, "param_name_$key=" . $value["name"]);
00648 array_push($params_array, "param_value_$key=" . $value["value"]);
00649 }
00650 return join($params_array, "<separator>");
00651 }
00652
00661 function isComplete()
00662 {
00663 if (($this->title) and ($this->author) and ($this->question) and ($this->javaapplet_filename) and ($this->java_width) and ($this->java_height) and ($this->points != ""))
00664 {
00665 return true;
00666 }
00667 else
00668 {
00669 return false;
00670 }
00671 }
00672
00673
00682 function saveToDb($original_id = "")
00683 {
00684 global $ilias;
00685
00686 $complete = 0;
00687 if ($this->isComplete())
00688 {
00689 $complete = 1;
00690 }
00691
00692 $db = & $ilias->db;
00693
00694 $params = $this->buildParams();
00695 $estw_time = $this->getEstimatedWorkingTime();
00696 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00697
00698 if ($original_id)
00699 {
00700 $original_id = $db->quote($original_id);
00701 }
00702 else
00703 {
00704 $original_id = "NULL";
00705 }
00706
00707 if ($this->id == -1)
00708 {
00709
00710 $now = getdate();
00711 $question_type = $this->getQuestionType();
00712 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00713 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, shuffle, complete, image_file, params, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00714 $db->quote($question_type . ""),
00715 $db->quote($this->obj_id . ""),
00716 $db->quote($this->title . ""),
00717 $db->quote($this->comment . ""),
00718 $db->quote($this->author . ""),
00719 $db->quote($this->owner . ""),
00720 $db->quote($this->question . ""),
00721 $db->quote($this->points . ""),
00722 $db->quote($estw_time . ""),
00723 $db->quote($this->shuffle . ""),
00724 $db->quote($complete . ""),
00725 $db->quote($this->javaapplet_filename . ""),
00726 $db->quote($params . ""),
00727 $db->quote($created . ""),
00728 $original_id
00729 );
00730
00731 $result = $db->query($query);
00732 if ($result == DB_OK)
00733 {
00734 $this->id = $this->ilias->db->getLastInsertId();
00735
00736
00737 $this->createPageObject();
00738
00739
00740 if ($this->getTestId() > 0)
00741 {
00742 $this->insertIntoTest($this->getTestId());
00743 }
00744 }
00745 }
00746 else
00747 {
00748
00749 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, shuffle = %s, complete = %s, image_file = %s, params = %s WHERE question_id = %s",
00750 $db->quote($this->obj_id. ""),
00751 $db->quote($this->title . ""),
00752 $db->quote($this->comment . ""),
00753 $db->quote($this->author . ""),
00754 $db->quote($this->question . ""),
00755 $db->quote($this->points . ""),
00756 $db->quote($estw_time . ""),
00757 $db->quote($this->shuffle . ""),
00758 $db->quote($complete . ""),
00759 $db->quote($this->javaapplet_filename . ""),
00760 $db->quote($params . ""),
00761 $db->quote($this->id . "")
00762 );
00763 $result = $db->query($query);
00764 }
00765 parent::saveToDb($original_id);
00766 }
00767
00777 function loadFromDb($question_id)
00778 {
00779 global $ilias;
00780
00781 $db = & $ilias->db;
00782 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
00783 $db->quote($question_id)
00784 );
00785 $result = $db->query($query);
00786
00787 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00788 {
00789 if ($result->numRows() == 1)
00790 {
00791 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00792 $this->id = $question_id;
00793 $this->title = $data->title;
00794 $this->comment = $data->comment;
00795 $this->obj_id = $data->obj_fi;
00796 $this->author = $data->author;
00797 $this->points = $data->points;
00798 $this->owner = $data->owner;
00799 $this->original_id = $data->original_id;
00800 $this->javaapplet_filename = $data->image_file;
00801 $this->question = $data->question_text;
00802 $this->solution_hint = $data->solution_hint;
00803 $this->splitParams($data->params);
00804 $this->setShuffle($data->shuffle);
00805 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00806 }
00807 }
00808 parent::loadFromDb($question_id);
00809 }
00810
00818 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00819 {
00820 if ($this->id <= 0)
00821 {
00822
00823 return;
00824 }
00825
00826 $clone = $this;
00827 include_once ("./assessment/classes/class.assQuestion.php");
00828 $original_id = ASS_Question::_getOriginalId($this->id);
00829 $clone->id = -1;
00830 if ($title)
00831 {
00832 $clone->setTitle($title);
00833 }
00834 if ($author)
00835 {
00836 $clone->setAuthor($author);
00837 }
00838 if ($owner)
00839 {
00840 $clone->setOwner($owner);
00841 }
00842 if ($for_test)
00843 {
00844 $clone->saveToDb($original_id);
00845 }
00846 else
00847 {
00848 $clone->saveToDb();
00849 }
00850
00851
00852 $clone->copyPageOfQuestion($original_id);
00853
00854
00855 $clone->duplicateApplet($original_id);
00856 return $clone->id;
00857 }
00858
00859 function duplicateApplet($question_id)
00860 {
00861 $javapath = $this->getJavaPath();
00862 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00863 if (!file_exists($javapath))
00864 {
00865 ilUtil::makeDirParents($javapath);
00866 }
00867 $filename = $this->getJavaAppletFilename();
00868 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00869 print "java applet could not be duplicated!!!! ";
00870 }
00871 }
00872
00882 function getQuestion()
00883 {
00884 return $this->question;
00885 }
00886
00896 function getPoints()
00897 {
00898 return $this->points;
00899 }
00900
00910 function setQuestion($question = "")
00911 {
00912 $this->question = $question;
00913 }
00914
00923 function getMaximumPoints()
00924 {
00925 return $this->points;
00926 }
00927
00936 function getJavaCode()
00937 {
00938 return $this->java_code;
00939 }
00940
00949 function setJavaCode($java_code = "")
00950 {
00951 $this->java_code = $java_code;
00952 }
00953
00962 function getJavaWidth()
00963 {
00964 return $this->java_width;
00965 }
00966
00975 function setPoints($points = 0.0)
00976 {
00977 $this->points = $points;
00978 }
00979
00988 function setJavaWidth($java_width = "")
00989 {
00990 $this->java_width = $java_width;
00991 }
00992
01001 function getJavaHeight()
01002 {
01003 return $this->java_height;
01004 }
01005
01014 function setJavaHeight($java_height = "")
01015 {
01016 $this->java_height = $java_height;
01017 }
01018
01028 function getReachedPoints($user_id, $test_id)
01029 {
01030 $found_values = array();
01031 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
01032 $this->ilias->db->quote($user_id),
01033 $this->ilias->db->quote($test_id),
01034 $this->ilias->db->quote($this->getId())
01035 );
01036 $result = $this->ilias->db->query($query);
01037 $points = 0;
01038 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01039 {
01040 $points += $data->points;
01041 }
01042 return $points;
01043 }
01044
01054 function getReachedInformation($user_id, $test_id)
01055 {
01056 $found_values = array();
01057 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
01058 $this->ilias->db->quote($user_id),
01059 $this->ilias->db->quote($test_id),
01060 $this->ilias->db->quote($this->getId())
01061 );
01062 $result = $this->ilias->db->query($query);
01063 $counter = 1;
01064 $user_result = array();
01065 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01066 {
01067 $true = 0;
01068 if ($data->points > 0)
01069 {
01070 $true = 1;
01071 }
01072 $solution = array(
01073 "order" => "$counter",
01074 "points" => "$data->points",
01075 "true" => "$true",
01076 "value1" => "$data->value1",
01077 "value2" => "$data->value2",
01078 );
01079 $counter++;
01080 array_push($user_result, $solution);
01081 }
01082 return $user_result;
01083 }
01084
01095 function addParameter($name = "", $value = "")
01096 {
01097 $index = $this->getParameterIndex($name);
01098 if ($index > -1)
01099 {
01100 $this->parameters[$index] = array("name" => $name, "value" => $value);
01101 }
01102 else
01103 {
01104 array_push($this->parameters, array("name" => $name, "value" => $value));
01105 }
01106 }
01107
01119 function addParameterAtIndex($index = 0, $name = "", $value = "")
01120 {
01121 $this->parameters[$index] = array("name" => $name, "value" => $value);
01122 }
01123
01133 function removeParameter($name)
01134 {
01135 foreach ($this->parameters as $key => $value)
01136 {
01137 if (strcmp($name, $value["name"]) == 0)
01138 {
01139 array_splice($this->parameters, $key, 1);
01140 return;
01141 }
01142 }
01143 }
01144
01155 function getParameter($index)
01156 {
01157 if (($index < 0) or ($index >= count($this->parameters)))
01158 {
01159 return undef;
01160 }
01161 return $this->parameters[$index];
01162 }
01163
01174 function getParameterIndex($name)
01175 {
01176 foreach ($this->parameters as $key => $value)
01177 {
01178 if (array_key_exists($name, $value))
01179 {
01180 return $key;
01181 }
01182 }
01183 return -1;
01184 }
01185
01195 function getParameterCount()
01196 {
01197 return count($this->parameters);
01198 }
01199
01208 function flushParams()
01209 {
01210 $this->parameters = array();
01211 }
01212
01223 function saveWorkingData($test_id, $limit_to = LIMIT_NO_LIMIT)
01224 {
01225 return true;
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274 }
01275
01285 function getJavaAppletFilename()
01286 {
01287 return $this->javaapplet_filename;
01288 }
01289
01299 function setJavaAppletFilename($javaapplet_filename, $javaapplet_tempfilename = "")
01300 {
01301 if (!empty($javaapplet_filename))
01302 {
01303 $this->javaapplet_filename = $javaapplet_filename;
01304 }
01305 if (!empty($javaapplet_tempfilename))
01306 {
01307 $javapath = $this->getJavaPath();
01308 if (!file_exists($javapath))
01309 {
01310 ilUtil::makeDirParents($javapath);
01311 }
01312
01313
01314 if (!ilUtil::moveUploadedFile($javaapplet_tempfilename, $javaapplet_filename, $javapath.$javaapplet_filename))
01315 {
01316 print "java applet not uploaded!!!! ";
01317 }
01318 }
01319 }
01320
01321 function syncWithOriginal()
01322 {
01323 global $ilias;
01324 if ($this->original_id)
01325 {
01326 $complete = 0;
01327 if ($this->isComplete())
01328 {
01329 $complete = 1;
01330 }
01331 $db = & $ilias->db;
01332
01333 $estw_time = $this->getEstimatedWorkingTime();
01334 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
01335
01336 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, shuffle = %s, complete = %s, image_file = %s, params = %s WHERE question_id = %s",
01337 $db->quote($this->obj_id. ""),
01338 $db->quote($this->title . ""),
01339 $db->quote($this->comment . ""),
01340 $db->quote($this->author . ""),
01341 $db->quote($this->question . ""),
01342 $db->quote($this->points . ""),
01343 $db->quote($estw_time . ""),
01344 $db->quote($this->shuffle . ""),
01345 $db->quote($complete . ""),
01346 $db->quote($this->javaapplet_filename . ""),
01347 $db->quote($params . ""),
01348 $db->quote($this->original_id . "")
01349 );
01350 $result = $db->query($query);
01351
01352 parent::syncWithOriginal();
01353 }
01354 }
01355
01364 function getQuestionType()
01365 {
01366 return 7;
01367 }
01368 }
01369
01370 ?>