24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
108 $this->matchingpairs = array();
110 $this->terms = array();
111 $this->definitions = array();
112 $this->masterTermIDs = array();
123 if (($this->title) and ($this->author) and ($this->question) and (count($this->matchingpairs)) and ($this->
getMaximumPoints() > 0))
145 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
147 array($this->
getId())
149 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, matching_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s, %s)",
150 array(
"integer",
"text",
"text",
"integer",
"integer"),
154 $this->matching_type,
161 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mterm WHERE question_fi = %s",
163 array($this->
getId())
167 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mdef WHERE question_fi = %s",
169 array($this->
getId())
174 foreach ($this->terms as $key => $term)
176 $next_id = $ilDB->nextId(
'qpl_a_mterm');
177 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mterm (term_id, question_fi, picture, term) VALUES (%s, %s, %s, %s)",
178 array(
'integer',
'integer',
'text',
'text'),
179 array($next_id, $this->
getId(), $term->picture, $term->text)
181 $termids[$term->identifier] = $next_id;
185 $this->masterTermIDs=&$termids;
191 $definitionids = array();
193 foreach ($this->definitions as $key => $definition)
195 $next_id = $ilDB->nextId(
'qpl_a_mdef');
196 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mdef (def_id, question_fi, picture, definition, morder) VALUES (%s, %s, %s, %s, %s)",
197 array(
'integer',
'integer',
'text',
'text',
'integer'),
198 array($next_id, $this->
getId(), $definition->picture, $definition->text, $definition->identifier)
200 $definitionids[$definition->identifier] = $next_id;
203 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_matching WHERE question_fi = %s",
205 array($this->
getId())
210 $next_id = $ilDB->nextId(
'qpl_a_matching');
211 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_matching (answer_id, question_fi, points, term_fi, definition_fi) VALUES (%s, %s, %s, %s, %s)",
212 array(
'integer',
'integer',
'float',
'integer',
'integer'),
217 $termids[$pair->term->identifier],
218 $definitionids[$pair->definition->identifier]
242 if ($result->numRows() == 1)
244 $data = $ilDB->fetchAssoc($result);
245 $this->
setId($question_id);
254 include_once(
"./Services/RTE/classes/class.ilRTE.php");
263 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
267 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
268 $this->terms = array();
269 if ($result->numRows() > 0)
271 while (
$data = $ilDB->fetchAssoc($result))
274 array_push($this->terms, $term);
275 $termids[
$data[
'term_id']] = $term;
279 $definitionids = array();
280 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id ASC",
284 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
285 $this->definitions = array();
286 if ($result->numRows() > 0)
288 while (
$data = $ilDB->fetchAssoc($result))
291 array_push($this->definitions, $definition);
292 $definitionids[
$data[
'def_id']] = $definition;
296 $this->matchingpairs = array();
297 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_matching WHERE question_fi = %s ORDER BY answer_id",
301 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
302 if ($result->numRows() > 0)
304 while (
$data = $ilDB->fetchAssoc($result))
306 array_push($this->matchingpairs,
new assAnswerMatchingPair($termids[
$data[
'term_fi']], $definitionids[$data[
'definition_fi']], $data[
'points']));
324 $this_id = $this->
getId();
326 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
351 $clone->copyPageOfQuestion($this_id);
353 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
355 $clone->duplicateFeedbackGeneric($this_id);
358 $clone->duplicateImages($this_id);
359 $clone->onDuplicate($this_id);
375 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
382 $source_questionpool = $this->
getObjId();
383 $clone->setObjId($target_questionpool);
403 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
404 foreach ($this->terms as $term)
406 if (strlen($term->picture))
409 if (!file_exists($imagepath))
413 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
415 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
417 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
421 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
426 foreach ($this->definitions as $definition)
428 if (strlen($definition->picture))
431 if (!file_exists($imagepath))
435 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
437 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
439 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
443 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
450 public function copyImages($question_id, $source_questionpool)
453 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
454 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
455 foreach ($this->terms as $term)
457 if (strlen($term->picture))
459 if (!file_exists($imagepath))
464 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
466 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
470 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
474 foreach ($this->definitions as $definition)
476 if (strlen($definition->picture))
479 if (!file_exists($imagepath))
483 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
485 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
489 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
507 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
508 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
509 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
513 if ($position < count($this->matchingpairs))
515 $part1 = array_slice($this->matchingpairs, 0, $position);
516 $part2 = array_slice($this->matchingpairs, $position);
517 $this->matchingpairs = array_merge($part1, array($pair), $part2);
521 array_push($this->matchingpairs, $pair);
535 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
536 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
537 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
541 array_push($this->matchingpairs, $pair);
549 foreach ($this->terms as $term)
551 if ($term->identifier == $a_identifier)
return $term;
561 foreach ($this->definitions as $definition)
563 if ($definition->identifier == $a_identifier)
return $definition;
582 if (count($this->matchingpairs) < 1)
586 if ($index >= count($this->matchingpairs))
590 return $this->matchingpairs[$index];
606 if (count($this->matchingpairs) < 1)
610 if ($index >= count($this->matchingpairs))
614 unset($this->matchingpairs[$index]);
615 $this->matchingpairs = array_values($this->matchingpairs);
624 $this->matchingpairs = array();
635 return count($this->matchingpairs);
668 return count($this->terms);
679 return count($this->definitions);
690 array_push($this->terms, $term);
701 array_push($this->definitions, $definition);
714 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
717 if ($position < count($this->terms))
719 $part1 = array_slice($this->terms, 0, $position);
720 $part2 = array_slice($this->terms, $position);
721 $this->terms = array_merge($part1, array($term), $part2);
725 array_push($this->terms, $term);
737 if (is_null($definition))
739 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
742 if ($position < count($this->definitions))
744 $part1 = array_slice($this->definitions, 0, $position);
745 $part2 = array_slice($this->definitions, $position);
746 $this->definitions = array_merge($part1, array($definition), $part2);
750 array_push($this->definitions, $definition);
760 $this->terms = array();
769 $this->definitions = array();
780 unset($this->terms[$position]);
781 $this->terms = array_values($this->terms);
792 unset($this->definitions[$position]);
793 $this->definitions = array_values($this->definitions);
805 $this->terms[$index] = $term;
821 $found_value1 = array();
822 $found_value2 = array();
827 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
828 array(
'integer',
'integer',
'integer'),
831 while (
$data = $ilDB->fetchAssoc($result))
833 if (strcmp(
$data[
"value1"],
"") != 0)
835 array_push($found_value1,
$data[
"value1"]);
836 array_push($found_value2,
$data[
"value2"]);
840 foreach ($found_value2 as $key => $value)
842 foreach ($this->matchingpairs as $pair)
844 if (($pair->definition->identifier == $value) && ($pair->term->identifier == $found_value1[$key]))
861 foreach ($this->matchingpairs as $key => $pair)
863 if ($pair->points > 0)
882 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
884 $extension = $matches[1];
886 return md5(
$filename) .
"." . $extension;
891 $term = $this->terms[$index];
892 if (is_object($term))
895 $term->picture = null;
901 $definition = $this->definitions[$index];
902 if (is_object($definition))
905 $definition->picture = null;
932 function setImageFile($image_tempfilename, $image_filename, $previous_filename =
'')
935 if (strlen($image_tempfilename))
937 $image_filename = str_replace(
" ",
"_", $image_filename);
939 if (!file_exists($imagepath))
943 $savename = $image_filename;
954 if ($result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
971 $matching_values = array();
972 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
976 array_push($matching_values, $term);
980 $check_matching = array_flip($matching_values);
981 if (count($check_matching) != count($matching_values))
1000 $entered_values = 0;
1001 if ($saveWorkingDataResult)
1005 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1009 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
1010 array(
'integer',
'integer',
'integer'),
1014 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
1017 $next_id = $ilDB->nextId(
'tst_solutions');
1018 $affectedRows = $ilDB->insert(
"tst_solutions", array(
1019 "solution_id" => array(
"integer", $next_id),
1020 "active_fi" => array(
"integer", $active_id),
1021 "question_fi" => array(
"integer", $this->
getId()),
1022 "value1" => array(
"clob", $term),
1023 "value2" => array(
"clob", $definition),
1024 "pass" => array(
"integer",
$pass),
1025 "tstamp" => array(
"integer", time())
1028 $saveWorkingDataResult =
true;
1030 if ($entered_values)
1032 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1040 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1047 return $saveWorkingDataResult;
1052 mt_srand((
double)microtime()*1000000);
1053 $random_number = mt_rand(1, 100000);
1058 foreach ($this->matchingpairs as $key => $pair)
1060 if (($pair->term->identifier == $random_number) || ($pair->definition->identifier == $random_number))
1067 return $random_number;
1099 return "assMatchingQuestion";
1109 return "qpl_qst_matching";
1119 return array(
"qpl_a_matching",
"qpl_a_mterm");
1161 $adapter->setCellValue($startrow, 0, $this->lng->txt($this->getQuestionType()),
CELL_FORMAT_TITLE);
1165 foreach ($solutions as $solution)
1167 $matches_written = FALSE;
1170 if (!$matches_written) $adapter->setCellValue($startrow + $i, 1, $this->lng->txt(
"matches"));
1171 $matches_written = TRUE;
1172 if ($pair->definition->identifier == $solution[
"value2"])
1174 if (strlen($pair->definition->text))
1176 $adapter->setCellValue($startrow + $i, 0, $pair->definition->text);
1180 $adapter->setCellValue($startrow + $i, 0, $pair->definition->picture);
1183 if ($pair->term->identifier == $solution[
"value1"])
1185 if (strlen($pair->term->text))
1187 $adapter->setCellValue($startrow + $i, 2, $pair->term->text);
1191 $adapter->setCellValue($startrow + $i, 2, $pair->term->picture);
1197 return $startrow + $i + 1;
1227 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1247 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1255 foreach ($this->terms as $term)
1259 foreach ($this->definitions as $definition)
1278 switch (strtoupper($path_info[
'extension']))
1297 foreach ($this->terms as $term)
1299 if (strlen($term->picture))
1304 foreach ($this->definitions as $definition)
1306 if (strlen($definition->picture))
1327 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1329 $result[
'id'] = (int) $this->
getId();
1331 $result[
'title'] = (string) $this->
getTitle();
1334 $result[
'shuffle'] =
true;
1335 $result[
'feedback'] = array(
1342 $terms[(int)$pair->term->identifier] = array(
1343 "term" => $pair->term->text,
1344 "id" =>(
int)$pair->term->identifier
1360 array_push($pairs, array(
1361 "term_id" => (
int) $pair->term->identifier,
1362 "points" => (
float) $pair->points,
1363 "definition" => (
string) $pair->definition->text,
1364 "def_id" => (
int) $this->getId().$pair->definition->identifier,
1368 $result[
'pairs'] = $pairs;
1370 $result[
'mobs'] =
$mobs;
1372 return json_encode($result);