00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00024 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00025
00035 class assJavaApplet extends assQuestion
00036 {
00044 var $javaapplet_filename;
00045
00053 var $java_code;
00054
00062 var $java_codebase;
00063
00071 var $java_archive;
00072
00080 var $java_width;
00081
00089 var $java_height;
00090
00098 var $parameters;
00099
00115 function assJavaApplet(
00116 $title = "",
00117 $comment = "",
00118 $author = "",
00119 $owner = -1,
00120 $question = "",
00121 $javaapplet_filename = ""
00122 )
00123 {
00124 $this->assQuestion($title, $comment, $author, $owner, $question);
00125 $this->javaapplet_filename = $javaapplet_filename;
00126 $this->parameters = array();
00127 }
00128
00137 function splitParams($params = "")
00138 {
00139 $params_array = split("<separator>", $params);
00140 foreach ($params_array as $pair)
00141 {
00142 if (preg_match("/(.*?)\=(.*)/", $pair, $matches))
00143 {
00144 switch ($matches[1])
00145 {
00146 case "java_code" :
00147 $this->java_code = $matches[2];
00148 break;
00149 case "java_codebase" :
00150 $this->java_codebase = $matches[2];
00151 break;
00152 case "java_archive" :
00153 $this->java_archive = $matches[2];
00154 break;
00155 case "java_width" :
00156 $this->java_width = $matches[2];
00157 break;
00158 case "java_height" :
00159 $this->java_height = $matches[2];
00160 break;
00161 }
00162 if (preg_match("/param_name_(\d+)/", $matches[1], $found_key))
00163 {
00164 $this->parameters[$found_key[1]]["name"] = $matches[2];
00165 }
00166 if (preg_match("/param_value_(\d+)/", $matches[1], $found_key))
00167 {
00168 $this->parameters[$found_key[1]]["value"] = $matches[2];
00169 }
00170 }
00171 }
00172 }
00173
00182 function buildParams()
00183 {
00184 $params_array = array();
00185 if ($this->java_code)
00186 {
00187 array_push($params_array, "java_code=$this->java_code");
00188 }
00189 if ($this->java_codebase)
00190 {
00191 array_push($params_array, "java_codebase=$this->java_codebase");
00192 }
00193 if ($this->java_archive)
00194 {
00195 array_push($params_array, "java_archive=$this->java_archive");
00196 }
00197 if ($this->java_width)
00198 {
00199 array_push($params_array, "java_width=$this->java_width");
00200 }
00201 if ($this->java_height)
00202 {
00203 array_push($params_array, "java_height=$this->java_height");
00204 }
00205 foreach ($this->parameters as $key => $value)
00206 {
00207 array_push($params_array, "param_name_$key=" . $value["name"]);
00208 array_push($params_array, "param_value_$key=" . $value["value"]);
00209 }
00210 return join($params_array, "<separator>");
00211 }
00212
00221 function buildParamsOnly()
00222 {
00223 $params_array = array();
00224 if ($this->java_code)
00225 {
00226 array_push($params_array, "java_code=$this->java_code");
00227 array_push($params_array, "java_codebase=$this->java_codebase");
00228 array_push($params_array, "java_archive=$this->java_archive");
00229 }
00230 foreach ($this->parameters as $key => $value)
00231 {
00232 array_push($params_array, "param_name_$key=" . $value["name"]);
00233 array_push($params_array, "param_value_$key=" . $value["value"]);
00234 }
00235 return join($params_array, "<separator>");
00236 }
00237
00246 function isComplete()
00247 {
00248 if (($this->title) and ($this->author) and ($this->question) and ($this->javaapplet_filename) and ($this->java_width) and ($this->java_height) and ($this->getMaximumPoints() > 0))
00249 {
00250 return true;
00251 }
00252 else if (($this->title) and ($this->author) and ($this->question) and ($this->getJavaArchive()) and ($this->getJavaCodebase()) and ($this->java_width) and ($this->java_height) and ($this->getMaximumPoints() > 0))
00253 {
00254 return true;
00255 }
00256 else
00257 {
00258 return false;
00259 }
00260 }
00261
00262
00271 function saveToDb($original_id = "")
00272 {
00273 global $ilDB;
00274
00275 $complete = 0;
00276 if ($this->isComplete())
00277 {
00278 $complete = 1;
00279 }
00280
00281 $params = $this->buildParams();
00282 $estw_time = $this->getEstimatedWorkingTime();
00283 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00284
00285 if ($original_id)
00286 {
00287 $original_id = $ilDB->quote($original_id);
00288 }
00289 else
00290 {
00291 $original_id = "NULL";
00292 }
00293
00294
00295 include_once("./Services/RTE/classes/class.ilRTE.php");
00296 if ($this->id == -1)
00297 {
00298
00299 $now = getdate();
00300 $question_type = $this->getQuestionTypeID();
00301 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00302 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00303 $ilDB->quote($question_type . ""),
00304 $ilDB->quote($this->obj_id . ""),
00305 $ilDB->quote($this->title . ""),
00306 $ilDB->quote($this->comment . ""),
00307 $ilDB->quote($this->author . ""),
00308 $ilDB->quote($this->owner . ""),
00309 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00310 $ilDB->quote($this->points . ""),
00311 $ilDB->quote($estw_time . ""),
00312 $ilDB->quote($complete . ""),
00313 $ilDB->quote($created . ""),
00314 $original_id
00315 );
00316
00317 $result = $ilDB->query($query);
00318 if ($result == DB_OK)
00319 {
00320 $this->id = $ilDB->getLastInsertId();
00321 $query = sprintf("INSERT INTO qpl_question_javaapplet (question_fi, image_file, params) VALUES (%s, %s, %s)",
00322 $ilDB->quote($this->id . ""),
00323 $ilDB->quote($this->javaapplet_filename . ""),
00324 $ilDB->quote($params . "")
00325 );
00326 $ilDB->query($query);
00327
00328
00329 $this->createPageObject();
00330
00331 if ($this->getTestId() > 0)
00332 {
00333 $this->insertIntoTest($this->getTestId());
00334 }
00335 }
00336 }
00337 else
00338 {
00339
00340 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
00341 $ilDB->quote($this->obj_id. ""),
00342 $ilDB->quote($this->title . ""),
00343 $ilDB->quote($this->comment . ""),
00344 $ilDB->quote($this->author . ""),
00345 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00346 $ilDB->quote($this->points . ""),
00347 $ilDB->quote($estw_time . ""),
00348 $ilDB->quote($complete . ""),
00349 $ilDB->quote($this->id . "")
00350 );
00351 $result = $ilDB->query($query);
00352 $query = sprintf("UPDATE qpl_question_javaapplet SET image_file = %s, params = %s WHERE question_fi = %s",
00353 $ilDB->quote($this->javaapplet_filename . ""),
00354 $ilDB->quote($params . ""),
00355 $ilDB->quote($this->id . "")
00356 );
00357 $result = $ilDB->query($query);
00358 }
00359 parent::saveToDb($original_id);
00360 }
00361
00371 function loadFromDb($question_id)
00372 {
00373 global $ilDB;
00374
00375 $query = sprintf("SELECT qpl_questions.*, qpl_question_javaapplet.* FROM qpl_questions, qpl_question_javaapplet WHERE question_id = %s AND qpl_questions.question_id = qpl_question_javaapplet.question_fi",
00376 $ilDB->quote($question_id)
00377 );
00378 $result = $ilDB->query($query);
00379
00380 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00381 {
00382 if ($result->numRows() == 1)
00383 {
00384 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00385 $this->id = $question_id;
00386 $this->title = $data->title;
00387 $this->comment = $data->comment;
00388 $this->obj_id = $data->obj_fi;
00389 $this->author = $data->author;
00390 $this->points = $data->points;
00391 $this->owner = $data->owner;
00392 $this->original_id = $data->original_id;
00393 $this->javaapplet_filename = $data->image_file;
00394 include_once("./Services/RTE/classes/class.ilRTE.php");
00395 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00396 $this->solution_hint = $data->solution_hint;
00397 $this->splitParams($data->params);
00398 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00399 }
00400 }
00401 parent::loadFromDb($question_id);
00402 }
00403
00411 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00412 {
00413 if ($this->id <= 0)
00414 {
00415
00416 return;
00417 }
00418
00419 $this_id = $this->getId();
00420 $clone = $this;
00421 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00422 $original_id = assQuestion::_getOriginalId($this->id);
00423 $clone->id = -1;
00424 if ($title)
00425 {
00426 $clone->setTitle($title);
00427 }
00428 if ($author)
00429 {
00430 $clone->setAuthor($author);
00431 }
00432 if ($owner)
00433 {
00434 $clone->setOwner($owner);
00435 }
00436 if ($for_test)
00437 {
00438 $clone->saveToDb($original_id);
00439 }
00440 else
00441 {
00442 $clone->saveToDb();
00443 }
00444
00445
00446 $clone->copyPageOfQuestion($this_id);
00447
00448 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00449
00450 $clone->duplicateFeedbackGeneric($this_id);
00451
00452
00453 $clone->duplicateApplet($this_id);
00454 return $clone->id;
00455 }
00456
00464 function copyObject($target_questionpool, $title = "")
00465 {
00466 if ($this->id <= 0)
00467 {
00468
00469 return;
00470 }
00471
00472 $clone = $this;
00473 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00474 $original_id = assQuestion::_getOriginalId($this->id);
00475 $clone->id = -1;
00476 $source_questionpool = $this->getObjId();
00477 $clone->setObjId($target_questionpool);
00478 if ($title)
00479 {
00480 $clone->setTitle($title);
00481 }
00482 $clone->saveToDb();
00483
00484
00485 $clone->copyPageOfQuestion($original_id);
00486
00487 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00488
00489 $clone->duplicateFeedbackGeneric($original_id);
00490
00491
00492 $clone->copyApplet($original_id, $source_questionpool);
00493 return $clone->id;
00494 }
00495
00496 function duplicateApplet($question_id)
00497 {
00498 $javapath = $this->getJavaPath();
00499 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00500 if (!file_exists($javapath))
00501 {
00502 ilUtil::makeDirParents($javapath);
00503 }
00504 $filename = $this->getJavaAppletFilename();
00505 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00506 print "java applet could not be duplicated!!!! ";
00507 }
00508 }
00509
00510 function copyApplet($question_id, $source_questionpool)
00511 {
00512 $javapath = $this->getJavaPath();
00513 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00514 $javapath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $javapath_original);
00515 if (!file_exists($javapath))
00516 {
00517 ilUtil::makeDirParents($javapath);
00518 }
00519 $filename = $this->getJavaAppletFilename();
00520 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00521 print "java applet could not be copied!!!! ";
00522 }
00523 }
00524
00533 function getMaximumPoints()
00534 {
00535 return $this->points;
00536 }
00537
00546 function getJavaCode()
00547 {
00548 return $this->java_code;
00549 }
00550
00559 function getJavaCodebase()
00560 {
00561 return $this->java_codebase;
00562 }
00563
00572 function getJavaArchive()
00573 {
00574 return $this->java_archive;
00575 }
00576
00585 function setJavaCode($java_code = "")
00586 {
00587 $this->java_code = $java_code;
00588 }
00589
00598 function setJavaCodebase($java_codebase = "")
00599 {
00600 $this->java_codebase = $java_codebase;
00601 }
00602
00611 function setJavaArchive($java_archive = "")
00612 {
00613 $this->java_archive = $java_archive;
00614 }
00615
00624 function getJavaWidth()
00625 {
00626 return $this->java_width;
00627 }
00628
00637 function setJavaWidth($java_width = "")
00638 {
00639 $this->java_width = $java_width;
00640 }
00641
00650 function getJavaHeight()
00651 {
00652 return $this->java_height;
00653 }
00654
00663 function setJavaHeight($java_height = "")
00664 {
00665 $this->java_height = $java_height;
00666 }
00667
00679 function calculateReachedPoints($active_id, $pass = NULL)
00680 {
00681 global $ilDB;
00682
00683 $found_values = array();
00684 if (is_null($pass))
00685 {
00686 $pass = $this->getSolutionMaxPass($active_id);
00687 }
00688 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00689 $ilDB->quote($active_id . ""),
00690 $ilDB->quote($this->getId() . ""),
00691 $ilDB->quote($pass . "")
00692 );
00693 $result = $ilDB->query($query);
00694 $points = 0;
00695 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00696 {
00697 $points += $data->points;
00698 }
00699
00700 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00701 return $points;
00702 }
00703
00713 function getReachedInformation($active_id, $pass = NULL)
00714 {
00715 global $ilDB;
00716
00717 $found_values = array();
00718 if (is_null($pass))
00719 {
00720 $pass = $this->getSolutionMaxPass($active_id);
00721 }
00722 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00723 $ilDB->quote($active_id . ""),
00724 $ilDB->quote($this->getId() . ""),
00725 $ilDB->quote($pass . "")
00726 );
00727 $result = $ilDB->query($query);
00728 $counter = 1;
00729 $user_result = array();
00730 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00731 {
00732 $true = 0;
00733 if ($data->points > 0)
00734 {
00735 $true = 1;
00736 }
00737 $solution = array(
00738 "order" => "$counter",
00739 "points" => "$data->points",
00740 "true" => "$true",
00741 "value1" => "$data->value1",
00742 "value2" => "$data->value2",
00743 );
00744 $counter++;
00745 array_push($user_result, $solution);
00746 }
00747 return $user_result;
00748 }
00749
00760 function addParameter($name = "", $value = "")
00761 {
00762 $index = $this->getParameterIndex($name);
00763 if ($index > -1)
00764 {
00765 $this->parameters[$index] = array("name" => $name, "value" => $value);
00766 }
00767 else
00768 {
00769 array_push($this->parameters, array("name" => $name, "value" => $value));
00770 }
00771 }
00772
00784 function addParameterAtIndex($index = 0, $name = "", $value = "")
00785 {
00786 $this->parameters[$index] = array("name" => $name, "value" => $value);
00787 }
00788
00798 function removeParameter($name)
00799 {
00800 foreach ($this->parameters as $key => $value)
00801 {
00802 if (strcmp($name, $value["name"]) == 0)
00803 {
00804 array_splice($this->parameters, $key, 1);
00805 return;
00806 }
00807 }
00808 }
00809
00820 function getParameter($index)
00821 {
00822 if (($index < 0) or ($index >= count($this->parameters)))
00823 {
00824 return undef;
00825 }
00826 return $this->parameters[$index];
00827 }
00828
00839 function getParameterIndex($name)
00840 {
00841 foreach ($this->parameters as $key => $value)
00842 {
00843 if (array_key_exists($name, $value))
00844 {
00845 return $key;
00846 }
00847 }
00848 return -1;
00849 }
00850
00860 function getParameterCount()
00861 {
00862 return count($this->parameters);
00863 }
00864
00873 function flushParams()
00874 {
00875 $this->parameters = array();
00876 }
00877
00888 function saveWorkingData($active_id, $pass = NULL)
00889 {
00890 parent::saveWorkingData($active_id, $pass);
00891 return true;
00892 }
00893
00903 function getJavaAppletFilename()
00904 {
00905 return $this->javaapplet_filename;
00906 }
00907
00917 function setJavaAppletFilename($javaapplet_filename, $javaapplet_tempfilename = "")
00918 {
00919 if (!empty($javaapplet_filename))
00920 {
00921 $this->javaapplet_filename = $javaapplet_filename;
00922 }
00923 if (!empty($javaapplet_tempfilename))
00924 {
00925 $javapath = $this->getJavaPath();
00926 if (!file_exists($javapath))
00927 {
00928 ilUtil::makeDirParents($javapath);
00929 }
00930
00931
00932 if (!ilUtil::moveUploadedFile($javaapplet_tempfilename, $javaapplet_filename, $javapath.$javaapplet_filename))
00933 {
00934 print "java applet not uploaded!!!! ";
00935 }
00936 else
00937 {
00938 $this->setJavaCodebase();
00939 $this->setJavaArchive();
00940 }
00941 }
00942 }
00943
00944 function deleteJavaAppletFilename()
00945 {
00946 unlink($this->getJavaPath() . $this->getJavaAppletFilename());
00947 $this->javaapplet_filename = "";
00948 }
00949
00958 function getQuestionType()
00959 {
00960 return "assJavaApplet";
00961 }
00962
00971 function getAdditionalTableName()
00972 {
00973 return "qpl_question_javaapplet";
00974 }
00975
00980 function getRTETextWithMediaObjects()
00981 {
00982 return parent::getRTETextWithMediaObjects();
00983 }
00984 }
00985
00986 ?>