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() )
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,
232 $data = $ilDB->fetchAssoc(
$result);
233 $this->
setId($question_id);
242 include_once(
"./Services/RTE/classes/class.ilRTE.php");
247 $this->
setEstimatedWorkingTime(substr($data[
"working_time"], 0, 2), substr($data[
"working_time"], 3, 2), substr($data[
"working_time"], 6, 2));
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();
267 while ($data = $ilDB->fetchAssoc(
$result))
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();
284 while ($data = $ilDB->fetchAssoc(
$result))
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";
300 while ($data = $ilDB->fetchAssoc(
$result))
302 array_push($this->matchingpairs,
new assAnswerMatchingPair($termids[$data[
'term_fi']], $definitionids[$data[
'definition_fi']], $data[
'points']));
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'),
892 while ($data = $ilDB->fetchAssoc(
$result))
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");
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);