24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
79 $this->answers = array();
93 if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
122 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
133 include_once(
"./Services/RTE/classes/class.ilRTE.php");
139 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
140 $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)",
141 $ilDB->quote($question_type .
""),
142 $ilDB->quote($this->obj_id .
""),
143 $ilDB->quote($this->title .
""),
144 $ilDB->quote($this->comment .
""),
145 $ilDB->quote($this->author .
""),
146 $ilDB->quote($this->owner .
""),
148 $ilDB->quote($estw_time .
""),
150 $ilDB->quote($complete .
""),
151 $ilDB->quote($created .
""),
154 $result = $ilDB->query($query);
155 if (PEAR::isError($result))
158 $ilias->raiseError($result->getMessage());
162 $this->
id = $ilDB->getLastInsertId();
163 $query = sprintf(
"INSERT INTO qpl_question_ordering (question_fi, ordering_type) VALUES (%s, %s)",
164 $ilDB->quote($this->id .
""),
165 $ilDB->quote($this->ordering_type .
"")
167 $ilDB->query($query);
181 $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",
182 $ilDB->quote($this->obj_id.
""),
183 $ilDB->quote($this->title .
""),
184 $ilDB->quote($this->comment .
""),
185 $ilDB->quote($this->author .
""),
187 $ilDB->quote($estw_time .
""),
189 $ilDB->quote($complete .
""),
190 $ilDB->quote($this->
id .
"")
192 $result = $ilDB->query($query);
193 $query = sprintf(
"UPDATE qpl_question_ordering SET ordering_type = %s WHERE question_fi = %s",
194 $ilDB->quote($this->ordering_type .
""),
195 $ilDB->quote($this->
id .
"")
197 $result = $ilDB->query($query);
202 $ilias->raiseError(
$result->getMessage());
208 $query = sprintf(
"DELETE FROM qpl_answer_ordering WHERE question_fi = %s",
209 $ilDB->quote($this->id)
211 $result = $ilDB->query($query);
214 foreach ($this->answers as $key => $value)
216 $answer_obj = $this->answers[$key];
217 $query = sprintf(
"INSERT INTO qpl_answer_ordering (answer_id, question_fi, answertext, points, aorder, solution_order) VALUES (NULL, %s, %s, %s, %s, %s)",
218 $ilDB->quote($this->id),
220 $ilDB->quote($answer_obj->getPoints() .
""),
221 $ilDB->quote($answer_obj->getOrder() .
""),
222 $ilDB->quote($answer_obj->getSolutionOrder() .
"")
224 $answer_result = $ilDB->query($query);
243 $query = sprintf(
"SELECT qpl_questions.*, qpl_question_ordering.* FROM qpl_questions, qpl_question_ordering WHERE question_id = %s AND qpl_questions.question_id = qpl_question_ordering.question_fi",
244 $ilDB->quote($question_id)
246 $result = $ilDB->query($query);
247 if ($result->numRows() == 1)
249 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
250 $this->
id = $question_id;
251 $this->title =
$data->title;
252 $this->obj_id =
$data->obj_fi;
253 $this->comment =
$data->comment;
254 $this->original_id =
$data->original_id;
255 $this->author =
$data->author;
256 $this->owner =
$data->owner;
257 include_once(
"./Services/RTE/classes/class.ilRTE.php");
259 $this->solution_hint =
$data->solution_hint;
260 $this->ordering_type =
$data->ordering_type;
261 $this->points =
$data->points;
264 $query = sprintf(
"SELECT * FROM qpl_answer_ordering WHERE question_fi = %s ORDER BY aorder ASC",
265 $ilDB->quote($question_id)
267 $result = $ilDB->query($query);
268 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
269 if ($result->numRows() > 0)
271 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
273 include_once(
"./Services/RTE/classes/class.ilRTE.php");
297 $this_id = $this->
getId();
299 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
324 $clone->copyPageOfQuestion($this_id);
326 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
328 $clone->duplicateFeedbackGeneric($this_id);
331 $clone->duplicateImages($this_id);
351 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
354 $source_questionpool = $this->
getObjId();
355 $clone->setObjId($target_questionpool);
380 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
381 if (!file_exists($imagepath)) {
384 foreach ($this->answers as $answer)
387 if (!copy($imagepath_original .
$filename, $imagepath . $filename)) {
388 print
"image could not be duplicated!!!! ";
390 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg")) {
391 print
"image thumbnail could not be duplicated!!!! ";
402 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
403 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
404 if (!file_exists($imagepath)) {
407 foreach ($this->answers as $answer)
410 if (!copy($imagepath_original .
$filename, $imagepath . $filename)) {
411 print
"image could not be copied!!!! ";
413 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg")) {
414 print
"image thumbnail could not be copied!!!! ";
471 foreach ($this->answers as $key => $value)
473 if ($value->getOrder() == $order)
478 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
483 array_push($this->answers, $answer);
484 for ($i = $found + 1; $i < count($this->answers); $i++)
486 $this->answers[$i] = $this->answers[$i-1];
488 $this->answers[$found] = $answer;
494 count($this->answers), $solution_order);
495 array_push($this->answers, $answer);
512 if ($index < 0)
return NULL;
513 if (count($this->answers) < 1)
return NULL;
514 if ($index >= count($this->answers))
return NULL;
515 return $this->answers[$index];
534 if (count($this->answers) < 1)
538 if ($index >= count($this->answers))
542 unset($this->answers[$index]);
543 $this->answers = array_values($this->answers);
544 for ($i = 0; $i < count($this->answers); $i++)
546 if ($this->answers[$i]->getOrder() > $index)
548 $this->answers[$i]->setOrder($i);
563 $this->answers = array();
577 return count($this->answers);
590 if (count($this->answers) == 0)
596 $max = $this->answers[0]->getSolutionOrder();
598 foreach ($this->answers as $key => $value)
600 if ($value->getSolutionOrder() > $max)
602 $max = $value->getSolutionOrder();
623 $found_value1 = array();
624 $found_value2 = array();
629 $query = sprintf(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
630 $ilDB->quote($active_id .
""),
631 $ilDB->quote($this->
getId() .
""),
632 $ilDB->quote(
$pass .
"")
634 $result = $ilDB->query($query);
635 $user_order = array();
636 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
638 if ((strcmp(
$data->value1,
"") != 0) && (strcmp(
$data->value2,
"") != 0))
644 $user_order = array_values($user_order);
645 $answer_order = array();
646 foreach ($this->answers as $key => $answer)
648 $answer_order[$answer->getSolutionOrder()] = $key;
650 ksort($answer_order);
651 $answer_order = array_values($answer_order);
653 foreach ($answer_order as $index => $answer_id)
655 if (strcmp($user_order[$index],
"") != 0)
657 if ($answer_id == $user_order[$index])
659 $points += $this->answers[$answer_id]->getPoints();
679 foreach ($this->answers as $key => $value)
681 $points += $value->getPoints();
699 if (!empty($image_tempfilename))
702 if (!file_exists($imagepath))
712 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
714 if (!preg_match(
"/^image/", $mimetype))
716 unlink($imagepath . $image_filename);
722 $thumbpath = $imagepath . $image_filename .
"." .
"thumb.jpg";
744 if (strlen($_POST[
"orderresult"]))
749 $order_values = array();
750 foreach ($_POST as $key => $value)
752 if (preg_match(
"/^order_(\d+)/", $key, $matches))
754 if (strcmp($value,
"") != 0)
756 array_push($order_values, $value);
760 $check_order = array_flip($order_values);
761 if (count($check_order) != count($order_values))
787 if ($saveWorkingDataResult)
791 include_once
"./Modules/Test/classes/class.ilObjTest.php";
795 $query = sprintf(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
796 $ilDB->quote($active_id .
""),
797 $ilDB->quote($this->
getId() .
""),
798 $ilDB->quote(
$pass .
"")
800 $result = $ilDB->query($query);
801 if (array_key_exists(
"orderresult", $_POST))
803 $orderresult = $_POST[
"orderresult"];
804 if (strlen($orderresult))
806 $orderarray = explode(
":", $orderresult);
808 foreach ($orderarray as $index)
810 $query = sprintf(
"INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
811 $ilDB->quote($active_id .
""),
812 $ilDB->quote($this->
getId() .
""),
813 $ilDB->quote(trim($index) .
""),
814 $ilDB->quote(trim($ordervalue) .
""),
815 $ilDB->quote(
$pass .
"")
817 $result = $ilDB->query($query);
825 foreach ($_POST as $key => $value)
827 if (preg_match(
"/^order_(\d+)/", $key, $matches))
829 if (!(preg_match(
"/initial_value_\d+/", $value)))
833 $query = sprintf(
"INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
834 $ilDB->quote($active_id .
""),
835 $ilDB->quote($this->
getId() .
""),
836 $ilDB->quote($matches[1] .
""),
837 $ilDB->quote($value .
""),
838 $ilDB->quote(
$pass .
"")
840 $result = $ilDB->query($query);
850 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
858 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
865 return $saveWorkingDataResult;
869 mt_srand((
double)microtime()*1000000);
878 $array[$j] = $array[$i];
895 return "assOrderingQuestion";
908 return "qpl_question_ordering";
921 return "qpl_answer_ordering";
931 foreach ($this->answers as $index => $answer)
933 $answer_obj = $this->answers[$index];
934 $text .= $answer_obj->getAnswertext();
974 include_once (
"./classes/class.ilExcelUtils.php");
977 foreach ($solutions as $solution)
979 $sol[$solution[
"value1"]] = $solution[
"value2"];
982 $sol = array_keys($sol);
987 foreach ($sol as $idx)
989 foreach ($solutions as $solution)
996 return $startrow + $i + 1;