34 include_once
"./classes/class.ilObject.php";
35 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
55 $this->
ilObject($a_id,$a_call_by_reference);
79 if (!parent::update())
94 function read($a_force_db =
false)
115 foreach ($questions as $question_id)
117 $newObj->copyQuestion($question_id, $newObj->getId());
121 include_once
"./Services/MetaData/classes/class.ilMD.php";
123 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
126 $newObj->updateMetaData();
132 if ((!$question_type) and ($question_id > 0))
137 include_once
"./Modules/SurveyQuestionPool/classes/class.".$question_type.
"GUI.php";
138 $question_type_gui = $question_type .
"GUI";
139 $question =&
new $question_type_gui();
141 if ($question_id > 0)
143 $question->object->loadFromDb($question_id);
161 if ($question_gui->object->getObjId() == $questionpool_to)
169 $newtitle = $question_gui->object->getTitle();
170 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to))
173 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() .
" ($counter)", $questionpool_to))
177 $newtitle = $question_gui->object->getTitle() .
" ($counter)";
179 $question_gui->object->copyObject($this->
getId(), $newtitle);
194 $query = sprintf(
"SELECT * FROM survey_questionpool WHERE obj_fi = %s",
195 $ilDB->quote($this->getId() .
"")
197 $result = $ilDB->query($query);
200 $row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC);
216 $query = sprintf(
"SELECT * FROM survey_questionpool WHERE obj_fi = %s",
217 $ilDB->quote($this->getId() .
"")
219 $result = $ilDB->query($query);
222 $query = sprintf(
"UPDATE survey_questionpool SET online = %s WHERE obj_fi = %s",
223 $ilDB->quote($this->getOnline() .
""),
224 $ilDB->quote($this->getId() .
"")
226 $result = $ilDB->query($query);
230 $ilias->raiseError(
$result->getMessage());
235 $query = sprintf(
"INSERT INTO survey_questionpool (online, obj_fi) VALUES (%s, %s)",
236 $ilDB->quote($this->getOnline() .
""),
237 $ilDB->quote($this->getId() .
"")
239 $result = $ilDB->query($query);
243 $ilias->raiseError(
$result->getMessage());
274 $query = sprintf(
"SELECT question_id FROM survey_question WHERE obj_fi = %s AND original_id IS NULL",
275 $this->ilias->db->quote($this->getId())
277 $result = $this->ilias->db->query($query);
278 $found_questions = array();
279 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
285 include_once
"./Services/Utilities/classes/class.ilUtil.php";
287 $directory = $spl_data_dir.
"/spl_".$this->
getId();
288 if (is_dir($directory))
290 include_once
"./Services/Utilities/classes/class.ilUtil.php";
308 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
348 if ($a_node_id==
$_GET[
"ref_id"])
350 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
351 $parent_type = $parent_obj->getType();
352 if($parent_type == $this->
getType())
354 $a_node_id = (int) $tree->getParentId($a_node_id);
358 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
390 if ($question_id < 1)
return;
391 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
393 $question->delete($question_id);
407 if ($question_id < 1)
return;
408 $query = sprintf(
"SELECT survey_questiontype.type_tag FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id = %s",
409 $this->ilias->db->quote($question_id)
411 $result = $this->ilias->db->query($query);
412 if ($result->numRows() == 1)
414 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
415 return $data->type_tag;
433 $query = sprintf(
"SELECT answer_id FROM survey_answer WHERE question_fi = %s",
434 $this->ilias->db->quote($question_id)
436 $result = $this->ilias->db->query($query);
437 $answered = $result->numRows();
440 $query = sprintf(
"SELECT survey_survey.* FROM survey_survey, survey_survey_question WHERE survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = %s",
441 $this->ilias->db->quote($question_id)
443 $result = $this->ilias->db->query($query);
444 $inserted = $result->numRows();
445 if (($inserted + $answered) == 0)
449 $result_array = array();
450 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
452 array_push($result_array, $row);
454 return $result_array;
481 $result_array = array();
482 $query = sprintf(
"SELECT survey_question.*, survey_questiontype.type_tag, survey_questiontype.plugin FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id IN ('%s')",
483 join($question_array,
"','")
485 $result = $this->ilias->db->query($query);
486 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
492 array_push($result_array, $row);
497 array_push($result_array, $row);
500 return $result_array;
514 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
518 while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id))
521 if ($counter > 1) $suffix =
" ($counter)";
525 $question->setObjId($obj_id);
527 $question->duplicate(
false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
541 if (strlen($filter_text) > 0)
543 switch($sel_filter_type)
546 $where =
" AND survey_question.title LIKE " . $this->ilias->db->quote(
"%" . $filter_text .
"%");
549 $where =
" AND survey_question.description LIKE " . $this->ilias->db->quote(
"%" . $filter_text .
"%");
552 $where =
" AND survey_question.author LIKE " . $this->ilias->db->quote(
"%" . $filter_text .
"%");
560 include_once
"./Services/Utilities/classes/class.ilUtil.php";
564 $order =
" ORDER BY title $sortorder";
565 $images[
"title"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
568 $order =
" ORDER BY description $sortorder";
569 $images[
"description"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
572 $order =
" ORDER BY questiontype_id $sortorder";
573 $images[
"type"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
576 $order =
" ORDER BY author $sortorder";
577 $images[
"author"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
580 $order =
" ORDER BY created $sortorder";
581 $images[
"created"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
584 $order =
" ORDER BY timestamp14 $sortorder";
585 $images[
"updated"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
588 $maxentries = $ilUser->prefs[
"hits_per_page"];
593 $query =
"SELECT survey_question.question_id, survey_question.TIMESTAMP + 0 AS timestamp14 FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.obj_fi = " . $this->
getId() .
" AND ISNULL(survey_question.original_id) $where$order$limit";
594 $query_result = $this->ilias->db->query($query);
595 $max = $query_result->numRows();
596 if ($startrow > $max -1)
598 $startrow = $max - ($max % $maxentries);
600 else if ($startrow < 0)
604 $limit =
" LIMIT $startrow, $maxentries";
605 $query =
"SELECT survey_question.*, survey_question.TIMESTAMP + 0 AS timestamp14, survey_questiontype.type_tag, survey_questiontype.plugin FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.obj_fi = " . $this->
getId() .
" AND ISNULL(survey_question.original_id) $where$order$limit";
606 $query_result = $this->ilias->db->query($query);
608 if ($query_result->numRows())
610 while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
616 array_push($rows, $row);
621 array_push($rows, $row);
625 $nextrow = $startrow + $maxentries;
626 if ($nextrow > $max - 1)
628 $nextrow = $startrow;
630 $prevrow = $startrow - $maxentries;
638 "startrow" => $startrow,
639 "nextrow" => $nextrow,
640 "prevrow" => $prevrow,
641 "step" => $maxentries,
653 include_once
"./Services/Utilities/classes/class.ilUtil.php";
656 if(!is_writable($spl_data_dir))
658 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
659 .
") not writeable.",$this->ilias->error_obj->FATAL);
663 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
665 if(!@is_dir($spl_dir))
667 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
670 $export_dir = $spl_dir.
"/export";
672 if(!@is_dir($export_dir))
674 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
683 include_once
"./Services/Utilities/classes/class.ilUtil.php";
694 if (!@is_dir(
$dir) or
707 while ($entry =
$dir->read())
709 if ($entry !=
"." and
711 substr($entry, -4) ==
".xml" and
712 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(spl__)*[0-9]+\.xml\$", $entry))
734 include_once
"./Services/Utilities/classes/class.ilUtil.php";
738 if(!is_writable($spl_data_dir))
740 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
741 .
") not writeable.",$this->ilias->error_obj->FATAL);
745 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
747 if(!@is_dir($spl_dir))
749 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
753 $import_dir = $spl_dir.
"/import";
755 if(!@is_dir($import_dir))
757 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
766 include_once
"./Services/Utilities/classes/class.ilUtil.php";
768 "/spl_".$this->getId().
"/import";
769 if(@is_dir($import_dir))
784 if (!is_array($questions))
788 if (count($questions) == 0)
794 include_once(
"./classes/class.ilXmlWriter.php");
799 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
800 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
802 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
804 "id" =>
"qpl_" . $this->
getId(),
807 $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
808 $a_xml_writer->xmlElement(
"dummy", NULL,
"dummy");
810 $a_xml_writer->xmlStartTag(
"metadata");
811 $a_xml_writer->xmlStartTag(
"metadatafield");
812 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
813 include_once
"./Services/MetaData/classes/class.ilMD.php";
817 $metadata = $writer->xmlDumpMem();
818 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
819 $a_xml_writer->xmlEndTag(
"metadatafield");
820 $a_xml_writer->xmlEndTag(
"metadata");
822 $a_xml_writer->xmlEndTag(
"surveyquestions");
823 $a_xml_writer->xmlEndTag(
"surveyobject");
825 $xml = $a_xml_writer->xmlDumpMem(FALSE);
828 foreach ($questions as $key => $value)
831 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
833 $question =
new $questiontype();
834 $question->loadFromDb($value);
835 $questionxml .= $question->toXML(
false);
838 $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, $xml);
844 $questions = array();
845 $query = sprintf(
"SELECT question_id FROM survey_question WHERE obj_fi = %s AND ISNULL(original_id)",
846 $this->ilias->db->quote($this->getId() .
"")
848 $result = $this->ilias->db->query($query);
851 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
853 array_push($questions, $row[
"question_id"]);
869 if (is_file($source))
871 $fh = fopen($source,
"r") or die(
"");
872 $xml = fread($fh, filesize($source));
873 fclose($fh) or die(
"");
874 if (strpos($xml,
"questestinterop") > 0)
877 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
879 $import->setXMLContent($xml);
880 $import->startParsing();
885 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
887 $import->setXMLContent($xml);
888 $import->startParsing();
904 switch ($a_online_status)
908 $this->online = $a_online_status;
918 if (strcmp($this->online,
"") == 0) $this->online =
"0";
926 $query = sprintf(
"SELECT online FROM survey_questionpool WHERE obj_fi = %s",
927 $ilDB->quote($a_obj_id .
"")
929 $result = $ilDB->query($query);
930 if ($result->numRows() == 1)
932 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
933 return $row[
"online"];
952 $result_array = array();
953 $query = sprintf(
"SELECT object_data.*, object_data.obj_id, object_reference.ref_id FROM object_data, object_reference WHERE object_data.obj_id = object_reference.obj_id AND object_data.obj_id = %s",
954 $ilDB->quote($object_id .
"")
956 $result = $ilDB->query($query);
957 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
959 include_once
"./classes/class.ilObject.php";
981 $lng->loadLanguageModule(
"survey");
983 $query =
"SELECT * FROM survey_questiontype ORDER BY type_tag";
984 $query_result = $ilDB->query($query);
985 while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
988 if ($row[
"plugin"] == 0)
990 $types[$lng->txt($row[
"type_tag"])] = $row;
994 global $ilPluginAdmin;
995 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
996 foreach ($pl_names as $pl_name)
999 if (strcmp($pl->getQuestionType(), $row[
"type_tag"]) == 0)
1001 $types[$pl->getQuestionTypeTranslation()] = $row;
1023 $result_array = array();
1029 if ($could_be_offline)
1031 $query = sprintf(
"SELECT object_data.*, object_reference.ref_id FROM object_data, object_reference, survey_questionpool WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') AND survey_questionpool.obj_fi = object_data.obj_id ORDER BY object_data.title",
1032 implode(
"','", $qpls)
1037 $query = sprintf(
"SELECT object_data.*, object_reference.ref_id FROM object_data, object_reference, survey_questionpool WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') AND survey_questionpool.online = '1' AND survey_questionpool.obj_fi = object_data.obj_id ORDER BY object_data.title",
1038 implode(
"','", $qpls)
1041 $result = $ilDB->query($query);
1042 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
1044 $title = (($showPath) ? $titles[$row[
"ref_id"]] : $row[
"title"]);
1048 $result_array[$row[
"obj_id"]] =
$title;
1052 $result_array[$row[
"ref_id"]] =
$title;
1056 return $result_array;
1067 global $ilPluginAdmin;
1068 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))