24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
86 $this->matchingpairs = array();
88 $this->terms = array();
101 if (($this->title) and ($this->author) and ($this->question) and (count($this->matchingpairs)) and ($this->
getMaximumPoints() > 0))
129 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
141 include_once(
"./Services/RTE/classes/class.ilRTE.php");
147 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
148 $query = sprintf(
"INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, working_time, points, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
149 $ilDB->quote($question_type.
""),
150 $ilDB->quote($this->obj_id.
""),
151 $ilDB->quote($this->title.
""),
152 $ilDB->quote($this->comment.
""),
153 $ilDB->quote($this->author.
""),
154 $ilDB->quote($this->owner.
""),
156 $ilDB->quote($estw_time.
""),
158 $ilDB->quote($complete.
""),
159 $ilDB->quote($created.
""),
163 $result = $ilDB->query($query);
164 if (PEAR::isError($result))
167 $ilias->raiseError($result->getMessage());
171 $this->
id = $ilDB->getLastInsertId();
172 $query = sprintf(
"INSERT INTO qpl_question_matching (question_fi, shuffle, matching_type) VALUES (%s, %s, %s)",
173 $ilDB->quote($this->id .
""),
174 $ilDB->quote($this->shuffle .
""),
175 $ilDB->quote($this->matching_type.
"")
177 $ilDB->query($query);
192 $query = sprintf(
"UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time=%s, points = %s, complete = %s WHERE question_id = %s",
193 $ilDB->quote($this->obj_id.
""),
194 $ilDB->quote($this->title.
""),
195 $ilDB->quote($this->comment.
""),
196 $ilDB->quote($this->author.
""),
198 $ilDB->quote($estw_time.
""),
200 $ilDB->quote($complete.
""),
201 $ilDB->quote($this->
id.
"")
203 $result = $ilDB->query($query);
204 $query = sprintf(
"UPDATE qpl_question_matching SET shuffle = %s, matching_type = %s WHERE question_fi = %s",
205 $ilDB->quote($this->shuffle .
""),
206 $ilDB->quote($this->matching_type.
""),
207 $ilDB->quote($this->
id .
"")
209 $result = $ilDB->query($query);
215 $ilias->raiseError(
$result->getMessage());
222 $query = sprintf(
"DELETE FROM qpl_answer_matching_term WHERE question_fi = %s",
223 $ilDB->quote($this->id)
225 $result = $ilDB->query($query);
229 foreach ($this->terms as $key => $value)
231 $query = sprintf(
"INSERT INTO qpl_answer_matching_term (term_id, question_fi, term) VALUES (NULL, %s, %s)",
232 $ilDB->quote($this->getId()),
233 $ilDB->quote($value .
"")
235 $term_result = $ilDB->query($query);
236 $newTermID = $ilDB->getLastInsertId();
237 $newterms[$newTermID] = $value;
238 foreach ($this->matchingpairs as $mkey => $mvalue)
240 if (strcmp($this->matchingpairs[$mkey]->getTerm(), $key) == 0)
242 $this->matchingpairs[$mkey]->setTerm($newTermID);
246 $this->terms = $newterms;
249 $query = sprintf(
"DELETE FROM qpl_answer_matching WHERE question_fi = %s",
250 $ilDB->quote($this->id)
252 $result = $ilDB->query($query);
255 foreach ($this->matchingpairs as $key => $value)
257 $matching_obj = $this->matchingpairs[$key];
258 $query = sprintf(
"INSERT INTO qpl_answer_matching (answer_id, question_fi, answertext, points, aorder, matchingtext, matching_order) VALUES (NULL, %s, %s, %s, %s, %s, %s)",
259 $ilDB->quote($this->id),
260 $ilDB->quote($matching_obj->getTerm() .
""),
261 $ilDB->quote($matching_obj->getPoints() .
""),
262 $ilDB->quote($matching_obj->getTerm() .
""),
263 $ilDB->quote($matching_obj->getDefinition() .
""),
264 $ilDB->quote($matching_obj->getDefinitionId() .
"")
266 $matching_result = $ilDB->query($query);
285 $query = sprintf(
"SELECT qpl_questions.*, qpl_question_matching.* FROM qpl_questions, qpl_question_matching WHERE question_id = %s AND qpl_questions.question_id = qpl_question_matching.question_fi",
286 $ilDB->quote($question_id)
288 $result = $ilDB->query($query);
289 if ($result->numRows() == 1)
291 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
292 $this->
id = $question_id;
293 $this->title =
$data->title;
294 $this->comment =
$data->comment;
295 $this->author =
$data->author;
296 $this->solution_hint =
$data->solution_hint;
297 $this->obj_id =
$data->obj_fi;
298 $this->original_id =
$data->original_id;
299 $this->owner =
$data->owner;
300 $this->matching_type =
$data->matching_type;
301 include_once(
"./Services/RTE/classes/class.ilRTE.php");
303 $this->points =
$data->points;
304 $this->shuffle =
$data->shuffle;
307 $query = sprintf(
"SELECT * FROM qpl_answer_matching WHERE question_fi = %s ORDER BY answer_id ASC",
308 $ilDB->quote($question_id)
310 $result = $ilDB->query($query);
311 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatching.php";
312 if ($result->numRows() > 0)
314 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
320 $query = sprintf(
"SELECT * FROM qpl_answer_matching_term WHERE question_fi = %s ORDER BY term ASC",
321 $ilDB->quote($question_id)
323 $result = $ilDB->query($query);
324 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatching.php";
325 if ($result->numRows() > 0)
327 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
352 $this_id = $this->
getId();
354 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
379 $clone->copyPageOfQuestion($this_id);
381 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
383 $clone->duplicateFeedbackGeneric($this_id);
386 $clone->duplicateImages($this_id);
406 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
413 $source_questionpool = $this->
getObjId();
414 $clone->setObjId($target_questionpool);
434 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
435 foreach ($this->matchingpairs as $answer)
438 if (!file_exists($imagepath))
442 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
444 print
"image could not be duplicated!!!! ";
446 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg"))
448 print
"image thumbnail could not be duplicated!!!! ";
459 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
460 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
461 foreach ($this->matchingpairs as $answer)
464 if (!file_exists($imagepath))
468 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
470 print
"image could not be duplicated!!!! ";
472 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg"))
474 print
"image thumbnail could not be duplicated!!!! ";
529 $picture_or_definition =
"",
532 $picture_or_definition_id = 0
541 if ($picture_or_definition_id == 0)
545 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatching.php";
547 array_push($this->matchingpairs, $matchingpair);
583 if (count($this->matchingpairs) < 1)
587 if ($index >= count($this->matchingpairs))
591 return $this->matchingpairs[$index];
610 if (count($this->matchingpairs) < 1)
614 if ($index >= count($this->matchingpairs))
618 unset($this->matchingpairs[$index]);
619 $this->matchingpairs = array_values($this->matchingpairs);
632 $this->matchingpairs = array();
646 return count($this->matchingpairs);
660 natcasesort($this->terms);
676 return $this->terms[
$id];
690 return count($this->terms);
704 $newkey = count($this->terms);
705 while (array_key_exists(
"term_" . $newkey, $this->terms))
709 $this->terms[
"term_" . $newkey] = $term;
722 $this->terms = array();
736 unset($this->terms[$term_id]);
751 $this->terms[$index] = $term;
769 $found_value1 = array();
770 $found_value2 = array();
775 $query = sprintf(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
776 $ilDB->quote($active_id .
""),
777 $ilDB->quote($this->
getId() .
""),
778 $ilDB->quote(
$pass .
"")
780 $result = $ilDB->query($query);
781 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
783 if (strcmp(
$data->value1,
"") != 0)
785 array_push($found_value1,
$data->value1);
786 array_push($found_value2,
$data->value2);
790 foreach ($found_value2 as $key => $value)
792 foreach ($this->matchingpairs as $answer_key => $answer_value)
794 if (($answer_value->getDefinitionId() == $value) and ($answer_value->getTerm() == $found_value1[$key]))
796 $points += $answer_value->getPoints();
816 foreach ($this->matchingpairs as $key => $value)
818 if ($value->getPoints() > 0)
820 $points += $value->getPoints();
839 if (!empty($image_tempfilename))
841 $image_filename = str_replace(
" ",
"_", $image_filename);
843 if (!file_exists($imagepath))
854 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
856 if (!preg_match(
"/^image/", $mimetype))
858 unlink($imagepath . $image_filename);
864 $thumbpath = $imagepath . $image_filename .
"." .
"thumb.jpg";
884 $matching_values = array();
885 foreach ($_POST as $key => $value)
887 if (preg_match(
"/^sel_matching_(\d+)/", $key, $matches))
889 if ((strcmp($value,
"") != 0) && ($value != -1))
891 array_push($matching_values, $value);
895 $check_matching = array_flip($matching_values);
896 if (count($check_matching) != count($matching_values))
900 ilUtil::sendInfo($this->lng->txt(
"duplicate_matching_values_selected"), TRUE);
922 if ($saveWorkingDataResult)
926 include_once
"./Modules/Test/classes/class.ilObjTest.php";
930 $query = sprintf(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
931 $ilDB->quote($active_id .
""),
932 $ilDB->quote($this->
getId() .
""),
933 $ilDB->quote(
$pass .
"")
935 $result = $ilDB->query($query);
936 foreach ($_POST as $key => $value)
938 if (preg_match(
"/^sel_matching_(\d+)/", $key, $matches))
943 $query = sprintf(
"INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
944 $ilDB->quote($active_id),
945 $ilDB->quote($this->
getId()),
946 $ilDB->quote(trim($value)),
947 $ilDB->quote(trim($matches[1])),
948 $ilDB->quote(
$pass .
"")
950 $result = $ilDB->query($query);
954 $saveWorkingDataResult =
true;
958 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
966 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
973 return $saveWorkingDataResult;
978 mt_srand((
double)microtime()*1000000);
979 $random_number = mt_rand(1, 100000);
984 foreach ($this->matchingpairs as $key => $value)
986 if (($value->getTermId() == $random_number) || ($value->getDefinitionId() == $random_number))
993 return $random_number;
998 mt_srand((
double)microtime()*1000000);
1001 $j = mt_rand(0, $i);
1006 $array[$j] = $array[$i];
1048 return "assMatchingQuestion";
1061 return "qpl_question_matching";
1074 return array(
"qpl_answer_matching",
"qpl_answer_matching_term");
1121 include_once (
"./classes/class.ilExcelUtils.php");
1128 foreach ($solutions as $solution)
1130 $matches_written = FALSE;
1134 $matches_written = TRUE;
1135 if ($answer->getDefinitionId() == $solution[
"value2"])
1137 if (strlen($answer->getDefinition())) $worksheet->writeString($startrow + $i, 0,
ilExcelUtils::_convert_text($answer->getDefinition()));
1139 if ($answer->getTermId() == $solution[
"value1"])
1146 return $startrow + $i + 1;