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 (strlen($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 if( (
int)$testObjId > 0 )
317 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
321 if( (
int)$testObjId > 0 )
323 $clone->setObjId($testObjId);
348 $clone->copyPageOfQuestion($this_id);
350 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
352 $clone->duplicateFeedbackGeneric($this_id);
355 $clone->duplicateImages($this_id, $thisObjId);
357 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
374 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
381 $source_questionpool = $this->
getObjId();
382 $clone->setObjId($target_questionpool);
402 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
404 if( (
int)$objectId > 0 )
406 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
409 foreach ($this->terms as $term)
411 if (strlen($term->picture))
414 if (!file_exists($imagepath))
418 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
420 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
422 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
426 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
431 foreach ($this->definitions as $definition)
433 if (strlen($definition->picture))
436 if (!file_exists($imagepath))
440 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
442 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
444 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
448 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
455 public function copyImages($question_id, $source_questionpool)
460 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
461 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
462 foreach ($this->terms as $term)
464 if (strlen($term->picture))
466 if (!file_exists($imagepath))
471 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
473 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
477 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
481 foreach ($this->definitions as $definition)
483 if (strlen($definition->picture))
486 if (!file_exists($imagepath))
490 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
492 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
496 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
514 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
515 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
516 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
520 if ($position < count($this->matchingpairs))
522 $part1 = array_slice($this->matchingpairs, 0, $position);
523 $part2 = array_slice($this->matchingpairs, $position);
524 $this->matchingpairs = array_merge($part1, array($pair), $part2);
528 array_push($this->matchingpairs, $pair);
542 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
543 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
544 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
548 array_push($this->matchingpairs, $pair);
556 foreach ($this->terms as $term)
558 if ($term->identifier == $a_identifier)
return $term;
568 foreach ($this->definitions as $definition)
570 if ($definition->identifier == $a_identifier)
return $definition;
589 if (count($this->matchingpairs) < 1)
593 if ($index >= count($this->matchingpairs))
597 return $this->matchingpairs[$index];
613 if (count($this->matchingpairs) < 1)
617 if ($index >= count($this->matchingpairs))
621 unset($this->matchingpairs[$index]);
622 $this->matchingpairs = array_values($this->matchingpairs);
631 $this->matchingpairs = array();
642 return count($this->matchingpairs);
675 return count($this->terms);
686 return count($this->definitions);
697 array_push($this->terms, $term);
708 array_push($this->definitions, $definition);
721 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
724 if ($position < count($this->terms))
726 $part1 = array_slice($this->terms, 0, $position);
727 $part2 = array_slice($this->terms, $position);
728 $this->terms = array_merge($part1, array($term), $part2);
732 array_push($this->terms, $term);
744 if (is_null($definition))
746 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
749 if ($position < count($this->definitions))
751 $part1 = array_slice($this->definitions, 0, $position);
752 $part2 = array_slice($this->definitions, $position);
753 $this->definitions = array_merge($part1, array($definition), $part2);
757 array_push($this->definitions, $definition);
767 $this->terms = array();
776 $this->definitions = array();
787 unset($this->terms[$position]);
788 $this->terms = array_values($this->terms);
799 unset($this->definitions[$position]);
800 $this->definitions = array_values($this->definitions);
812 $this->terms[$index] = $term;
828 $found_value1 = array();
829 $found_value2 = array();
834 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
835 array(
'integer',
'integer',
'integer'),
840 if (strcmp(
$data[
"value1"],
"") != 0)
842 array_push($found_value1,
$data[
"value1"]);
843 array_push($found_value2,
$data[
"value2"]);
847 foreach ($found_value2 as $key => $value)
849 foreach ($this->matchingpairs as $pair)
851 if (($pair->definition->identifier == $value) && ($pair->term->identifier == $found_value1[$key]))
868 foreach ($this->matchingpairs as $key => $pair)
870 if ($pair->points > 0)
889 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
891 $extension = $matches[1];
893 return md5(
$filename) .
"." . $extension;
898 $term = $this->terms[$index];
899 if (is_object($term))
902 $term->picture = null;
908 $definition = $this->definitions[$index];
909 if (is_object($definition))
912 $definition->picture = null;
939 function setImageFile($image_tempfilename, $image_filename, $previous_filename =
'')
942 if (strlen($image_tempfilename))
944 $image_filename = str_replace(
" ",
"_", $image_filename);
946 if (!file_exists($imagepath))
950 $savename = $image_filename;
961 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
978 $matching_values = array();
979 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
983 array_push($matching_values, $term);
987 $check_matching = array_flip($matching_values);
988 if (count($check_matching) != count($matching_values))
1007 $entered_values = 0;
1008 if ($saveWorkingDataResult)
1012 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1016 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
1017 array(
'integer',
'integer',
'integer'),
1021 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
1024 $next_id = $ilDB->nextId(
'tst_solutions');
1025 $affectedRows = $ilDB->insert(
"tst_solutions", array(
1026 "solution_id" => array(
"integer", $next_id),
1027 "active_fi" => array(
"integer", $active_id),
1028 "question_fi" => array(
"integer", $this->
getId()),
1029 "value1" => array(
"clob", $term),
1030 "value2" => array(
"clob", $definition),
1031 "pass" => array(
"integer",
$pass),
1032 "tstamp" => array(
"integer", time())
1035 $saveWorkingDataResult =
true;
1037 if ($entered_values)
1039 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1047 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1054 return $saveWorkingDataResult;
1059 mt_srand((
double)microtime()*1000000);
1060 $random_number = mt_rand(1, 100000);
1065 foreach ($this->matchingpairs as $key => $pair)
1067 if (($pair->term->identifier == $random_number) || ($pair->definition->identifier == $random_number))
1074 return $random_number;
1106 return "assMatchingQuestion";
1116 return "qpl_qst_matching";
1126 return array(
"qpl_a_matching",
"qpl_a_mterm");
1170 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1176 foreach ($solutions as $solution)
1178 $matches_written = FALSE;
1182 $matches_written = TRUE;
1183 if ($pair->definition->identifier == $solution[
"value2"])
1185 if (strlen($pair->definition->text))
1194 if ($pair->term->identifier == $solution[
"value1"])
1196 if (strlen($pair->term->text))
1208 return $startrow + $i + 1;
1238 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1258 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1266 foreach ($this->terms as $term)
1270 foreach ($this->definitions as $definition)
1289 switch (strtoupper($path_info[
'extension']))
1308 foreach ($this->terms as $term)
1310 if (strlen($term->picture))
1315 foreach ($this->definitions as $definition)
1317 if (strlen($definition->picture))
1338 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1353 $terms[(int)$pair->term->identifier] = array(
1354 "term" => $pair->term->text,
1355 "id" =>(
int)$pair->term->identifier
1370 array_push($pairs, array(
1371 "term_id" => (
int) $pair->term->identifier,
1372 "points" => (
float) $pair->points,
1373 "definition" => (
string) $pair->definition->text,
1374 "def_id" => (
int) $this->getId().$pair->definition->identifier,