19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
36 private \ILIAS\TestQuestionPool\InternalRequestService
$request;
88 $this->answers = array();
89 $this->coords = array();
92 $this->request = $DIC->testQuestionPool()->internal()->request();
123 if (strlen($this->title)
126 && ($this->image_filename)
127 && (count($this->answers))
159 $ilDB = $DIC[
'ilDB'];
161 "DELETE FROM qpl_a_imagemap WHERE question_fi = %s",
163 array( $this->
getId() )
167 foreach ($this->answers as
$key => $value) {
168 $answer_obj = $this->answers[
$key];
169 $answer_obj->setOrder(
$key);
170 $next_id =
$ilDB->nextId(
'qpl_a_imagemap');
172 "INSERT INTO qpl_a_imagemap (answer_id, question_fi, answertext, points, aorder, coords, area, points_unchecked) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
173 array(
"integer",
"integer",
"text",
"float",
"integer",
"text",
"text",
"float" ),
174 array( $next_id, $this->
id, $answer_obj->getAnswertext(
175 ), $answer_obj->getPoints(), $answer_obj->getOrder(
176 ), $answer_obj->getCoords(), $answer_obj->getArea(
177 ), $answer_obj->getPointsUnchecked() )
185 $ilDB = $DIC[
'ilDB'];
190 array( $this->
getId() )
195 ) .
" (question_fi, image_file, is_multiple_choice) VALUES (%s, %s, %s)",
196 array(
"integer",
"text",
'integer' ),
199 $this->image_filename,
200 (
int) $this->is_multiple_choice
212 if ($this->
id <= 0) {
217 $this_id = $this->
getId();
221 $original_id = $this->questioninfo->getOriginalId($this->
id);
224 if ((
int) $testObjId > 0) {
225 $clone->setObjId($testObjId);
244 $clone->copyPageOfQuestion($this_id);
246 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
248 $clone->duplicateImage($this_id, $thisObjId);
250 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
264 if ($this->
getId() <= 0) {
265 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
270 $original_id = $this->questioninfo->getOriginalId($this->
id);
272 $source_questionpool_id = $this->
getObjId();
273 $clone->setObjId($target_questionpool_id);
284 $clone->copyImage(
$original_id, $source_questionpool_id);
286 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
293 if ($this->
getId() <= 0) {
294 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
298 $sourceParentId = $this->
getObjId();
304 $clone->setObjId($targetParentId);
306 if ($targetQuestionTitle) {
307 $clone->setTitle($targetQuestionTitle);
312 $clone->copyPageOfQuestion($sourceQuestionId);
314 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
316 $clone->copyImage($sourceQuestionId, $sourceParentId);
318 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
329 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
331 if ((
int) $objectId > 0) {
332 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
335 if (!file_exists($imagepath)) {
341 if (!file_exists($imagepath_original .
$filename)) {
342 $ilLog->write(
"Could not find an image map file when trying to duplicate image: " . $imagepath_original . $filename);
343 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
344 $ilLog->write(
"Using fallback source directory:" . $imagepath_original);
347 if (!file_exists($imagepath_original . $filename) || !copy($imagepath_original . $filename, $imagepath . $filename)) {
348 $ilLog->write(
"Could not duplicate image for image map question: " . $imagepath_original . $filename);
352 public function copyImage($question_id, $source_questionpool): void
355 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
356 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
357 if (!file_exists($imagepath)) {
361 if (!copy($imagepath_original .
$filename, $imagepath . $filename)) {
362 print
"image could not be copied!!!! ";
378 $ilDB = $DIC[
'ilDB'];
380 $result =
$ilDB->queryF(
385 if ($result->numRows() == 1) {
387 $this->
setId($question_id);
390 $this->
setComment((
string) $data[
"description"]);
411 $result =
$ilDB->queryF(
412 "SELECT * FROM qpl_a_imagemap WHERE question_fi = %s ORDER BY aorder ASC",
416 if ($result->numRows() > 0) {
417 while ($data =
$ilDB->fetchAssoc($result)) {
418 $image_map_question =
new ASS_AnswerImagemap($data[
"answertext"] ??
'', $data[
"points"], $data[
"aorder"]);
419 $image_map_question->setCoords($data[
"coords"]);
420 $image_map_question->setArea($data[
"area"]);
421 $image_map_question->setPointsUnchecked($data[
'points_unchecked']);
422 array_push($this->answers, $image_map_question);
426 parent::loadFromDb($question_id);
439 if (count($shapes) > 0) {
440 foreach ($shapes as $shape) {
441 $this->
addAnswer($shape->getAnswertext(), 0.0, count($this->answers), $shape->getCoords(), $shape->getArea());
467 if (!empty($image_tempfilename)) {
469 if (!file_exists($imagepath)) {
473 $this->tpl->setOnScreenMessage(
'failure',
'The image could not be uploaded!');
478 $ilLog->write(
"gespeichert: " . $imagepath . $image_filename);
494 for ($i = 0; $i < count($this->answers); $i++) {
498 $imagemap_contents .=
"href=\"$href&selimage=" . $this->answers[$i]->getOrder() .
"\" /> ";
524 $points_unchecked = 0.0
526 if (array_key_exists($order, $this->answers)) {
530 $answer->setArea($area);
531 $answer->setPointsUnchecked($points_unchecked);
532 for ($i = count($this->answers) - 1; $i >= $order; $i--) {
533 $this->answers[$i + 1] = $this->answers[$i];
534 $this->answers[$i + 1]->setOrder($i + 1);
536 $this->answers[$order] = $answer;
541 $answer->setArea($area);
542 $answer->setPointsUnchecked($points_unchecked);
543 array_push($this->answers, $answer);
558 return count($this->answers);
577 if (count($this->answers) < 1) {
580 if ($index >= count($this->answers)) {
583 return $this->answers[$index];
615 if (count($this->answers) < 1) {
618 if ($index >= count($this->answers)) {
621 unset($this->answers[$index]);
622 $this->answers = array_values($this->answers);
623 for ($i = 0; $i < count($this->answers); $i++) {
624 if ($this->answers[$i]->
getOrder() > $index) {
625 $this->answers[$i]->setOrder($i);
640 $this->answers = array();
654 foreach ($this->answers as
$key => $value) {
655 if ($this->is_multiple_choice) {
656 if ($value->getPoints() > $value->getPointsUnchecked()) {
657 $points += $value->getPoints();
659 $points += $value->getPointsUnchecked();
662 if ($value->getPoints() >
$points) {
680 public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution =
true, $returndetails =
false): float
682 if ($returndetails) {
683 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
687 $ilDB = $DIC[
'ilDB'];
689 $found_values = array();
690 if (is_null($pass)) {
695 if (strcmp(
$data[
"value1"],
"") != 0) {
696 array_push($found_values,
$data[
"value1"]);
726 $ilDB = $DIC[
'ilDB'];
728 if (is_null($pass)) {
732 $solutionSelectionChanged =
false;
734 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$solutionSelectionChanged,
$ilDB, $active_id, $pass, $authorized) {
743 $solutionSelectionChanged =
true;
748 $this->is_multiple_choice
754 foreach ($selection as $selectedIndex) {
756 $solutionSelectionChanged =
true;
762 'value1' => (
int) $selection
765 $solutionSelectionChanged =
true;
769 if ($this->is_multiple_choice) {
771 'value1' => (
int) $this->request->raw(
'selImage')
777 $this->
saveCurrentSolution($active_id, $pass, $this->request->raw(
'selImage'), null, $authorized);
779 $solutionSelectionChanged =
true;
785 if ($solutionSelectionChanged) {
788 "log_user_entered_values",
790 ), $active_id, $this->
getId());
794 "log_user_not_entered_values",
796 ), $active_id, $this->
getId());
807 if ($this->is_multiple_choice
808 && $this->request->isset(
'remImage')) {
809 unset($solution[$this->request->int(
'remImage')]);
812 if ($this->request->isset(
'selImage')) {
813 if (!$this->is_multiple_choice) {
817 $solution[$this->request->int(
'selImage')] = $this->request->int(
'selImage');
825 if ($this->questioninfo->getOriginalId($this->getId())) {
826 parent::syncWithOriginal();
840 return "assImagemapQuestion";
853 return "qpl_qst_imagemap";
866 return "qpl_a_imagemap";
875 $text = parent::getRTETextWithMediaObjects();
876 foreach ($this->answers as $index => $answer) {
877 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), 0, $index);
887 parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
893 $worksheet->
setCell($startrow + $i, $col, $answer->getArea() .
": " . $answer->getCoords());
897 foreach ($solution as $solIndex => $sol) {
898 if ($sol[
'value1'] ==
$id) {
904 $worksheet->
setCell($startrow + $i, $col + 2, $cellValue);
909 return $startrow + $i + 1;
920 $this->image_filename =
"";
929 $result[
'id'] = $this->
getId();
936 $result[
'feedback'] = array(
937 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
938 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
946 "answertext" => (
string) $answer_obj->getAnswertext(),
947 "points" => (float) $answer_obj->getPoints(),
948 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
950 "coords" => $answer_obj->getCoords(),
951 "state" => $answer_obj->getState(),
952 "area" => $answer_obj->getArea(),
954 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0,
$key)
962 $result[
'mobs'] = $mobs;
964 return json_encode($result);
973 if ($found_values == null) {
977 if (count($found_values) > 0) {
978 foreach ($this->answers as
$key => $answer) {
979 if (in_array(
$key, $found_values)) {
980 $points += $answer->getPoints();
982 $points += $answer->getPointsUnchecked();
1029 $ilDB = $DIC[
'ilDB'];
1036 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1037 array(
"integer",
"integer",
"integer",
"integer"),
1038 array($active_id, $pass, $this->
getId(), $maxStep)
1042 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step IS NULL",
1043 array(
"integer",
"integer",
"integer"),
1044 array($active_id, $pass, $this->
getId())
1049 $result->addKeyValue($row[
"value1"], $row[
"value1"]);
1055 $result->setReachedPercentage((
$points / $max_points) * 100);
1069 if ($index !== null) {
1079 $solution = parent::getTestOutputSolutions($activeId, $pass);
1081 $this->currentSolution = array();
1082 foreach ($solution as $record) {
1083 $this->currentSolution[] = $record[
'value1'];
1094 return $this->request->raw(
'selImage');
1098 if (!$this->request->isset(
"selImage")) {
1102 if (!strlen($this->request->raw(
'selImage'))) {
1114 return $this->request->raw(
'remImage');
1118 if (!$this->is_multiple_choice) {
1122 if (!$this->request->isset(
"remImage")) {
1126 if (!strlen($this->request->raw(
'remImage'))) {
1146 if (!$this->request->isset(
"reuseSelection")) {
1150 if (!strlen($this->request->raw(
"reuseSelection"))) {
1154 if (!preg_match(
'/\d(,\d)*/', $this->request->raw(
"reuseSelection"))) {
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
setNrOfTries(int $a_nr_of_tries)
static getInstance($identifier)
calculateReachedPointsForSolution($found_values)
const PercentageResultExpression
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
const NumberOfResultExpression
savePreviewData(ilAssQuestionPreviewSession $previewSession)
const ExclusiveResultExpression
updateCurrentSolutionsAuthorization(int $activeId, int $pass, bool $authorized, bool $keepTime=false)
getRemoveSolutionSelectionParameter()
duplicate(bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
Duplicates an assImagemapQuestion.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Abstract basic class which is to be extended by the concrete assessment question type classes...
ILIAS TestQuestionPool InternalRequestService $request
getOperators($expression)
Get all available operations for a specific question.
getColumnCoord(int $a_col)
Get column "name" from number.
ensureNonNegativePoints($points)
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $image_filename="")
assImagemapQuestion constructor
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getParticipantsSolution()
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
deleteArea($index=0)
Deletes an answer.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
setComment(string $comment="")
getAddSolutionSelectionParameter()
float $points
The maximum available points for the question.
Base Exception for all Exceptions relating to Modules/Test.
setParticipantsSolution($participantSolution)
getIsMultipleChoice()
Returns true, if the imagemap question is a multiplechoice question.
deleteDummySolutionRecord(int $activeId, int $passIndex)
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
getTestOutputSolutions($activeId, $pass)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
setBold(string $a_coords)
Set cell(s) to bold.
static _enabledAssessmentLogging()
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
getAnswer($index=0)
Returns an answer.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveToDb($original_id="")
Saves an assImagemapQuestion object to a database.
uploadImagemap(array $shapes)
Uploads an image map and takes over the areas.
toJSON()
Returns a JSON representation of the question.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static logAction(string $logtext, int $active_id, int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteImage()
Deletes the image file.
const MODE_MULTIPLE_CHOICE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
string $question
The question text.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
setExportDetailsXLSX(ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
{}
isComplete()
Returns true, if a imagemap question is complete for use.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
copyImage($question_id, $source_questionpool)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
static getOperatorsByExpression($expression)
duplicateImage($question_id, $objectId=null)
setIsMultipleChoice($is_multiple_choice)
Set true if the Imagemapquestion is a multiplechoice Question.
getExpressionTypes()
Get all available expression types for a specific question.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
isRemoveSolutionSelectionRequest()
addAnswer( $answertext="", $points=0.0, $order=0, $coords="", $area="", $points_unchecked=0.0)
Adds a possible answer for a imagemap question.
saveQuestionDataToDb(int $original_id=-1)
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
getSolutionMaxPass(int $active_id)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
& getAnswers()
Returns the answer array.
copyObject($target_questionpool_id, $title="")
Copies an assImagemapQuestion object.
getAnswerCount()
Returns the number of answers.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOriginalId(?int $original_id)
getTestPresentationConfig()
setImageFilename($image_filename, $image_tempfilename="")
Sets the image file name.
setTitle(string $title="")
deleteSolutionRecordByValues(int $activeId, int $passIndex, bool $authorized, array $matchValues)
isReuseSolutionSelectionRequest()
setLifecycle(ilAssQuestionLifecycle $lifecycle)
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
getAnswerTableName()
Returns the name of the answer table in the database.
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getQuestionType()
Returns the question type of the question.
flushAnswers()
Deletes all answers.
forceExistingIntermediateSolution(int $activeId, int $passIndex, bool $considerDummyRecordCreation)
ILIAS DI LoggingServices $ilLog
lookupMaxStep(int $active_id, int $pass)
setAuthor(string $author="")
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
loadFromDb($question_id)
Loads a assImagemapQuestion object from a database.
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
getReuseSolutionSelectionParameter()
get_imagemap_contents($href="#")
Gets the imagemap file contents.
static explodeKeyValues(string $keyValues)
isAddSolutionSelectionRequest()
getAdditionalTableName()
Returns the name of the additional question data table in the database.
static getDraftInstance()
setQuestion(string $question="")
const EmptyAnswerExpression