24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
101 $this->matchingpairs = array();
103 $this->terms = array();
104 $this->definitions = array();
115 if (($this->title) and ($this->author) and ($this->question) and (count($this->matchingpairs)) and ($this->
getMaximumPoints() > 0))
137 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
139 array($this->
getId())
141 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, matching_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s, %s)",
142 array(
"integer",
"text",
"text",
"integer",
"integer"),
146 $this->matching_type,
153 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mterm WHERE question_fi = %s",
155 array($this->
getId())
159 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mdef WHERE question_fi = %s",
161 array($this->
getId())
166 foreach ($this->terms as $key => $term)
168 $next_id = $ilDB->nextId(
'qpl_a_mterm');
169 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mterm (term_id, question_fi, picture, term) VALUES (%s, %s, %s, %s)",
170 array(
'integer',
'integer',
'text',
'text'),
171 array($next_id, $this->
getId(), $term->picture, $term->text)
173 $termids[$term->identifier] = $next_id;
176 $definitionids = array();
178 foreach ($this->definitions as $key => $definition)
180 $next_id = $ilDB->nextId(
'qpl_a_mdef');
181 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mdef (def_id, question_fi, picture, definition, morder) VALUES (%s, %s, %s, %s, %s)",
182 array(
'integer',
'integer',
'text',
'text',
'integer'),
183 array($next_id, $this->
getId(), $definition->picture, $definition->text, $definition->identifier)
185 $definitionids[$definition->identifier] = $next_id;
188 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_matching WHERE question_fi = %s",
190 array($this->
getId())
195 $next_id = $ilDB->nextId(
'qpl_a_matching');
196 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_matching (answer_id, question_fi, points, term_fi, definition_fi) VALUES (%s, %s, %s, %s, %s)",
197 array(
'integer',
'integer',
'float',
'integer',
'integer'),
202 $termids[$pair->term->identifier],
203 $definitionids[$pair->definition->identifier]
230 $this->
setId($question_id);
239 include_once(
"./Services/RTE/classes/class.ilRTE.php");
248 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
252 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
253 $this->terms = array();
259 array_push($this->terms, $term);
260 $termids[
$data[
'term_id']] = $term;
264 $definitionids = array();
265 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id ASC",
269 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
270 $this->definitions = array();
276 array_push($this->definitions, $definition);
277 $definitionids[
$data[
'def_id']] = $definition;
281 $this->matchingpairs = array();
282 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_matching WHERE question_fi = %s ORDER BY answer_id",
286 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
291 array_push($this->matchingpairs,
new assAnswerMatchingPair($termids[
$data[
'term_fi']], $definitionids[$data[
'definition_fi']], $data[
'points']));
309 $this_id = $this->
getId();
311 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
336 $clone->copyPageOfQuestion($this_id);
338 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
340 $clone->duplicateFeedbackGeneric($this_id);
343 $clone->duplicateImages($this_id);
344 $clone->onDuplicate($this_id);
360 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
367 $source_questionpool = $this->
getObjId();
368 $clone->setObjId($target_questionpool);
388 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
389 foreach ($this->terms as $term)
391 if (strlen($term->picture))
394 if (!file_exists($imagepath))
398 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
400 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
402 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
406 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
411 foreach ($this->definitions as $definition)
413 if (strlen($definition->picture))
416 if (!file_exists($imagepath))
420 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
422 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
424 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
428 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
435 public function copyImages($question_id, $source_questionpool)
440 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
441 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
442 foreach ($this->terms as $term)
444 if (strlen($term->picture))
446 if (!file_exists($imagepath))
451 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
453 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
457 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
461 foreach ($this->definitions as $definition)
463 if (strlen($definition->picture))
466 if (!file_exists($imagepath))
470 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
472 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
476 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
494 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
495 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
496 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
500 if ($position < count($this->matchingpairs))
502 $part1 = array_slice($this->matchingpairs, 0, $position);
503 $part2 = array_slice($this->matchingpairs, $position);
504 $this->matchingpairs = array_merge($part1, array($pair), $part2);
508 array_push($this->matchingpairs, $pair);
522 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
523 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
524 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
528 array_push($this->matchingpairs, $pair);
536 foreach ($this->terms as $term)
538 if ($term->identifier == $a_identifier)
return $term;
548 foreach ($this->definitions as $definition)
550 if ($definition->identifier == $a_identifier)
return $definition;
569 if (count($this->matchingpairs) < 1)
573 if ($index >= count($this->matchingpairs))
577 return $this->matchingpairs[$index];
593 if (count($this->matchingpairs) < 1)
597 if ($index >= count($this->matchingpairs))
601 unset($this->matchingpairs[$index]);
602 $this->matchingpairs = array_values($this->matchingpairs);
611 $this->matchingpairs = array();
622 return count($this->matchingpairs);
655 return count($this->terms);
666 return count($this->definitions);
677 array_push($this->terms, $term);
688 array_push($this->definitions, $definition);
701 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
704 if ($position < count($this->terms))
706 $part1 = array_slice($this->terms, 0, $position);
707 $part2 = array_slice($this->terms, $position);
708 $this->terms = array_merge($part1, array($term), $part2);
712 array_push($this->terms, $term);
724 if (is_null($definition))
726 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
729 if ($position < count($this->definitions))
731 $part1 = array_slice($this->definitions, 0, $position);
732 $part2 = array_slice($this->definitions, $position);
733 $this->definitions = array_merge($part1, array($definition), $part2);
737 array_push($this->definitions, $definition);
747 $this->terms = array();
756 $this->definitions = array();
767 unset($this->terms[$position]);
768 $this->terms = array_values($this->terms);
779 unset($this->definitions[$position]);
780 $this->definitions = array_values($this->definitions);
792 $this->terms[$index] = $term;
808 $found_value1 = array();
809 $found_value2 = array();
814 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
815 array(
'integer',
'integer',
'integer'),
820 if (strcmp(
$data[
"value1"],
"") != 0)
822 array_push($found_value1,
$data[
"value1"]);
823 array_push($found_value2,
$data[
"value2"]);
827 foreach ($found_value2 as $key => $value)
829 foreach ($this->matchingpairs as $pair)
831 if (($pair->definition->identifier == $value) && ($pair->term->identifier == $found_value1[$key]))
848 foreach ($this->matchingpairs as $key => $pair)
850 if ($pair->points > 0)
869 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
871 $extension = $matches[1];
873 return md5(
$filename) .
"." . $extension;
878 $term = $this->terms[$index];
879 if (is_object($term))
882 $term->picture = null;
888 $definition = $this->definitions[$index];
889 if (is_object($definition))
892 $definition->picture = null;
919 function setImageFile($image_tempfilename, $image_filename, $previous_filename =
'')
922 if (strlen($image_tempfilename))
924 $image_filename = str_replace(
" ",
"_", $image_filename);
926 if (!file_exists($imagepath))
930 $savename = $image_filename;
941 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
958 $matching_values = array();
959 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
963 array_push($matching_values, $term);
967 $check_matching = array_flip($matching_values);
968 if (count($check_matching) != count($matching_values))
988 if ($saveWorkingDataResult)
992 include_once
"./Modules/Test/classes/class.ilObjTest.php";
996 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
997 array(
'integer',
'integer',
'integer'),
1001 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
1004 $next_id = $ilDB->nextId(
'tst_solutions');
1005 $affectedRows = $ilDB->insert(
"tst_solutions", array(
1006 "solution_id" => array(
"integer", $next_id),
1007 "active_fi" => array(
"integer", $active_id),
1008 "question_fi" => array(
"integer", $this->
getId()),
1009 "value1" => array(
"clob", $term),
1010 "value2" => array(
"clob", $definition),
1011 "pass" => array(
"integer",
$pass),
1012 "tstamp" => array(
"integer", time())
1015 $saveWorkingDataResult =
true;
1017 if ($entered_values)
1019 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1027 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1034 return $saveWorkingDataResult;
1039 mt_srand((
double)microtime()*1000000);
1040 $random_number = mt_rand(1, 100000);
1045 foreach ($this->matchingpairs as $key => $pair)
1047 if (($pair->term->identifier == $random_number) || ($pair->definition->identifier == $random_number))
1054 return $random_number;
1086 return "assMatchingQuestion";
1096 return "qpl_qst_matching";
1106 return array(
"qpl_a_matching",
"qpl_a_mterm");
1150 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1156 foreach ($solutions as $solution)
1158 $matches_written = FALSE;
1162 $matches_written = TRUE;
1163 if ($pair->definition->identifier == $solution[
"value2"])
1165 if (strlen($pair->definition->text))
1174 if ($pair->term->identifier == $solution[
"value1"])
1176 if (strlen($pair->term->text))
1188 return $startrow + $i + 1;
1218 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1238 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1246 foreach ($this->terms as $term)
1250 foreach ($this->definitions as $definition)
1269 switch (strtoupper($path_info[
'extension']))
1288 foreach ($this->terms as $term)
1290 if (strlen($term->picture))
1295 foreach ($this->definitions as $definition)
1297 if (strlen($definition->picture))
1318 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1333 $terms[(int)$pair->term->identifier] = array(
1334 "term" => $pair->term->text,
1335 "id" =>(
int)$pair->term->identifier
1351 array_push($pairs, array(
1352 "term_id" => (
int) $pair->term->identifier,
1353 "points" => (
float) $pair->points,
1354 "definition" => (
string) $pair->definition->text,
1355 "def_id" => (
int) $this->getId().$pair->definition->identifier,