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 foreach ($questions as $question_id)
114 $newObj->copyQuestion($question_id, $newObj->getId());
118 include_once
"./Services/MetaData/classes/class.ilMD.php";
120 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
123 $newObj->updateMetaData();
129 if ((!$question_type) and ($question_id > 0))
134 include_once
"./Modules/SurveyQuestionPool/classes/class.".$question_type.
"GUI.php";
135 $question_type_gui = $question_type .
"GUI";
136 $question =&
new $question_type_gui();
138 if ($question_id > 0)
140 $question->object->loadFromDb($question_id);
156 if ($question_gui->object->getObjId() == $questionpool_to)
164 $newtitle = $question_gui->object->getTitle();
165 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to))
168 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() .
" ($counter)", $questionpool_to))
172 $newtitle = $question_gui->object->getTitle() .
" ($counter)";
174 $question_gui->object->copyObject($this->
getId(), $newtitle);
187 $result = $ilDB->queryF(
"SELECT * FROM svy_qpl WHERE obj_fi = %s",
189 array($this->
getId())
207 $result = $ilDB->queryF(
"SELECT * FROM svy_qpl WHERE obj_fi = %s",
209 array($this->
getId())
213 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
214 array(
'text',
'integer',
'integer'),
220 $next_id = $ilDB->nextId(
'svy_qpl');
221 $query = $ilDB->manipulateF(
"INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
222 array(
'integer',
'text',
'integer',
'integer'),
255 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
257 array($this->
getId())
259 $found_questions = array();
266 include_once
"./Services/Utilities/classes/class.ilUtil.php";
268 $directory = $spl_data_dir.
"/spl_".$this->
getId();
269 if (is_dir($directory))
271 include_once
"./Services/Utilities/classes/class.ilUtil.php";
289 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
329 if ($a_node_id==
$_GET[
"ref_id"])
331 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
332 $parent_type = $parent_obj->getType();
333 if($parent_type == $this->
getType())
335 $a_node_id = (int) $tree->getParentId($a_node_id);
339 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
369 if ($question_id < 1)
return;
370 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
372 $question->delete($question_id);
385 if ($question_id < 1)
return;
386 $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",
392 $data = $ilDB->fetchAssoc(
$result);
393 return $data[
"type_tag"];
412 $result = $ilDB->queryF(
"SELECT answer_id FROM svy_answer WHERE question_fi = %s",
416 $answered =
$result->numRows();
419 $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",
423 $inserted =
$result->numRows();
424 if (($inserted + $answered) == 0)
428 $result_array = array();
431 array_push($result_array,
$row);
433 return $result_array;
457 $result_array = array();
458 $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'));
465 array_push($result_array,
$row);
470 array_push($result_array,
$row);
473 return $result_array;
485 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
489 while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id))
492 if ($counter > 1) $suffix =
" ($counter)";
496 $question->setObjId($obj_id);
498 $question->duplicate(
false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
511 if (is_array($arrFilter))
513 foreach ($arrFilter as $key => $value)
515 $arrFilter[$key] = str_replace(
'%',
'', $arrFilter[$key]);
517 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
519 $where .=
" AND " . $ilDB->like(
'svy_question.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
521 if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description']))
523 $where .=
" AND " . $ilDB->like(
'svy_question.description',
'text',
"%%" . $arrFilter[
'description'] .
"%%");
525 if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author']))
527 $where .=
" AND " . $ilDB->like(
'svy_question.author',
'text',
"%%" . $arrFilter[
'author'] .
"%%");
529 if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type']))
531 $where .=
" AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter[
'type'],
'text');
534 $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,
536 array($this->
getId())
539 if ($query_result->numRows())
541 while (
$row = $ilDB->fetchAssoc($query_result))
547 array_push($rows,
$row);
552 array_push($rows,
$row);
566 include_once
"./Services/Utilities/classes/class.ilUtil.php";
569 if(!is_writable($spl_data_dir))
571 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
572 .
") not writeable.",$this->ilias->error_obj->FATAL);
576 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
578 if(!@is_dir($spl_dir))
580 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
583 $export_dir = $spl_dir.
"/export";
585 if(!@is_dir($export_dir))
587 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
596 include_once
"./Services/Utilities/classes/class.ilUtil.php";
607 if (!@is_dir($dir) or
620 while ($entry = $dir->read())
624 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(spl_)*[0-9]+\.[A-Za-z]{3}\$", $entry))
646 include_once
"./Services/Utilities/classes/class.ilUtil.php";
650 if(!is_writable($spl_data_dir))
652 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
653 .
") not writeable.",$this->ilias->error_obj->FATAL);
657 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
659 if(!@is_dir($spl_dir))
661 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
665 $import_dir = $spl_dir.
"/import";
667 if(!@is_dir($import_dir))
669 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
678 include_once
"./Services/Utilities/classes/class.ilUtil.php";
680 "/spl_".$this->getId().
"/import";
681 if(@is_dir($import_dir))
696 if (!is_array($questions))
700 if (count($questions) == 0)
706 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
711 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
712 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
714 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
716 "id" =>
"qpl_" . $this->
getId(),
720 $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
721 $a_xml_writer->xmlElement(
"dummy", NULL,
"dummy");
723 $a_xml_writer->xmlStartTag(
"metadata");
724 $a_xml_writer->xmlStartTag(
"metadatafield");
725 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
726 include_once
"./Services/MetaData/classes/class.ilMD.php";
730 $metadata = $writer->xmlDumpMem();
731 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
732 $a_xml_writer->xmlEndTag(
"metadatafield");
733 $a_xml_writer->xmlEndTag(
"metadata");
735 $a_xml_writer->xmlEndTag(
"surveyquestions");
736 $a_xml_writer->xmlEndTag(
"surveyobject");
738 $xml = $a_xml_writer->xmlDumpMem(FALSE);
741 foreach ($questions as $key => $value)
744 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
746 $question =
new $questiontype();
747 $question->loadFromDb($value);
748 $questionxml .= $question->toXML(
false);
751 $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, $xml);
758 $questions = array();
759 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
761 array($this->
getId())
767 array_push($questions,
$row[
"question_id"]);
781 if (is_file($source))
783 $isZip = (strcmp(strtolower(substr($source, -3)),
'zip') == 0);
790 $subdir = basename($source,
".zip");
791 $source = dirname($source).
"/".$subdir.
"/".$subdir.
".xml";
794 $fh = fopen($source,
"r") or die(
"");
795 $xml = fread($fh, filesize($source));
796 fclose($fh) or die(
"");
799 $subdir = basename($source,
".zip");
800 if (@is_dir(dirname($source).
"/".$subdir))
805 if (strpos($xml,
"questestinterop") > 0)
808 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
810 $import->setXMLContent($xml);
811 $import->startParsing();
816 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
818 $import->setXMLContent($xml);
819 $import->startParsing();
824 public static function _setOnline($a_obj_id, $a_online_status)
829 switch ($a_online_status)
833 $status =
"$a_online_status";
836 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
837 array(
'text',
'integer'),
838 array($status, $a_obj_id)
851 switch ($a_online_status)
855 $this->online = $a_online_status;
865 if (strcmp($this->online,
"") == 0) $this->online =
"0";
873 $result = $ilDB->queryF(
"SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
880 return $row[
"isonline"];
899 foreach ($refs as $ref)
920 $lng->loadLanguageModule(
"survey");
922 $query_result = $ilDB->query(
"SELECT * FROM svy_qtype ORDER BY type_tag");
923 while (
$row = $ilDB->fetchAssoc($query_result))
926 if (
$row[
"plugin"] == 0)
928 $types[$lng->txt(
$row[
"type_tag"])] =
$row;
932 global $ilPluginAdmin;
933 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
934 foreach ($pl_names as $pl_name)
937 if (strcmp($pl->getQuestionType(),
$row[
"type_tag"]) == 0)
939 $types[$pl->getQuestionTypeTranslation()] =
$row;
953 global $ilPluginAdmin;
955 $lng->loadLanguageModule(
"survey");
956 $result = $ilDB->query(
"SELECT * FROM svy_qtype");
960 if (
$row[
"plugin"] == 0)
962 $types[
$row[
'type_tag']] = $lng->txt($row[
"type_tag"]);
966 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
967 foreach ($pl_names as $pl_name)
970 if (strcmp($pl->getQuestionType(),
$row[
"type_tag"]) == 0)
972 $types[
$row[
'type_tag']] = $pl->getQuestionTypeTranslation();
992 $result_array = array();
996 $result = $ilDB->query(
"SELECT obj_fi, isonline FROM svy_qpl");
999 $allqpls[
$row[
'obj_fi']] = $row[
'isonline'];
1004 if ($could_be_offline || $allqpls[$obj_id] == 1)
1008 $result_array[$obj_id] = $titles[
$ref_id];
1016 return $result_array;
1027 global $ilPluginAdmin;
1028 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))
1049 $query_result = $ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
1050 "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
1051 "AND svy_question.tstamp > 0 AND " . $ilDB->in(
'svy_question.question_id', $question_ids,
false,
'integer') .
" " .
1052 "ORDER BY svy_question.title");
1053 if ($query_result->numRows() > 0)
1055 while ($data = $ilDB->fetchAssoc($query_result))
1057 if (in_array($data[
"question_id"], $question_ids))
1059 array_push($found, array(
'id' => $data[
"question_id"],
1060 'title' => $data[
"title"],
1061 'description' => $data[
"description"],
1062 'type_tag' => $data[
"type_tag"]));
1076 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1077 array(
"integer",
"integer"),
1078 array($ilUser->getId(), 0)
1080 while ($data = $ilDB->fetchAssoc(
$result))
1093 if (!array_key_exists(
"spl_clipboard",
$_SESSION))
1097 $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id,
"action" =>
"copy");
1107 if (!array_key_exists(
"spl_clipboard",
$_SESSION))
1111 $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id,
"action" =>
"move");
1121 if (array_key_exists(
"spl_clipboard",
$_SESSION))
1123 foreach (
$_SESSION[
"spl_clipboard"] as $question_object)
1125 if (strcmp($question_object[
"action"],
"move") == 0)
1127 $result = $ilDB->queryF(
"SELECT obj_fi FROM svy_question WHERE question_id = %s",
1129 array($question_object[
"question_id"])
1134 $source_questionpool =
$row[
"obj_fi"];
1135 if ($this->
getId() != $source_questionpool)
1138 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1139 array(
'integer',
'integer'),
1140 array($this->
getId(), $question_object[
"question_id"])
1144 $source_path = CLIENT_WEB_DIR .
"/survey/" . $source_questionpool .
"/" . $question_object[
"question_id"] .
"/";
1145 if (@is_dir($source_path))
1147 $target_path = CLIENT_WEB_DIR .
"/survey/" . $this->
getId() .
"/";
1148 if (!@is_dir($target_path))
1150 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1153 @rename($source_path, $target_path . $question_object[
"question_id"]);
1185 $status = (int)(in_array($question_id, $obligatory_questions));
1187 $ilDB->manipulate(
"UPDATE svy_question".
1188 " SET obligatory = ".$ilDB->quote($status,
"integer").
1189 " WHERE question_id = ".$ilDB->quote($question_id,
"integer"));