5 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
6 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
86 $this->matchingpairs = array();
88 $this->terms = array();
89 $this->definitions = array();
100 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->matchingpairs)) and ($this->
getMaximumPoints() > 0))
122 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
124 array($this->
getId())
126 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, matching_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s, %s)",
127 array(
"integer",
"text",
"text",
"integer",
"integer"),
131 $this->matching_type,
138 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mterm WHERE question_fi = %s",
140 array($this->
getId())
144 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mdef WHERE question_fi = %s",
146 array($this->
getId())
151 foreach ($this->terms as $key => $term)
153 $next_id = $ilDB->nextId(
'qpl_a_mterm');
154 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mterm (term_id, question_fi, picture, term) VALUES (%s, %s, %s, %s)",
155 array(
'integer',
'integer',
'text',
'text'),
156 array($next_id, $this->
getId(), $term->picture, $term->text)
158 $termids[$term->identifier] = $next_id;
161 $definitionids = array();
163 foreach ($this->definitions as $key => $definition)
165 $next_id = $ilDB->nextId(
'qpl_a_mdef');
166 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mdef (def_id, question_fi, picture, definition, morder) VALUES (%s, %s, %s, %s, %s)",
167 array(
'integer',
'integer',
'text',
'text',
'integer'),
168 array($next_id, $this->
getId(), $definition->picture, $definition->text, $definition->identifier)
170 $definitionids[$definition->identifier] = $next_id;
173 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_matching WHERE question_fi = %s",
175 array($this->
getId())
180 $next_id = $ilDB->nextId(
'qpl_a_matching');
181 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_matching (answer_id, question_fi, points, term_fi, definition_fi) VALUES (%s, %s, %s, %s, %s)",
182 array(
'integer',
'integer',
'float',
'integer',
'integer'),
187 $termids[$pair->term->identifier],
188 $definitionids[$pair->definition->identifier]
215 $this->
setId($question_id);
224 include_once(
"./Services/RTE/classes/class.ilRTE.php");
233 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
237 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
238 $this->terms = array();
244 array_push($this->terms, $term);
245 $termids[
$data[
'term_id']] = $term;
249 $definitionids = array();
250 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id ASC",
254 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
255 $this->definitions = array();
261 array_push($this->definitions, $definition);
262 $definitionids[
$data[
'def_id']] = $definition;
266 $this->matchingpairs = array();
267 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_matching WHERE question_fi = %s ORDER BY answer_id",
271 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
276 array_push($this->matchingpairs,
new assAnswerMatchingPair($termids[
$data[
'term_fi']], $definitionids[$data[
'definition_fi']], $data[
'points']));
294 $this_id = $this->
getId();
296 if( (
int)$testObjId > 0 )
302 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
306 if( (
int)$testObjId > 0 )
308 $clone->setObjId($testObjId);
333 $clone->copyPageOfQuestion($this_id);
335 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
337 $clone->duplicateGenericFeedback($this_id);
339 $clone->duplicateSpecificFeedback($this_id);
342 $clone->duplicateImages($this_id, $thisObjId);
344 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
361 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
368 $source_questionpool = $this->
getObjId();
369 $clone->setObjId($target_questionpool);
391 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
393 if( (
int)$objectId > 0 )
395 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
398 foreach ($this->terms as $term)
400 if (strlen($term->picture))
403 if (!file_exists($imagepath))
407 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
409 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
411 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
415 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
420 foreach ($this->definitions as $definition)
422 if (strlen($definition->picture))
425 if (!file_exists($imagepath))
429 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
431 $ilLog->write(
"matching question image could not be duplicated: $imagepath_original$filename");
433 if (@file_exists($imagepath_original . $this->
getThumbPrefix() . $filename))
437 $ilLog->write(
"matching question image thumbnail could not be duplicated: $imagepath_original" . $this->
getThumbPrefix() . $filename);
444 public function copyImages($question_id, $source_questionpool)
449 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
450 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
451 foreach ($this->terms as $term)
453 if (strlen($term->picture))
455 if (!file_exists($imagepath))
460 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
462 $ilLog->write(
"matching question image could not be copied: $imagepath_original$filename");
466 $ilLog->write(
"matching question image thumbnail could not be copied: $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 copied: $imagepath_original$filename");
485 $ilLog->write(
"matching question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
503 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
504 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
505 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
509 if ($position < count($this->matchingpairs))
511 $part1 = array_slice($this->matchingpairs, 0, $position);
512 $part2 = array_slice($this->matchingpairs, $position);
513 $this->matchingpairs = array_merge($part1, array($pair), $part2);
517 array_push($this->matchingpairs, $pair);
531 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
532 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
533 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
537 array_push($this->matchingpairs, $pair);
545 foreach ($this->terms as $term)
547 if ($term->identifier == $a_identifier)
return $term;
557 foreach ($this->definitions as $definition)
559 if ($definition->identifier == $a_identifier)
return $definition;
578 if (count($this->matchingpairs) < 1)
582 if ($index >= count($this->matchingpairs))
586 return $this->matchingpairs[$index];
602 if (count($this->matchingpairs) < 1)
606 if ($index >= count($this->matchingpairs))
610 unset($this->matchingpairs[$index]);
611 $this->matchingpairs = array_values($this->matchingpairs);
620 $this->matchingpairs = array();
631 return count($this->matchingpairs);
664 return count($this->terms);
675 return count($this->definitions);
686 array_push($this->terms, $term);
697 array_push($this->definitions, $definition);
710 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
713 if ($position < count($this->terms))
715 $part1 = array_slice($this->terms, 0, $position);
716 $part2 = array_slice($this->terms, $position);
717 $this->terms = array_merge($part1, array($term), $part2);
721 array_push($this->terms, $term);
733 if (is_null($definition))
735 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
738 if ($position < count($this->definitions))
740 $part1 = array_slice($this->definitions, 0, $position);
741 $part2 = array_slice($this->definitions, $position);
742 $this->definitions = array_merge($part1, array($definition), $part2);
746 array_push($this->definitions, $definition);
756 $this->terms = array();
765 $this->definitions = array();
776 unset($this->terms[$position]);
777 $this->terms = array_values($this->terms);
788 unset($this->definitions[$position]);
789 $this->definitions = array_values($this->definitions);
801 $this->terms[$index] = $term;
818 throw new ilTestException(
'return details not implemented for '.__METHOD__);
823 $found_value1 = array();
824 $found_value2 = array();
829 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
830 array(
'integer',
'integer',
'integer'),
835 if (strcmp(
$data[
"value1"],
"") != 0)
837 array_push($found_value1,
$data[
"value1"]);
838 array_push($found_value2,
$data[
"value2"]);
842 foreach ($found_value2 as $key => $value)
844 foreach ($this->matchingpairs as $pair)
846 if (($pair->definition->identifier == $value) && ($pair->term->identifier == $found_value1[$key]))
862 foreach ($this->matchingpairs as $key => $pair)
864 if ($pair->points > 0)
883 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
885 $extension = $matches[1];
887 return md5(
$filename) .
"." . $extension;
892 $term = $this->terms[$index];
893 if (is_object($term))
896 $term->picture = null;
902 $definition = $this->definitions[$index];
903 if (is_object($definition))
906 $definition->picture = null;
933 function setImageFile($image_tempfilename, $image_filename, $previous_filename =
'')
936 if (strlen($image_tempfilename))
938 $image_filename = str_replace(
" ",
"_", $image_filename);
940 if (!file_exists($imagepath))
944 $savename = $image_filename;
955 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
972 $matching_values = array();
973 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
977 array_push($matching_values, $term);
981 $check_matching = array_flip($matching_values);
982 if (count($check_matching) != count($matching_values))
1003 $entered_values = 0;
1004 if ($saveWorkingDataResult)
1008 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1012 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
1013 array(
'integer',
'integer',
'integer'),
1017 foreach (
$_POST[
'matching'][$this->
getId()] as $definition => $term)
1020 $next_id = $ilDB->nextId(
'tst_solutions');
1021 $affectedRows = $ilDB->insert(
"tst_solutions", array(
1022 "solution_id" => array(
"integer", $next_id),
1023 "active_fi" => array(
"integer", $active_id),
1024 "question_fi" => array(
"integer", $this->
getId()),
1025 "value1" => array(
"clob", $term),
1026 "value2" => array(
"clob", $definition),
1027 "pass" => array(
"integer",
$pass),
1028 "tstamp" => array(
"integer", time())
1031 $saveWorkingDataResult =
true;
1033 if ($entered_values)
1035 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1043 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1050 return $saveWorkingDataResult;
1068 mt_srand((
double)microtime()*1000000);
1069 $random_number = mt_rand(1, 100000);
1074 foreach ($this->matchingpairs as $key => $pair)
1076 if (($pair->term->identifier == $random_number) || ($pair->definition->identifier == $random_number))
1083 return $random_number;
1115 return "assMatchingQuestion";
1125 return "qpl_qst_matching";
1135 return array(
"qpl_a_matching",
"qpl_a_mterm");
1179 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1185 foreach ($solutions as $solution)
1187 $matches_written = FALSE;
1191 $matches_written = TRUE;
1192 if ($pair->definition->identifier == $solution[
"value2"])
1194 if (strlen($pair->definition->text))
1203 if ($pair->term->identifier == $solution[
"value1"])
1205 if (strlen($pair->term->text))
1217 return $startrow + $i + 1;
1247 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1267 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1275 foreach ($this->terms as $term)
1279 foreach ($this->definitions as $definition)
1298 switch (strtoupper($path_info[
'extension']))
1317 foreach ($this->terms as $term)
1319 if (strlen($term->picture))
1324 foreach ($this->definitions as $definition)
1326 if (strlen($definition->picture))
1347 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1360 $terms = array(
"" => array(
"id"=>
"-1",
1361 "term"=>$this->lng->txt(
"please_select")));
1362 foreach ($this->
getTerms() as $term)
1364 $terms[(int)$term->identifier] = array(
1365 "term" => $term->text,
1366 "id" =>(
int)$term->identifier
1381 array_push($pairs, array(
1382 "definition" => (
string) $def->text,
1383 "def_id" => (
int) $this->getId().$def->identifier,
1393 $pid = $pair->definition->identifier;
1396 if(!isset($match[$pid]) || $match[$pid][
"points"] < $pair->points)
1398 $match[$pid] = array(
1399 "term_id" => (
int) $pair->term->identifier,
1400 "def_id" => (
int) $this->getId().$pair->definition->identifier,
1401 "points" => (int) $pair->points
1405 $result[
'match'] = array_values($match);
1420 function saveFeedbackSingleAnswer($answer_index, $feedback)
1424 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_matching WHERE question_fi = %s AND answer = %s",
1425 array(
'integer',
'integer'),
1426 array($this->
getId(), $answer_index)
1428 if (strlen($feedback))
1430 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1431 $next_id = $ilDB->nextId(
'qpl_fb_matching');
1433 $ilDB->insert(
'qpl_fb_matching', array(
1434 'feedback_id' => array(
'integer', $next_id ),
1435 'question_fi' => array(
'integer', $this->
getId() ),
1436 'answer' => array(
'integer', $answer_index ),
1438 'tstamp' => array(
'integer', time() ),
1456 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_matching WHERE question_fi = %s AND answer = %s",
1457 array(
'integer',
'integer'),
1458 array($this->
getId(), $answer_index)
1463 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1474 FROM qpl_fb_matching
1475 WHERE question_fi = %s',
1492 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_matching WHERE question_fi = %s",
1500 $next_id = $ilDB->nextId(
'qpl_fb_matching');
1502 $ilDB->insert(
'qpl_fb_matching', array(
1503 'feedback_id' => array(
'integer', $next_id ),
1504 'question_fi' => array(
'integer', $this->
getId() ),
1505 'answer' => array(
'integer',
$row[
"answer"] ),
1506 'feedback' => array(
'clob',
$row[
"feedback"] ),
1507 'tstamp' => array(
'integer', time() ),