24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
93 $this->answers = array();
105 if (strlen($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 if( (
int)$testObjId > 0 )
250 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
254 if( (
int)$testObjId > 0 )
256 $clone->setObjId($testObjId);
281 $clone->copyPageOfQuestion($this_id);
283 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
285 $clone->duplicateFeedbackGeneric($this_id);
288 $clone->duplicateImages($this_id, $thisObjId, $clone->getId(), $testObjId);
290 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
309 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
312 $source_questionpool = $this->
getObjId();
313 $clone->setObjId($target_questionpool);
334 function duplicateImages($src_question_id, $src_object_id, $dest_question_id, $dest_object_id)
339 $imagepath_original = $this->
getImagePath($src_question_id, $src_object_id);
340 $imagepath = $this->
getImagePath($dest_question_id, $dest_object_id);
342 if (!file_exists($imagepath)) {
345 foreach ($this->answers as $answer)
348 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
350 $ilLog->write(
"image could not be duplicated!!!!");
352 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
356 $ilLog->write(
"image thumbnail could not be duplicated!!!!");
369 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
370 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
371 if (!file_exists($imagepath)) {
374 foreach ($this->answers as $answer)
377 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
379 $ilLog->write(
"Ordering Question image could not be copied: $imagepath_original$filename");
381 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
385 $ilLog->write(
"Ordering Question image thumbnail could not be copied: $imagepath_original" . $this->
getThumbPrefix() . $filename);
434 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
436 if (($solution_order >= 0) && ($solution_order < count($this->answers)))
438 $part1 = array_slice($this->answers, 0, $solution_order);
439 $part2 = array_slice($this->answers, $solution_order);
440 $this->answers = array_merge($part1, array($answer), $part2);
444 array_push($this->answers, $answer);
452 $temp = $this->answers[$position-1];
453 $this->answers[$position-1] = $this->answers[$position];
454 $this->answers[$position] = $temp;
460 if ($position < count($this->answers)-1)
462 $temp = $this->answers[$position+1];
463 $this->answers[$position+1] = $this->answers[$position];
464 $this->answers[$position] = $temp;
470 $random_number = mt_rand(1, 100000);
477 if ($answer->getRandomID() == $random_number)
484 return $random_number;
498 if ($index < 0)
return NULL;
499 if (count($this->answers) < 1)
return NULL;
500 if ($index >= count($this->answers))
return NULL;
501 return $this->answers[$index];
518 if (count($this->answers) < 1)
522 if ($index >= count($this->answers))
526 unset($this->answers[$index]);
527 $this->answers = array_values($this->answers);
528 for ($i = 0; $i < count($this->answers); $i++)
530 if ($this->answers[$i]->getOrder() > $index)
532 $this->answers[$i]->setOrder($i);
545 $this->answers = array();
557 return count($this->answers);
568 if (count($this->answers) == 0)
574 $max = $this->answers[0]->getSolutionOrder();
576 foreach ($this->answers as $key => $value)
578 if ($value->getSolutionOrder() > $max)
580 $max = $value->getSolutionOrder();
599 $found_value1 = array();
600 $found_value2 = array();
605 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
606 array(
'integer',
'integer',
'integer'),
609 $user_order = array();
612 if ((strcmp(
$data[
"value1"],
"") != 0) && (strcmp(
$data[
"value2"],
"") != 0))
614 $user_order[
$data[
"value2"]] = $data[
"value1"];
618 $user_order = array_values($user_order);
621 foreach ($this->answers as $index => $answer)
623 if ($index == $user_order[$index])
628 if ($correctcount == count($this->answers))
659 if (preg_match(
"/.*\\.(\\w+)$/",
$filename, $matches))
661 $extension = $matches[1];
663 return md5(
$filename) .
"." . $extension;
673 foreach ($contents as $f)
675 if (strcmp($f[
'type'],
'file') == 0)
680 if (strcmp($f[
'entry'], $answer->getAnswertext()) == 0) $found =
true;
681 if (strcmp($f[
'entry'], $this->
getThumbPrefix() . $answer->getAnswertext()) == 0) $found =
true;
722 function setImageFile($image_tempfilename, $image_filename, $previous_filename)
725 if (strlen($image_tempfilename))
727 $image_filename = str_replace(
" ",
"_", $image_filename);
729 if (!file_exists($imagepath))
733 $savename = $image_filename;
744 if (
$result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
764 if (strlen(
$_POST[
"orderresult"]))
769 $order_values = array();
770 foreach (
$_POST as $key => $value)
772 if (preg_match(
"/^order_(\d+)/", $key, $matches))
774 if (strcmp($value,
"") != 0)
776 array_push($order_values, $value);
780 $check_order = array_flip($order_values);
781 if (count($check_order) != count($order_values))
805 if ($saveWorkingDataResult)
809 include_once
"./Modules/Test/classes/class.ilObjTest.php";
813 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
814 array(
'integer',
'integer',
'integer'),
817 if (array_key_exists(
"orderresult",
$_POST))
819 $orderresult =
$_POST[
"orderresult"];
820 if (strlen($orderresult))
822 $orderarray = explode(
":", $orderresult);
824 foreach ($orderarray as $index)
826 if (preg_match(
"/id_(\\d+)/", $index, $idmatch))
828 $randomid = $idmatch[1];
829 foreach ($this->
getAnswers() as $answeridx => $answer)
831 if ($answer->getRandomID() == $randomid)
833 $next_id = $ilDB->nextId(
'tst_solutions');
834 $affectedRows = $ilDB->insert(
"tst_solutions", array(
835 "solution_id" => array(
"integer", $next_id),
836 "active_fi" => array(
"integer", $active_id),
837 "question_fi" => array(
"integer", $this->
getId()),
838 "value1" => array(
"clob", $answeridx),
839 "value2" => array(
"clob", trim($ordervalue)),
840 "pass" => array(
"integer",
$pass),
841 "tstamp" => array(
"integer", time())
853 foreach (
$_POST as $key => $value)
855 if (preg_match(
"/^order_(\d+)/", $key, $matches))
857 if (!(preg_match(
"/initial_value_\d+/", $value)))
861 foreach ($this->
getAnswers() as $answeridx => $answer)
863 if ($answer->getRandomID() == $matches[1])
865 $next_id = $ilDB->nextId(
'tst_solutions');
866 $affectedRows = $ilDB->insert(
"tst_solutions", array(
867 "solution_id" => array(
"integer", $next_id),
868 "active_fi" => array(
"integer", $active_id),
869 "question_fi" => array(
"integer", $this->
getId()),
870 "value1" => array(
"clob", $answeridx),
871 "value2" => array(
"clob", $value),
872 "pass" => array(
"integer",
$pass),
873 "tstamp" => array(
"integer", time())
886 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
894 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
901 return $saveWorkingDataResult;
912 return "assOrderingQuestion";
923 return "qpl_qst_ordering";
934 return "qpl_a_ordering";
944 foreach ($this->answers as $index => $answer)
946 $answer_obj = $this->answers[$index];
947 $text .= $answer_obj->getAnswertext();
985 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
988 foreach ($solutions as $solution)
990 $sol[$solution[
"value1"]] = $solution[
"value2"];
993 $sol = array_keys($sol);
998 foreach ($sol as $idx)
1000 foreach ($solutions as $solution)
1007 return $startrow + $i + 1;
1032 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1052 $this->element_height = ($a_height < 20) ?
"" : $a_height;
1082 switch (strtoupper($path_info[
'extension']))
1103 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1110 $result[
'shuffle'] = (bool)
true;
1125 $answers[$counter] = $answer_obj->getAnswertext();
1130 foreach (
$answers as $order => $answer)
1132 array_push($arr, array(
1133 "answertext" => (
string) $answer,
1134 "order" => (
int) $order
1147 $answer = $this->answers[$index];
1148 if (is_object($answer))
1151 $answer->setAnswertext(
'');