ILIAS  release_8 Revision v8.24
class.ilObjSurveyQuestionPool.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\SurveyQuestionPool\Editing\EditManager $edit_manager;
27 protected ilObjUser $user;
28 public bool $online = false;
30 private \ilGlobalTemplateInterface $main_tpl;
31
32 public function __construct(
33 int $a_id = 0,
34 bool $a_call_by_reference = true
35 ) {
36 global $DIC;
37 $this->main_tpl = $DIC->ui()->mainTemplate();
38
39 $this->log = $DIC["ilLog"];
40 $this->db = $DIC->database();
41 $this->user = $DIC->user();
42 $this->component_repository = $DIC["component.repository"];
43 $this->type = "spl";
44 parent::__construct($a_id, $a_call_by_reference);
45 $this->edit_manager = $DIC->surveyQuestionPool()
46 ->internal()
47 ->domain()
48 ->editing();
49 }
50
51 public function create($a_upload = false): int
52 {
53 $id = parent::create();
54 if (!$a_upload) {
55 $this->createMetaData();
56 }
57 return $id;
58 }
59
60 public function update(): bool
61 {
62 $this->updateMetaData();
63 if (!parent::update()) {
64 return false;
65 }
66 return true;
67 }
68
69 public function read(): void
70 {
71 parent::read();
72 $this->loadFromDb();
73 }
74
75 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
76 {
77 $newObj = parent::cloneObject($target_id, $copy_id, $omit_tree);
78
79 //copy online status if object is not the root copy object
80 $cp_options = ilCopyWizardOptions::_getInstance($copy_id);
81
82 if (!$cp_options->isRootNode($this->getRefId())) {
83 $newObj->setOnline($this->getOnline());
84 }
85
86 $newObj->saveToDb();
87 // clone the questions in the question pool
88 $questions = $this->getQuestions();
89 foreach ($questions as $question_id) {
90 $newObj->copyQuestion($question_id, $newObj->getId());
91 }
92
93 // clone meta data
94 $md = new ilMD($this->getId(), 0, $this->getType());
95 $new_md = $md->cloneMD($newObj->getId(), 0, $newObj->getType());
96
97 // update the metadata with the new title of the question pool
98 $newObj->updateMetaData();
99 return $newObj;
100 }
101
105 public function createQuestion(
106 string $question_type,
107 int $question_id = -1
109 if ((!$question_type) and ($question_id > 0)) {
110 $question_type = $this->getQuestiontype($question_id);
111 }
112
113 $question_type_gui = $question_type . "GUI";
114 $question = new $question_type_gui();
115
116 if ($question_id > 0) {
117 $question->object->loadFromDb($question_id);
118 }
119
120 return $question;
121 }
122
127 public function copyQuestion(
128 int $question_id,
129 int $questionpool_to
130 ): void {
131 $question_gui = $this->createQuestion("", $question_id);
132 if ($question_gui->object->getObjId() === $questionpool_to) {
133 // the question is copied into the same question pool
134 $this->duplicateQuestion($question_id);
135 } else {
136 // the question is copied into another question pool
137 $newtitle = $question_gui->object->getTitle();
138 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to)) {
139 $counter = 2;
140 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() . " ($counter)", $questionpool_to)) {
141 $counter++;
142 }
143 $newtitle = $question_gui->object->getTitle() . " ($counter)";
144 }
145 $question_gui->object->copyObject($this->getId(), $newtitle);
146 }
147 }
148
149 public function loadFromDb(): void
150 {
151 $ilDB = $this->db;
152
153 $result = $ilDB->queryF(
154 "SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
155 array('integer'),
156 array($this->getId())
157 );
158 if ($result->numRows() === 1) {
159 $row = $ilDB->fetchAssoc($result);
160 $this->setOnline((bool) $row["isonline"]);
161 }
162 }
163
164 public function saveToDb(): void
165 {
166 $ilDB = $this->db;
167
168 parent::update();
169
170 $result = $ilDB->queryF(
171 "SELECT * FROM svy_qpl WHERE obj_fi = %s",
172 array('integer'),
173 array($this->getId())
174 );
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'),
179 array($this->getOnline(), time(), $this->getId())
180 );
181 } else {
182 $next_id = $ilDB->nextId('svy_qpl');
183 $query = $ilDB->manipulateF(
184 "INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
185 array('integer', 'text', 'integer', 'integer'),
186 array($next_id, $this->getOnline(), $this->getId(), time())
187 );
188 }
189 }
190
191 public function delete(): bool
192 {
193 $remove = parent::delete();
194 // always call parent delete function first!!
195 if (!$remove) {
196 return false;
197 }
198
199 // delete all related questions
200 $this->deleteAllData();
201
202 // delete meta data
203 $this->deleteMetaData();
204
205 return true;
206 }
207
208 public function deleteAllData(): void
209 {
210 $ilDB = $this->db;
211 $result = $ilDB->queryF(
212 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
213 array('integer'),
214 array($this->getId())
215 );
216 $found_questions = array();
217 while ($row = $ilDB->fetchAssoc($result)) {
218 $this->removeQuestion($row["question_id"]);
219 }
220
221 // delete export files
222 $spl_data_dir = ilFileUtils::getDataDir() . "/spl_data";
223 $directory = $spl_data_dir . "/spl_" . $this->getId();
224 if (is_dir($directory)) {
225 ilFileUtils::delDir($directory);
226 }
227 }
228
232 public function removeQuestion(int $question_id): void
233 {
234 if ($question_id < 1) {
235 return;
236 }
237 $question = SurveyQuestion::_instanciateQuestion($question_id);
238 $question->delete($question_id);
239 }
240
244 public function getQuestiontype(
245 int $question_id
246 ): ?string {
247 $ilDB = $this->db;
248 if ($question_id < 1) {
249 return null;
250 }
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",
253 array('integer'),
254 array($question_id)
255 );
256 if ($result->numRows() === 1) {
257 $data = $ilDB->fetchAssoc($result);
258 return $data["type_tag"];
259 } else {
260 return null;
261 }
262 }
263
269 public function isInUse(int $question_id): ?array
270 {
271 $ilDB = $this->db;
272 // check out the already answered questions
273 $result = $ilDB->queryF(
274 "SELECT answer_id FROM svy_answer WHERE question_fi = %s",
275 array('integer'),
276 array($question_id)
277 );
278 $answered = $result->numRows();
279
280 // check out the questions inserted in surveys
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",
283 array('integer'),
284 array($question_id)
285 );
286 $inserted = $result->numRows();
287 if (($inserted + $answered) === 0) {
288 return null;
289 }
290 $result_array = array();
291 while ($row = $ilDB->fetchObject($result)) {
292 $result_array[] = $row;
293 }
294 return $result_array;
295 }
296
300 public function paste(int $question_id): void
301 {
302 $this->duplicateQuestion($question_id, $this->getId());
303 }
304
309 public function getQuestionsInfo(
310 array $question_array
311 ): array {
312 $ilDB = $this->db;
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"]) {
317 if ($this->isPluginActive($row["type_tag"])) {
318 $result_array[] = $row;
319 }
320 } else {
321 $result_array[] = $row;
322 }
323 }
324 return $result_array;
325 }
326
330 public function duplicateQuestion(
331 int $question_id,
332 int $obj_id = 0
333 ): void {
334 $ilUser = $this->user;
335 $question = SurveyQuestion::_instanciateQuestion($question_id);
336 $suffix = "";
337 $counter = 1;
338 while ($question->questionTitleExists($question->getTitle() . $suffix, $obj_id)) {
339 $counter++;
340 if ($counter > 1) {
341 $suffix = " ($counter)";
342 }
343 }
344 if ($obj_id) {
345 $question->setObjId($obj_id);
346 }
347 $max_len = 195;
348 if (strlen($question->getTitle() . $suffix) > $max_len) {
349 $title = substr($question->getTitle(), 0, $max_len - strlen($suffix)) . $suffix;
350 } else {
351 $title = $question->getTitle() . $suffix;
352 }
353 $question->duplicate(false, $title, $ilUser->fullname, $ilUser->id);
354 }
355
360 public function getQuestionsData(
361 array $arrFilter
362 ): array {
363 $ilDB = $this->db;
364 $where = "";
365 if (count($arrFilter) > 0) {
366 foreach ($arrFilter as $key => $value) {
367 $arrFilter[$key] = str_replace('%', '', $value);
368 }
369 if (array_key_exists('title', $arrFilter) && strlen($arrFilter['title'])) {
370 $where .= " AND " . $ilDB->like('svy_question.title', 'text', "%%" . $arrFilter['title'] . "%%");
371 }
372 if (array_key_exists('description', $arrFilter) && strlen($arrFilter['description'])) {
373 $where .= " AND " . $ilDB->like('svy_question.description', 'text', "%%" . $arrFilter['description'] . "%%");
374 }
375 if (array_key_exists('author', $arrFilter) && strlen($arrFilter['author'])) {
376 $where .= " AND " . $ilDB->like('svy_question.author', 'text', "%%" . $arrFilter['author'] . "%%");
377 }
378 if (array_key_exists('type', $arrFilter) && strlen($arrFilter['type'])) {
379 $where .= " AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter['type'], 'text');
380 }
381 }
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,
384 array('integer'),
385 array($this->getId())
386 );
387 $rows = array();
388 if ($query_result->numRows()) {
389 while ($row = $ilDB->fetchAssoc($query_result)) {
390 if ($row["plugin"]) {
391 if ($this->isPluginActive($row["type_tag"])) {
392 $rows[] = $row;
393 }
394 } else {
395 $rows[] = $row;
396 }
397 }
398 }
399 return $rows;
400 }
401
407 public function createExportDirectory(): void
408 {
409 $spl_data_dir = ilFileUtils::getDataDir() . "/spl_data";
410 ilFileUtils::makeDir($spl_data_dir);
411 if (!is_writable($spl_data_dir)) {
412 throw new ilSurveyException("Survey Questionpool Data Directory (" . $spl_data_dir . ") not writeable.");
413 }
414
415 // create learning module directory (data_dir/lm_data/lm_<id>)
416 $spl_dir = $spl_data_dir . "/spl_" . $this->getId();
417 ilFileUtils::makeDir($spl_dir);
418 if (!is_dir($spl_dir)) {
419 throw new ilSurveyException("Creation of Survey Questionpool Directory failed.");
420 }
421 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
422 $export_dir = $spl_dir . "/export";
423 ilFileUtils::makeDir($export_dir);
424 if (!is_dir($export_dir)) {
425 throw new ilSurveyException("Creation of Survey Questionpool Export Directory failed.");
426 }
427 }
428
432 public function getExportDirectory(): string
433 {
434 $export_dir = ilFileUtils::getDataDir() . "/spl_data" . "/spl_" . $this->getId() . "/export";
435 return $export_dir;
436 }
437
441 public function getExportFiles(string $dir): array
442 {
443 // quit if import dir not available
444 if (!is_dir($dir) or
445 !is_writable($dir)) {
446 return array();
447 }
448
449 // open directory
450 $dir = dir($dir);
451
452 // initialize array
453 $file = array();
454
455 // get files and save the in the array
456 while ($entry = $dir->read()) {
457 if ($entry !== "." &&
458 $entry !== ".." &&
459 preg_match("/^[0-9]{10}__[0-9]+__(spl_)*[0-9]+\.[A-Za-z]{3}$/", $entry)) {
460 $file[] = $entry;
461 }
462 }
463
464 // close import directory
465 $dir->close();
466 // sort files
467 sort($file);
468
469 return $file;
470 }
471
477 public function createImportDirectory(): void
478 {
479 $spl_data_dir = ilFileUtils::getDataDir() . "/spl_data";
480 ilFileUtils::makeDir($spl_data_dir);
481
482 if (!is_writable($spl_data_dir)) {
483 throw new ilSurveyException("Survey Questionpool Data Directory (" . $spl_data_dir . ") not writeable.");
484 }
485
486 // create test directory (data_dir/spl_data/spl_<id>)
487 $spl_dir = $spl_data_dir . "/spl_" . $this->getId();
488 ilFileUtils::makeDir($spl_dir);
489 if (!is_dir($spl_dir)) {
490 throw new ilSurveyException("Creation of Survey Questionpool Directory failed.");
491 }
492
493 // create import subdirectory (data_dir/spl_data/spl_<id>/import)
494 $import_dir = $spl_dir . "/import";
495 ilFileUtils::makeDir($import_dir);
496 if (!is_dir($import_dir)) {
497 throw new ilSurveyException("Creation of Survey Questionpool Import Directory failed.");
498 }
499 }
500
501 public function getImportDirectory(): string
502 {
503 return ilFileUtils::getDataDir() . "/spl_data" .
504 "/spl_" . $this->getId() . "/import";
505 }
506
511 public function toXML(?array $questions): string
512 {
513 if (is_null($questions) || count($questions) === 0) {
514 $questions = $this->getQuestions();
515 }
516 $a_xml_writer = new ilXmlWriter();
517 // set xml header
518 $a_xml_writer->xmlHeader();
519 $attrs = array(
520 "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
521 "xsi:noNamespaceSchemaLocation" => "https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
522 );
523 $a_xml_writer->xmlStartTag("surveyobject", $attrs);
524 $attrs = array(
525 "id" => "qpl_" . $this->getId(),
526 "label" => $this->getTitle(),
527 "online" => $this->getOnline()
528 );
529 $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
530 $a_xml_writer->xmlElement("dummy", null, "dummy");
531 // add ILIAS specific metadata
532 $a_xml_writer->xmlStartTag("metadata");
533 $a_xml_writer->xmlStartTag("metadatafield");
534 $a_xml_writer->xmlElement("fieldlabel", null, "SCORM");
535 $md = new ilMD($this->getId(), 0, $this->getType());
536 $writer = new ilXmlWriter();
537 $md->toXML($writer);
538 $metadata = $writer->xmlDumpMem();
539 $a_xml_writer->xmlElement("fieldentry", null, $metadata);
540 $a_xml_writer->xmlEndTag("metadatafield");
541 $a_xml_writer->xmlEndTag("metadata");
542
543 $a_xml_writer->xmlEndTag("surveyquestions");
544 $a_xml_writer->xmlEndTag("surveyobject");
545
546 $xml = $a_xml_writer->xmlDumpMem(false);
547
548 $questionxml = "";
549 foreach ($questions as $key => $value) {
550 $questiontype = $this->getQuestiontype($value);
551 SurveyQuestion::_includeClass($questiontype);
552 $question = new $questiontype();
553 $question->loadFromDb($value);
554 $questionxml .= $question->toXML(false);
555 }
556
557 $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
558 return $xml;
559 }
560
561 public function getQuestions(): array
562 {
563 $ilDB = $this->db;
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",
567 array('integer'),
568 array($this->getId())
569 );
570 if ($result->numRows()) {
571 while ($row = $ilDB->fetchAssoc($result)) {
572 $questions[] = $row["question_id"];
573 }
574 }
575 return $questions;
576 }
577
583 public function importObject(
584 string $source,
585 bool $spl_exists = false
586 ): void {
587 if (is_file($source)) {
588 $isZip = (strcmp(strtolower(substr($source, -3)), 'zip') === 0);
589 if ($isZip) {
590 // unzip file
592
593 // determine filenames of xml files
594 $subdir = basename($source, ".zip");
595 $source = dirname($source) . "/" . $subdir . "/" . $subdir . ".xml";
596 }
597
598 $fh = fopen($source, 'rb') or die("");
599 $xml = fread($fh, filesize($source));
600 fclose($fh) or die("");
601 if ($isZip) {
602 $subdir = basename($source, ".zip");
603 if (is_dir(dirname($source) . "/" . $subdir)) {
604 ilFileUtils::delDir(dirname($source) . "/" . $subdir);
605 }
606 }
607 if (strpos($xml, "questestinterop") > 0) {
608 throw new ilInvalidSurveyImportFileException("Unsupported survey version (< 3.8) found.");
609 }
610
611 // survey questions for ILIAS >= 3.8
612 $import = new SurveyImportParser($this->getId(), "", $spl_exists);
613 $import->setXMLContent($xml);
614 $import->startParsing();
615 }
616 }
617
618 public static function _setOnline(
619 int $a_obj_id,
620 bool $a_online_status
621 ): void {
622 global $DIC;
623
624 $status = (string) (int) $a_online_status;
625 $db = $DIC->database();
626
627 $db->manipulateF(
628 "UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
629 array('text','integer'),
630 array($status, $a_obj_id)
631 );
632 }
633
634 public function setOnline(bool $a_online_status): void
635 {
636 $this->online = $a_online_status;
637 }
638
639 public function getOnline(): bool
640 {
641 return $this->online;
642 }
643
644 public static function _lookupOnline(int $a_obj_id): bool
645 {
646 global $DIC;
647
648 $ilDB = $DIC->database();
649
650 $result = $ilDB->queryF(
651 "SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
652 array('integer'),
653 array($a_obj_id)
654 );
655 if ($row = $ilDB->fetchAssoc($result)) {
656 return (bool) $row["isonline"];
657 }
658 return false;
659 }
660
665 public static function _isWriteable(
666 int $object_id
667 ): bool {
668 global $DIC;
669
670 $rbacsystem = $DIC->rbac()->system();
671 $refs = ilObject::_getAllReferences($object_id);
672 $result = false;
673 foreach ($refs as $ref) {
674 if ($rbacsystem->checkAccess("write", $ref) && (ilObject::_hasUntrashedReference($object_id))) {
675 $result = true;
676 }
677 }
678 return $result;
679 }
680
685 public static function _getQuestiontypes(): array
686 {
687 global $DIC;
688
689 $ilDB = $DIC->database();
690 $lng = $DIC->language();
691
692 $lng->loadLanguageModule("survey");
693 $types = array();
694 $query_result = $ilDB->query("SELECT * FROM svy_qtype ORDER BY type_tag");
695 while ($row = $ilDB->fetchAssoc($query_result)) {
696 //array_push($questiontypes, $row["type_tag"]);
697 if ((int) $row["plugin"] === 0) {
698 $types[$lng->txt($row["type_tag"])] = $row;
699 } else {
700 global $DIC;
701
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;
706 }
707 }
708 }
709 }
710 ksort($types);
711
712
713 // #14263 - default sorting
714
715 $default_sorting = array_flip(array(
716 "SurveySingleChoiceQuestion",
717 "SurveyMultipleChoiceQuestion",
718 "SurveyMatrixQuestion",
719 "SurveyMetricQuestion",
720 "SurveyTextQuestion"
721 ));
722
723 $sorted = array();
724 $idx = count($default_sorting);
725 foreach ($types as $caption => $item) {
726 $type = $item["type_tag"];
727 $item["caption"] = $caption;
728
729 // default
730 if (array_key_exists($type, $default_sorting)) {
731 $sorted[$default_sorting[$type]] = $item;
732 }
733 // plugin (append alphabetically sorted)
734 else {
735 $sorted[$idx] = $item;
736 $idx++;
737 }
738 }
739 ksort($sorted);
740
741 // redo captions as index
742 $types = array();
743 foreach ($sorted as $item) {
744 $types[$item["caption"]] = $item;
745 }
746
747 return $types;
748 }
749
750 public static function _getQuestionClasses(): array
751 {
752 $classes = array_map(
753 static function (array $c): string {
754 return $c["type_tag"];
755 },
756 self::_getQuestiontypes()
757 );
758 return $classes;
759 }
760
764 public static function _getQuestionTypeTranslations(): array
765 {
766 global $DIC;
767
768 $ilDB = $DIC->database();
769 $lng = $DIC->language();
770
771 $component_factory = $DIC["component.factory"];
772
773 $lng->loadLanguageModule("survey");
774 $result = $ilDB->query("SELECT * FROM svy_qtype");
775 $types = array();
776 while ($row = $ilDB->fetchAssoc($result)) {
777 if ((int) $row["plugin"] === 0) {
778 $types[$row['type_tag']] = $lng->txt($row["type_tag"]);
779 } else {
780 foreach ($component_factory->getActivePluginsInSlot("svyq") as $pl) {
781 if (strcmp($pl->getQuestionType(), $row["type_tag"]) === 0) {
782 $types[$row['type_tag']] = $pl->getQuestionTypeTranslation();
783 }
784 }
785 }
786 }
787 ksort($types);
788 return $types;
789 }
790
795 public static function _getAvailableQuestionpools(
796 bool $use_object_id = false,
797 bool $could_be_offline = false,
798 bool $showPath = false,
799 string $permission = "read"
800 ): array {
801 global $DIC;
802
803 $ilUser = $DIC->user();
804 global $DIC;
805
806 $ilDB = $DIC->database();
807
808 $result_array = array();
809 $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
810 $titles = ilObject::_prepareCloneSelection($qpls, "spl", $showPath);
811 $allqpls = 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'];
815 }
816 foreach ($qpls as $ref_id) {
818 if ($could_be_offline || ($allqpls[$obj_id] ?? 0) == 1) {
819 if ($use_object_id) {
820 $result_array[$obj_id] = $titles[$ref_id];
821 } else {
822 $result_array[(int) $ref_id] = $titles[$ref_id];
823 }
824 }
825 }
826 return $result_array;
827 }
828
832 public function isPluginActive(string $a_pname): bool
833 {
834 return $this->component_repository->getPluginByName($a_pname)->isActive();
835 }
836
843 public function getQuestionInfos(array $question_ids): array
844 {
845 $ilDB = $this->db;
846
847 $found = array();
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"]
859 );
860 }
861 }
862 }
863 return $found;
864 }
865
869 public function purgeQuestions(): void
870 {
871 $ilDB = $this->db;
872 $ilUser = $this->user;
873
874 $result = $ilDB->queryF(
875 "SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
876 array("integer", "integer"),
877 array($ilUser->getId(), 0)
878 );
879 while ($data = $ilDB->fetchAssoc($result)) {
880 $this->removeQuestion($data["question_id"]);
881 }
882 }
883
888 public function copyToClipboard(
889 int $question_id
890 ): void {
891 $this->edit_manager->addQuestionToClipboard($question_id, "copy");
892 }
893
897 public function moveToClipboard(
898 int $question_id
899 ): void {
900 $this->edit_manager->addQuestionToClipboard($question_id, "move");
901 }
902
906 public function pasteFromClipboard(): void
907 {
908 $ilDB = $this->db;
909
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",
916 array('integer'),
917 array($question_object["question_id"])
918 );
919 if ($result->numRows() === 1) {
920 $row = $ilDB->fetchAssoc($result);
921 $source_questionpool = $row["obj_fi"];
922 if ($this->getId() != $source_questionpool) {
923 // change the questionpool id in the qpl_questions table
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"])
928 );
929
930 // move question data to the new target directory
931 $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
932 if (is_dir($source_path)) {
933 $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/";
934 if (!is_dir($target_path)) {
935 ilFileUtils::makeDirParents($target_path);
936 }
937 ilFileUtils::rename($source_path, $target_path . $question_object["question_id"]);
938 }
939 } else {
940 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("spl_move_same_pool"), true);
941 return;
942 }
943 }
944 } else {
945 $this->copyQuestion($question_object["question_id"], $this->getId());
946 }
947 }
948 }
949 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("spl_paste_success"), true);
950 $this->edit_manager->clearClipboardQuestions();
951 }
952
956 public function setObligatoryStates(
957 array $obligatory_questions
958 ): void {
959 $ilDB = $this->db;
960 foreach ($this->getQuestions() as $question_id) {
961 $status = (int) (isset($obligatory_questions["$question_id"]));
962
963 $ilDB->manipulate("UPDATE svy_question" .
964 " SET obligatory = " . $ilDB->quote($status, "integer") .
965 " WHERE question_id = " . $ilDB->quote($question_id, "integer"));
966 }
967 }
968}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Basic class for all survey question types The SurveyQuestionGUI class defines and encapsulates basic ...
static _includeClass(string $question_type, int $gui=0)
Include the php class file for a given question type.
static _instanciateQuestion(int $question_id)
Get question object.
static _getInstance(int $a_copy_id)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static rename(string $a_source, string $a_target)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getDataDir()
get data directory (outside webspace)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
duplicateQuestion(int $question_id, int $obj_id=0)
Duplicates a question for a question pool.
createQuestion(string $question_type, int $question_id=-1)
copyQuestion(int $question_id, int $questionpool_to)
setObligatoryStates(array $obligatory_questions)
createImportDirectory()
creates data directory for import files (data_dir/spl_data/spl_<id>/import
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
getExportFiles(string $dir)
get export files
importObject(string $source, bool $spl_exists=false)
Imports survey questions into ILIAS.
getQuestionInfos(array $question_ids)
Returns title, description and type for an array of question id's.
createExportDirectory()
creates data directory for export files data_dir/spl_data/spl_<id>/export
isPluginActive(string $a_pname)
Checks whether or not a question plugin with a given name is active.
__construct(int $a_id=0, bool $a_call_by_reference=true)
moveToClipboard(int $question_id)
Moves a question to the clipboard.
ilComponentRepository $component_repository
static _getQuestiontypes()
Get all available question types.
getExportDirectory()
get export directory of survey
pasteFromClipboard()
Copies/Moves a question from the clipboard.
ilGlobalTemplateInterface $main_tpl
toXML(?array $questions)
export questions to xml
removeQuestion(int $question_id)
Removes a question from the question pool.
getQuestionsData(array $arrFilter)
Retrieve the data for the output of the question pool.
static _isWriteable(int $object_id)
Returns true, if the question pool is writeable for the current user.
isInUse(int $question_id)
Checks if a question is in use by a survey.
ILIAS SurveyQuestionPool Editing EditManager $edit_manager
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.
purgeQuestions()
Remove all questions with tstamp = 0.
copyToClipboard(int $question_id)
Copies a question to the clipboard.
static _setOnline(int $a_obj_id, bool $a_online_status)
paste(int $question_id)
Pastes a duplicate of a question in the question pool.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjectId(int $ref_id)
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _getAllReferences(int $id)
get all reference ids for object ID
static _prepareCloneSelection(array $ref_ids, string $new_type, bool $show_path=true)
Prepare copy wizard object selection.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const CLIENT_WEB_DIR
Definition: constants.php:47
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$ilUser
Definition: imgupload.php:34
Readable part of repository interface to ilComponentDataDB.
$ref_id
Definition: ltiauth.php:67
$source
Definition: metadata.php:93
$xml
Definition: metadata.php:351
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$query
$type
$lng
$rows
Definition: xhr_table.php:10