5 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
6 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
78 $this->answers = array();
90 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
113 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
115 array($this->
getId())
118 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, ordering_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s)",
119 array(
"integer",
"text",
"integer",
"integer"),
122 $this->ordering_type,
128 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_ordering WHERE question_fi = %s",
130 array($this->
getId())
134 foreach ($this->answers as $key => $value)
136 $answer_obj = $this->answers[$key];
137 $next_id = $ilDB->nextId(
'qpl_a_ordering');
138 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_ordering (answer_id, question_fi, answertext, solution_order, ".
139 "random_id, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
140 array(
'integer',
'integer',
'text',
'integer',
'integer',
'integer'),
146 $answer_obj->getRandomID(),
179 $this->
setId($question_id);
188 include_once(
"./Services/RTE/classes/class.ilRTE.php");
190 $this->ordering_type = strlen(
$data[
"ordering_type"]) ?
$data[
"ordering_type"] :
OQ_TERMS;
191 $this->thumb_geometry =
$data[
"thumb_geometry"];
192 $this->element_height =
$data[
"element_height"];
196 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY solution_order ASC",
201 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
206 include_once(
"./Services/RTE/classes/class.ilRTE.php");
227 $this_id = $this->
getId();
229 if( (
int)$testObjId > 0 )
235 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
239 if( (
int)$testObjId > 0 )
241 $clone->setObjId($testObjId);
266 $clone->copyPageOfQuestion($this_id);
268 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
270 $clone->duplicateGenericFeedback($this_id);
273 $clone->duplicateImages($this_id, $thisObjId, $clone->getId(), $testObjId);
275 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
294 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
297 $source_questionpool = $this->
getObjId();
298 $clone->setObjId($target_questionpool);
319 function duplicateImages($src_question_id, $src_object_id, $dest_question_id, $dest_object_id)
324 $imagepath_original = $this->
getImagePath($src_question_id, $src_object_id);
325 $imagepath = $this->
getImagePath($dest_question_id, $dest_object_id);
327 if (!file_exists($imagepath)) {
330 foreach ($this->answers as $answer)
333 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
335 $ilLog->write(
"image could not be duplicated!!!!");
337 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
341 $ilLog->write(
"image thumbnail could not be duplicated!!!!");
354 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
355 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
356 if (!file_exists($imagepath)) {
359 foreach ($this->answers as $answer)
362 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
364 $ilLog->write(
"Ordering Question image could not be copied: $imagepath_original$filename");
366 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
370 $ilLog->write(
"Ordering Question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
419 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
421 if (($solution_order >= 0) && ($solution_order < count($this->answers)))
423 $part1 = array_slice($this->answers, 0, $solution_order);
424 $part2 = array_slice($this->answers, $solution_order);
425 $this->answers = array_merge($part1, array($answer), $part2);
429 array_push($this->answers, $answer);
437 $temp = $this->answers[$position-1];
438 $this->answers[$position-1] = $this->answers[$position];
439 $this->answers[$position] = $temp;
445 if ($position < count($this->answers)-1)
447 $temp = $this->answers[$position+1];
448 $this->answers[$position+1] = $this->answers[$position];
449 $this->answers[$position] = $temp;
455 $random_number = mt_rand(1, 100000);
462 if ($answer->getRandomID() == $random_number)
469 return $random_number;
483 if ($index < 0)
return NULL;
484 if (count($this->answers) < 1)
return NULL;
485 if ($index >= count($this->answers))
return NULL;
486 return $this->answers[$index];
503 if (count($this->answers) < 1)
507 if ($index >= count($this->answers))
511 unset($this->answers[$index]);
512 $this->answers = array_values($this->answers);
513 for ($i = 0; $i < count($this->answers); $i++)
515 if ($this->answers[$i]->getOrder() > $index)
517 $this->answers[$i]->setOrder($i);
530 $this->answers = array();
542 return count($this->answers);
553 if (count($this->answers) == 0)
559 $max = $this->answers[0]->getSolutionOrder();
561 foreach ($this->answers as $key => $value)
563 if ($value->getSolutionOrder() > $max)
565 $max = $value->getSolutionOrder();
585 throw new ilTestException(
'return details not implemented for '.__METHOD__);
590 $found_value1 = array();
591 $found_value2 = array();
596 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
597 array(
'integer',
'integer',
'integer'),
600 $user_order = array();
603 if ((strcmp(
$data[
"value1"],
"") != 0) && (strcmp(
$data[
"value2"],
"") != 0))
605 $user_order[
$data[
"value2"]] = $data[
"value1"];
609 $user_order = array_values($user_order);
612 foreach ($this->answers as $index => $answer)
614 if ($index == $user_order[$index])
619 if ($correctcount == count($this->answers))
649 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
651 $extension = $matches[1];
653 return md5(
$filename) .
"." . $extension;
663 foreach ($contents as $f)
665 if (strcmp($f[
'type'],
'file') == 0)
670 if (strcmp($f[
'entry'], $answer->getAnswertext()) == 0) $found =
true;
671 if (strcmp($f[
'entry'], $this->
getThumbPrefix() . $answer->getAnswertext()) == 0) $found =
true;
712 function setImageFile($image_tempfilename, $image_filename, $previous_filename)
715 if (strlen($image_tempfilename))
717 $image_filename = str_replace(
" ",
"_", $image_filename);
719 if (!file_exists($imagepath))
723 $savename = $image_filename;
734 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
754 if (strlen(
$_POST[
"orderresult"]))
759 $order_values = array();
760 foreach (
$_POST as $key => $value)
762 if (preg_match(
"/^order_(\d+)/", $key, $matches))
764 if (strcmp($value,
"") != 0)
766 array_push($order_values, $value);
770 $check_order = array_flip($order_values);
771 if (count($check_order) != count($order_values))
795 if ($saveWorkingDataResult)
799 include_once
"./Modules/Test/classes/class.ilObjTest.php";
803 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
804 array(
'integer',
'integer',
'integer'),
807 if (array_key_exists(
"orderresult",
$_POST))
809 $orderresult =
$_POST[
"orderresult"];
810 if (strlen($orderresult))
812 $orderarray = explode(
":", $orderresult);
814 foreach ($orderarray as $index)
816 if (preg_match(
"/id_(\\d+)/", $index, $idmatch))
818 $randomid = $idmatch[1];
819 foreach ($this->
getAnswers() as $answeridx => $answer)
821 if ($answer->getRandomID() == $randomid)
823 $next_id = $ilDB->nextId(
'tst_solutions');
824 $affectedRows = $ilDB->insert(
"tst_solutions", array(
825 "solution_id" => array(
"integer", $next_id),
826 "active_fi" => array(
"integer", $active_id),
827 "question_fi" => array(
"integer", $this->
getId()),
828 "value1" => array(
"clob", $answeridx),
829 "value2" => array(
"clob", trim($ordervalue)),
830 "pass" => array(
"integer",
$pass),
831 "tstamp" => array(
"integer", time())
843 foreach (
$_POST as $key => $value)
845 if (preg_match(
"/^order_(\d+)/", $key, $matches))
847 if (!(preg_match(
"/initial_value_\d+/", $value)))
851 foreach ($this->
getAnswers() as $answeridx => $answer)
853 if ($answer->getRandomID() == $matches[1])
855 $next_id = $ilDB->nextId(
'tst_solutions');
856 $affectedRows = $ilDB->insert(
"tst_solutions", array(
857 "solution_id" => array(
"integer", $next_id),
858 "active_fi" => array(
"integer", $active_id),
859 "question_fi" => array(
"integer", $this->
getId()),
860 "value1" => array(
"clob", $answeridx),
861 "value2" => array(
"clob", $value),
862 "pass" => array(
"integer",
$pass),
863 "tstamp" => array(
"integer", time())
876 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
884 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
891 return $saveWorkingDataResult;
915 return "assOrderingQuestion";
926 return "qpl_qst_ordering";
937 return "qpl_a_ordering";
947 foreach ($this->answers as $index => $answer)
949 $answer_obj = $this->answers[$index];
950 $text .= $answer_obj->getAnswertext();
988 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
991 foreach ($solutions as $solution)
993 $sol[$solution[
"value1"]] = $solution[
"value2"];
996 $sol = array_keys($sol);
1001 foreach ($sol as $idx)
1003 foreach ($solutions as $solution)
1010 return $startrow + $i + 1;
1035 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1055 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1085 switch (strtoupper($path_info[
'extension']))
1106 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1113 $result[
'shuffle'] = (bool)
true;
1128 $answers[$counter] = $answer_obj->getAnswertext();
1133 foreach (
$answers as $order => $answer)
1135 array_push($arr, array(
1136 "answertext" => (
string) $answer,
1137 "order" => (
int) $order
1150 $answer = $this->answers[$index];
1151 if (is_object($answer))
1154 $answer->setAnswertext(
'');