ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 public function __construct(
41 $title = "",
42 $comment = "",
43 $author = "",
44 $owner = -1,
45 $question = ""
46 ) {
48 $this->parameters = array();
49 $this->width = 540;
50 $this->height = 400;
51 $this->applet = "";
52 }
53
60 public function isComplete()
61 {
62 if (strlen($this->title)
63 && ($this->author)
64 && ($this->question)
65 && ($this->getMaximumPoints() > 0)
66 && (strlen($this->getApplet()))
67 ) {
68 return true;
69 }
70 return false;
71 }
72
78 public function saveToDb($original_id = "")
79 {
82 parent::saveToDb();
83 }
84
86 {
87 global $DIC;
88 $ilDB = $DIC['ilDB'];
89 $ilDB->manipulateF(
90 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
91 array( "integer" ),
92 array( $this->getId() )
93 );
94 $ilDB->manipulateF(
95 "INSERT INTO " . $this->getAdditionalTableName(
96 ) . " (question_fi, width, height, applet, params) VALUES (%s, %s, %s, %s, %s)",
97 array( "integer", "integer", "integer", "text", "text" ),
98 array(
99 $this->getId(),
100 (strlen($this->getWidth())) ? $this->getWidth() : 550,
101 (strlen($this->getHeight())) ? $this->getHeight() : 400,
102 $this->getApplet(),
103 serialize($this->getParameters())
104 )
105 );
106
107 try {
108 $this->moveAppletIfExists();
109 } catch (\ilFileUtilsException $e) {
110 \ilLoggerFactory::getRootLogger()->error($e->getMessage());
111 }
112 }
113
118 protected function moveAppletIfExists()
119 {
120 if (
121 isset($_SESSION['flash_upload_filename']) && is_string($_SESSION['flash_upload_filename']) &&
122 file_exists($_SESSION['flash_upload_filename']) && is_file($_SESSION['flash_upload_filename'])
123 ) {
124 $path = $this->getFlashPath();
126
127 require_once 'Services/Utilities/classes/class.ilFileUtils.php';
128 \ilFileUtils::rename($_SESSION['flash_upload_filename'], $path . $this->getApplet());
129 unset($_SESSION['flash_upload_filename']);
130 }
131 }
132
140 public function loadFromDb($question_id)
141 {
142 global $DIC;
143 $ilDB = $DIC['ilDB'];
144 $result = $ilDB->queryF(
145 "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",
146 array("integer"),
147 array($question_id)
148 );
149 if ($result->numRows() == 1) {
150 $data = $ilDB->fetchAssoc($result);
151 $this->setId($question_id);
152 $this->setNrOfTries($data['nr_of_tries']);
153 $this->setTitle($data["title"]);
154 $this->setComment($data["description"]);
155 $this->setSuggestedSolution($data["solution_hint"]);
156 $this->setOriginalId($data["original_id"]);
157 $this->setObjId($data["obj_fi"]);
158 $this->setAuthor($data["author"]);
159 $this->setOwner($data["owner"]);
160 $this->setPoints($data["points"]);
161
162 include_once("./Services/RTE/classes/class.ilRTE.php");
163 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
164 $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
165
166 try {
170 }
171
172 try {
173 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
175 }
176
177 // load additional data
178 $result = $ilDB->queryF(
179 "SELECT * FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
180 array("integer"),
181 array($question_id)
182 );
183 if ($result->numRows() == 1) {
184 $data = $ilDB->fetchAssoc($result);
185 $this->setWidth($data["width"]);
186 $this->setHeight($data["height"]);
187 $this->setApplet($data["applet"]);
188 $this->parameters = unserialize($data["params"]);
189 if (!is_array($this->parameters)) {
190 $this->clearParameters();
191 }
192 unset($_SESSION["flash_upload_filename"]);
193 }
194 }
195 parent::loadFromDb($question_id);
196 }
197
205 public function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
206 {
207 if ($this->id <= 0) {
208 // The question has not been saved. It cannot be duplicated
209 return;
210 }
211 // duplicate the question in database
212 $this_id = $this->getId();
213 $thisObjId = $this->getObjId();
214
215 $clone = $this;
216 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
218 $clone->id = -1;
219
220 if ((int) $testObjId > 0) {
221 $clone->setObjId($testObjId);
222 }
223
224 if ($title) {
225 $clone->setTitle($title);
226 }
227
228 if ($author) {
229 $clone->setAuthor($author);
230 }
231 if ($owner) {
232 $clone->setOwner($owner);
233 }
234
235 if ($for_test) {
236 $clone->saveToDb($original_id);
237 } else {
238 $clone->saveToDb();
239 }
240
241 // copy question page content
242 $clone->copyPageOfQuestion($this_id);
243 // copy XHTML media objects
244 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
245 // duplicate the applet
246 $clone->duplicateApplet($this_id, $thisObjId);
247
248 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
249
250 return $clone->id;
251 }
252
260 public function copyObject($target_questionpool_id, $title = "")
261 {
262 if ($this->id <= 0) {
263 // The question has not been saved. It cannot be duplicated
264 return;
265 }
266 // duplicate the question in database
267 $clone = $this;
268 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
270 $clone->id = -1;
271 $source_questionpool_id = $this->getObjId();
272 $clone->setObjId($target_questionpool_id);
273 if ($title) {
274 $clone->setTitle($title);
275 }
276 $clone->saveToDb();
277
278 // copy question page content
279 $clone->copyPageOfQuestion($original_id);
280 // copy XHTML media objects
281 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
282 // duplicate the applet
283 $clone->copyApplet($original_id, $source_questionpool_id);
284
285 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
286
287 return $clone->id;
288 }
289
290 public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
291 {
292 if ($this->id <= 0) {
293 // The question has not been saved. It cannot be duplicated
294 return;
295 }
296
297 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
298
299 $sourceQuestionId = $this->id;
300 $sourceParentId = $this->getObjId();
301
302 // duplicate the question in database
303 $clone = $this;
304 $clone->id = -1;
305
306 $clone->setObjId($targetParentId);
307
308 if ($targetQuestionTitle) {
309 $clone->setTitle($targetQuestionTitle);
310 }
311
312 $clone->saveToDb();
313 // copy question page content
314 $clone->copyPageOfQuestion($sourceQuestionId);
315 // copy XHTML media objects
316 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
317 // duplicate the applet
318 $clone->copyApplet($sourceQuestionId, $sourceParentId);
319
320 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
321
322 return $clone->id;
323 }
324
331 protected function duplicateApplet($question_id, $objectId = null)
332 {
333 $flashpath = $this->getFlashPath();
334 $flashpath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $flashpath);
335
336 if ((int) $objectId > 0) {
337 $flashpath_original = str_replace("/$this->obj_id/", "/$objectId/", $flashpath_original);
338 }
339
340 if (!file_exists($flashpath)) {
341 ilUtil::makeDirParents($flashpath);
342 }
343 $filename = $this->getApplet();
344 if (!copy($flashpath_original . $filename, $flashpath . $filename)) {
345 print "flash applet could not be duplicated!!!! ";
346 }
347 }
348
355 protected function copyApplet($question_id, $source_questionpool)
356 {
357 $flashpath = $this->getFlashPath();
358 $flashpath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $flashpath);
359 $flashpath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $flashpath_original);
360 if (!file_exists($flashpath)) {
361 ilUtil::makeDirParents($flashpath);
362 }
363 $filename = $this->getApplet();
364 if (!copy($flashpath_original . $filename, $flashpath . $filename)) {
365 print "flash applet could not be copied!!!! ";
366 }
367 }
368
375 public function getMaximumPoints()
376 {
377 return $this->points;
378 }
379
390 public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution = true, $returndetails = false)
391 {
392 if ($returndetails) {
393 throw new ilTestException('return details not implemented for ' . __METHOD__);
394 }
395
396 global $DIC;
397 $ilDB = $DIC['ilDB'];
398
399 $found_values = array();
400 if (is_null($pass)) {
401 $pass = $this->getSolutionMaxPass($active_id);
402 }
403
404 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
405
406 $points = 0;
407 while ($data = $ilDB->fetchAssoc($result)) {
408 $points += $data["points"];
409 }
410
411 return $points;
412 }
413
415 {
416 $points = 0;
417 foreach ($previewSession->getParticipantsSolution() as $solution) {
418 if (isset($solution['points'])) {
419 $points += $solution['points'];
420 }
421 }
422
423 $reachedPoints = $this->deductHintPointsFromReachedPoints($previewSession, $points);
424
425 return $this->ensureNonNegativePoints($reachedPoints);
426 }
427
428 public function sendToHost($url, $data, $optional_headers = null)
429 {
430 $params = array('http' => array(
431 'method' => 'POST',
432 'content' => $data
433 ));
434 if ($optional_headers !== null) {
435 $params['http']['header'] = $optional_headers;
436 }
437 $ctx = stream_context_create($params);
438 $fp = @fopen($url, 'rb', false, $ctx);
439 if (!$fp) {
440 throw new Exception("Problem with $url, $php_errormsg");
441 }
442 $response = @stream_get_contents($fp);
443 if ($response === false) {
444 throw new Exception("Problem reading data from $url, $php_errormsg");
445 }
446 return $response;
447 }
448
457 public function moveUploadedFile($tmpfile, $flashfile)
458 {
459 $result = "";
460 if (!empty($tmpfile)) {
461 $flashfile = str_replace(" ", "_", $flashfile);
462 $flashpath = $this->getFlashPath();
463 if (!file_exists($flashpath)) {
464 ilUtil::makeDirParents($flashpath);
465 }
466 if (ilUtil::moveUploadedFile($tmpfile, $flashfile, $flashpath . $flashfile)) {
467 $result = $flashfile;
468 }
469 }
470 return $result;
471 }
472
473 public function deleteApplet()
474 {
475 @unlink($this->getFlashPath() . $this->getApplet());
476 $this->applet = "";
477 }
478
487 public function saveWorkingData($active_id, $pass = null, $authorized = true)
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 public function getQuestionType()
514 {
515 return "assFlashQuestion";
516 }
517
526 public function getAdditionalTableName()
527 {
528 return "qpl_qst_flash";
529 }
530
539 public function getAnswerTableName()
540 {
541 return "";
542 }
543
550 public function deleteAnswers($question_id)
551 {
552 }
553
559 {
560 $text = parent::getRTETextWithMediaObjects();
561 return $text;
562 }
563
567 public function setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
568 {
569 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
570
571 return $startrow + 1;
572 }
573
587 public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
588 {
589 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assFlashQuestionImport.php";
590 $import = new assFlashQuestionImport($this);
591 $import->fromXML($item, $questionpool_id, $tst_id, $tst_object, $question_counter, $import_mapping);
592 }
593
601 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
602 {
603 include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assFlashQuestionExport.php";
604 $export = new assFlashQuestionExport($this);
605 return $export->toXML($a_include_header, $a_include_binary, $a_shuffle, $test_output, $force_image_references);
606 }
607
614 public function getBestSolution($active_id, $pass)
615 {
616 $user_solution = array();
617 return $user_solution;
618 }
619
620 public function setHeight($a_height)
621 {
622 if (!$a_height) {
623 $a_height = 400;
624 }
625 $this->height = $a_height;
626 }
627
628 public function getHeight()
629 {
630 return $this->height;
631 }
632
633 public function setWidth($a_width)
634 {
635 if (!$a_width) {
636 $a_width = 550;
637 }
638 $this->width = $a_width;
639 }
640
641 public function getWidth()
642 {
643 return $this->width;
644 }
645
646 public function setApplet($a_applet)
647 {
648 $this->applet = $a_applet;
649 }
650
651 public function getApplet()
652 {
653 return $this->applet;
654 }
655
656 public function addParameter($name, $value)
657 {
658 $this->parameters[$name] = $value;
659 }
660
661 public function setParameters($params)
662 {
663 if (is_array($params)) {
664 $this->parameters = $params;
665 } else {
666 $this->parameters = array();
667 }
668 }
669
670 public function removeParameter($name)
671 {
672 unset($this->parameters[$name]);
673 }
674
675 public function clearParameters()
676 {
677 $this->parameters = array();
678 }
679
680 public function getParameters()
681 {
682 return $this->parameters;
683 }
684
685 public function isAutosaveable()
686 {
687 return false;
688 }
689
698 public function getOperators($expression)
699 {
700 require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
702 }
703
708 public function getExpressionTypes()
709 {
710 return array(
714 );
715 }
716
725 public function getUserQuestionResult($active_id, $pass)
726 {
727 // TODO: Implement getUserQuestionResult() method.
728 }
729
738 public function getAvailableAnswerOptions($index = null)
739 {
740 // TODO: Implement getAvailableAnswerOptions() method.
741 }
742
743 // fau: testNav - new function getTestQuestionConfig()
748 // hey: refactored identifiers
750 // hey.
751 {
752 // hey: refactored identifiers
753 return parent::buildTestPresentationConfig()
754 // hey.
755 ->setFormChangeDetectionEnabled(false)
756 ->setBackgroundChangeDetectionEnabled(true);
757 }
758 // fau.
759}
$result
if(! $in) print
$filename
Definition: buildRTE.php:89
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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)
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{Creates an Excel worksheet for the detailed cumulated results of this question.object}
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.
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
__construct( $title="", $comment="", $author="", $owner=-1, $question="")
assFlashQuestion constructor
moveAppletIfExists()
Moves an applet file (maybe stored in the PHP session) to its final filesystem destination.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
copyApplet($question_id, $source_questionpool)
Copy the flash applet.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
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...
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="")
buildTestPresentationConfig()
Get the test question configuration.
Abstract basic class which is to be extended by the concrete assessment question type classes.
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass.
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.
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
getFlashPath()
Returns the image path for web accessable flash files of a question.
setAuthor($author="")
Sets the authors name of the assQuestion object.
setLifecycle(ilAssQuestionLifecycle $lifecycle)
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.
ensureNonNegativePoints($points)
Class to report exception.
static rename($a_source, $a_target)
Rename a file.
static getRootLogger()
The unique root logger has a fixed error level.
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.
Class iQuestionCondition.
Interface ilObjQuestionScoringAdjustable.
if($format !==null) $name
Definition: metadata.php:230
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url
$response
global $ilDB
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46