34 bool $a_call_by_reference =
true 37 $this->main_tpl = $DIC->ui()->mainTemplate();
39 $this->log = $DIC[
"ilLog"];
40 $this->db = $DIC->database();
41 $this->
user = $DIC->user();
42 $this->component_repository = $DIC[
"component.repository"];
45 $this->edit_manager = $DIC->surveyQuestionPool()
53 $id = parent::create();
63 if (!parent::update()) {
69 public function read(): void
77 $newObj = parent::cloneObject($target_id, $copy_id, $omit_tree);
82 if (!$cp_options->isRootNode($this->getRefId())) {
89 foreach ($questions as $question_id) {
90 $newObj->copyQuestion($question_id, $newObj->getId());
95 $new_md = $md->cloneMD($newObj->getId(), 0, $newObj->getType());
98 $newObj->updateMetaData();
106 string $question_type,
107 int $question_id = -1
109 if ((!$question_type) and ($question_id > 0)) {
113 $question_type_gui = $question_type .
"GUI";
114 $question =
new $question_type_gui();
116 if ($question_id > 0) {
117 $question->object->loadFromDb($question_id);
132 if ($question_gui->object->getObjId() === $questionpool_to) {
137 $newtitle = $question_gui->object->getTitle();
138 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to)) {
140 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() .
" ($counter)", $questionpool_to)) {
143 $newtitle = $question_gui->object->getTitle() .
" ($counter)";
145 $question_gui->object->copyObject($this->
getId(), $newtitle);
153 $result =
$ilDB->queryF(
154 "SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
156 array($this->
getId())
158 if ($result->numRows() === 1) {
159 $row =
$ilDB->fetchAssoc($result);
160 $this->
setOnline((
bool) $row[
"isonline"]);
170 $result =
$ilDB->queryF(
171 "SELECT * FROM svy_qpl WHERE obj_fi = %s",
173 array($this->
getId())
175 if ($result->numRows() === 1) {
176 $affectedRows =
$ilDB->manipulateF(
177 "UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
178 array(
'text',
'integer',
'integer'),
182 $next_id =
$ilDB->nextId(
'svy_qpl');
184 "INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
185 array(
'integer',
'text',
'integer',
'integer'),
191 public function delete():
bool 193 $remove = parent::delete();
211 $result =
$ilDB->queryF(
212 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
214 array($this->
getId())
216 $found_questions = array();
217 while ($row =
$ilDB->fetchAssoc($result)) {
223 $directory = $spl_data_dir .
"/spl_" . $this->
getId();
224 if (is_dir($directory)) {
234 if ($question_id < 1) {
238 $question->delete($question_id);
248 if ($question_id < 1) {
251 $result =
$ilDB->queryF(
252 "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",
256 if ($result->numRows() === 1) {
258 return $data[
"type_tag"];
269 public function isInUse(
int $question_id): ?array
273 $result =
$ilDB->queryF(
274 "SELECT answer_id FROM svy_answer WHERE question_fi = %s",
278 $answered = $result->numRows();
281 $result =
$ilDB->queryF(
282 "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",
286 $inserted = $result->numRows();
287 if (($inserted + $answered) === 0) {
290 $result_array = array();
291 while ($row =
$ilDB->fetchObject($result)) {
292 $result_array[] = $row;
294 return $result_array;
300 public function paste(
int $question_id): void
310 array $question_array
313 $result_array = array();
314 $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'));
315 while ($row =
$ilDB->fetchAssoc($result)) {
316 if ($row[
"plugin"]) {
318 $result_array[] = $row;
321 $result_array[] = $row;
324 return $result_array;
338 while ($question->questionTitleExists($question->getTitle() . $suffix, $obj_id)) {
341 $suffix =
" ($counter)";
345 $question->setObjId($obj_id);
348 if (strlen($question->getTitle() . $suffix) > $max_len) {
349 $title = substr($question->getTitle(), 0, $max_len - strlen($suffix)) . $suffix;
351 $title = $question->getTitle() . $suffix;
365 if (count($arrFilter) > 0) {
366 foreach ($arrFilter as
$key => $value) {
367 $arrFilter[
$key] = str_replace(
'%',
'', $value);
369 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title'])) {
370 $where .=
" AND " .
$ilDB->like(
'svy_question.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
372 if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description'])) {
373 $where .=
" AND " .
$ilDB->like(
'svy_question.description',
'text',
"%%" . $arrFilter[
'description'] .
"%%");
375 if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author'])) {
376 $where .=
" AND " .
$ilDB->like(
'svy_question.author',
'text',
"%%" . $arrFilter[
'author'] .
"%%");
378 if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type'])) {
379 $where .=
" AND svy_qtype.type_tag = " .
$ilDB->quote($arrFilter[
'type'],
'text');
382 $query_result =
$ilDB->queryF(
383 "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,
385 array($this->
getId())
388 if ($query_result->numRows()) {
389 while ($row =
$ilDB->fetchAssoc($query_result)) {
390 if ($row[
"plugin"]) {
411 if (!is_writable($spl_data_dir)) {
412 throw new ilSurveyException(
"Survey Questionpool Data Directory (" . $spl_data_dir .
") not writeable.");
416 $spl_dir = $spl_data_dir .
"/spl_" . $this->
getId();
418 if (!is_dir($spl_dir)) {
419 throw new ilSurveyException(
"Creation of Survey Questionpool Directory failed.");
422 $export_dir = $spl_dir .
"/export";
424 if (!is_dir($export_dir)) {
425 throw new ilSurveyException(
"Creation of Survey Questionpool Export Directory failed.");
445 !is_writable($dir)) {
456 while ($entry = $dir->read()) {
457 if ($entry !==
"." &&
459 preg_match(
"/^[0-9]{10}__[0-9]+__(spl_)*[0-9]+\.[A-Za-z]{3}$/", $entry)) {
482 if (!is_writable($spl_data_dir)) {
483 throw new ilSurveyException(
"Survey Questionpool Data Directory (" . $spl_data_dir .
") not writeable.");
487 $spl_dir = $spl_data_dir .
"/spl_" . $this->
getId();
489 if (!is_dir($spl_dir)) {
490 throw new ilSurveyException(
"Creation of Survey Questionpool Directory failed.");
494 $import_dir = $spl_dir .
"/import";
496 if (!is_dir($import_dir)) {
497 throw new ilSurveyException(
"Creation of Survey Questionpool Import Directory failed.");
504 "/spl_" . $this->
getId() .
"/import";
511 public function toXML(?array $questions): string
513 if (is_null($questions) || count($questions) === 0) {
518 $a_xml_writer->xmlHeader();
520 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
521 "xsi:noNamespaceSchemaLocation" =>
"https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd" 523 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
525 "id" =>
"qpl_" . $this->
getId(),
529 $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
530 $a_xml_writer->xmlElement(
"dummy", null,
"dummy");
532 $a_xml_writer->xmlStartTag(
"metadata");
533 $a_xml_writer->xmlStartTag(
"metadatafield");
534 $a_xml_writer->xmlElement(
"fieldlabel", null,
"SCORM");
538 $metadata = $writer->xmlDumpMem();
539 $a_xml_writer->xmlElement(
"fieldentry", null, $metadata);
540 $a_xml_writer->xmlEndTag(
"metadatafield");
541 $a_xml_writer->xmlEndTag(
"metadata");
543 $a_xml_writer->xmlEndTag(
"surveyquestions");
544 $a_xml_writer->xmlEndTag(
"surveyobject");
546 $xml = $a_xml_writer->xmlDumpMem(
false);
549 foreach ($questions as
$key => $value) {
552 $question =
new $questiontype();
553 $question->loadFromDb($value);
554 $questionxml .= $question->toXML(
false);
557 $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml,
$xml);
564 $questions = array();
565 $result =
$ilDB->queryF(
566 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
568 array($this->
getId())
570 if ($result->numRows()) {
571 while ($row =
$ilDB->fetchAssoc($result)) {
572 $questions[] = $row[
"question_id"];
585 bool $spl_exists =
false 587 if (is_file($source)) {
588 $isZip = (strcmp(strtolower(substr($source, -3)),
'zip') === 0);
594 $subdir = basename($source,
".zip");
595 $source = dirname($source) .
"/" . $subdir .
"/" . $subdir .
".xml";
598 $fh = fopen($source,
'rb') or die(
"");
599 $xml = fread($fh, filesize($source));
600 fclose($fh) or die(
"");
602 $subdir = basename($source,
".zip");
603 if (is_dir(dirname($source) .
"/" . $subdir)) {
607 if (strpos(
$xml,
"questestinterop") > 0) {
613 $import->setXMLContent(
$xml);
614 $import->startParsing();
620 bool $a_online_status
624 $status = (string) (
int) $a_online_status;
625 $db = $DIC->database();
628 "UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
629 array(
'text',
'integer'),
630 array($status, $a_obj_id)
636 $this->online = $a_online_status;
648 $ilDB = $DIC->database();
650 $result =
$ilDB->queryF(
651 "SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
655 if ($row =
$ilDB->fetchAssoc($result)) {
656 return (
bool) $row[
"isonline"];
670 $rbacsystem = $DIC->rbac()->system();
673 foreach ($refs as $ref) {
689 $ilDB = $DIC->database();
690 $lng = $DIC->language();
694 $query_result =
$ilDB->query(
"SELECT * FROM svy_qtype ORDER BY type_tag");
695 while ($row =
$ilDB->fetchAssoc($query_result)) {
697 if ((
int) $row[
"plugin"] === 0) {
698 $types[
$lng->
txt($row[
"type_tag"])] = $row;
702 $component_factory = $DIC[
"component.factory"];
703 foreach ($component_factory->getActivePluginsInSlot(
"svyq") as $pl) {
704 if (strcmp($pl->getQuestionType(), $row[
"type_tag"]) === 0) {
705 $types[$pl->getQuestionTypeTranslation()] = $row;
715 $default_sorting = array_flip(array(
716 "SurveySingleChoiceQuestion",
717 "SurveyMultipleChoiceQuestion",
718 "SurveyMatrixQuestion",
719 "SurveyMetricQuestion",
724 $idx = count($default_sorting);
725 foreach ($types as $caption => $item) {
726 $type = $item[
"type_tag"];
727 $item[
"caption"] = $caption;
730 if (array_key_exists(
$type, $default_sorting)) {
731 $sorted[$default_sorting[
$type]] = $item;
735 $sorted[$idx] = $item;
743 foreach ($sorted as $item) {
744 $types[$item[
"caption"]] = $item;
752 $classes = array_map(
753 static function (array
$c):
string {
754 return $c[
"type_tag"];
756 self::_getQuestiontypes()
768 $ilDB = $DIC->database();
769 $lng = $DIC->language();
771 $component_factory = $DIC[
"component.factory"];
774 $result =
$ilDB->query(
"SELECT * FROM svy_qtype");
776 while ($row =
$ilDB->fetchAssoc($result)) {
777 if ((
int) $row[
"plugin"] === 0) {
778 $types[$row[
'type_tag']] =
$lng->
txt($row[
"type_tag"]);
780 foreach ($component_factory->getActivePluginsInSlot(
"svyq") as $pl) {
781 if (strcmp($pl->getQuestionType(), $row[
"type_tag"]) === 0) {
782 $types[$row[
'type_tag']] = $pl->getQuestionTypeTranslation();
796 bool $use_object_id =
false,
797 bool $could_be_offline =
false,
798 bool $showPath =
false,
799 string $permission =
"read" 806 $ilDB = $DIC->database();
808 $result_array = array();
812 $result =
$ilDB->query(
"SELECT obj_fi, isonline FROM svy_qpl");
813 while ($row =
$ilDB->fetchAssoc($result)) {
814 $allqpls[$row[
'obj_fi']] = $row[
'isonline'];
818 if ($could_be_offline || ($allqpls[$obj_id] ?? 0) == 1) {
819 if ($use_object_id) {
820 $result_array[$obj_id] = $titles[
$ref_id];
822 $result_array[(
int) $ref_id] = $titles[$ref_id];
826 return $result_array;
834 return $this->component_repository->getPluginByName($a_pname)->isActive();
848 $query_result =
$ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
849 "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
850 "AND svy_question.tstamp > 0 AND " .
$ilDB->in(
'svy_question.question_id', $question_ids,
false,
'integer') .
" " .
851 "ORDER BY svy_question.title");
852 if ($query_result->numRows() > 0) {
853 while (
$data =
$ilDB->fetchAssoc($query_result)) {
854 if (in_array(
$data[
"question_id"], $question_ids)) {
855 $found[] = array(
'id' =>
$data[
"question_id"],
856 'title' =>
$data[
"title"],
857 'description' =>
$data[
"description"],
858 'type_tag' =>
$data[
"type_tag"]
874 $result =
$ilDB->queryF(
875 "SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
876 array(
"integer",
"integer"),
891 $this->edit_manager->addQuestionToClipboard($question_id,
"copy");
900 $this->edit_manager->addQuestionToClipboard($question_id,
"move");
910 $qentries = $this->edit_manager->getQuestionsFromClipboard();
911 if (count($qentries) > 0) {
912 foreach ($qentries as $question_object) {
913 if (strcmp($question_object[
"action"],
"move") === 0) {
914 $result =
$ilDB->queryF(
915 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
917 array($question_object[
"question_id"])
919 if ($result->numRows() === 1) {
920 $row =
$ilDB->fetchAssoc($result);
921 $source_questionpool = $row[
"obj_fi"];
922 if ($this->
getId() != $source_questionpool) {
924 $affectedRows =
$ilDB->manipulateF(
925 "UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
926 array(
'integer',
'integer'),
927 array($this->
getId(), $question_object[
"question_id"])
931 $source_path =
CLIENT_WEB_DIR .
"/survey/" . $source_questionpool .
"/" . $question_object[
"question_id"] .
"/";
932 if (is_dir($source_path)) {
934 if (!is_dir($target_path)) {
940 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"spl_move_same_pool"),
true);
949 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"spl_paste_success"),
true);
950 $this->edit_manager->clearClipboardQuestions();
957 array $obligatory_questions
961 $status = (
int) (isset($obligatory_questions[
"$question_id"]));
963 $ilDB->manipulate(
"UPDATE svy_question" .
964 " SET obligatory = " .
$ilDB->quote($status,
"integer") .
965 " WHERE question_id = " .
$ilDB->quote($question_id,
"integer"));
removeQuestion(int $question_id)
Removes a question from the question pool.
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
Readable part of repository interface to ilComponentDataDB.
setOnline(bool $a_online_status)
manipulateF(string $query, array $types, array $values)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getQuestionInfos(array $question_ids)
Returns title, description and type for an array of question id's.
__construct(int $a_id=0, bool $a_call_by_reference=true)
static _getAllReferences(int $id)
get all reference ids for object ID
createImportDirectory()
creates data directory for import files (data_dir/spl_data/spl_<id>/import
getExportDirectory()
get export directory of survey
duplicateQuestion(int $question_id, int $obj_id=0)
Duplicates a question for a question pool.
copyQuestion(int $question_id, int $questionpool_to)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _getAvailableQuestionpools(bool $use_object_id=false, bool $could_be_offline=false, bool $showPath=false, string $permission="read")
Returns the available question pools for the active user.
getQuestiontype(int $question_id)
isInUse(int $question_id)
Checks if a question is in use by a survey.
loadLanguageModule(string $a_module)
Load language module.
static _setOnline(int $a_obj_id, bool $a_online_status)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getQuestionTypeTranslations()
purgeQuestions()
Remove all questions with tstamp = 0.
ilGlobalTemplateInterface $main_tpl
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
createQuestion(string $question_type, int $question_id=-1)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isWriteable(int $object_id)
Returns true, if the question pool is writeable for the current user.
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
moveToClipboard(int $question_id)
Moves a question to the clipboard.
static _prepareCloneSelection(array $ref_ids, string $new_type, bool $show_path=true)
Prepare copy wizard object selection.
ILIAS SurveyQuestionPool Editing EditManager $edit_manager
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static _lookupObjectId(int $ref_id)
getQuestionsInfo(array $question_array)
static _includeClass(string $question_type, int $gui=0)
Include the php class file for a given question type.
static _lookupOnline(int $a_obj_id)
static _getObjectsByOperations( $a_obj_type, string $a_operation, int $a_usr_id=0, int $limit=0)
Get all objects of a specific type and check access This function is not recursive, instead it parses the serialized rbac_pa entries.
static getDataDir()
get data directory (outside webspace)
isPluginActive(string $a_pname)
Checks whether or not a question plugin with a given name is active.
importObject(string $source, bool $spl_exists=false)
Imports survey questions into ILIAS.
pasteFromClipboard()
Copies/Moves a question from the clipboard.
paste(int $question_id)
Pastes a duplicate of a question in the question pool.
getQuestionsData(array $arrFilter)
Retrieve the data for the output of the question pool.
getExportFiles(string $dir)
get export files
__construct(Container $dic, ilPlugin $plugin)
static _getQuestiontypes()
Get all available question types.
setObligatoryStates(array $obligatory_questions)
copyToClipboard(int $question_id)
Copies a question to the clipboard.
static _getQuestionClasses()
static rename(string $a_source, string $a_target)
static _getInstance(int $a_copy_id)
toXML(?array $questions)
export questions to xml
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _instanciateQuestion(int $question_id)
Get question object.
Basic class for all survey question types The SurveyQuestionGUI class defines and encapsulates basic ...
createExportDirectory()
creates data directory for export files data_dir/spl_data/spl_<id>/export
ilComponentRepository $component_repository
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...