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 $qtiComment = $this->domxml->create_element("qticomment");
00167 $qtiCommentText = $this->domxml->create_text_node("ILIAS Version=".$this->ilias->getSetting("ilias_version"));
00168 $qtiComment->append_child($qtiCommentText);
00169 $qtiIdent->append_child($qtiComment);
00170 $qtiComment = $this->domxml->create_element("qticomment");
00171 $qtiCommentText = $this->domxml->create_text_node("Questiontype=".JAVAAPPLET_QUESTION_IDENTIFIER);
00172 $qtiComment->append_child($qtiCommentText);
00173 $qtiIdent->append_child($qtiComment);
00174 $qtiComment = $this->domxml->create_element("qticomment");
00175 $qtiCommentText = $this->domxml->create_text_node("Author=".$this->getAuthor());
00176 $qtiComment->append_child($qtiCommentText);
00177 $qtiIdent->append_child($qtiComment);
00178
00179 $qtiDuration = $this->domxml->create_element("duration");
00180 $workingtime = $this->getEstimatedWorkingTime();
00181 $qtiDurationText = $this->domxml->create_text_node(sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]));
00182 $qtiDuration->append_child($qtiDurationText);
00183 $qtiIdent->append_child($qtiDuration);
00184
00185
00186 $qtiPresentation = $this->domxml->create_element("presentation");
00187 $qtiPresentation->set_attribute("label", $this->getTitle());
00188
00189
00190 $qtiFlow = $this->domxml->create_element("flow");
00191
00192
00193 $qtiMaterial = $this->domxml->create_element("material");
00194 $qtiMatText = $this->domxml->create_element("mattext");
00195 $qtiMatTextText = $this->domxml->create_text_node($this->getQuestion());
00196 $qtiMatText->append_child($qtiMatTextText);
00197 $qtiMaterial->append_child($qtiMatText);
00198 $qtiFlow->append_child($qtiMaterial);
00199
00200 $solution = $this->getSuggestedSolution(0);
00201 if (count($solution))
00202 {
00203 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00204 {
00205 $qtiMaterial = $this->domxml->create_element("material");
00206 $qtiMaterial->set_attribute("label", "suggested_solution");
00207 $qtiMatText = $this->domxml->create_element("mattext");
00208 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00209 if (strcmp($matches[1], "") != 0)
00210 {
00211 $intlink = $solution["internal_link"];
00212 }
00213 $qtiMatTextText = $this->domxml->create_text_node($intlink);
00214 $qtiMatText->append_child($qtiMatTextText);
00215 $qtiMaterial->append_child($qtiMatText);
00216 $qtiFlow->append_child($qtiMaterial);
00217 }
00218 }
00219
00220 $qtiMaterial = $this->domxml->create_element("material");
00221 $qtiMatApplet = $this->domxml->create_element("matapplet");
00222 $qtiMatApplet->set_attribute("label", "applet data");
00223 $qtiMatApplet->set_attribute("uri", $this->getJavaAppletFilename());
00224 $qtiMatApplet->set_attribute("height", $this->getJavaHeight());
00225 $qtiMatApplet->set_attribute("width", $this->getJavaWidth());
00226 $qtiMatApplet->set_attribute("embedded", "base64");
00227 $javapath = $this->getJavaPath() . $this->getJavaAppletFilename();
00228 $fh = @fopen($javapath, "rb");
00229 if ($fh == false)
00230 {
00231
00232
00233 return;
00234 }
00235 $javafile = fread($fh, filesize($javapath));
00236 fclose($fh);
00237 $base64 = base64_encode($javafile);
00238 $qtiBase64Data = $this->domxml->create_text_node($base64);
00239 $qtiMatApplet->append_child($qtiBase64Data);
00240 $qtiMaterial->append_child($qtiMatApplet);
00241 if ($this->buildParamsOnly())
00242 {
00243 if ($this->java_code)
00244 {
00245 $qtiMatText = $this->domxml->create_element("mattext");
00246 $qtiMatText->set_attribute("label", "java_code");
00247 $qtiAppletParams = $this->domxml->create_text_node($this->java_code);
00248 $qtiMatText->append_child($qtiAppletParams);
00249 $qtiMaterial->append_child($qtiMatText);
00250 }
00251 foreach ($this->parameters as $key => $value)
00252 {
00253 $qtiMatText = $this->domxml->create_element("mattext");
00254 $qtiMatText->set_attribute("label", $value["name"]);
00255 $qtiAppletParams = $this->domxml->create_text_node($value["value"]);
00256 $qtiMatText->append_child($qtiAppletParams);
00257 $qtiMaterial->append_child($qtiMatText);
00258 }
00259 if ($test_output)
00260 {
00261 require_once "./assessment/classes/class.ilObjTest.php";
00262 $qtiMatText = $this->domxml->create_element("mattext");
00263 $qtiMatText->set_attribute("label", "test_type");
00264 $qtiAppletParams = $this->domxml->create_text_node(ilObjTest::_getTestType($test_output));
00265 $qtiMatText->append_child($qtiAppletParams);
00266 $qtiMaterial->append_child($qtiMatText);
00267 $qtiMatText = $this->domxml->create_element("mattext");
00268 $qtiMatText->set_attribute("label", "test_id");
00269 $qtiAppletParams = $this->domxml->create_text_node($test_output);
00270 $qtiMatText->append_child($qtiAppletParams);
00271 $qtiMaterial->append_child($qtiMatText);
00272 $qtiMatText = $this->domxml->create_element("mattext");
00273 $qtiMatText->set_attribute("label", "question_id");
00274 $qtiAppletParams = $this->domxml->create_text_node($this->getId());
00275 $qtiMatText->append_child($qtiAppletParams);
00276 $qtiMaterial->append_child($qtiMatText);
00277 $qtiMatText = $this->domxml->create_element("mattext");
00278 $qtiMatText->set_attribute("label", "user_id");
00279 global $ilUser;
00280 $qtiAppletParams = $this->domxml->create_text_node($ilUser->id);
00281 $qtiMatText->append_child($qtiAppletParams);
00282 $qtiMaterial->append_child($qtiMatText);
00283 $qtiMatText = $this->domxml->create_element("mattext");
00284 $qtiMatText->set_attribute("label", "points_max");
00285 $qtiAppletParams = $this->domxml->create_text_node($this->getPoints());
00286 $qtiMatText->append_child($qtiAppletParams);
00287 $qtiMaterial->append_child($qtiMatText);
00288 $qtiMatText = $this->domxml->create_element("mattext");
00289 $qtiMatText->set_attribute("label", "post_url");
00290 $qtiAppletParams = $this->domxml->create_text_node(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/assessment/save_java_question_result.php");
00291 $qtiMatText->append_child($qtiAppletParams);
00292 $qtiMaterial->append_child($qtiMatText);
00293 $info = $this->getReachedInformation($ilUser->id, $test_output);
00294 foreach ($info as $kk => $infodata)
00295 {
00296 $qtiMatText->append_child($qtiAppletParams);
00297 $qtiMaterial->append_child($qtiMatText);
00298 $qtiMatText = $this->domxml->create_element("mattext");
00299 $qtiMatText->set_attribute("label", "value_" . $infodata["order"] . "_1");
00300 $qtiAppletParams = $this->domxml->create_text_node($infodata["value1"]);
00301 $qtiMatText->append_child($qtiAppletParams);
00302 $qtiMaterial->append_child($qtiMatText);
00303 $qtiMatText->append_child($qtiAppletParams);
00304 $qtiMaterial->append_child($qtiMatText);
00305 $qtiMatText = $this->domxml->create_element("mattext");
00306 $qtiMatText->set_attribute("label", "value_" . $infodata["order"] . "_2");
00307 $qtiAppletParams = $this->domxml->create_text_node($infodata["value2"]);
00308 $qtiMatText->append_child($qtiAppletParams);
00309 $qtiMaterial->append_child($qtiMatText);
00310 }
00311 }
00312 }
00313
00314 $qtiFlow->append_child($qtiMaterial);
00315
00316
00317 $qtiMaterial = $this->domxml->create_element("material");
00318 $qtiMatText = $this->domxml->create_element("mattext");
00319 $qtiMatText->set_attribute("label", "points");
00320 $qtiMatTextText = $this->domxml->create_text_node($this->getPoints());
00321 $qtiMatText->append_child($qtiMatTextText);
00322 $qtiMaterial->append_child($qtiMatText);
00323 $qtiFlow->append_child($qtiMaterial);
00324
00325 $qtiPresentation->append_child($qtiFlow);
00326 $qtiIdent->append_child($qtiPresentation);
00327
00328 $xml = $this->domxml->dump_mem(true);
00329 if (!$a_include_header)
00330 {
00331 $pos = strpos($xml, "?>");
00332 $xml = substr($xml, $pos + 2);
00333 }
00334
00335 return $xml;
00336
00337 }
00338
00348 function from_xml($xml_text)
00349 {
00350 $result = false;
00351 if (!empty($this->domxml))
00352 {
00353 $this->domxml->free();
00354 }
00355 $xml_text = preg_replace("/>\s*?</", "><", $xml_text);
00356 $this->domxml = domxml_open_mem($xml_text);
00357 if (!empty($this->domxml))
00358 {
00359 $root = $this->domxml->document_element();
00360 $item = $root->first_child();
00361 $this->setTitle($item->get_attribute("title"));
00362 $this->gaps = array();
00363 $itemnodes = $item->child_nodes();
00364 $materials = array();
00365 $images = array();
00366 $shuffle = "";
00367 foreach ($itemnodes as $index => $node)
00368 {
00369 switch ($node->node_name())
00370 {
00371 case "qticomment":
00372 $comment = $node->get_content();
00373 if (strpos($comment, "ILIAS Version=") !== false)
00374 {
00375 }
00376 elseif (strpos($comment, "Questiontype=") !== false)
00377 {
00378 }
00379 elseif (strpos($comment, "Author=") !== false)
00380 {
00381 $comment = str_replace("Author=", "", $comment);
00382 $this->setAuthor($comment);
00383 }
00384 else
00385 {
00386 $this->setComment($comment);
00387 }
00388 break;
00389 case "duration":
00390 $iso8601period = $node->get_content();
00391 if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $iso8601period, $matches))
00392 {
00393 $this->setEstimatedWorkingTime($matches[4], $matches[5], $matches[6]);
00394 }
00395 break;
00396 case "presentation":
00397 $flow = $node->first_child();
00398 $flownodes = $flow->child_nodes();
00399 foreach ($flownodes as $idx => $flownode)
00400 {
00401 if (strcmp($flownode->node_name(), "material") == 0)
00402 {
00403 $childnodes = $flownode->child_nodes();
00404 foreach ($childnodes as $childnodeindex => $childnode)
00405 {
00406 if (strcmp($childnode->get_attribute("label"), "suggested_solution") == 0)
00407 {
00408 $mattype = $childnode->first_child();
00409 if (strcmp($mattype->node_name(), "mattext") == 0)
00410 {
00411 $suggested_solution = $mattype->get_content();
00412 if ($suggested_solution)
00413 {
00414 if ($this->getId() < 1)
00415 {
00416 $this->saveToDb();
00417 }
00418 $this->setSuggestedSolution($suggested_solution, 0, true);
00419 }
00420 }
00421 }
00422 elseif (strcmp($childnode->node_name(), "mattext") == 0)
00423 {
00424 if (!$childnode->has_attribute("label"))
00425 {
00426 $this->setQuestion($childnode->get_content());
00427 }
00428 elseif (strcmp($childnode->get_attribute("label"), "points") == 0)
00429 {
00430 $this->setPoints($childnode->get_content());
00431 }
00432 elseif (strcmp($childnode->get_attribute("label"), "java_code") == 0)
00433 {
00434 $this->java_code = $childnode->get_content();
00435 }
00436 elseif (strcmp($childnode->get_attribute("label"), "") != 0)
00437 {
00438 $this->addParameter($childnode->get_attribute("label"), $childnode->get_content());
00439 }
00440 }
00441 elseif (strcmp($childnode->node_name(), "matapplet") == 0)
00442 {
00443 if (strcmp($childnode->get_attribute("label"), "applet data") == 0)
00444 {
00445 $this->javaapplet_filename = $childnode->get_attribute("uri");
00446 $this->java_height = $childnode->get_attribute("height");
00447 $this->java_width = $childnode->get_attribute("width");
00448 $java = base64_decode($childnode->get_content());
00449 }
00450 }
00451 }
00452 }
00453 }
00454 break;
00455 }
00456 }
00457 if ($this->javaapplet_filename)
00458 {
00459 $this->saveToDb();
00460 $javapath = $this->getJavaPath();
00461 if (!file_exists($javapath))
00462 {
00463 ilUtil::makeDirParents($javapath);
00464 }
00465 $javapath .= $this->javaapplet_filename;
00466 $fh = fopen($javapath, "wb");
00467 if ($fh == false)
00468 {
00469 global $ilErr;
00470 $ilErr->raiseError($this->lng->txt("error_save_java_file") . ": $php_errormsg", $ilErr->WARNING);
00471 return;
00472 }
00473 $javafile = fwrite($fh, $java);
00474 fclose($fh);
00475 }
00476 $result = true;
00477 }
00478 return $result;
00479 }
00480
00481
00490 function splitParams($params = "")
00491 {
00492 $params_array = split("<separator>", $params);
00493 foreach ($params_array as $pair)
00494 {
00495 if (preg_match("/(.*?)\=(.*)/", $pair, $matches))
00496 {
00497 switch ($matches[1])
00498 {
00499 case "java_code" :
00500 $this->java_code = $matches[2];
00501 break;
00502 case "java_width" :
00503 $this->java_width = $matches[2];
00504 break;
00505 case "java_height" :
00506 $this->java_height = $matches[2];
00507 break;
00508 }
00509 if (preg_match("/param_name_(\d+)/", $matches[1], $found_key))
00510 {
00511 $this->parameters[$found_key[1]]["name"] = $matches[2];
00512 }
00513 if (preg_match("/param_value_(\d+)/", $matches[1], $found_key))
00514 {
00515 $this->parameters[$found_key[1]]["value"] = $matches[2];
00516 }
00517 }
00518 }
00519 }
00520
00529 function buildParams()
00530 {
00531 $params_array = array();
00532 if ($this->java_code)
00533 {
00534 array_push($params_array, "java_code=$this->java_code");
00535 }
00536 if ($this->java_width)
00537 {
00538 array_push($params_array, "java_width=$this->java_width");
00539 }
00540 if ($this->java_height)
00541 {
00542 array_push($params_array, "java_height=$this->java_height");
00543 }
00544 foreach ($this->parameters as $key => $value)
00545 {
00546 array_push($params_array, "param_name_$key=" . $value["name"]);
00547 array_push($params_array, "param_value_$key=" . $value["value"]);
00548 }
00549 return join($params_array, "<separator>");
00550 }
00551
00560 function buildParamsOnly()
00561 {
00562 $params_array = array();
00563 if ($this->java_code)
00564 {
00565 array_push($params_array, "java_code=$this->java_code");
00566 }
00567 foreach ($this->parameters as $key => $value)
00568 {
00569 array_push($params_array, "param_name_$key=" . $value["name"]);
00570 array_push($params_array, "param_value_$key=" . $value["value"]);
00571 }
00572 return join($params_array, "<separator>");
00573 }
00574
00583 function isComplete()
00584 {
00585 if (($this->title) and ($this->author) and ($this->question) and ($this->javaapplet_filename) and ($this->java_width) and ($this->java_height) and ($this->points != ""))
00586 {
00587 return true;
00588 }
00589 else
00590 {
00591 return false;
00592 }
00593 }
00594
00595
00604 function saveToDb($original_id = "")
00605 {
00606 global $ilias;
00607
00608 $complete = 0;
00609 if ($this->isComplete())
00610 {
00611 $complete = 1;
00612 }
00613
00614 $db = & $ilias->db;
00615
00616 $params = $this->buildParams();
00617 $estw_time = $this->getEstimatedWorkingTime();
00618 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00619
00620 if ($original_id)
00621 {
00622 $original_id = $db->quote($original_id);
00623 }
00624 else
00625 {
00626 $original_id = "NULL";
00627 }
00628
00629 if ($this->id == -1)
00630 {
00631
00632 $now = getdate();
00633 $question_type = $this->getQuestionType();
00634 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00635 $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)",
00636 $db->quote($question_type . ""),
00637 $db->quote($this->obj_id . ""),
00638 $db->quote($this->title . ""),
00639 $db->quote($this->comment . ""),
00640 $db->quote($this->author . ""),
00641 $db->quote($this->owner . ""),
00642 $db->quote($this->question . ""),
00643 $db->quote($this->points . ""),
00644 $db->quote($estw_time . ""),
00645 $db->quote($this->shuffle . ""),
00646 $db->quote($complete . ""),
00647 $db->quote($this->javaapplet_filename . ""),
00648 $db->quote($params . ""),
00649 $db->quote($created . ""),
00650 $original_id
00651 );
00652
00653 $result = $db->query($query);
00654 if ($result == DB_OK)
00655 {
00656 $this->id = $this->ilias->db->getLastInsertId();
00657
00658
00659 $this->createPageObject();
00660
00661
00662 if ($this->getTestId() > 0)
00663 {
00664 $this->insertIntoTest($this->getTestId());
00665 }
00666 }
00667 }
00668 else
00669 {
00670
00671 $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",
00672 $db->quote($this->obj_id. ""),
00673 $db->quote($this->title . ""),
00674 $db->quote($this->comment . ""),
00675 $db->quote($this->author . ""),
00676 $db->quote($this->question . ""),
00677 $db->quote($this->points . ""),
00678 $db->quote($estw_time . ""),
00679 $db->quote($this->shuffle . ""),
00680 $db->quote($complete . ""),
00681 $db->quote($this->javaapplet_filename . ""),
00682 $db->quote($params . ""),
00683 $db->quote($this->id . "")
00684 );
00685 $result = $db->query($query);
00686 }
00687 parent::saveToDb($original_id);
00688 }
00689
00699 function loadFromDb($question_id)
00700 {
00701 global $ilias;
00702
00703 $db = & $ilias->db;
00704 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
00705 $db->quote($question_id)
00706 );
00707 $result = $db->query($query);
00708
00709 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00710 {
00711 if ($result->numRows() == 1)
00712 {
00713 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00714 $this->id = $question_id;
00715 $this->title = $data->title;
00716 $this->comment = $data->comment;
00717 $this->obj_id = $data->obj_fi;
00718 $this->author = $data->author;
00719 $this->points = $data->points;
00720 $this->owner = $data->owner;
00721 $this->original_id = $data->original_id;
00722 $this->javaapplet_filename = $data->image_file;
00723 $this->question = $data->question_text;
00724 $this->solution_hint = $data->solution_hint;
00725 $this->splitParams($data->params);
00726 $this->setShuffle($data->shuffle);
00727 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00728 }
00729 }
00730 parent::loadFromDb($question_id);
00731 }
00732
00740 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00741 {
00742 if ($this->id <= 0)
00743 {
00744
00745 return;
00746 }
00747
00748 $clone = $this;
00749 $original_id = $this->id;
00750 if ($original_id <= 0)
00751 {
00752 $original_id = "";
00753 }
00754 $clone->id = -1;
00755 if ($title)
00756 {
00757 $clone->setTitle($title);
00758 }
00759 if ($author)
00760 {
00761 $clone->setAuthor($author);
00762 }
00763 if ($owner)
00764 {
00765 $clone->setOwner($owner);
00766 }
00767 if ($for_test)
00768 {
00769 $clone->saveToDb($original_id);
00770 }
00771 else
00772 {
00773 $clone->saveToDb();
00774 }
00775
00776
00777 $clone->copyPageOfQuestion($original_id);
00778
00779
00780 $clone->duplicateApplet($original_id);
00781 return $clone->id;
00782 }
00783
00784 function duplicateApplet($question_id)
00785 {
00786 $javapath = $this->getJavaPath();
00787 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00788 if (!file_exists($javapath))
00789 {
00790 ilUtil::makeDirParents($javapath);
00791 }
00792 $filename = $this->getJavaAppletFilename();
00793 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00794 print "java applet could not be duplicated!!!! ";
00795 }
00796 }
00797
00807 function getQuestion()
00808 {
00809 return $this->question;
00810 }
00811
00821 function getPoints()
00822 {
00823 return $this->points;
00824 }
00825
00835 function setQuestion($question = "")
00836 {
00837 $this->question = $question;
00838 }
00839
00848 function getMaximumPoints()
00849 {
00850 return $this->points;
00851 }
00852
00861 function getJavaCode()
00862 {
00863 return $this->java_code;
00864 }
00865
00874 function setJavaCode($java_code = "")
00875 {
00876 $this->java_code = $java_code;
00877 }
00878
00887 function getJavaWidth()
00888 {
00889 return $this->java_width;
00890 }
00891
00900 function setPoints($points = 0.0)
00901 {
00902 $this->points = $points;
00903 }
00904
00913 function setJavaWidth($java_width = "")
00914 {
00915 $this->java_width = $java_width;
00916 }
00917
00926 function getJavaHeight()
00927 {
00928 return $this->java_height;
00929 }
00930
00939 function setJavaHeight($java_height = "")
00940 {
00941 $this->java_height = $java_height;
00942 }
00943
00953 function getReachedPoints($user_id, $test_id)
00954 {
00955 $found_values = array();
00956 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
00957 $this->ilias->db->quote($user_id),
00958 $this->ilias->db->quote($test_id),
00959 $this->ilias->db->quote($this->getId())
00960 );
00961 $result = $this->ilias->db->query($query);
00962 $points = 0;
00963 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00964 {
00965 $points += $data->points;
00966 }
00967 return $points;
00968 }
00969
00979 function getReachedInformation($user_id, $test_id)
00980 {
00981 $found_values = array();
00982 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
00983 $this->ilias->db->quote($user_id),
00984 $this->ilias->db->quote($test_id),
00985 $this->ilias->db->quote($this->getId())
00986 );
00987 $result = $this->ilias->db->query($query);
00988 $counter = 1;
00989 $user_result = array();
00990 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00991 {
00992 $true = 0;
00993 if ($data->points > 0)
00994 {
00995 $true = 1;
00996 }
00997 $solution = array(
00998 "order" => "$counter",
00999 "points" => "$data->points",
01000 "true" => "$true",
01001 "value1" => "$data->value1",
01002 "value2" => "$data->value2",
01003 );
01004 $counter++;
01005 array_push($user_result, $solution);
01006 }
01007 return $user_result;
01008 }
01009
01020 function addParameter($name = "", $value = "")
01021 {
01022 $index = $this->getParameterIndex($name);
01023 if ($index > -1)
01024 {
01025 $this->parameters[$index] = array("name" => $name, "value" => $value);
01026 }
01027 else
01028 {
01029 array_push($this->parameters, array("name" => $name, "value" => $value));
01030 }
01031 }
01032
01044 function addParameterAtIndex($index = 0, $name = "", $value = "")
01045 {
01046 $this->parameters[$index] = array("name" => $name, "value" => $value);
01047 }
01048
01058 function removeParameter($name)
01059 {
01060 foreach ($this->parameters as $key => $value)
01061 {
01062 if (strcmp($name, $value["name"]) == 0)
01063 {
01064 array_splice($this->parameters, $key, 1);
01065 return;
01066 }
01067 }
01068 }
01069
01080 function getParameter($index)
01081 {
01082 if (($index < 0) or ($index >= count($this->parameters)))
01083 {
01084 return undef;
01085 }
01086 return $this->parameters[$index];
01087 }
01088
01099 function getParameterIndex($name)
01100 {
01101 foreach ($this->parameters as $key => $value)
01102 {
01103 if (array_key_exists($name, $value))
01104 {
01105 return $key;
01106 }
01107 }
01108 return -1;
01109 }
01110
01120 function getParameterCount()
01121 {
01122 return count($this->parameters);
01123 }
01124
01133 function flushParams()
01134 {
01135 $this->parameters = array();
01136 }
01137
01148 function saveWorkingData($test_id, $limit_to = LIMIT_NO_LIMIT)
01149 {
01150 return true;
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199 }
01200
01210 function getJavaAppletFilename()
01211 {
01212 return $this->javaapplet_filename;
01213 }
01214
01224 function setJavaAppletFilename($javaapplet_filename, $javaapplet_tempfilename = "")
01225 {
01226 if (!empty($javaapplet_filename))
01227 {
01228 $this->javaapplet_filename = $javaapplet_filename;
01229 }
01230 if (!empty($javaapplet_tempfilename))
01231 {
01232 $javapath = $this->getJavaPath();
01233 if (!file_exists($javapath))
01234 {
01235 ilUtil::makeDirParents($javapath);
01236 }
01237
01238
01239 if (!ilUtil::moveUploadedFile($javaapplet_tempfilename, $javaapplet_filename, $javapath.$javaapplet_filename))
01240 {
01241 print "java applet not uploaded!!!! ";
01242 }
01243 }
01244 }
01245
01246 function syncWithOriginal()
01247 {
01248 global $ilias;
01249 if ($this->original_id)
01250 {
01251 $complete = 0;
01252 if ($this->isComplete())
01253 {
01254 $complete = 1;
01255 }
01256 $db = & $ilias->db;
01257
01258 $estw_time = $this->getEstimatedWorkingTime();
01259 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
01260
01261 $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",
01262 $db->quote($this->obj_id. ""),
01263 $db->quote($this->title . ""),
01264 $db->quote($this->comment . ""),
01265 $db->quote($this->author . ""),
01266 $db->quote($this->question . ""),
01267 $db->quote($this->points . ""),
01268 $db->quote($estw_time . ""),
01269 $db->quote($this->shuffle . ""),
01270 $db->quote($complete . ""),
01271 $db->quote($this->javaapplet_filename . ""),
01272 $db->quote($params . ""),
01273 $db->quote($this->original_id . "")
01274 );
01275 $result = $db->query($query);
01276
01277 parent::syncWithOriginal();
01278 }
01279 }
01280
01289 function getQuestionType()
01290 {
01291 return 7;
01292 }
01293 }
01294
01295 ?>