ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.assFlashQuestion.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
5require_once './Modules/Test/classes/inc.AssessmentConstants.php';
6require_once './Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7require_once './Modules/TestQuestionPool/interfaces/interface.iQuestionCondition.php';
8
21{
22 private $width;
23 private $height;
24 private $parameters;
25 private $applet;
26
40 function __construct(
41 $title = "",
42 $comment = "",
43 $author = "",
44 $owner = -1,
45 $question = ""
46 )
47 {
48 parent::__construct($title, $comment, $author, $owner, $question);
49 $this->parameters = array();
50 $this->width = 540;
51 $this->height = 400;
52 $this->applet = "";
53 }
54
61 function isComplete()
62 {
63 if (strlen($this->title)
64 && ($this->author)
65 && ($this->question)
66 && ($this->getMaximumPoints() > 0)
67 && (strlen($this->getApplet()))
68 )
69 {
70 return true;
71 }
72 return false;
73 }
74
80 function saveToDb($original_id = "")
81 {
84 parent::saveToDb();
85 }
86
88 {
89 global $ilDB;
90 $ilDB->manipulateF( "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
91 array( "integer" ),
92 array( $this->getId() )
93 );
94 $ilDB->manipulateF( "INSERT INTO " . $this->getAdditionalTableName(
95 ) . " (question_fi, width, height, applet, params) VALUES (%s, %s, %s, %s, %s)",
96 array( "integer", "integer", "integer", "text", "text" ),
97 array(
98 $this->getId(),
99 (strlen( $this->getWidth() )) ? $this->getWidth() : 550,
100 (strlen( $this->getHeight() )) ? $this->getHeight() : 400,
101 $this->getApplet(),
102 serialize( $this->getParameters() )
103 )
104 );
105 if ($_SESSION["flash_upload_filename"])
106 {
107 $path = $this->getFlashPath();
109 @rename( $_SESSION["flash_upload_filename"], $path . $this->getApplet() );
110 unset($_SESSION["flash_upload_filename"]);
111 }
112 }
113
121 function loadFromDb($question_id)
122 {
123 global $ilDB;
124 $result = $ilDB->queryF("SELECT qpl_questions.*, " . $this->getAdditionalTableName() . ".* FROM qpl_questions LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = qpl_questions.question_id WHERE qpl_questions.question_id = %s",
125 array("integer"),
126 array($question_id)
127 );
128 if ($result->numRows() == 1)
129 {
130 $data = $ilDB->fetchAssoc($result);
131 $this->setId($question_id);
132 $this->setNrOfTries($data['nr_of_tries']);
133 $this->setTitle($data["title"]);
134 $this->setComment($data["description"]);
135 $this->setSuggestedSolution($data["solution_hint"]);
136 $this->setOriginalId($data["original_id"]);
137 $this->setObjId($data["obj_fi"]);
138 $this->setAuthor($data["author"]);
139 $this->setOwner($data["owner"]);
140 $this->setPoints($data["points"]);
141
142 include_once("./Services/RTE/classes/class.ilRTE.php");
143 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
144 $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
145
146 try
147 {
148 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
149 }
151 {
152 }
153
154 // load additional data
155 $result = $ilDB->queryF("SELECT * FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
156 array("integer"),
157 array($question_id)
158 );
159 if ($result->numRows() == 1)
160 {
161 $data = $ilDB->fetchAssoc($result);
162 $this->setWidth($data["width"]);
163 $this->setHeight($data["height"]);
164 $this->setApplet($data["applet"]);
165 $this->parameters = unserialize($data["params"]);
166 if (!is_array($this->parameters)) $this->clearParameters();
167 unset($_SESSION["flash_upload_filename"]);
168 }
169 }
170 parent::loadFromDb($question_id);
171 }
172
180 function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
181 {
182 if ($this->id <= 0)
183 {
184 // The question has not been saved. It cannot be duplicated
185 return;
186 }
187 // duplicate the question in database
188 $this_id = $this->getId();
189 $thisObjId = $this->getObjId();
190
191 $clone = $this;
192 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
194 $clone->id = -1;
195
196 if( (int)$testObjId > 0 )
197 {
198 $clone->setObjId($testObjId);
199 }
200
201 if ($title)
202 {
203 $clone->setTitle($title);
204 }
205
206 if ($author)
207 {
208 $clone->setAuthor($author);
209 }
210 if ($owner)
211 {
212 $clone->setOwner($owner);
213 }
214
215 if ($for_test)
216 {
217 $clone->saveToDb($original_id);
218 }
219 else
220 {
221 $clone->saveToDb();
222 }
223
224 // copy question page content
225 $clone->copyPageOfQuestion($this_id);
226 // copy XHTML media objects
227 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
228 // duplicate the applet
229 $clone->duplicateApplet($this_id, $thisObjId);
230
231 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
232
233 return $clone->id;
234 }
235
243 function copyObject($target_questionpool_id, $title = "")
244 {
245 if ($this->id <= 0)
246 {
247 // The question has not been saved. It cannot be duplicated
248 return;
249 }
250 // duplicate the question in database
251 $clone = $this;
252 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
254 $clone->id = -1;
255 $source_questionpool_id = $this->getObjId();
256 $clone->setObjId($target_questionpool_id);
257 if ($title)
258 {
259 $clone->setTitle($title);
260 }
261 $clone->saveToDb();
262
263 // copy question page content
264 $clone->copyPageOfQuestion($original_id);
265 // copy XHTML media objects
266 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
267 // duplicate the applet
268 $clone->copyApplet($original_id, $source_questionpool_id);
269
270 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
271
272 return $clone->id;
273 }
274
275 public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
276 {
277 if ($this->id <= 0)
278 {
279 // The question has not been saved. It cannot be duplicated
280 return;
281 }
282
283 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
284
285 $sourceQuestionId = $this->id;
286 $sourceParentId = $this->getObjId();
287
288 // duplicate the question in database
289 $clone = $this;
290 $clone->id = -1;
291
292 $clone->setObjId($targetParentId);
293
294 if ($targetQuestionTitle)
295 {
296 $clone->setTitle($targetQuestionTitle);
297 }
298
299 $clone->saveToDb();
300 // copy question page content
301 $clone->copyPageOfQuestion($sourceQuestionId);
302 // copy XHTML media objects
303 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
304 // duplicate the applet
305 $clone->copyApplet($sourceQuestionId, $sourceParentId);
306
307 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
308
309 return $clone->id;
310 }
311
318 protected function duplicateApplet($question_id, $objectId = null)
319 {
320 $flashpath = $this->getFlashPath();
321 $flashpath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $flashpath);
322
323 if( (int)$objectId > 0 )
324 {
325 $flashpath_original = str_replace("/$this->obj_id/", "/$objectId/", $flashpath_original);
326 }
327
328 if (!file_exists($flashpath))
329 {
330 ilUtil::makeDirParents($flashpath);
331 }
332 $filename = $this->getApplet();
333 if (!copy($flashpath_original . $filename, $flashpath . $filename)) {
334 print "flash applet could not be duplicated!!!! ";
335 }
336 }
337
344 protected function copyApplet($question_id, $source_questionpool)
345 {
346 $flashpath = $this->getFlashPath();
347 $flashpath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $flashpath);
348 $flashpath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $flashpath_original);
349 if (!file_exists($flashpath))
350 {
351 ilUtil::makeDirParents($flashpath);
352 }
353 $filename = $this->getApplet();
354 if (!copy($flashpath_original . $filename, $flashpath . $filename))
355 {
356 print "flash applet could not be copied!!!! ";
357 }
358 }
359
367 {
368 return $this->points;
369 }
370
381 public function calculateReachedPoints($active_id, $pass = NULL, $returndetails = FALSE)
382 {
383 if( $returndetails )
384 {
385 throw new ilTestException('return details not implemented for '.__METHOD__);
386 }
387
388 global $ilDB;
389
390 $found_values = array();
391 if (is_null($pass))
392 {
393 $pass = $this->getSolutionMaxPass($active_id);
394 }
395 $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
396 array("integer", "integer", "integer"),
397 array($active_id, $this->getId(), $pass)
398 );
399
400 $points = 0;
401 while ($data = $ilDB->fetchAssoc($result))
402 {
403 $points += $data["points"];
404 }
405
406 return $points;
407 }
408
410 {
411 $points = 0;
412 foreach($previewSession->getParticipantsSolution() as $solution)
413 {
414 if( isset($solution['points']) )
415 {
416 $points += $solution['points'];
417 }
418 }
419 return $points;
420 }
421
422 function sendToHost($url, $data, $optional_headers = null)
423 {
424 $params = array('http' => array(
425 'method' => 'POST',
426 'content' => $data
427 ));
428 if ($optional_headers !== null)
429 {
430 $params['http']['header'] = $optional_headers;
431 }
432 $ctx = stream_context_create($params);
433 $fp = @fopen($url, 'rb', false, $ctx);
434 if (!$fp)
435 {
436 throw new Exception("Problem with $url, $php_errormsg");
437 }
438 $response = @stream_get_contents($fp);
439 if ($response === false)
440 {
441 throw new Exception("Problem reading data from $url, $php_errormsg");
442 }
443 return $response;
444 }
445
454 function moveUploadedFile($tmpfile, $flashfile)
455 {
456 $result = "";
457 if (!empty($tmpfile))
458 {
459 $flashfile = str_replace(" ", "_", $flashfile);
460 $flashpath = $this->getFlashPath();
461 if (!file_exists($flashpath))
462 {
463 ilUtil::makeDirParents($flashpath);
464 }
465 if (ilUtil::moveUploadedFile($tmpfile, $flashfile, $flashpath.$flashfile))
466 {
467 $result = $flashfile;
468 }
469 }
470 return $result;
471 }
472
473 function deleteApplet()
474 {
475 @unlink($this->getFlashPath() . $this->getApplet());
476 $this->applet = "";
477 }
478
487 public function saveWorkingData($active_id, $pass = NULL)
488 {
489 // nothing to save!
490
491 //$this->getProcessLocker()->requestUserSolutionUpdateLock();
492 // store in tst_solutions
493 //$this->getProcessLocker()->releaseUserSolutionUpdateLock();
494
495 return true;
496 }
497
498 protected function savePreviewData(ilAssQuestionPreviewSession $previewSession)
499 {
500 // nothing to save!
501
502 return true;
503 }
504
513 protected function reworkWorkingData($active_id, $pass, $obligationsAnswered)
514 {
515 // nothing to rework!
516 }
517
527 {
528 return "assFlashQuestion";
529 }
530
540 {
541 return "qpl_qst_flash";
542 }
543
553 {
554 return "";
555 }
556
563 function deleteAnswers($question_id)
564 {
565 }
566
572 {
573 $text = parent::getRTETextWithMediaObjects();
574 return $text;
575 }
576
589 public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
590 {
591 include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
592 $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
593 $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
594 return $startrow + 1;
595 }
596
610 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
611 {
612 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assFlashQuestionImport.php";
613 $import = new assFlashQuestionImport($this);
614 $import->fromXML($item, $questionpool_id, $tst_id, $tst_object, $question_counter, $import_mapping);
615 }
616
624 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
625 {
626 include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assFlashQuestionExport.php";
627 $export = new assFlashQuestionExport($this);
628 return $export->toXML($a_include_header, $a_include_binary, $a_shuffle, $test_output, $force_image_references);
629 }
630
637 public function getBestSolution($active_id, $pass)
638 {
639 $user_solution = array();
640 return $user_solution;
641 }
642
643 public function setHeight($a_height)
644 {
645 if (!$a_height) $a_height = 400;
646 $this->height = $a_height;
647 }
648
649 public function getHeight()
650 {
651 return $this->height;
652 }
653
654 public function setWidth($a_width)
655 {
656 if (!$a_width) $a_width = 550;
657 $this->width = $a_width;
658 }
659
660 public function getWidth()
661 {
662 return $this->width;
663 }
664
665 public function setApplet($a_applet)
666 {
667 $this->applet = $a_applet;
668 }
669
670 public function getApplet()
671 {
672 return $this->applet;
673 }
674
675 public function addParameter($name, $value)
676 {
677 $this->parameters[$name] = $value;
678 }
679
680 public function setParameters($params)
681 {
682 if (is_array($params))
683 {
684 $this->parameters = $params;
685 }
686 else
687 {
688 $this->parameters = array();
689 }
690 }
691
692 public function removeParameter($name)
693 {
694 unset($this->parameters[$name]);
695 }
696
697 public function clearParameters()
698 {
699 $this->parameters = array();
700 }
701
702 public function getParameters()
703 {
704 return $this->parameters;
705 }
706
707 public function isAutosaveable()
708 {
709 return FALSE;
710 }
711
720 public function getOperators($expression)
721 {
722 require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
724 }
725
730 public function getExpressionTypes()
731 {
732 return array(
736 );
737 }
738
747 public function getUserQuestionResult($active_id, $pass)
748 {
749 // TODO: Implement getUserQuestionResult() method.
750 }
751
760 public function getAvailableAnswerOptions($index = null)
761 {
762 // TODO: Implement getAvailableAnswerOptions() method.
763 }
764}
$result
$filename
Definition: buildRTE.php:89
Class for flash question exports.
Class for flash question imports.
Class for Flash based questions.
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
moveUploadedFile($tmpfile, $flashfile)
Uploads a flash file.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assFlashQuestion.
getOperators($expression)
Get all available operations for a specific question.
getBestSolution($active_id, $pass)
Returns the best solution for a given pass of a participant.
fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
saveToDb($original_id="")
Saves a assFlashQuestion object to a database.
savePreviewData(ilAssQuestionPreviewSession $previewSession)
getAnswerTableName()
Returns the name of the answer table in the database.
isComplete()
Returns true, if a single choice question is complete for use.
sendToHost($url, $data, $optional_headers=null)
getExpressionTypes()
Get all available expression types for a specific question.
getQuestionType()
Returns the question type of the question.
saveWorkingData($active_id, $pass=NULL)
Saves the learners input of the question to the database.
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assFlashQuestion constructor
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
copyApplet($question_id, $source_questionpool)
Copy the flash applet.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
calculateReachedPoints($active_id, $pass=NULL, $returndetails=FALSE)
Returns the points, a learner has reached answering the question.
toXML($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM X...
reworkWorkingData($active_id, $pass, $obligationsAnswered)
Reworks the allready saved working data if neccessary.
loadFromDb($question_id)
Loads a assFlashQuestion object from a database.
deleteAnswers($question_id)
Deletes datasets from answers tables.
duplicateApplet($question_id, $objectId=null)
Duplicate the flash applet.
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
copyObject($target_questionpool_id, $title="")
Copies an assFlashQuestion object.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
Creates an Excel worksheet for the detailed cumulated results of this question.
Abstract basic class which is to be extended by the concrete assessment question type classes.
static _getOriginalId($question_id)
Returns the original id of a question.
setId($id=-1)
Sets the id of the assQuestion object.
setOriginalId($original_id)
setObjId($obj_id=0)
Set the object id of the container object.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
setSuggestedSolution($solution_id="", $subquestion_index=0, $is_import=false)
Sets a suggested solution for the question.
saveQuestionDataToDb($original_id="")
getId()
Gets the id of the assQuestion object.
getObjId()
Get the object id of the container object.
setTitle($title="")
Sets the title string of the assQuestion object.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second.
getFlashPath()
Returns the image path for web accessable flash files of a question.
setAuthor($author="")
Sets the authors name of the assQuestion object.
getTitle()
Gets the title string of the assQuestion object.
setPoints($a_points)
Sets the maximum available points for the question.
setComment($comment="")
Sets the comment string of the assQuestion object.
setNrOfTries($a_nr_of_tries)
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
setQuestion($question="")
Sets the question string of the question object.
_convert_text($a_text, $a_target="has been removed")
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
Base Exception for all Exceptions relating to Modules/Test.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
if(! $in) print
Class iQuestionCondition.
Interface ilObjQuestionScoringAdjustable.
$path
Definition: index.php:22
global $ilDB