34 include_once
"./Services/Object/classes/class.ilObject.php";
54 $this->
ilObject($a_id,$a_call_by_reference);
78 if (!parent::update())
93 function read($a_force_db =
false)
112 if(!$cp_options->isRootNode($this->getRefId()))
120 foreach ($questions as $question_id)
122 $newObj->copyQuestion($question_id, $newObj->getId());
126 include_once
"./Services/MetaData/classes/class.ilMD.php";
128 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
131 $newObj->updateMetaData();
137 if ((!$question_type) and ($question_id > 0))
142 include_once
"./Modules/SurveyQuestionPool/classes/class.".$question_type.
"GUI.php";
143 $question_type_gui = $question_type .
"GUI";
144 $question =&
new $question_type_gui();
146 if ($question_id > 0)
148 $question->object->loadFromDb($question_id);
164 if ($question_gui->object->getObjId() == $questionpool_to)
172 $newtitle = $question_gui->object->getTitle();
173 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to))
176 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() .
" ($counter)", $questionpool_to))
180 $newtitle = $question_gui->object->getTitle() .
" ($counter)";
182 $question_gui->object->copyObject($this->
getId(), $newtitle);
195 $result = $ilDB->queryF(
"SELECT * FROM svy_qpl WHERE obj_fi = %s",
197 array($this->
getId())
215 $result = $ilDB->queryF(
"SELECT * FROM svy_qpl WHERE obj_fi = %s",
217 array($this->
getId())
221 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
222 array(
'text',
'integer',
'integer'),
228 $next_id = $ilDB->nextId(
'svy_qpl');
229 $query = $ilDB->manipulateF(
"INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
230 array(
'integer',
'text',
'integer',
'integer'),
263 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
265 array($this->
getId())
267 $found_questions = array();
274 include_once
"./Services/Utilities/classes/class.ilUtil.php";
276 $directory = $spl_data_dir.
"/spl_".$this->
getId();
277 if (is_dir($directory))
279 include_once
"./Services/Utilities/classes/class.ilUtil.php";
297 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
337 if ($a_node_id==
$_GET[
"ref_id"])
339 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
340 $parent_type = $parent_obj->getType();
341 if($parent_type == $this->
getType())
343 $a_node_id = (int) $tree->getParentId($a_node_id);
347 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
377 if ($question_id < 1)
return;
378 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
380 $question->delete($question_id);
393 if ($question_id < 1)
return;
394 $result = $ilDB->queryF(
"SELECT svy_qtype.type_tag FROM svy_question, svy_qtype WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.question_id = %s",
400 $data = $ilDB->fetchAssoc(
$result);
401 return $data[
"type_tag"];
420 $result = $ilDB->queryF(
"SELECT answer_id FROM svy_answer WHERE question_fi = %s",
424 $answered =
$result->numRows();
427 $result = $ilDB->queryF(
"SELECT svy_svy.* FROM svy_svy, svy_svy_qst WHERE svy_svy_qst.survey_fi = svy_svy.survey_id AND svy_svy_qst.question_fi = %s",
431 $inserted =
$result->numRows();
432 if (($inserted + $answered) == 0)
436 $result_array = array();
439 array_push($result_array,
$row);
441 return $result_array;
465 $result_array = array();
466 $result = $ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag, svy_qtype.plugin FROM svy_question, svy_qtype WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.tstamp > 0 AND " . $ilDB->in(
'svy_question.question_id', $question_array,
false,
'integer'));
473 array_push($result_array,
$row);
478 array_push($result_array,
$row);
481 return $result_array;
493 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
497 while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id))
500 if ($counter > 1) $suffix =
" ($counter)";
504 $question->setObjId($obj_id);
506 $question->duplicate(
false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
519 if (is_array($arrFilter))
521 foreach ($arrFilter as $key => $value)
523 $arrFilter[$key] = str_replace(
'%',
'', $arrFilter[$key]);
525 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
527 $where .=
" AND " . $ilDB->like(
'svy_question.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
529 if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description']))
531 $where .=
" AND " . $ilDB->like(
'svy_question.description',
'text',
"%%" . $arrFilter[
'description'] .
"%%");
533 if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author']))
535 $where .=
" AND " . $ilDB->like(
'svy_question.author',
'text',
"%%" . $arrFilter[
'author'] .
"%%");
537 if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type']))
539 $where .=
" AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter[
'type'],
'text');
542 $query_result = $ilDB->queryF(
"SELECT svy_question.*, svy_qtype.type_tag, svy_qtype.plugin FROM svy_question, svy_qtype WHERE svy_question.original_id IS NULL AND svy_question.tstamp > 0 AND svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.obj_fi = %s" . $where,
544 array($this->
getId())
547 if ($query_result->numRows())
549 while (
$row = $ilDB->fetchAssoc($query_result))
555 array_push($rows,
$row);
560 array_push($rows,
$row);
574 include_once
"./Services/Utilities/classes/class.ilUtil.php";
577 if(!is_writable($spl_data_dir))
579 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
580 .
") not writeable.",$this->ilias->error_obj->FATAL);
584 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
586 if(!@is_dir($spl_dir))
588 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
591 $export_dir = $spl_dir.
"/export";
593 if(!@is_dir($export_dir))
595 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
604 include_once
"./Services/Utilities/classes/class.ilUtil.php";
615 if (!@is_dir($dir) or
628 while ($entry = $dir->read())
632 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(spl_)*[0-9]+\.[A-Za-z]{3}\$", $entry))
654 include_once
"./Services/Utilities/classes/class.ilUtil.php";
658 if(!is_writable($spl_data_dir))
660 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
661 .
") not writeable.",$this->ilias->error_obj->FATAL);
665 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
667 if(!@is_dir($spl_dir))
669 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
673 $import_dir = $spl_dir.
"/import";
675 if(!@is_dir($import_dir))
677 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
686 include_once
"./Services/Utilities/classes/class.ilUtil.php";
688 "/spl_".$this->getId().
"/import";
689 if(@is_dir($import_dir))
704 if (!is_array($questions))
708 if (count($questions) == 0)
714 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
719 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
720 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
722 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
724 "id" =>
"qpl_" . $this->
getId(),
728 $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
729 $a_xml_writer->xmlElement(
"dummy", NULL,
"dummy");
731 $a_xml_writer->xmlStartTag(
"metadata");
732 $a_xml_writer->xmlStartTag(
"metadatafield");
733 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
734 include_once
"./Services/MetaData/classes/class.ilMD.php";
738 $metadata = $writer->xmlDumpMem();
739 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
740 $a_xml_writer->xmlEndTag(
"metadatafield");
741 $a_xml_writer->xmlEndTag(
"metadata");
743 $a_xml_writer->xmlEndTag(
"surveyquestions");
744 $a_xml_writer->xmlEndTag(
"surveyobject");
746 $xml = $a_xml_writer->xmlDumpMem(FALSE);
749 foreach ($questions as $key => $value)
752 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
754 $question =
new $questiontype();
755 $question->loadFromDb($value);
756 $questionxml .= $question->toXML(
false);
759 $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, $xml);
766 $questions = array();
767 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
769 array($this->
getId())
775 array_push($questions,
$row[
"question_id"]);
789 if (is_file($source))
791 $isZip = (strcmp(strtolower(substr($source, -3)),
'zip') == 0);
798 $subdir = basename($source,
".zip");
799 $source = dirname($source).
"/".$subdir.
"/".$subdir.
".xml";
802 $fh = fopen($source,
"r") or die(
"");
803 $xml = fread($fh, filesize($source));
804 fclose($fh) or die(
"");
807 $subdir = basename($source,
".zip");
808 if (@is_dir(dirname($source).
"/".$subdir))
813 if (strpos($xml,
"questestinterop") > 0)
816 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
818 $import->setXMLContent($xml);
819 $import->startParsing();
824 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
826 $import->setXMLContent($xml);
827 $import->startParsing();
832 public static function _setOnline($a_obj_id, $a_online_status)
837 switch ($a_online_status)
841 $status =
"$a_online_status";
844 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
845 array(
'text',
'integer'),
846 array($status, $a_obj_id)
859 switch ($a_online_status)
863 $this->online = $a_online_status;
873 if (strcmp($this->online,
"") == 0) $this->online =
"0";
881 $result = $ilDB->queryF(
"SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
888 return $row[
"isonline"];
907 foreach ($refs as $ref)
928 $lng->loadLanguageModule(
"survey");
930 $query_result = $ilDB->query(
"SELECT * FROM svy_qtype ORDER BY type_tag");
931 while (
$row = $ilDB->fetchAssoc($query_result))
934 if (
$row[
"plugin"] == 0)
936 $types[$lng->txt(
$row[
"type_tag"])] =
$row;
940 global $ilPluginAdmin;
941 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
942 foreach ($pl_names as $pl_name)
945 if (strcmp($pl->getQuestionType(),
$row[
"type_tag"]) == 0)
947 $types[$pl->getQuestionTypeTranslation()] =
$row;
957 $default_sorting = array_flip(array(
958 "SurveySingleChoiceQuestion",
959 "SurveyMultipleChoiceQuestion",
960 "SurveyMatrixQuestion",
961 "SurveyMetricQuestion",
966 $idx =
sizeof($default_sorting);
967 foreach($types as $caption => $item)
969 $type = $item[
"type_tag"];
970 $item[
"caption"] = $caption;
973 if(array_key_exists(
$type, $default_sorting))
975 $sorted[$default_sorting[
$type]] = $item;
980 $sorted[$idx] = $item;
988 foreach($sorted as $item)
990 $types[$item[
"caption"]] = $item;
1001 global $ilPluginAdmin;
1003 $lng->loadLanguageModule(
"survey");
1004 $result = $ilDB->query(
"SELECT * FROM svy_qtype");
1008 if (
$row[
"plugin"] == 0)
1010 $types[
$row[
'type_tag']] = $lng->txt($row[
"type_tag"]);
1014 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
1015 foreach ($pl_names as $pl_name)
1018 if (strcmp($pl->getQuestionType(),
$row[
"type_tag"]) == 0)
1020 $types[
$row[
'type_tag']] = $pl->getQuestionTypeTranslation();
1040 $result_array = array();
1044 $result = $ilDB->query(
"SELECT obj_fi, isonline FROM svy_qpl");
1047 $allqpls[
$row[
'obj_fi']] = $row[
'isonline'];
1052 if ($could_be_offline || $allqpls[$obj_id] == 1)
1056 $result_array[$obj_id] = $titles[
$ref_id];
1064 return $result_array;
1075 global $ilPluginAdmin;
1076 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))
1097 $query_result = $ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
1098 "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
1099 "AND svy_question.tstamp > 0 AND " . $ilDB->in(
'svy_question.question_id', $question_ids,
false,
'integer') .
" " .
1100 "ORDER BY svy_question.title");
1101 if ($query_result->numRows() > 0)
1103 while ($data = $ilDB->fetchAssoc($query_result))
1105 if (in_array($data[
"question_id"], $question_ids))
1107 array_push($found, array(
'id' => $data[
"question_id"],
1108 'title' => $data[
"title"],
1109 'description' => $data[
"description"],
1110 'type_tag' => $data[
"type_tag"]));
1124 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1125 array(
"integer",
"integer"),
1126 array($ilUser->getId(), 0)
1128 while ($data = $ilDB->fetchAssoc(
$result))
1141 if (!array_key_exists(
"spl_clipboard",
$_SESSION))
1145 $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id,
"action" =>
"copy");
1155 if (!array_key_exists(
"spl_clipboard",
$_SESSION))
1159 $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id,
"action" =>
"move");
1169 if (array_key_exists(
"spl_clipboard",
$_SESSION))
1171 foreach (
$_SESSION[
"spl_clipboard"] as $question_object)
1173 if (strcmp($question_object[
"action"],
"move") == 0)
1175 $result = $ilDB->queryF(
"SELECT obj_fi FROM svy_question WHERE question_id = %s",
1177 array($question_object[
"question_id"])
1182 $source_questionpool =
$row[
"obj_fi"];
1183 if ($this->
getId() != $source_questionpool)
1186 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1187 array(
'integer',
'integer'),
1188 array($this->
getId(), $question_object[
"question_id"])
1192 $source_path = CLIENT_WEB_DIR .
"/survey/" . $source_questionpool .
"/" . $question_object[
"question_id"] .
"/";
1193 if (@is_dir($source_path))
1195 $target_path = CLIENT_WEB_DIR .
"/survey/" . $this->
getId() .
"/";
1196 if (!@is_dir($target_path))
1198 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1201 @rename($source_path, $target_path . $question_object[
"question_id"]);
1233 $status = (int)(in_array($question_id, $obligatory_questions));
1235 $ilDB->manipulate(
"UPDATE svy_question".
1236 " SET obligatory = ".$ilDB->quote($status,
"integer").
1237 " WHERE question_id = ".$ilDB->quote($question_id,
"integer"));