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';
111 $this->thumb_size = 150;
112 $this->answers = array();
124 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
145 $this->ensureNoInvalidObligation($this->
getId());
158 if (strlen($answer->getImage()))
186 switch (strtoupper($path_info[
'extension']))
219 $this->
setId($question_id);
228 include_once(
"./Services/RTE/classes/class.ilRTE.php");
234 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
235 $this->lastChange =
$data[
'tstamp'];
236 $this->feedback_setting =
$data[
'feedback_setting'];
247 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
251 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
257 if (!@file_exists($imagefilename))
259 $data[
"imagefile"] =
"";
261 include_once(
"./Services/RTE/classes/class.ilRTE.php");
267 parent::loadFromDb($question_id);
281 $this_id = $this->
getId();
285 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
289 if( (
int)$testObjId > 0 )
291 $clone->setObjId($testObjId);
318 $clone->copyPageOfQuestion($this_id);
320 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
322 $clone->duplicateImages($this_id, $thisObjId);
324 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
341 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
344 $source_questionpool_id = $this->
getObjId();
345 $clone->setObjId($target_questionpool_id);
356 $clone->copyImages(
$original_id, $source_questionpool_id);
358 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
371 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
374 $sourceParentId = $this->
getObjId();
380 $clone->setObjId($targetParentId);
382 if ($targetQuestionTitle)
384 $clone->setTitle($targetQuestionTitle);
389 $clone->copyPageOfQuestion($sourceQuestionId);
391 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
393 $clone->copyImages($sourceQuestionId, $sourceParentId);
395 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
439 $points_unchecked = 0.0,
444 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
445 if (array_key_exists($order, $this->answers))
449 $newchoices = array();
450 for ($i = 0; $i < $order; $i++)
452 array_push($newchoices, $this->answers[$i]);
454 array_push($newchoices, $answer);
455 for ($i = $order; $i < count($this->answers); $i++)
461 $this->answers = $newchoices;
467 array_push($this->answers, $answer);
479 return count($this->answers);
492 if ($index < 0)
return NULL;
493 if (count($this->answers) < 1)
return NULL;
494 if ($index >= count($this->answers))
return NULL;
496 return $this->answers[$index];
508 if ($index < 0)
return;
509 if (count($this->answers) < 1)
return;
510 if ($index >= count($this->answers))
return;
511 $answer = $this->answers[$index];
512 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
513 unset($this->answers[$index]);
514 $this->answers = array_values($this->answers);
515 for ($i = 0; $i < count($this->answers); $i++)
517 if ($this->answers[$i]->getOrder() > $index)
519 $this->answers[$i]->setOrder($i);
531 $this->answers = array();
543 foreach ($this->answers as $key => $value)
545 if ($value->getPoints() > $value->getPointsUnchecked())
547 $allpoints += $value->getPoints();
551 $allpoints += $value->getPointsUnchecked();
572 throw new ilTestException(
'return details not implemented for '.__METHOD__);
577 $found_values = array();
582 $result = $this->getCurrentSolutionResultSet($active_id,
$pass);
585 if (strcmp(
$data[
"value1"],
"") != 0)
587 array_push($found_values,
$data[
"value1"]);
611 include_once
"./Modules/Test/classes/class.ilObjTest.php";
619 $this->removeCurrentSolution($active_id,
$pass);
623 foreach($solutionSubmit as $value)
627 $this->saveCurrentSolution($active_id,
$pass, $value, null);
636 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
644 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
663 ) .
" WHERE question_fi = %s",
665 array( $this->
getId() )
670 $oldthumbsize =
$data[
'thumb_size'];
674 if (!$this->isSingleline)
682 array( $this->
getId() )
686 .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
687 array(
"integer",
"text",
"text",
"integer" ),
691 ($this->isSingleline) ?
"0" :
"1",
701 $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
703 array( $this->
getId() )
706 foreach ($this->answers as $key => $value)
708 $answer_obj = $this->answers[$key];
709 $next_id = $ilDB->nextId(
'qpl_a_mc' );
710 $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)",
711 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer' ),
716 $answer_obj->getPoints(),
717 $answer_obj->getPointsUnchecked(),
718 $answer_obj->getOrder(),
719 $answer_obj->getImage(),
744 parent::syncWithOriginal();
755 return "assMultipleChoice";
785 public function setImageFile($image_filename, $image_tempfilename =
"")
788 if (!empty($image_tempfilename))
790 $image_filename = str_replace(
" ",
"_", $image_filename);
792 if (!file_exists($imagepath))
802 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
804 if (!preg_match(
"/^image/", $mimetype))
806 unlink($imagepath . $image_filename);
830 @unlink($imagepath . $image_filename);
831 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
839 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
841 if( (
int)$objectId > 0 )
843 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
846 foreach ($this->answers as $answer)
851 if (!file_exists($imagepath))
855 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
857 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
858 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
860 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
864 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
865 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
876 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
877 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
878 foreach ($this->answers as $answer)
883 if (!file_exists($imagepath))
887 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
889 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
890 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
892 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
896 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
897 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
914 $originalObjId = parent::lookupParentObjId($this->
getOriginalId());
915 $imagepath_original = $this->
getImagePath($question_id, $originalObjId);
918 foreach ($this->answers as $answer)
923 if (@file_exists($imagepath .
$filename))
925 if (!file_exists($imagepath))
929 if (!file_exists($imagepath_original))
933 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
935 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
936 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
939 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
943 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
944 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
956 $text = parent::getRTETextWithMediaObjects();
957 foreach ($this->answers as $index => $answer)
959 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), $index);
960 $answer_obj = $this->answers[$index];
961 $text .= $answer_obj->getAnswertext();
988 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
997 foreach ($solution as $solutionvalue)
999 if (
$id == $solutionvalue[
"value1"])
1006 $worksheet->write($startrow + $i, 1, 1);
1010 $worksheet->write($startrow + $i, 1, 0);
1014 return $startrow + $i + 1;
1024 $this->thumb_size = $a_size;
1032 require_once
'./Services/RTE/classes/class.ilRTE.php';
1041 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
1042 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1047 foreach ($this->
getAnswers() as $key => $answer_obj)
1049 if((
string) $answer_obj->getImage())
1053 array_push($answers, array(
1054 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1055 "points_checked" => (
float) $answer_obj->getPointsChecked(),
1056 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1057 "order" => (int) $answer_obj->getOrder(),
1058 "image" => (string) $answer_obj->getImage(),
1060 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
1080 $answer = $this->answers[$index];
1081 if (is_object($answer))
1084 $answer->setImage(
'');
1092 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1093 if ($multilineAnswerSetting != 1)
1095 $multilineAnswerSetting = 0;
1097 return $multilineAnswerSetting;
1103 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1117 $this->feedback_setting = $a_feedback_setting;
1131 if ($this->feedback_setting)
1156 return $numExistingSolutionRecords > 0;
1176 SELECT SUM(points) points_for_checked_answers 1178 WHERE question_fi = %s AND points > 0 1181 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1185 return $row[
'points_for_checked_answers'] > 0;
1196 public function ensureNoInvalidObligation($questionId)
1202 SELECT SUM(qpl_a_mc.points) points_for_checked_answers, 1205 FROM tst_test_question 1208 ON qpl_a_mc.question_fi = tst_test_question.question_fi 1210 WHERE tst_test_question.question_fi = %s 1211 AND tst_test_question.obligatory = 1 1213 GROUP BY test_question_id 1216 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1218 $updateTestQuestionIds = array();
1220 while(
$row = $ilDB->fetchAssoc(
$res) )
1222 if(
$row[
'points_for_checked_answers'] <= 0 )
1224 $updateTestQuestionIds[] =
$row[
'test_question_id'];
1228 if( count($updateTestQuestionIds) )
1230 $test_question_id__IN__updateTestQuestionIds = $ilDB->in(
1231 'test_question_id', $updateTestQuestionIds,
false,
'integer' 1235 UPDATE tst_test_question 1237 WHERE $test_question_id__IN__updateTestQuestionIds 1240 $ilDB->manipulate(
$query);
1249 $solutionSubmit = array();
1250 foreach(
$_POST as $key => $value)
1252 if(preg_match(
"/^multiple_choice_result_(\d+)/", $key))
1256 $solutionSubmit[] = $value;
1260 return $solutionSubmit;
1271 foreach($this->answers as $key => $answer)
1273 if(in_array($key, $found_values))
1275 $points += $answer->getPoints();
1278 $points += $answer->getPointsUnchecked();
1283 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1285 if(($mc_scoring == 0) && (count($found_values) == 0))
1303 require_once
"./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1335 $data = $ilDB->queryF(
1336 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = ( 1337 SELECT MAX(step) FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s 1339 array(
"integer",
"integer",
"integer",
"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.
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)
duplicateImages($question_id, $objectId=null)
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)
isComplete()
Returns true, if a multiple choice question is complete for use.
isAnswered($active_id, $pass)
returns boolean wether the question is answered during test pass or not
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.
& getSolutionValues($active_id, $pass=NULL)
Loads solutions of a given user from the database an returns it.
Abstract basic class which is to be extended by the concrete assessment question type classes...
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
_convert_text($a_text, $a_target="has been removed")
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
setId($id=-1)
Sets the id of the assQuestion object.
_getMCScoring($active_id)
Gets the scoring type for multiple choice questions.
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. ...
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)
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
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.
getShuffle()
Gets the shuffle flag.
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.
reworkWorkingData($active_id, $pass, $obligationsAnswered)
Reworks the allready saved working data if neccessary.
setAuthor($author="")
Sets the authors name of the assQuestion object.
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.
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.
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.
_getLogLanguage()
retrieve the log language for assessment logging
static getOperatorsByExpression($expression)
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, $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.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setOriginalId($original_id)
getAnswerTableName()
Returns the name of the answer table in the database.
logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getTitle()
Gets the title string of the assQuestion object.
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.
setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
Creates an Excel worksheet for the detailed cumulated results of this question.
setMultilineAnswerSetting($a_setting=0)
copyImages($question_id, $source_questionpool)
saveWorkingData($active_id, $pass=NULL)
Saves the learners input of the question to the database.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
const EmptyAnswerExpression