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';
84 $this->thumb_size = 150;
86 $this->answers = array();
88 $this->feedback_setting = 2;
100 foreach ($this->answers as $answer) {
101 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) {
121 $ilDB = $DIC[
'ilDB'];
132 array($this->
getId())
136 $oldthumbsize =
$data[
'thumb_size'];
155 if (strlen($answer->getImage())) {
174 switch (strtoupper($path_info[
'extension'])) {
199 $ilDB = $DIC[
'ilDB'];
210 $this->
setId($question_id);
219 include_once(
"./Services/RTE/classes/class.ilRTE.php");
225 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
226 $this->lastChange =
$data[
'tstamp'];
227 $this->feedback_setting =
$data[
'feedback_setting'];
236 "SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
240 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
244 if (!@file_exists($imagefilename)) {
245 $data[
"imagefile"] =
"";
247 include_once(
"./Services/RTE/classes/class.ilRTE.php");
253 parent::loadFromDb($question_id);
263 if ($this->
id <= 0) {
268 $this_id = $this->
getId();
272 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
276 if ((
int) $testObjId > 0) {
277 $clone->setObjId($testObjId);
297 $clone->copyPageOfQuestion($this_id);
300 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
302 $clone->duplicateImages($this_id, $thisObjId);
304 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
316 if ($this->
id <= 0) {
322 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
325 $source_questionpool_id = $this->
getObjId();
326 $clone->setObjId($target_questionpool_id);
336 $clone->copyImages(
$original_id, $source_questionpool_id);
338 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
345 if ($this->
id <= 0) {
350 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
353 $sourceParentId = $this->
getObjId();
359 $clone->setObjId($targetParentId);
361 if ($targetQuestionTitle) {
362 $clone->setTitle($targetQuestionTitle);
367 $clone->copyPageOfQuestion($sourceQuestionId);
369 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
371 $clone->copyImages($sourceQuestionId, $sourceParentId);
373 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
421 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
422 if (array_key_exists($order, $this->answers)) {
425 $newchoices = array();
426 for (
$i = 0;
$i < $order;
$i++) {
427 array_push($newchoices, $this->answers[
$i]);
429 array_push($newchoices, $answer);
430 for (
$i = $order;
$i < count($this->answers);
$i++) {
435 $this->answers = $newchoices;
439 array_push($this->answers, $answer);
452 return count($this->answers);
469 if (count($this->answers) < 1) {
472 if (
$index >= count($this->answers)) {
476 return $this->answers[
$index];
492 if (count($this->answers) < 1) {
495 if (
$index >= count($this->answers)) {
498 $answer = $this->answers[
$index];
499 if (strlen($answer->getImage())) {
502 unset($this->answers[
$index]);
503 $this->answers = array_values($this->answers);
504 for (
$i = 0;
$i < count($this->answers);
$i++) {
505 if ($this->answers[
$i]->getOrder() >
$index) {
506 $this->answers[
$i]->setOrder(
$i);
519 $this->answers = array();
531 foreach ($this->answers as
$key => $value) {
532 if ($value->getPoints() >
$points) {
551 if ($returndetails) {
552 throw new ilTestException(
'return details not implemented for ' . __METHOD__);
556 $ilDB = $DIC[
'ilDB'];
558 $found_values = array();
559 if (is_null(
$pass)) {
564 if (strcmp(
$data[
"value1"],
"") != 0) {
565 array_push($found_values,
$data[
"value1"]);
569 foreach ($this->answers as
$key => $answer) {
570 if (count($found_values) > 0) {
571 if (in_array(
$key, $found_values)) {
572 $points += $answer->getPoints();
586 foreach ($this->answers as
$key => $answer) {
587 if (is_numeric($participantSolution) &&
$key == $participantSolution) {
588 $points = $answer->getPoints();
608 $ilDB = $DIC[
'ilDB'];
611 if (is_null(
$pass)) {
612 include_once
"./Modules/Test/classes/class.ilObjTest.php";
618 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values,
$ilDB, $active_id,
$pass, $authorized) {
621 $update =
$row[
"solution_id"];
624 if (strlen(
$_POST[
"multiple_choice_result"])) {
631 if (strlen(
$_POST[
"multiple_choice_result"])) {
638 if ($entered_values) {
639 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
644 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
655 if (strlen(
$_POST[
'multiple_choice_result' . $this->
getId() .
'ID'])) {
666 $ilDB = $DIC[
'ilDB'];
672 array( $this->
getId() )
677 ) .
" (question_fi, shuffle, allow_images, thumb_size, feedback_setting) VALUES (%s, %s, %s, %s, %s)",
678 array(
"integer",
"text",
"text",
"integer",
'integer' ),
682 ($this->isSingleline) ?
"0" :
"1",
693 $ilDB = $DIC[
'ilDB'];
694 if (!$this->isSingleline) {
698 "DELETE FROM qpl_a_sc WHERE question_fi = %s",
700 array( $this->
getId() )
703 foreach ($this->answers as
$key => $value) {
705 $answer_obj = $this->answers[
$key];
706 $next_id =
$ilDB->nextId(
'qpl_a_sc');
708 "INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
709 array(
'integer',
'integer',
'text',
'float',
'integer',
'text',
'integer' ),
714 $answer_obj->getPoints(),
715 $answer_obj->getOrder(),
716 $answer_obj->getImage(),
732 return "assSingleChoice";
765 public function setImageFile($image_filename, $image_tempfilename =
"")
768 if (!empty($image_tempfilename)) {
769 $image_filename = str_replace(
" ",
"_", $image_filename);
771 if (!file_exists($imagepath)) {
775 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
778 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
780 if (!preg_match(
"/^image/", $mimetype)) {
781 unlink($imagepath . $image_filename);
803 @unlink($imagepath . $image_filename);
804 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
813 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
815 if ((
int) $objectId > 0) {
816 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
819 foreach ($this->answers as $answer) {
822 if (!file_exists($imagepath)) {
825 if (!@copy($imagepath_original .
$filename, $imagepath . $filename)) {
826 $ilLog->write(
"image could not be duplicated!!!!",
$ilLog->ERROR);
827 $ilLog->write(
"object: " . print_r($this,
true),
$ilLog->ERROR);
829 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename)) {
831 $ilLog->write(
"image thumbnail could not be duplicated!!!!",
$ilLog->ERROR);
832 $ilLog->write(
"object: " . print_r($this,
true),
$ilLog->ERROR);
839 public function copyImages($question_id, $source_questionpool)
846 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
847 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
848 foreach ($this->answers as $answer) {
851 if (!file_exists($imagepath)) {
855 if (file_exists($imagepath_original .
$filename)) {
856 if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
858 "Could not clone source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
859 $imagepath_original . $filename,
860 $imagepath . $filename,
863 $source_questionpool,
869 if (file_exists($imagepath_original . $this->
getThumbPrefix() . $filename)) {
872 "Could not clone thumbnail source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
877 $source_questionpool,
895 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
897 foreach ($this->answers as $answer) {
900 if (@file_exists($imagepath .
$filename)) {
901 if (!file_exists($imagepath)) {
904 if (!file_exists($imagepath_original)) {
907 if (!@copy($imagepath . $filename, $imagepath_original . $filename)) {
908 $ilLog->write(
"image could not be duplicated!!!!",
$ilLog->ERROR);
909 $ilLog->write(
"object: " . print_r($this,
true),
$ilLog->ERROR);
912 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename)) {
914 $ilLog->write(
"image thumbnail could not be duplicated!!!!",
$ilLog->ERROR);
915 $ilLog->write(
"object: " . print_r($this,
true),
$ilLog->ERROR);
928 $text = parent::getRTETextWithMediaObjects();
929 foreach ($this->answers as
$index => $answer) {
930 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), 0,
$index);
931 $answer_obj = $this->answers[
$index];
932 $text .= $answer_obj->getAnswertext();
950 parent::setExportDetailsXLS($worksheet, $startrow, $active_id,
$pass);
955 $worksheet->setCell($startrow +
$i, 0, $answer->getAnswertext());
956 $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow +
$i));
958 count($solution) > 0 &&
959 isset($solution[0]) &&
960 is_array($solution[0]) &&
961 strlen($solution[0][
'value1']) > 0 &&
$id == $solution[0][
'value1']
963 $worksheet->setCell($startrow +
$i, 1, 1);
965 $worksheet->setCell($startrow +
$i, 1, 0);
970 return $startrow +
$i + 1;
980 $this->thumb_size = $a_size;
999 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1009 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
1010 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1016 if ((
string) $answer_obj->getImage()) {
1019 array_push($answers, array(
1020 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1021 'html_id' => (
int) $this->
getId() .
'_' .
$key,
1022 "points" => (float) $answer_obj->getPoints(),
1023 "order" => (int) $answer_obj->getOrder(),
1024 "image" => (string) $answer_obj->getImage(),
1026 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0,
$key)
1044 $answer = $this->answers[
$index];
1045 if (is_object($answer)) {
1047 $answer->setImage(
'');
1053 $value = rand(0, count($this->answers) - 1);
1054 $_POST[
"multiple_choice_result"] = (strlen($value)) ? (
string) $value :
'0';
1064 $multilineAnswerSetting =
$ilUser->getPref(
"tst_multiline_answers");
1065 if ($multilineAnswerSetting != 1) {
1066 $multilineAnswerSetting = 0;
1068 return $multilineAnswerSetting;
1075 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1089 $this->feedback_setting = $a_feedback_setting;
1103 if ($this->feedback_setting) {
1112 return 'feedback_correct_sc_mc';
1129 return $numExistingSolutionRecords > 0;
1157 require_once
"./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1186 $ilDB = $DIC[
'ilDB'];
1189 $maxStep = $this->lookupMaxStep($active_id,
$pass);
1191 if ($maxStep !== null) {
1193 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1194 array(
"integer",
"integer",
"integer",
"integer"),
1195 array($active_id,
$pass, $this->
getId(), $maxStep)
1199 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1200 array(
"integer",
"integer",
"integer"),
1242 parent::afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
1244 $origImagePath = $this->
buildImagePath($origQuestionId, $origParentObjId);
1245 $dupImagePath = $this->
buildImagePath($dupQuestionId, $dupParentObjId);
1248 if (is_dir($dupImagePath)) {
getSpecificFeedbackAllCorrectOptionLabel()
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.
getOutputType()
Gets the single choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1)...
getId()
Gets the id of the assQuestion object.
saveToDb($original_id="")
Saves the question to the database.
generateThumbForFile($path, $file)
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
const PercentageResultExpression
removeAnswerImage($index)
Class iQuestionCondition.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static getNumExistingSolutionRecords($activeId, $pass, $questionId)
returns the number of existing solution records for the given test active / pass and given question i...
const NumberOfResultExpression
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
Abstract basic class which is to be extended by the concrete assessment question type classes...
Class for answers with a binary state indicator.
setOutputType($output_type=OUTPUT_ORDER)
Sets the output type of the assSingleChoice object.
setMultilineAnswerSetting($a_setting=0)
& getAnswers()
Returns a reference to the answers array.
afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
{}
getAnswerCount()
Returns the number of answers.
ensureNonNegativePoints($points)
calculateResultsFromSolution($active_id, $pass=null, $obligationsEnabled=false)
Calculates the question results from a previously saved question solution.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
getSolutionValues($active_id, $pass=null, $authorized=true)
Loads solutions of a given user from the database an returns it.
isComplete()
Returns true, if a single choice question is complete for use.
setId($id=-1)
Sets the id of the assQuestion object.
copyObject($target_questionpool_id, $title="")
Copies an assSingleChoice object.
getQuestionType()
Returns the question type of the question.
getAnswerTableName()
Returns the name of the answer table in the database.
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)
loadFromDb($question_id)
Loads a assSingleChoice object from a database.
getParticipantsSolution()
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
setNrOfTries($a_nr_of_tries)
setSpecificFeedbackSetting($a_feedback_setting)
Sets the feedback settings in effect for the question.
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assSingleChoiceQuestion.
getAnswer($index=0)
Returns an answer with a given index.
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...
getOperators($expression)
Get all available operations for a specific question.
getObjId()
Get the object id of the container object.
getShuffle()
Gets the shuffle flag.
Base Exception for all Exceptions relating to Modules/Test.
getMultilineAnswerSetting()
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
getSpecificFeedbackSetting()
Gets the current feedback settings in effect for the question.
setParticipantsSolution($participantSolution)
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
removeSolutionRecordById($solutionId)
deleteImage($image_filename)
Deletes an image file.
static _getLogLanguage()
retrieve the log language for assessment logging
setAuthor($author="")
Sets the authors name of the assQuestion object.
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
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.
createRandomSolution($active_id, $pass)
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{}
isAnswered($active_id, $pass=null)
returns boolean wether the question is answered during test pass or not
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true, $tstamp=null)
Class for single choice questions.
deleteAnswer($index=0)
Deletes an answer with a given index.
Interface ilObjAnswerScoringAdjustable.
toJSON()
Returns a JSON representation of the question.
addAnswer( $answertext="", $points=0.0, $order=0, $answerimage="")
Adds a possible answer for a single choice question.
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
assSingleChoice constructor
getQuestion()
Gets the question string of the question object.
syncImages()
Sync images of a MC question on synchronisation with the original question.
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
flushAnswers()
Deletes all answers.
updateCurrentSolution($solutionId, $value1, $value2, $authorized=true)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
lmMigrateQuestionTypeSpecificContent(ilAssSelfAssessmentMigrator $migrator)
static getOperatorsByExpression($expression)
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
setPoints($a_points)
Sets the maximum available points for the question.
saveQuestionDataToDb($original_id="")
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
setImageFile($image_filename, $image_tempfilename="")
Sets the image file and uploads the image to the object's image directory.
setQuestion($question="")
Sets the question string of the question object.
duplicateImages($question_id, $objectId=null)
Interface ilObjQuestionScoringAdjustable.
buildImagePath($questionId, $parentObjectId)
setOriginalId($original_id)
getExpressionTypes()
Get all available expression types for a specific question.
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass...
getTitle()
Gets the title string of the assQuestion object.
static isObligationPossible($questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
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.
savePreviewData(ilAssQuestionPreviewSession $previewSession)
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
const EmptyAnswerExpression