• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/TestQuestionPool/classes/class.assFlashApp.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00024 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00025 
00037 class assFlashApp extends assQuestion
00038 {
00046         var $question;
00047 
00055         var $flash_filename;
00056 
00057 
00065         var $flash_width;
00066 
00074         var $flash_height;
00075 
00083         var $parameters;
00084 
00100         function assFlashApp(
00101                 $title = "",
00102                 $comment = "",
00103                 $author = "",
00104                 $owner = -1,
00105                 $question = "",
00106                 $flash_filename = ""
00107         )
00108         {
00109                 $this->assQuestion($title, $comment, $author, $owner);
00110                 $this->question = $question;
00111                 $this->flash_filename = $flash_filename;
00112                 $this->parameters = array();
00113         }
00114 
00123         function splitParams($params = "")
00124         {
00125                 $params_array = split("<separator>", $params);
00126                 foreach ($params_array as $pair)
00127                 {
00128                         if (preg_match("/(.*?)\=(.*)/", $pair, $matches))
00129                         {
00130                                 switch ($matches[1])
00131                                 {
00132                                         case "flash_width" :
00133                                                 $this->flash_width = $matches[2];
00134                                                 break;
00135                                         case "flash_height" :
00136                                                 $this->flash_height = $matches[2];
00137                                                 break;
00138                                 }
00139                                 if (preg_match("/param_name_(\d+)/", $matches[1], $found_key))
00140                                 {
00141                                         $this->parameters[$found_key[1]]["name"] = $matches[2];
00142                                 }
00143                                 if (preg_match("/param_value_(\d+)/", $matches[1], $found_key))
00144                                 {
00145                                         $this->parameters[$found_key[1]]["value"] = $matches[2];
00146                                 }
00147                         }
00148                 }
00149         }
00150 
00159         function buildParams()
00160         {
00161                 $params_array = array();
00162                 if ($this->flash_width)
00163                 {
00164                         array_push($params_array, "flash_width=$this->flash_width");
00165                 }
00166                 if ($this->flash_height)
00167                 {
00168                         array_push($params_array, "flash_height=$this->flash_height");
00169                 }
00170                 foreach ($this->parameters as $key => $value)
00171                 {
00172                         array_push($params_array, "param_name_$key=" . $value["name"]);
00173                         array_push($params_array, "param_value_$key=" . $value["value"]);
00174                 }
00175                 return join($params_array, "<separator>");
00176         }
00177 
00186         function buildParamsOnly()
00187         {
00188                 $params_array = array();
00189                 
00190                 foreach ($this->parameters as $key => $value)
00191                 {
00192                         array_push($params_array, "param_name_$key=" . $value["name"]);
00193                         array_push($params_array, "param_value_$key=" . $value["value"]);
00194                 }
00195                 return join($params_array, "<separator>");
00196         }
00197 
00206         function isComplete()
00207         {
00208                 if (($this->title) and ($this->author) and ($this->question) and ($this->flash_filename) and ($this->flash_width) and ($this->flash_height) and ($this->getMaximumPoints() > 0))
00209                 {
00210                         return true;
00211                 }
00212                 /*
00213                 else if (($this->title) and ($this->author) and ($this->question) and ($this->getJavaArchive()) and ($this->getJavaCodebase()) and ($this->flash_width) and ($this->flash_height) and ($this->getMaximumPoints() > 0))
00214                 {
00215                         return true;
00216                 }*/
00217                 else
00218                 {
00219                         return false;
00220                 }
00221         }
00222 
00223 
00232         function saveToDb($original_id = "")
00233         {
00234                 global $ilDB;
00235 
00236                 $complete = 0;
00237                 if ($this->isComplete())
00238                 {
00239                         $complete = 1;
00240                 }
00241 
00242                 $params = $this->buildParams();
00243                 $estw_time = $this->getEstimatedWorkingTime();
00244                 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00245                 $original_id = $original_id ? $ilDB->quote($original_id) : "NULL";
00246 
00247                 // cleanup RTE images which are not inserted into the question text
00248                 include_once("./Services/RTE/classes/class.ilRTE.php");
00249 
00250                 if ($this->id == -1)
00251                 {
00252                         // Neuen Datensatz schreiben
00253                         $now = getdate();
00254                         $question_type = $this->getQuestionType();
00255                         $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00256                         $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)",
00257                                 $ilDB->quote($this->getQuestionTypeID() . ""),
00258                                 $ilDB->quote($this->obj_id . ""),
00259                                 $ilDB->quote($this->title . ""),
00260                                 $ilDB->quote($this->comment . ""),
00261                                 $ilDB->quote($this->author . ""),
00262                                 $ilDB->quote($this->owner . ""),
00263                                 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00264                                 $ilDB->quote($this->points . ""),
00265                                 $ilDB->quote($estw_time . ""),
00266                                 $ilDB->quote($complete . ""),
00267                                 $ilDB->quote($created . ""),
00268                                 $original_id
00269                         );
00270 
00271                         $result = $ilDB->query($query);
00272                         if ($result == DB_OK)
00273                         {
00274                                 $this->id = $ilDB->getLastInsertId();
00275                                 $query = sprintf("INSERT INTO qpl_question_flashapp (question_fi, flash_file, params) VALUES (%s, %s, %s)",
00276                                         $ilDB->quote($this->id . ""),
00277                                         $ilDB->quote($this->flash_filename . ""),
00278                                         $ilDB->quote($params . "")
00279                                 );
00280                                 $ilDB->query($query);
00281 
00282                                 // create page object of question
00283                                 $this->createPageObject();
00284 
00285                                 if ($this->getTestId() > 0)
00286                                 {
00287                                         $this->insertIntoTest($this->getTestId());
00288                                 }
00289                         }
00290                 }
00291                 else
00292                 {
00293                         // Vorhandenen Datensatz aktualisieren
00294                         $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",
00295                                 $ilDB->quote($this->obj_id. ""),
00296                                 $ilDB->quote($this->title . ""),
00297                                 $ilDB->quote($this->comment . ""),
00298                                 $ilDB->quote($this->author . ""),
00299                                 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00300                                 $ilDB->quote($this->points . ""),
00301                                 $ilDB->quote($estw_time . ""),
00302                                 $ilDB->quote($complete . ""),
00303                                 $ilDB->quote($this->id . "")
00304                         );
00305                         $result = $ilDB->query($query);
00306                         $query = sprintf("UPDATE qpl_question_flashapp SET flash_file = %s, params = %s WHERE question_fi = %s",
00307                                 $ilDB->quote($this->flash_filename . ""),
00308                                 $ilDB->quote($params . ""),
00309                                 $ilDB->quote($this->id . "")
00310                         );
00311                         $result = $ilDB->query($query);
00312                 }
00313                 parent::saveToDb($original_id);
00314         }
00315 
00325         function loadFromDb($question_id)
00326         {
00327                 global $ilDB;
00328 
00329     $query = sprintf("SELECT qpl_questions.*, qpl_question_flashapp.* FROM qpl_questions, qpl_question_flashapp WHERE question_id = %s AND qpl_questions.question_id = qpl_question_flashapp.question_fi",
00330                         $ilDB->quote($question_id)
00331                 );
00332                 $result = $ilDB->query($query);
00333 
00334                 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00335                 {
00336                         if ($result->numRows() == 1)
00337                         {
00338                                 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00339                                 $this->id = $question_id;
00340                                 $this->title = $data->title;
00341                                 $this->comment = $data->comment;
00342                                 $this->obj_id = $data->obj_fi;
00343                                 $this->author = $data->author;
00344                                 $this->points = $data->points;
00345                                 $this->owner = $data->owner;
00346                                 $this->original_id = $data->original_id;
00347                                 $this->flash_filename = $data->flash_file;
00348                                 include_once("./Services/RTE/classes/class.ilRTE.php");
00349                                 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00350                                 $this->solution_hint = $data->solution_hint;
00351                                 $this->splitParams($data->params);
00352                                 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00353                         }
00354                 }
00355                 parent::loadFromDb($question_id);
00356         }
00357 
00365         function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00366         {
00367                 if ($this->id <= 0)
00368                 {
00369                         // The question has not been saved. It cannot be duplicated
00370                         return;
00371                 }
00372                 // duplicate the question in database
00373                 $this_id = $this->getId();
00374                 $clone = $this;
00375                 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00376                 $original_id = assQuestion::_getOriginalId($this->id);
00377                 $clone->id = -1;
00378                 if ($title)
00379                 {
00380                         $clone->setTitle($title);
00381                 }
00382                 if ($author)
00383                 {
00384                         $clone->setAuthor($author);
00385                 }
00386                 if ($owner)
00387                 {
00388                         $clone->setOwner($owner);
00389                 }
00390                 if ($for_test)
00391                 {
00392                         $clone->saveToDb($original_id);
00393                 }
00394                 else
00395                 {
00396                         $clone->saveToDb();
00397                 }
00398 
00399                 // copy question page content
00400                 $clone->copyPageOfQuestion($this_id);
00401                 // copy XHTML media objects
00402                 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00403 
00404                 // duplicate the image
00405                 $clone->duplicateApplet($this_id);
00406                 return $clone->id;
00407         }
00408 
00416         function copyObject($target_questionpool, $title = "")
00417         {
00418                 if ($this->id <= 0)
00419                 {
00420                         // The question has not been saved. It cannot be duplicated
00421                         return;
00422                 }
00423                 // duplicate the question in database
00424                 $clone = $this;
00425                 include_once ("./Modules/TestQuestionPoll/classes/class.assQuestion.php");
00426                 $original_id = assQuestion::_getOriginalId($this->id);
00427                 $clone->id = -1;
00428                 $source_questionpool = $this->getObjId();
00429                 $clone->setObjId($target_questionpool);
00430                 if ($title)
00431                 {
00432                         $clone->setTitle($title);
00433                 }
00434                 $clone->saveToDb();
00435 
00436                 // copy question page content
00437                 $clone->copyPageOfQuestion($original_id);
00438                 // copy XHTML media objects
00439                 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00440 
00441                 // duplicate the image
00442                 $clone->copyApplet($original_id, $source_questionpool);
00443                 return $clone->id;
00444         }
00445         
00446         function duplicateApplet($question_id)
00447         {
00448                 $javapath = $this->getFlashPath();
00449                 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00450                 if (!file_exists($javapath))
00451                 {
00452                         ilUtil::makeDirParents($javapath);
00453                 }
00454                 $filename = $this->getFlashFilename();
00455                 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00456                         print "Flash Application could not be duplicated!!!! ";
00457                 }
00458         }
00459 
00460         function copyApplet($question_id, $source_questionpool)
00461         {
00462                 $javapath = $this->getFlashPath();
00463                 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00464                 $javapath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $javapath_original);
00465                 if (!file_exists($javapath))
00466                 {
00467                         ilUtil::makeDirParents($javapath);
00468                 }
00469                 $filename = $this->getFlashFilename();
00470                 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00471                         print "Flash Application could not be copied!!!! ";
00472                 }
00473         }
00474 
00484         function getQuestion()
00485         {
00486                 return $this->question;
00487         }
00488 
00498         function setQuestion($question = "")
00499         {
00500                 $this->question = $question;
00501         }
00502 
00511         function getMaximumPoints()
00512         {
00513                 return $this->points;
00514         }
00515 
00516 
00525         function getFlashWidth()
00526         {
00527                 return $this->flash_width;
00528         }
00529 
00538         function setFlashWidth($flash_width = "")
00539         {
00540                 $this->flash_width = $flash_width;
00541         }
00542 
00551         function getFlashHeight()
00552         {
00553                 return $this->flash_height;
00554         }
00555 
00564         function setFlashHeight($flash_height = "")
00565         {
00566                 $this->flash_height = $flash_height;
00567         }
00568 
00580         function calculateReachedPoints($active_id, $pass = NULL)
00581         {
00582                 global $ilDB;
00583                 
00584                 $found_values = array();
00585                 if (is_null($pass))
00586                 {
00587                         $pass = $this->getSolutionMaxPass($active_id);
00588                 }
00589                 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00590                         $ilDB->quote($active_id . ""),
00591                         $ilDB->quote($this->getId() . ""),
00592                         $ilDB->quote($pass . "")
00593                 );
00594                 $result = $ilDB->query($query);
00595                 $points = 0;
00596                 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00597                 {
00598                         $points += $data->points;
00599                 }
00600 
00601                 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00602                 return $points;
00603         }
00604 
00614         function getReachedInformation($active_id, $pass = NULL)
00615         {
00616                 global $ilDB;
00617                 
00618                 $found_values = array();
00619                 if (is_null($pass))
00620                 {
00621                         $pass = $this->getSolutionMaxPass($active_id);
00622                 }
00623                 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00624                         $ilDB->quote($active_id . ""),
00625                         $ilDB->quote($this->getId() . ""),
00626                         $ilDB->quote($pass . "")
00627                 );
00628                 $result = $ilDB->query($query);
00629                 $counter = 0;
00630                 $user_result = array();
00631                 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00632                 {
00633                         $true = 0;
00634                         if ($data->points > 0)
00635                         {
00636                                 $true = 1;
00637                         }
00638                         $solution = array(
00639                                 "order" => "$counter",
00640                                 "points" => "$data->points",
00641                                 "true" => "$true",
00642                                 "value1" => "$data->value1",
00643                                 "value2" => "$data->value2",
00644                         );
00645                         $counter++;
00646                         array_push($user_result, $solution);
00647                 }
00648                 return $user_result;
00649         }
00650 
00661         function addParameter($name = "", $value = "")
00662         {
00663                 $index = $this->getParameterIndex($name);
00664                 if ($index > -1)
00665                 {
00666                         $this->parameters[$index] = array("name" => $name, "value" => $value);
00667                 }
00668                 else
00669                 {
00670                         array_push($this->parameters, array("name" => $name, "value" => $value));
00671                 }
00672         }
00673 
00685         function addParameterAtIndex($index = 0, $name = "", $value = "")
00686         {
00687                 $this->parameters[$index] = array("name" => $name, "value" => $value);
00688         }
00689 
00699         function removeParameter($name)
00700         {
00701                 foreach ($this->parameters as $key => $value)
00702                 {
00703                         if (strcmp($name, $value["name"]) == 0)
00704                         {
00705                                 array_splice($this->parameters, $key, 1);
00706                                 return;
00707                         }
00708                 }
00709         }
00710 
00721         function getParameter($index)
00722         {
00723                 if (($index < 0) or ($index >= count($this->parameters)))
00724                 {
00725                         return undef;
00726                 }
00727                 return $this->parameters[$index];
00728         }
00729 
00740         function getParameterIndex($name)
00741         {
00742                 foreach ($this->parameters as $key => $value)
00743                 {
00744                         if (array_key_exists($name, $value))
00745                         {
00746                                 return $key;
00747                         }
00748                 }
00749                 return -1;
00750         }
00751 
00761         function getParameterCount()
00762         {
00763                 return count($this->parameters);
00764         }
00765 
00774         function flushParams()
00775         {
00776                 $this->parameters = array();
00777         }
00778 
00789         function saveWorkingData($active_id, $pass = NULL)
00790         {
00791     parent::saveWorkingData($active_id, $pass);
00792                 return true;
00793   }
00794 
00804         function getFlashFilename()
00805         {
00806                 return $this->flash_filename;
00807         }
00808 
00818         function setFlashFilename($flash_filename, $javaapplet_tempfilename = "")
00819         {
00820                 if (!empty($flash_filename))
00821                 {
00822                         $this->flash_filename = $flash_filename;
00823                 }
00824                 if (!empty($javaapplet_tempfilename))
00825                 {
00826                         $javapath = $this->getFlashPath();
00827                         if (!file_exists($javapath))
00828                         {
00829                                 ilUtil::makeDirParents($javapath);
00830                         }
00831                         
00832                         //if (!move_uploaded_file($javaapplet_tempfilename, $javapath . $flash_filename))
00833                         if (!ilUtil::moveUploadedFile($javaapplet_tempfilename, $flash_filename, $javapath.$flash_filename))
00834                         {
00835                                 print "Flash Application not uploaded!!!! ";
00836                         }
00837                         else
00838                         {
00839                                 //$this->setJavaCodebase();
00840                                 //$this->setJavaArchive();
00841                         }
00842                 }
00843         }
00844         
00845         function deleteFlashFilename()
00846         {
00847                 unlink($this->getFlashPath() . $this->getFlashFilename());
00848                 $this->flash_filename = "";
00849         }
00850 
00851         function syncWithOriginal()
00852         {
00853                 global $ilDB;
00854                 
00855                 if ($this->original_id)
00856                 {
00857                         $complete = 0;
00858                         if ($this->isComplete())
00859                         {
00860                                 $complete = 1;
00861                         }
00862         
00863                         $estw_time = $this->getEstimatedWorkingTime();
00864                         $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00865         
00866                         $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",
00867                                 $ilDB->quote($this->obj_id. ""),
00868                                 $ilDB->quote($this->title . ""),
00869                                 $ilDB->quote($this->comment . ""),
00870                                 $ilDB->quote($this->author . ""),
00871                                 $ilDB->quote($this->question . ""),
00872                                 $ilDB->quote($this->points . ""),
00873                                 $ilDB->quote($estw_time . ""),
00874                                 $ilDB->quote($complete . ""),
00875                                 $ilDB->quote($this->original_id . "")
00876                         );
00877                         $result = $ilDB->query($query);
00878                         $query = sprintf("UPDATE qpl_question_flashapp SET flash_file = %s, params = %s WHERE question_fi = %s",
00879                                 $ilDB->quote($this->flash_filename . ""),
00880                                 $ilDB->quote($params . ""),
00881                                 $ilDB->quote($this->original_id . "")
00882                         );
00883                         $result = $ilDB->query($query);
00884 
00885                         parent::syncWithOriginal();
00886                 }
00887         }
00888 
00897         function getQuestionType()
00898         {
00899                 return "assFlashApp";
00900         }
00901 
00910         function getAdditionalTableName()
00911         {
00912                 return "qpl_question_flashapp";
00913         }
00914         
00924         function writeTmpFile($tmp_data)
00925         {
00926         // tmp directory erzeugen 
00927         $tmp_flash_dir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/$this->obj_id/$this->id/flash/tmp";
00928         //echo $tmp_flash_dir;
00929         if (    ilUtil::makeDirParents($tmp_flash_dir)) 
00930                 
00931 
00932             $fp = @fopen ($tmp_flash_dir."/".$_COOKIE["PHPSESSID"], "w");
00933 
00934                         
00935                         if ($fp == false)
00936                         {
00937                                 die("FlashApp tmp file: cannot create file.");
00938                         }
00939 
00940                         if (fwrite($fp,$tmp_data) == -1)
00941                         {
00942                                 die("FlashApp tmp file: cannot write to file. Please check Writepermissions.");
00943                         }
00944 
00945                         fclose($fp);
00946         
00947                 return true;
00948         }       
00949 
00954         function getRTETextWithMediaObjects()
00955         {
00956                 return parent::getRTETextWithMediaObjects();
00957         }
00958 
00959 }
00960 
00961 ?>

Generated on Fri Dec 13 2013 17:56:53 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1