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';
109 $this->thumb_size = 150;
110 $this->answers = array();
122 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
143 $this->ensureNoInvalidObligation($this->
getId());
156 if (strlen($answer->getImage()))
184 switch (strtoupper($path_info[
'extension']))
217 $this->
setId($question_id);
226 include_once(
"./Services/RTE/classes/class.ilRTE.php");
232 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
233 $this->lastChange =
$data[
'tstamp'];
234 $this->feedback_setting =
$data[
'feedback_setting'];
245 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
249 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
255 if (!@file_exists($imagefilename))
257 $data[
"imagefile"] =
"";
259 include_once(
"./Services/RTE/classes/class.ilRTE.php");
265 parent::loadFromDb($question_id);
279 $this_id = $this->
getId();
283 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
287 if( (
int)$testObjId > 0 )
289 $clone->setObjId($testObjId);
316 $clone->copyPageOfQuestion($this_id);
318 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
320 $clone->duplicateImages($this_id, $thisObjId);
322 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
339 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
342 $source_questionpool_id = $this->
getObjId();
343 $clone->setObjId($target_questionpool_id);
354 $clone->copyImages(
$original_id, $source_questionpool_id);
356 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
369 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
372 $sourceParentId = $this->
getObjId();
378 $clone->setObjId($targetParentId);
380 if ($targetQuestionTitle)
382 $clone->setTitle($targetQuestionTitle);
387 $clone->copyPageOfQuestion($sourceQuestionId);
389 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
391 $clone->copyImages($sourceQuestionId, $sourceParentId);
393 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
437 $points_unchecked = 0.0,
442 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
443 if (array_key_exists($order, $this->answers))
447 $newchoices = array();
448 for ($i = 0; $i < $order; $i++)
450 array_push($newchoices, $this->answers[$i]);
452 array_push($newchoices, $answer);
453 for ($i = $order; $i < count($this->answers); $i++)
459 $this->answers = $newchoices;
465 array_push($this->answers, $answer);
477 return count($this->answers);
490 if ($index < 0)
return NULL;
491 if (count($this->answers) < 1)
return NULL;
492 if ($index >= count($this->answers))
return NULL;
494 return $this->answers[$index];
506 if ($index < 0)
return;
507 if (count($this->answers) < 1)
return;
508 if ($index >= count($this->answers))
return;
509 $answer = $this->answers[$index];
510 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
511 unset($this->answers[$index]);
512 $this->answers = array_values($this->answers);
513 for ($i = 0; $i < count($this->answers); $i++)
515 if ($this->answers[$i]->getOrder() > $index)
517 $this->answers[$i]->setOrder($i);
529 $this->answers = array();
541 foreach ($this->answers as $key => $value)
543 if ($value->getPoints() > $value->getPointsUnchecked())
545 $allpoints += $value->getPoints();
549 $allpoints += $value->getPointsUnchecked();
570 throw new ilTestException(
'return details not implemented for '.__METHOD__);
575 $found_values = array();
580 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
581 array(
'integer',
'integer',
'integer'),
586 if (strcmp(
$data[
"value1"],
"") != 0)
588 array_push($found_values,
$data[
"value1"]);
592 foreach ($this->answers as $key => $answer)
594 if (in_array($key, $found_values))
596 $points += $answer->getPoints();
600 $points += $answer->getPointsUnchecked();
603 include_once
"./Modules/Test/classes/class.ilObjTest.php";
605 if (($mc_scoring == 0) && (count($found_values) == 0))
627 include_once
"./Modules/Test/classes/class.ilObjTest.php";
635 $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
636 array(
'integer',
'integer',
'integer'),
639 foreach (
$_POST as $key => $value)
641 if (preg_match(
"/^multiple_choice_result_(\d+)/", $key, $matches))
645 $next_id = $ilDB->nextId(
'tst_solutions');
646 $ilDB->insert(
"tst_solutions", array(
647 "solution_id" => array(
"integer", $next_id),
648 "active_fi" => array(
"integer", $active_id),
649 "question_fi" => array(
"integer", $this->
getId()),
650 "value1" => array(
"clob", $value),
651 "value2" => array(
"clob", null),
652 "pass" => array(
"integer",
$pass),
653 "tstamp" => array(
"integer", time())
664 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
672 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
691 ) .
" WHERE question_fi = %s",
693 array( $this->
getId() )
698 $oldthumbsize =
$data[
'thumb_size'];
702 if (!$this->isSingleline)
710 array( $this->
getId() )
714 .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
715 array(
"integer",
"text",
"text",
"integer" ),
719 ($this->isSingleline) ?
"0" :
"1",
729 $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
731 array( $this->
getId() )
734 foreach ($this->answers as $key => $value)
736 $answer_obj = $this->answers[$key];
737 $next_id = $ilDB->nextId(
'qpl_a_mc' );
738 $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)",
739 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer' ),
744 $answer_obj->getPoints(),
745 $answer_obj->getPointsUnchecked(),
746 $answer_obj->getOrder(),
747 $answer_obj->getImage(),
772 parent::syncWithOriginal();
783 return "assMultipleChoice";
813 public function setImageFile($image_filename, $image_tempfilename =
"")
816 if (!empty($image_tempfilename))
818 $image_filename = str_replace(
" ",
"_", $image_filename);
820 if (!file_exists($imagepath))
830 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
832 if (!preg_match(
"/^image/", $mimetype))
834 unlink($imagepath . $image_filename);
858 @unlink($imagepath . $image_filename);
859 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
867 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
869 if( (
int)$objectId > 0 )
871 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
874 foreach ($this->answers as $answer)
879 if (!file_exists($imagepath))
883 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
885 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
886 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
888 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
892 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
893 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
904 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
905 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
906 foreach ($this->answers as $answer)
911 if (!file_exists($imagepath))
915 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
917 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
918 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
920 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
924 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
925 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
942 $originalObjId = parent::lookupOriginalParentObjId($this->
getOriginalId());
943 $imagepath_original = $this->
getImagePath($question_id, $originalObjId);
946 foreach ($this->answers as $answer)
951 if (@file_exists($imagepath .
$filename))
953 if (!file_exists($imagepath))
957 if (!file_exists($imagepath_original))
961 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
963 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
964 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
967 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
971 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
972 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
984 $text = parent::getRTETextWithMediaObjects();
985 foreach ($this->answers as $index => $answer)
987 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), $index);
988 $answer_obj = $this->answers[$index];
989 $text .= $answer_obj->getAnswertext();
1016 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1025 foreach ($solution as $solutionvalue)
1027 if (
$id == $solutionvalue[
"value1"])
1034 $worksheet->write($startrow + $i, 1, 1);
1038 $worksheet->write($startrow + $i, 1, 0);
1042 return $startrow + $i + 1;
1052 $this->thumb_size = $a_size;
1060 require_once
'./Services/RTE/classes/class.ilRTE.php';
1069 "onenotcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false),
1070 "allcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true)
1075 foreach ($this->
getAnswers() as $key => $answer_obj)
1077 if((
string) $answer_obj->getImage())
1081 array_push($answers, array(
1082 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1083 "points_checked" => (
float) $answer_obj->getPointsChecked(),
1084 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1085 "order" => (int) $answer_obj->getOrder(),
1086 "image" => (string) $answer_obj->getImage(),
1088 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1108 $answer = $this->answers[$index];
1109 if (is_object($answer))
1112 $answer->setImage(
'');
1120 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1121 if ($multilineAnswerSetting != 1)
1123 $multilineAnswerSetting = 0;
1125 return $multilineAnswerSetting;
1131 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1145 $this->feedback_setting = $a_feedback_setting;
1159 if ($this->feedback_setting)
1204 SELECT SUM(points) points_for_checked_answers 1206 WHERE question_fi = %s 1209 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1213 return $row[
'points_for_checked_answers'] > 0;
1224 public function ensureNoInvalidObligation($questionId)
1230 SELECT SUM(qpl_a_mc.points) points_for_checked_answers, 1233 FROM tst_test_question 1236 ON qpl_a_mc.question_fi = tst_test_question.question_fi 1238 WHERE tst_test_question.question_fi = %s 1239 AND tst_test_question.obligatory = 1 1241 GROUP BY test_question_id 1244 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1246 $updateTestQuestionIds = array();
1248 while(
$row = $ilDB->fetchAssoc(
$res) )
1250 if(
$row[
'points_for_checked_answers'] <= 0 )
1252 $updateTestQuestionIds[] =
$row[
'test_question_id'];
1256 if( count($updateTestQuestionIds) )
1258 $test_question_id__IN__updateTestQuestionIds = $ilDB->in(
1259 'test_question_id', $updateTestQuestionIds,
false,
'integer' 1263 UPDATE tst_test_question 1265 WHERE $test_question_id__IN__updateTestQuestionIds 1268 $ilDB->manipulate(
$query);
flushAnswers()
Deletes all answers.
static isObligationPossible($questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
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 ...
toJSON()
Returns a JSON representation of the question.
generateThumbForFile($path, $file)
static doesSolutionRecordsExist($activeId, $pass, $questionId)
checks wether there are existing solution records for the given test active / pass and given question...
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
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assMultipleChoiceQuestion.
copyObject($target_questionpool_id, $title="")
Copies an assMultipleChoice object.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
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.
setOutputType($output_type=OUTPUT_ORDER)
Sets the output type of the assMultipleChoice object.
getQuestionType()
Returns the question type of the question.
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.
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.
fetchAssoc($a_set)
Fetch row as associative array from result set.
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.
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.
__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.
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.
_getLogLanguage()
retrieve the log language for assessment logging
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.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
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.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
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.