24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
93 $this->answers = array();
105 if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
128 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
130 array($this->
getId())
133 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, ordering_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s)",
134 array(
"integer",
"text",
"integer",
"integer"),
137 $this->ordering_type,
143 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_ordering WHERE question_fi = %s",
145 array($this->
getId())
149 foreach ($this->answers as $key => $value)
151 $answer_obj = $this->answers[$key];
152 $next_id = $ilDB->nextId(
'qpl_a_ordering');
153 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_ordering (answer_id, question_fi, answertext, solution_order, ".
154 "random_id, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
155 array(
'integer',
'integer',
'text',
'integer',
'integer',
'integer'),
161 $answer_obj->getRandomID(),
194 $this->
setId($question_id);
203 include_once(
"./Services/RTE/classes/class.ilRTE.php");
205 $this->ordering_type = strlen(
$data[
"ordering_type"]) ?
$data[
"ordering_type"] :
OQ_TERMS;
206 $this->thumb_geometry =
$data[
"thumb_geometry"];
207 $this->element_height =
$data[
"element_height"];
211 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY solution_order ASC",
216 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
221 include_once(
"./Services/RTE/classes/class.ilRTE.php");
242 $this_id = $this->
getId();
244 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
269 $clone->copyPageOfQuestion($this_id);
271 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
273 $clone->duplicateFeedbackGeneric($this_id);
276 $clone->duplicateImages($this_id);
277 $clone->onDuplicate($this_id);
295 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
298 $source_questionpool = $this->
getObjId();
299 $clone->setObjId($target_questionpool);
326 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
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();
584 $found_value1 = array();
585 $found_value2 = array();
590 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
591 array(
'integer',
'integer',
'integer'),
594 $user_order = array();
597 if ((strcmp(
$data[
"value1"],
"") != 0) && (strcmp(
$data[
"value2"],
"") != 0))
599 $user_order[
$data[
"value2"]] = $data[
"value1"];
603 $user_order = array_values($user_order);
606 foreach ($this->answers as $index => $answer)
608 if ($index == $user_order[$index])
613 if ($correctcount == count($this->answers))
644 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
646 $extension = $matches[1];
648 return md5(
$filename) .
"." . $extension;
658 foreach ($contents as $f)
660 if (strcmp($f[
'type'],
'file') == 0)
665 if (strcmp($f[
'entry'], $answer->getAnswertext()) == 0) $found =
true;
666 if (strcmp($f[
'entry'], $this->
getThumbPrefix() . $answer->getAnswertext()) == 0) $found =
true;
707 function setImageFile($image_tempfilename, $image_filename, $previous_filename)
710 if (strlen($image_tempfilename))
712 $image_filename = str_replace(
" ",
"_", $image_filename);
714 if (!file_exists($imagepath))
718 $savename = $image_filename;
729 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
749 if (strlen(
$_POST[
"orderresult"]))
754 $order_values = array();
755 foreach (
$_POST as $key => $value)
757 if (preg_match(
"/^order_(\d+)/", $key, $matches))
759 if (strcmp($value,
"") != 0)
761 array_push($order_values, $value);
765 $check_order = array_flip($order_values);
766 if (count($check_order) != count($order_values))
790 if ($saveWorkingDataResult)
794 include_once
"./Modules/Test/classes/class.ilObjTest.php";
798 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
799 array(
'integer',
'integer',
'integer'),
802 if (array_key_exists(
"orderresult",
$_POST))
804 $orderresult =
$_POST[
"orderresult"];
805 if (strlen($orderresult))
807 $orderarray = explode(
":", $orderresult);
809 foreach ($orderarray as $index)
811 if (preg_match(
"/id_(\\d+)/", $index, $idmatch))
813 $randomid = $idmatch[1];
814 foreach ($this->
getAnswers() as $answeridx => $answer)
816 if ($answer->getRandomID() == $randomid)
818 $next_id = $ilDB->nextId(
'tst_solutions');
819 $affectedRows = $ilDB->insert(
"tst_solutions", array(
820 "solution_id" => array(
"integer", $next_id),
821 "active_fi" => array(
"integer", $active_id),
822 "question_fi" => array(
"integer", $this->
getId()),
823 "value1" => array(
"clob", $answeridx),
824 "value2" => array(
"clob", trim($ordervalue)),
825 "pass" => array(
"integer",
$pass),
826 "tstamp" => array(
"integer", time())
838 foreach (
$_POST as $key => $value)
840 if (preg_match(
"/^order_(\d+)/", $key, $matches))
842 if (!(preg_match(
"/initial_value_\d+/", $value)))
846 foreach ($this->
getAnswers() as $answeridx => $answer)
848 if ($answer->getRandomID() == $matches[1])
850 $next_id = $ilDB->nextId(
'tst_solutions');
851 $affectedRows = $ilDB->insert(
"tst_solutions", array(
852 "solution_id" => array(
"integer", $next_id),
853 "active_fi" => array(
"integer", $active_id),
854 "question_fi" => array(
"integer", $this->
getId()),
855 "value1" => array(
"clob", $answeridx),
856 "value2" => array(
"clob", $value),
857 "pass" => array(
"integer",
$pass),
858 "tstamp" => array(
"integer", time())
871 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
879 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
886 return $saveWorkingDataResult;
897 return "assOrderingQuestion";
908 return "qpl_qst_ordering";
919 return "qpl_a_ordering";
929 foreach ($this->answers as $index => $answer)
931 $answer_obj = $this->answers[$index];
932 $text .= $answer_obj->getAnswertext();
970 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
973 foreach ($solutions as $solution)
975 $sol[$solution[
"value1"]] = $solution[
"value2"];
978 $sol = array_keys($sol);
983 foreach ($sol as $idx)
985 foreach ($solutions as $solution)
992 return $startrow + $i + 1;
1017 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1037 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1067 switch (strtoupper($path_info[
'extension']))
1088 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1095 $result[
'shuffle'] = (bool)
true;
1105 $answers[$counter] = $answer_obj->getAnswertext();
1110 foreach (
$answers as $order => $answer)
1112 array_push($arr, array(
1113 "answertext" => (
string) $answer,
1114 "order" => (
int) $order
1125 $answer = $this->answers[$index];
1126 if (is_object($answer))
1129 $answer->setAnswertext(
'');