4 require_once
'./Modules/TestQuestionPool/classes/class.assQuestion.php';
5 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
6 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
8 require_once
'./Modules/TestQuestionPool/interfaces/interface.iQuestionCondition.php';
9 require_once
'./Modules/TestQuestionPool/classes/class.ilUserQuestionResult.php';
10 require_once
'Modules/TestQuestionPool/interfaces/interface.ilAssSpecificFeedbackOptionLabelProvider.php';
117 $this->thumb_size = 150;
118 $this->answers =
array();
120 $this->selectionLimit = null;
121 $this->feedback_setting = 0;
169 $this->ensureNoInvalidObligation($this->
getId());
182 if (strlen($answer->getImage()))
210 switch (strtoupper($path_info[
'extension']))
243 $this->
setId($question_id);
252 include_once(
"./Services/RTE/classes/class.ilRTE.php");
258 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
259 $this->lastChange =
$data[
'tstamp'];
261 $this->feedback_setting =
$data[
'feedback_setting'];
272 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
276 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
282 if (!@file_exists($imagefilename))
284 $data[
"imagefile"] =
"";
286 include_once(
"./Services/RTE/classes/class.ilRTE.php");
292 parent::loadFromDb($question_id);
306 $this_id = $this->
getId();
310 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
314 if( (
int)$testObjId > 0 )
316 $clone->setObjId($testObjId);
343 $clone->copyPageOfQuestion($this_id);
345 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
347 $clone->duplicateImages($this_id, $thisObjId);
349 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
366 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
369 $source_questionpool_id = $this->
getObjId();
370 $clone->setObjId($target_questionpool_id);
381 $clone->copyImages(
$original_id, $source_questionpool_id);
383 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
396 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
399 $sourceParentId = $this->
getObjId();
405 $clone->setObjId($targetParentId);
407 if ($targetQuestionTitle)
409 $clone->setTitle($targetQuestionTitle);
414 $clone->copyPageOfQuestion($sourceQuestionId);
416 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
418 $clone->copyImages($sourceQuestionId, $sourceParentId);
420 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
464 $points_unchecked = 0.0,
469 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
470 if (array_key_exists($order, $this->answers))
474 $newchoices =
array();
475 for ($i = 0; $i < $order; $i++)
477 array_push($newchoices, $this->answers[$i]);
479 array_push($newchoices, $answer);
480 for ($i = $order; $i < count($this->answers); $i++)
486 $this->answers = $newchoices;
492 array_push($this->answers, $answer);
504 return count($this->answers);
517 if ($index < 0)
return NULL;
518 if (count($this->answers) < 1)
return NULL;
519 if ($index >= count($this->answers))
return NULL;
521 return $this->answers[$index];
533 if ($index < 0)
return;
534 if (count($this->answers) < 1)
return;
535 if ($index >= count($this->answers))
return;
536 $answer = $this->answers[$index];
537 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
538 unset($this->answers[$index]);
539 $this->answers = array_values($this->answers);
540 for ($i = 0; $i < count($this->answers); $i++)
542 if ($this->answers[$i]->getOrder() > $index)
544 $this->answers[$i]->setOrder($i);
556 $this->answers =
array();
568 foreach ($this->answers as $key => $value)
570 if ($value->getPoints() > $value->getPointsUnchecked())
572 $allpoints += $value->getPoints();
576 $allpoints += $value->getPointsUnchecked();
597 throw new ilTestException(
'return details not implemented for '.__METHOD__);
602 $found_values =
array();
610 if (strcmp(
$data[
"value1"],
"") != 0)
612 array_push($found_values,
$data[
"value1"]);
629 $failureMsg = sprintf($this->lng->txt(
'ass_mc_sel_lim_exhausted_hint'),
656 include_once
"./Modules/Test/classes/class.ilObjTest.php";
662 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function() use (&$entered_values, $active_id,
$pass, $authorized) {
668 foreach($solutionSubmit as $value)
678 if (!empty(
$_POST[
'mc_none_above']))
688 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
696 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
715 ) .
" WHERE question_fi = %s",
722 $oldthumbsize =
$data[
'thumb_size'];
726 if (!$this->isSingleline)
735 'allow_images' =>
array(
'text', $this->isSingleline ? 0 : 1),
741 'question_fi' =>
array(
'integer', $this->
getId())
750 $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
755 foreach ($this->answers as $key => $value)
757 $answer_obj = $this->answers[$key];
758 $next_id = $ilDB->nextId(
'qpl_a_mc' );
759 $ilDB->manipulateF(
"INSERT INTO qpl_a_mc (answer_id, question_fi, answertext, points, points_unchecked, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
760 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer' ),
765 $answer_obj->getPoints(),
766 $answer_obj->getPointsUnchecked(),
767 $answer_obj->getOrder(),
768 $answer_obj->getImage(),
789 parent::syncWithOriginal();
800 return "assMultipleChoice";
830 public function setImageFile($image_filename, $image_tempfilename =
"")
833 if (!empty($image_tempfilename))
835 $image_filename = str_replace(
" ",
"_", $image_filename);
837 if (!file_exists($imagepath))
847 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
849 if (!preg_match(
"/^image/", $mimetype))
851 unlink($imagepath . $image_filename);
875 @unlink($imagepath . $image_filename);
876 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
880 function duplicateImages($question_id, $objectId = null)
886 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
888 if( (
int)$objectId > 0 )
890 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
893 foreach ($this->answers as $answer)
898 if(!file_exists($imagepath))
903 if(file_exists($imagepath_original .
$filename))
905 if(!copy($imagepath_original . $filename, $imagepath . $filename))
907 $ilLog->warning(sprintf(
908 "Could not clone source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
909 $imagepath_original . $filename, $imagepath . $filename,
910 $question_id, $this->
id, $objectId, $this->obj_id
915 if(file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
919 $ilLog->warning(sprintf(
920 "Could not clone thumbnail source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
922 $question_id, $this->
id, $objectId, $this->obj_id
934 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
935 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
936 foreach ($this->answers as $answer)
941 if (!file_exists($imagepath))
945 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
947 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
948 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
950 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
954 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
955 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
972 $originalObjId = parent::lookupParentObjId($this->
getOriginalId());
973 $imagepath_original = $this->
getImagePath($question_id, $originalObjId);
976 foreach ($this->answers as $answer)
981 if (@file_exists($imagepath .
$filename))
983 if (!file_exists($imagepath))
987 if (!file_exists($imagepath_original))
991 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
993 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
994 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
997 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
1001 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
1002 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
1014 $text = parent::getRTETextWithMediaObjects();
1015 foreach ($this->answers as $index => $answer)
1017 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), $index);
1018 $answer_obj = $this->answers[$index];
1019 $text .= $answer_obj->getAnswertext();
1037 parent::setExportDetailsXLS(
$worksheet, $startrow, $active_id,
$pass);
1044 $worksheet->setCell($startrow + $i, 0, $answer->getAnswertext());
1047 foreach ($solution as $solutionvalue)
1049 if (
$id == $solutionvalue[
"value1"])
1065 return $startrow + $i + 1;
1075 $this->thumb_size = $a_size;
1095 require_once
'./Services/RTE/classes/class.ilRTE.php';
1105 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
1106 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1111 foreach ($this->
getAnswers() as $key => $answer_obj)
1113 if((
string) $answer_obj->getImage())
1117 array_push($answers,
array(
1118 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1119 "points_checked" => (
float) $answer_obj->getPointsChecked(),
1120 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1121 "order" => (int) $answer_obj->getOrder(),
1122 "image" => (
string) $answer_obj->getImage(),
1124 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
1144 $answer = $this->answers[$index];
1145 if (is_object($answer))
1148 $answer->setImage(
'');
1156 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1157 if ($multilineAnswerSetting != 1)
1159 $multilineAnswerSetting = 0;
1161 return $multilineAnswerSetting;
1167 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1181 $this->feedback_setting = $a_feedback_setting;
1195 if ($this->feedback_setting)
1207 return 'feedback_correct_sc_mc';
1225 return $numExistingSolutionRecords > 0;
1245 SELECT SUM(points) points_for_checked_answers 1247 WHERE question_fi = %s AND points > 0 1254 return $row[
'points_for_checked_answers'] > 0;
1265 public function ensureNoInvalidObligation($questionId)
1271 SELECT SUM(qpl_a_mc.points) points_for_checked_answers, 1274 FROM tst_test_question 1277 ON qpl_a_mc.question_fi = tst_test_question.question_fi 1279 WHERE tst_test_question.question_fi = %s 1280 AND tst_test_question.obligatory = 1 1282 GROUP BY test_question_id 1287 $updateTestQuestionIds =
array();
1289 while(
$row = $ilDB->fetchAssoc(
$res) )
1291 if(
$row[
'points_for_checked_answers'] <= 0 )
1293 $updateTestQuestionIds[] =
$row[
'test_question_id'];
1297 if( count($updateTestQuestionIds) )
1299 $test_question_id__IN__updateTestQuestionIds = $ilDB->in(
1300 'test_question_id', $updateTestQuestionIds,
false,
'integer' 1304 UPDATE tst_test_question 1306 WHERE $test_question_id__IN__updateTestQuestionIds 1309 $ilDB->manipulate(
$query);
1318 $solutionSubmit =
array();
1319 foreach(
$_POST as $key => $value)
1321 if(preg_match(
"/^multiple_choice_result_(\d+)/", $key))
1325 $solutionSubmit[] = $value;
1329 return $solutionSubmit;
1340 foreach($this->answers as $key => $answer)
1342 if(in_array($key, $found_values))
1344 $points += $answer->getPoints();
1347 $points += $answer->getPointsUnchecked();
1352 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1354 if(($mc_scoring == 0) && (count($found_values) == 0))
1372 require_once
"./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1404 $maxStep = $this->lookupMaxStep($active_id,
$pass);
1406 if( $maxStep !== null )
1408 $data = $ilDB->queryF(
1409 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1410 array(
"integer",
"integer",
"integer",
"integer"),
1416 $data = $ilDB->queryF(
1417 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1418 array(
"integer",
"integer",
"integer"),
flushAnswers()
Deletes all answers.
static isObligationPossible($questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
calculateReachedPointsForSolution($found_values, $active_id=0)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getId()
Gets the id of the assQuestion object.
addAnswer( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
Adds a possible answer for a multiple choice question.
setLastChange($lastChange)
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
const PercentageResultExpression
toJSON()
Returns a JSON representation of the question.
Class iQuestionCondition.
generateThumbForFile($path, $file)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
isComplete()
Returns true, if a multiple choice question is complete for use.
static getNumExistingSolutionRecords($activeId, $pass, $questionId)
returns the number of existing solution records for the given test active / pass and given question i...
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assMultipleChoiceQuestion.
copyObject($target_questionpool_id, $title="")
Copies an assMultipleChoice object.
const NumberOfResultExpression
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
const ExclusiveResultExpression
rebuildThumbnails()
Rebuild the thumbnail images with a new thumbnail size.
reworkWorkingData($active_id, $pass, $obligationsAnswered, $authorized)
{}
isAnswered($active_id, $pass=NULL)
returns boolean wether the question is answered during test pass or not
Abstract basic class which is to be extended by the concrete assessment question type classes...
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
setSelectionLimit($selectionLimit)
setId($id=-1)
Sets the id of the assQuestion object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second. ...
migrateToLmContent($content)
Add rich text string
The name of the decorator.
setOutputType($output_type=OUTPUT_ORDER)
Sets the output type of the assMultipleChoice object.
getQuestionType()
Returns the question type of the question.
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
setNrOfTries($a_nr_of_tries)
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
loadFromDb($question_id)
Loads a assMultipleChoice object from a database.
setShuffle($shuffle=true)
Sets the shuffle flag.
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...
Class for multiple choice tests.
getObjId()
Get the object id of the container object.
getSpecificFeedbackAllCorrectOptionLabel()
getShuffle()
Gets the shuffle flag.
lmMigrateQuestionTypeSpecificContent(ilAssSelfAssessmentMigrator $migrator)
Base Exception for all Exceptions relating to Modules/Test.
getMultilineAnswerSetting()
removeAnswerImage($index)
saveToDb($original_id="")
Saves a assMultipleChoice object to a database.
deleteAnswer($index=0)
Deletes an answer with a given index.
static _getLogLanguage()
retrieve the log language for assessment logging
setAuthor($author="")
Sets the authors name of the assQuestion object.
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
Class ilUserQuestionResult.
getAnswerCount()
Returns the number of answers.
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true, $tstamp=null)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
getSpecificFeedbackSetting()
Gets the current feedback settings in effect for the question.
Interface ilObjAnswerScoringAdjustable.
saveWorkingData($active_id, $pass=NULL, $authorized=true)
Saves the learners input of the question to the database.
getQuestion()
Gets the question string of the question object.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
assMultipleChoice constructor
syncImages()
Sync images of a MC question on synchronisation with the original question.
getOperators($expression)
Get all available operations for a specific question.
setIsSingleline($isSingleline)
getAnswer($index=0)
Returns an answer with a given index.
& getAnswers()
Returns a reference to the answers array.
setSpecificFeedbackSetting($a_feedback_setting)
Sets the feedback settings in effect for the question.
deleteImage($image_filename)
Deletes an image file.
getExpressionTypes()
Get all available expression types for a specific question.
Create styles array
The data for the language used.
static getOperatorsByExpression($expression)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
setPoints($a_points)
Sets the maximum available points for the question.
saveQuestionDataToDb($original_id="")
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
setImageFile($image_filename, $image_tempfilename="")
Sets the image file and uploads the image to the object's image directory.
calculateReachedPoints($active_id, $pass=NULL, $authorizedSolution=true, $returndetails=FALSE)
Returns the points, a learner has reached answering the question.
setQuestion($question="")
Sets the question string of the question object.
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
Interface ilObjQuestionScoringAdjustable.
removeCurrentSolution($active_id, $pass, $authorized=true)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
static _getMCScoring($active_id)
Gets the scoring type for multiple choice questions.
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{}
setOriginalId($original_id)
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass...
getAnswerTableName()
Returns the name of the answer table in the database.
getSolutionValues($active_id, $pass=NULL, $authorized=true)
Loads solutions of a given user from the database an returns it.
getTitle()
Gets the title string of the assQuestion object.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
getOutputType()
Gets the multiple choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1)...
setTitle($title="")
Sets the title string of the assQuestion object.
setObjId($obj_id=0)
Set the object id of the container object.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
setComment($comment="")
Sets the comment string of the assQuestion object.
setMultilineAnswerSetting($a_setting=0)
copyImages($question_id, $source_questionpool)
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
const EmptyAnswerExpression