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';
89 $this->matchingpairs = array();
91 $this->terms = array();
92 $this->definitions = array();
102 if (strlen($this->title)
105 && count($this->matchingpairs)
136 $ilDB->manipulateF(
"DELETE FROM qpl_a_mterm WHERE question_fi = %s",
138 array( $this->
getId() )
142 $ilDB->manipulateF(
"DELETE FROM qpl_a_mdef WHERE question_fi = %s",
144 array( $this->
getId() )
149 foreach ($this->terms as $key => $term)
151 $next_id = $ilDB->nextId(
'qpl_a_mterm' );
152 $ilDB->manipulateF(
"INSERT INTO qpl_a_mterm (term_id, question_fi, picture, term) VALUES (%s, %s, %s, %s)",
153 array(
'integer',
'integer',
'text',
'text' ),
154 array( $next_id, $this->
getId(), $term->picture, $term->text )
156 $termids[$term->identifier] = $next_id;
159 $definitionids = array();
161 foreach ($this->definitions as $key => $definition)
163 $next_id = $ilDB->nextId(
'qpl_a_mdef' );
164 $ilDB->manipulateF(
"INSERT INTO qpl_a_mdef (def_id, question_fi, picture, definition, morder) VALUES (%s, %s, %s, %s, %s)",
165 array(
'integer',
'integer',
'text',
'text',
'integer' ),
166 array( $next_id, $this->
getId(
167 ), $definition->picture, $definition->text, $definition->identifier )
169 $definitionids[$definition->identifier] = $next_id;
172 $ilDB->manipulateF(
"DELETE FROM qpl_a_matching WHERE question_fi = %s",
174 array( $this->
getId() )
177 foreach ($matchingpairs as $key => $pair)
179 $next_id = $ilDB->nextId(
'qpl_a_matching' );
180 $ilDB->manipulateF(
"INSERT INTO qpl_a_matching (answer_id, question_fi, points, term_fi, definition_fi) VALUES (%s, %s, %s, %s, %s)",
181 array(
'integer',
'integer',
'float',
'integer',
'integer' ),
186 $termids[$pair->term->identifier],
187 $definitionids[$pair->definition->identifier]
201 array( $this->
getId() )
204 ) .
" (question_fi, shuffle, matching_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s, %s)",
205 array(
"integer",
"text",
"text",
"integer",
"integer" ),
209 $this->matching_type,
233 $this->
setId($question_id);
242 include_once(
"./Services/RTE/classes/class.ilRTE.php");
259 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
263 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
264 $this->terms = array();
270 array_push($this->terms, $term);
271 $termids[
$data[
'term_id']] = $term;
275 $definitionids = array();
276 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id ASC",
280 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
281 $this->definitions = array();
287 array_push($this->definitions, $definition);
288 $definitionids[
$data[
'def_id']] = $definition;
292 $this->matchingpairs = array();
293 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_matching WHERE question_fi = %s ORDER BY answer_id",
297 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
302 array_push($this->matchingpairs,
new assAnswerMatchingPair($termids[
$data[
'term_fi']], $definitionids[$data[
'definition_fi']], $data[
'points']));
305 parent::loadFromDb($question_id);
320 $this_id = $this->
getId();
324 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
328 if( (
int)$testObjId > 0 )
330 $clone->setObjId($testObjId);
355 $clone->copyPageOfQuestion($this_id);
357 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
359 $clone->duplicateImages($this_id, $thisObjId);
361 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
378 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
381 $source_questionpool_id = $this->
getObjId();
382 $clone->setObjId($target_questionpool_id);
393 $clone->copyImages(
$original_id, $source_questionpool_id);
395 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
408 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
411 $sourceParentId = $this->
getObjId();
417 $clone->setObjId($targetParentId);
419 if ($targetQuestionTitle)
421 $clone->setTitle($targetQuestionTitle);
426 $clone->copyPageOfQuestion($sourceQuestionId);
428 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
430 $clone->copyImages($sourceQuestionId, $sourceParentId);
432 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
441 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
443 if( (
int)$objectId > 0 )
445 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
448 foreach ($this->terms as $term)
450 if (strlen($term->picture))
453 if (!file_exists($imagepath))
457 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
459 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
461 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
465 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
470 foreach ($this->definitions as $definition)
472 if (strlen($definition->picture))
475 if (!file_exists($imagepath))
479 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
481 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
483 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
487 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
494 public function copyImages($question_id, $source_questionpool)
499 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
500 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
501 foreach ($this->terms as $term)
503 if (strlen($term->picture))
505 if (!file_exists($imagepath))
510 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
512 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
516 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
520 foreach ($this->definitions as $definition)
522 if (strlen($definition->picture))
525 if (!file_exists($imagepath))
529 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
531 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
535 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
553 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
554 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
555 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
559 if ($position < count($this->matchingpairs))
561 $part1 = array_slice($this->matchingpairs, 0, $position);
562 $part2 = array_slice($this->matchingpairs, $position);
563 $this->matchingpairs = array_merge($part1, array($pair), $part2);
567 array_push($this->matchingpairs, $pair);
584 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php';
585 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php';
586 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php';
591 if (is_null($definition))
596 array_push($this->matchingpairs, $pair);
604 foreach ($this->terms as $term)
606 if ($term->identifier == $a_identifier)
return $term;
616 foreach ($this->definitions as $definition)
618 if ($definition->identifier == $a_identifier)
return $definition;
637 if (count($this->matchingpairs) < 1)
641 if ($index >= count($this->matchingpairs))
645 return $this->matchingpairs[$index];
661 if (count($this->matchingpairs) < 1)
665 if ($index >= count($this->matchingpairs))
669 unset($this->matchingpairs[$index]);
670 $this->matchingpairs = array_values($this->matchingpairs);
679 $this->matchingpairs = array();
690 return count($this->matchingpairs);
723 return count($this->terms);
734 return count($this->definitions);
745 array_push($this->terms, $term);
756 array_push($this->definitions, $definition);
769 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
772 if ($position < count($this->terms))
774 $part1 = array_slice($this->terms, 0, $position);
775 $part2 = array_slice($this->terms, $position);
776 $this->terms = array_merge($part1, array($term), $part2);
780 array_push($this->terms, $term);
792 if (is_null($definition))
794 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
797 if ($position < count($this->definitions))
799 $part1 = array_slice($this->definitions, 0, $position);
800 $part2 = array_slice($this->definitions, $position);
801 $this->definitions = array_merge($part1, array($definition), $part2);
805 array_push($this->definitions, $definition);
815 $this->terms = array();
824 $this->definitions = array();
835 unset($this->terms[$position]);
836 $this->terms = array_values($this->terms);
847 unset($this->definitions[$position]);
848 $this->definitions = array_values($this->definitions);
860 $this->terms[$index] = $term;
877 throw new ilTestException(
'return details not implemented for '.__METHOD__);
882 $found_value1 = array();
883 $found_value2 = array();
888 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
889 array(
'integer',
'integer',
'integer'),
894 if (strcmp(
$data[
"value1"],
"") != 0)
896 array_push($found_value1,
$data[
"value1"]);
897 array_push($found_value2,
$data[
"value2"]);
901 foreach ($found_value2 as $key => $value)
903 foreach ($this->matchingpairs as $pair)
905 if (($pair->definition->identifier == $value) && ($pair->term->identifier == $found_value1[$key]))
921 foreach ($this->matchingpairs as $key => $pair)
923 if ($pair->points > 0)
942 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
944 $extension = $matches[1];
946 return md5(
$filename) .
"." . $extension;
951 $term = $this->terms[$index];
952 if (is_object($term))
955 $term->picture = null;
961 $definition = $this->definitions[$index];
962 if (is_object($definition))
965 $definition->picture = null;
992 function setImageFile($image_tempfilename, $image_filename, $previous_filename =
'')
995 if (strlen($image_tempfilename))
997 $image_filename = str_replace(
" ",
"_", $image_filename);
999 if (!file_exists($imagepath))
1003 $savename = $image_filename;
1014 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
1031 $matching_values = array();
1032 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
1036 array_push($matching_values, $term);
1040 $check_matching = array_flip($matching_values);
1041 if (count($check_matching) != count($matching_values))
1062 $entered_values = 0;
1063 if ($saveWorkingDataResult)
1067 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1073 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
1074 array(
'integer',
'integer',
'integer'),
1078 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
1081 $next_id = $ilDB->nextId(
'tst_solutions');
1082 $affectedRows = $ilDB->insert(
"tst_solutions", array(
1083 "solution_id" => array(
"integer", $next_id),
1084 "active_fi" => array(
"integer", $active_id),
1085 "question_fi" => array(
"integer", $this->
getId()),
1086 "value1" => array(
"clob", $term),
1087 "value2" => array(
"clob", $definition),
1088 "pass" => array(
"integer",
$pass),
1089 "tstamp" => array(
"integer", time())
1095 $saveWorkingDataResult =
true;
1097 if ($entered_values)
1099 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1107 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1114 return $saveWorkingDataResult;
1132 mt_srand((
double)microtime()*1000000);
1133 $random_number = mt_rand(1, 100000);
1138 foreach ($this->matchingpairs as $key => $pair)
1140 if (($pair->term->identifier == $random_number) || ($pair->definition->identifier == $random_number))
1147 return $random_number;
1179 return "assMatchingQuestion";
1189 return "qpl_qst_matching";
1199 return array(
"qpl_a_matching",
"qpl_a_mterm");
1208 return parent::getRTETextWithMediaObjects();
1243 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1249 foreach ($solutions as $solution)
1251 $matches_written = FALSE;
1255 $matches_written = TRUE;
1256 if ($pair->definition->identifier == $solution[
"value2"])
1258 if (strlen($pair->definition->text))
1267 if ($pair->term->identifier == $solution[
"value1"])
1269 if (strlen($pair->term->text))
1281 return $startrow + $i + 1;
1311 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1331 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1339 foreach ($this->terms as $term)
1343 foreach ($this->definitions as $definition)
1362 switch (strtoupper($path_info[
'extension']))
1381 foreach ($this->terms as $term)
1383 if (strlen($term->picture))
1388 foreach ($this->definitions as $definition)
1390 if (strlen($definition->picture))
1411 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1420 "onenotcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false),
1421 "allcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true)
1424 $terms = array(
"" => array(
"id"=>
"-1",
1425 "term"=>$this->lng->txt(
"please_select")));
1426 foreach ($this->
getTerms() as $term)
1428 $terms[(int)$term->identifier] = array(
1429 "term" => $term->text,
1430 "id" =>(
int)$term->identifier
1445 array_push($pairs, array(
1446 "definition" => (
string) $def->text,
1447 "def_id" => (
int) $this->getId().$def->identifier,
1457 $pid = $pair->definition->identifier;
1460 if(!isset($match[$pid]) || $match[$pid][
"points"] < $pair->points)
1462 $match[$pid] = array(
1463 "term_id" => (
int) $pair->term->identifier,
1464 "def_id" => (
int) $this->getId().$pair->definition->identifier,
1465 "points" => (int) $pair->points
1469 $result[
'match'] = array_values($match);
getThumbGeometry()
Get the thumbnail geometry.
Class for matching question terms.
supportsJavascriptOutput()
Returns true if the question type supports JavaScript output.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getId()
Gets the id of the assQuestion object.
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assMatchingQuestion.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
Class for matching question pairs.
getElementHeight()
Get the minimum element height.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
getTermCount()
Returns the number of terms.
setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
Creates an Excel worksheet for the detailed cumulated results of this question.
copyObject($target_questionpool_id, $title="")
Copies an assMatchingQuestion.
generateThumbForFile($path, $file)
& getSolutionValues($active_id, $pass=NULL)
Loads solutions of a given user from the database an returns it.
deleteMatchingPair($index=0)
Deletes a matching pair with a given index.
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")
getDefinitionCount()
Returns the number of definitions.
getQuestionType()
Returns the question type of the question.
addTerm($term)
Adds a term.
setId($id=-1)
Sets the id of the assQuestion object.
saveWorkingData($active_id, $pass=NULL)
Saves the learners input of the question to the database.
flushMatchingPairs()
Deletes all matching pairs.
setImageFile($image_tempfilename, $image_filename, $previous_filename='')
Sets the image file and uploads the image to the object's image directory.
getEncryptedFilename($filename)
Returns the encrypted save filename of a matching picture Images are saved with an encrypted filename...
flushTerms()
Deletes all terms.
deleteImagefile($filename)
Deletes an imagefile from the system if the file is deleted manually.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
const MT_TERMS_DEFINITIONS
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question.
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
getAdditionalTableName()
Returns the name of the additional question data table in the database.
calculateReachedPoints($active_id, $pass=NULL, $returndetails=FALSE)
Returns the points, a learner has reached answering the question.
setNrOfTries($a_nr_of_tries)
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
deleteTerm($position)
Deletes a term.
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
getEstimatedElementHeight()
rebuildThumbnails()
Rebuild the thumbnail images with a new thumbnail size.
getObjId()
Get the object id of the container object.
getDefinitions()
Returns the definitions of the matching question.
loadFromDb($question_id)
Loads a assMatchingQuestion object from a database.
getMatchingPair($index=0)
Returns a matching pair with a given index.
Base Exception for all Exceptions relating to Modules/Test.
Class for matching questions.
checkSaveData()
Checks the data to be saved for consistency.
duplicateImages($question_id, $objectId=null)
fetchAssoc($a_set)
Fetch row as associative array from result set.
getTermWithIdentifier($a_identifier)
Returns a term with a given identifier.
insertMatchingPair($position, $term=null, $definition=null, $points=0.0)
Inserts a matching pair for an matching choice question.
setAuthor($author="")
Sets the authors name of the assQuestion object.
removeDefinitionImage($index)
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
insertDefinition($position, $definition=null)
Inserts a definition.
setTerm($term, $index)
Sets a specific term.
getMatchingPairCount()
Returns the number of matching pairs.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
Interface ilObjAnswerScoringAdjustable.
getQuestion()
Gets the question string of the question object.
addDefinition($definition)
Adds a definition.
setElementHeight($a_height)
Set the minimum element height.
flushDefinitions()
Deletes all definitions.
insertTerm($position, $term=null)
Inserts a term.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
_getLogLanguage()
retrieve the log language for assessment logging
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
setShuffle($shuffle)
Sets the shuffle flag.
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $matching_type=MT_TERMS_DEFINITIONS)
assMatchingQuestion constructor
toJSON()
Returns a JSON representation of the question TODO.
setPoints($a_points)
Sets the maximum available points for the question.
saveQuestionDataToDb($original_id="")
deleteDefinition($position)
Deletes a definition.
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...
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
getTerms()
Returns the terms of the matching question.
getDefinitionWithIdentifier($a_identifier)
Returns a definition with a given identifier.
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.
setThumbGeometry($a_geometry)
Set the thumbnail geometry.
setOriginalId($original_id)
Class for matching question definitions.
addMatchingPair($term=null, $definition=null, $points=0.0)
Adds an matching pair for an matching choice question.
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.
saveToDb($original_id="")
Saves a assMatchingQuestion object to a database.
& getMatchingPairs()
Returns the matchingpairs array.
copyImages($question_id, $source_questionpool)
setTitle($title="")
Sets the title string of the assQuestion object.
reworkWorkingData($active_id, $pass, $obligationsAnswered)
Reworks the allready saved working data if neccessary.
setObjId($obj_id=0)
Set the object id of the container object.
setComment($comment="")
Sets the comment string of the assQuestion object.
isComplete()
Returns true, if a matching question is complete for use.
getThumbSize()
Get the thumbnail geometry.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.