34 include_once
"./Services/Object/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)
113 foreach ($questions as $question_id)
115 $newObj->copyQuestion($question_id, $newObj->getId());
119 include_once
"./Services/MetaData/classes/class.ilMD.php";
121 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
124 $newObj->updateMetaData();
130 if ((!$question_type) and ($question_id > 0))
135 include_once
"./Modules/SurveyQuestionPool/classes/class.".$question_type.
"GUI.php";
136 $question_type_gui = $question_type .
"GUI";
137 $question =&
new $question_type_gui();
139 if ($question_id > 0)
141 $question->object->loadFromDb($question_id);
157 if ($question_gui->object->getObjId() == $questionpool_to)
165 $newtitle = $question_gui->object->getTitle();
166 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to))
169 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() .
" ($counter)", $questionpool_to))
173 $newtitle = $question_gui->object->getTitle() .
" ($counter)";
175 $question_gui->object->copyObject($this->
getId(), $newtitle);
188 $result = $ilDB->queryF(
"SELECT * FROM svy_qpl WHERE obj_fi = %s",
190 array($this->
getId())
208 $result = $ilDB->queryF(
"SELECT * FROM svy_qpl WHERE obj_fi = %s",
210 array($this->
getId())
214 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
215 array(
'text',
'integer',
'integer'),
221 $next_id = $ilDB->nextId(
'svy_qpl');
222 $query = $ilDB->manipulateF(
"INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
223 array(
'integer',
'text',
'integer',
'integer'),
256 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
258 array($this->
getId())
260 $found_questions = array();
267 include_once
"./Services/Utilities/classes/class.ilUtil.php";
269 $directory = $spl_data_dir.
"/spl_".$this->
getId();
270 if (is_dir($directory))
272 include_once
"./Services/Utilities/classes/class.ilUtil.php";
290 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
330 if ($a_node_id==
$_GET[
"ref_id"])
332 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
333 $parent_type = $parent_obj->getType();
334 if($parent_type == $this->
getType())
336 $a_node_id = (int) $tree->getParentId($a_node_id);
340 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
370 if ($question_id < 1)
return;
371 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
373 $question->delete($question_id);
386 if ($question_id < 1)
return;
387 $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",
394 return $data[
"type_tag"];
413 $result = $ilDB->queryF(
"SELECT answer_id FROM svy_answer WHERE question_fi = %s",
417 $answered =
$result->numRows();
420 $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",
424 $inserted =
$result->numRows();
425 if (($inserted + $answered) == 0)
429 $result_array = array();
432 array_push($result_array,
$row);
434 return $result_array;
458 $result_array = array();
459 $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'));
466 array_push($result_array,
$row);
471 array_push($result_array,
$row);
474 return $result_array;
486 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
490 while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id))
493 if ($counter > 1) $suffix =
" ($counter)";
497 $question->setObjId($obj_id);
499 $question->duplicate(
false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
512 if (is_array($arrFilter))
514 foreach ($arrFilter as $key => $value)
516 $arrFilter[$key] = str_replace(
'%',
'', $arrFilter[$key]);
518 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
520 $where .=
" AND " . $ilDB->like(
'svy_question.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
522 if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description']))
524 $where .=
" AND " . $ilDB->like(
'svy_question.description',
'text',
"%%" . $arrFilter[
'description'] .
"%%");
526 if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author']))
528 $where .=
" AND " . $ilDB->like(
'svy_question.author',
'text',
"%%" . $arrFilter[
'author'] .
"%%");
530 if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type']))
532 $where .=
" AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter[
'type'],
'text');
535 $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,
537 array($this->
getId())
540 if ($query_result->numRows())
542 while (
$row = $ilDB->fetchAssoc($query_result))
548 array_push($rows,
$row);
553 array_push($rows,
$row);
567 include_once
"./Services/Utilities/classes/class.ilUtil.php";
570 if(!is_writable($spl_data_dir))
572 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
573 .
") not writeable.",$this->ilias->error_obj->FATAL);
577 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
579 if(!@is_dir($spl_dir))
581 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
584 $export_dir = $spl_dir.
"/export";
586 if(!@is_dir($export_dir))
588 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
597 include_once
"./Services/Utilities/classes/class.ilUtil.php";
608 if (!@is_dir($dir) or
621 while ($entry = $dir->read())
625 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(spl_)*[0-9]+\.[A-Za-z]{3}\$", $entry))
647 include_once
"./Services/Utilities/classes/class.ilUtil.php";
651 if(!is_writable($spl_data_dir))
653 $this->ilias->raiseError(
"Survey Questionpool Data Directory (".$spl_data_dir
654 .
") not writeable.",$this->ilias->error_obj->FATAL);
658 $spl_dir = $spl_data_dir.
"/spl_".$this->
getId();
660 if(!@is_dir($spl_dir))
662 $this->ilias->raiseError(
"Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
666 $import_dir = $spl_dir.
"/import";
668 if(!@is_dir($import_dir))
670 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
679 include_once
"./Services/Utilities/classes/class.ilUtil.php";
681 "/spl_".$this->getId().
"/import";
682 if(@is_dir($import_dir))
697 if (!is_array($questions))
701 if (count($questions) == 0)
707 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
712 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
713 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
715 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
717 "id" =>
"qpl_" . $this->
getId(),
721 $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
722 $a_xml_writer->xmlElement(
"dummy", NULL,
"dummy");
724 $a_xml_writer->xmlStartTag(
"metadata");
725 $a_xml_writer->xmlStartTag(
"metadatafield");
726 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
727 include_once
"./Services/MetaData/classes/class.ilMD.php";
731 $metadata = $writer->xmlDumpMem();
732 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
733 $a_xml_writer->xmlEndTag(
"metadatafield");
734 $a_xml_writer->xmlEndTag(
"metadata");
736 $a_xml_writer->xmlEndTag(
"surveyquestions");
737 $a_xml_writer->xmlEndTag(
"surveyobject");
739 $xml = $a_xml_writer->xmlDumpMem(FALSE);
742 foreach ($questions as $key => $value)
745 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
747 $question =
new $questiontype();
748 $question->loadFromDb($value);
749 $questionxml .= $question->toXML(
false);
752 $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, $xml);
759 $questions = array();
760 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
762 array($this->
getId())
768 array_push($questions,
$row[
"question_id"]);
782 if (is_file($source))
784 $isZip = (strcmp(strtolower(substr($source, -3)),
'zip') == 0);
791 $subdir = basename($source,
".zip");
792 $source = dirname($source).
"/".$subdir.
"/".$subdir.
".xml";
795 $fh = fopen($source,
"r") or die(
"");
796 $xml = fread($fh, filesize($source));
797 fclose($fh) or die(
"");
800 $subdir = basename($source,
".zip");
801 if (@is_dir(dirname($source).
"/".$subdir))
806 if (strpos($xml,
"questestinterop") > 0)
809 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
811 $import->setXMLContent($xml);
812 $import->startParsing();
817 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
819 $import->setXMLContent($xml);
820 $import->startParsing();
825 public static function _setOnline($a_obj_id, $a_online_status)
830 switch ($a_online_status)
834 $status =
"$a_online_status";
837 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
838 array(
'text',
'integer'),
839 array($status, $a_obj_id)
852 switch ($a_online_status)
856 $this->online = $a_online_status;
866 if (strcmp($this->online,
"") == 0) $this->online =
"0";
874 $result = $ilDB->queryF(
"SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
881 return $row[
"isonline"];
900 foreach ($refs as $ref)
921 $lng->loadLanguageModule(
"survey");
923 $query_result = $ilDB->query(
"SELECT * FROM svy_qtype ORDER BY type_tag");
924 while (
$row = $ilDB->fetchAssoc($query_result))
927 if (
$row[
"plugin"] == 0)
929 $types[$lng->txt(
$row[
"type_tag"])] =
$row;
933 global $ilPluginAdmin;
934 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
935 foreach ($pl_names as $pl_name)
938 if (strcmp($pl->getQuestionType(),
$row[
"type_tag"]) == 0)
940 $types[$pl->getQuestionTypeTranslation()] =
$row;
954 global $ilPluginAdmin;
956 $lng->loadLanguageModule(
"survey");
957 $result = $ilDB->query(
"SELECT * FROM svy_qtype");
961 if (
$row[
"plugin"] == 0)
963 $types[
$row[
'type_tag']] = $lng->txt($row[
"type_tag"]);
967 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq");
968 foreach ($pl_names as $pl_name)
971 if (strcmp($pl->getQuestionType(),
$row[
"type_tag"]) == 0)
973 $types[
$row[
'type_tag']] = $pl->getQuestionTypeTranslation();
993 $result_array = array();
997 $result = $ilDB->query(
"SELECT obj_fi, isonline FROM svy_qpl");
1000 $allqpls[
$row[
'obj_fi']] = $row[
'isonline'];
1005 if (($could_be_offline) || ($allqpls[$obj_id][
'isonline'] == 1))
1009 $result_array[$obj_id] = $titles[
$ref_id];
1017 return $result_array;
1028 global $ilPluginAdmin;
1029 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))
1050 $query_result = $ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
1051 "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
1052 "AND svy_question.tstamp > 0 AND " . $ilDB->in(
'svy_question.question_id', $question_ids,
false,
'integer') .
" " .
1053 "ORDER BY svy_question.title");
1054 if ($query_result->numRows() > 0)
1056 while (
$data = $ilDB->fetchAssoc($query_result))
1058 if (in_array(
$data[
"question_id"], $question_ids))
1060 array_push($found, array(
'id' =>
$data[
"question_id"],
1061 'title' =>
$data[
"title"],
1062 'description' =>
$data[
"description"],
1063 'type_tag' =>
$data[
"type_tag"]));
1077 $result = $ilDB->queryF(
"SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1078 array(
"integer",
"integer"),
1079 array($ilUser->getId(), 0)
1094 if (!array_key_exists(
"spl_clipboard",
$_SESSION))
1098 $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id,
"action" =>
"copy");
1108 if (!array_key_exists(
"spl_clipboard",
$_SESSION))
1112 $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id,
"action" =>
"move");
1122 if (array_key_exists(
"spl_clipboard",
$_SESSION))
1124 foreach (
$_SESSION[
"spl_clipboard"] as $question_object)
1126 if (strcmp($question_object[
"action"],
"move") == 0)
1128 $result = $ilDB->queryF(
"SELECT obj_fi FROM svy_question WHERE question_id = %s",
1130 array($question_object[
"question_id"])
1135 $source_questionpool =
$row[
"obj_fi"];
1136 if ($this->
getId() != $source_questionpool)
1139 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1140 array(
'integer',
'integer'),
1141 array($this->
getId(), $question_object[
"question_id"])
1145 $source_path = CLIENT_WEB_DIR .
"/survey/" . $source_questionpool .
"/" . $question_object[
"question_id"] .
"/";
1146 if (@is_dir($source_path))
1148 $target_path = CLIENT_WEB_DIR .
"/survey/" . $this->
getId() .
"/";
1149 if (!@is_dir($target_path))
1151 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1154 @rename($source_path, $target_path . $question_object[
"question_id"]);
1186 $status = (int)(in_array($question_id, $obligatory_questions));
1188 $ilDB->manipulate(
"UPDATE svy_question".
1189 " SET obligatory = ".$ilDB->quote($status,
"integer").
1190 " WHERE question_id = ".$ilDB->quote($question_id,
"integer"));