ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjSurveyQuestionPool.php
Go to the documentation of this file.
1<?php
2
21
28{
31 protected ilObjUser $user;
32 public bool $online = false;
34 private \ilGlobalTemplateInterface $main_tpl;
35
36 public function __construct(
37 int $a_id = 0,
38 bool $a_call_by_reference = true
39 ) {
40 global $DIC;
41 $this->main_tpl = $DIC->ui()->mainTemplate();
42
43 $this->log = $DIC["ilLog"];
44 $this->db = $DIC->database();
45 $this->user = $DIC->user();
46 $this->component_repository = $DIC["component.repository"];
47 $this->type = "spl";
48 parent::__construct($a_id, $a_call_by_reference);
49 $this->edit_manager = $DIC->surveyQuestionPool()
50 ->internal()
51 ->domain()
52 ->editing();
53 $this->domain = $DIC->surveyQuestionPool()->internal()->domain();
54 }
55
56 public function create($a_upload = false): int
57 {
58 $id = parent::create();
59 if (!$a_upload) {
60 $this->createMetaData();
61 }
62 return $id;
63 }
64
65 public function update(): bool
66 {
67 $this->updateMetaData();
68 if (!parent::update()) {
69 return false;
70 }
71 return true;
72 }
73
74 public function read(): void
75 {
76 parent::read();
77 $this->loadFromDb();
78 }
79
80 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
81 {
82 $newObj = parent::cloneObject($target_id, $copy_id, $omit_tree);
83
84 //copy online status if object is not the root copy object
85 $cp_options = ilCopyWizardOptions::_getInstance($copy_id);
86
87 $newObj->saveToDb();
88 // clone the questions in the question pool
89 $questions = $this->getQuestions();
90 foreach ($questions as $question_id) {
91 $newObj->copyQuestion($question_id, $newObj->getId());
92 }
93
94 // clone meta data
95 $this->cloneMetaData($newObj);
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 }
152
153 public function saveToDb(): void
154 {
155 $ilDB = $this->db;
156
157 parent::update();
158
159 $result = $ilDB->queryF(
160 "SELECT * FROM svy_qpl WHERE obj_fi = %s",
161 array('integer'),
162 array($this->getId())
163 );
164 if ($result->numRows() !== 1) {
165 $next_id = $ilDB->nextId('svy_qpl');
166 $query = $ilDB->manipulateF(
167 "INSERT INTO svy_qpl (id_questionpool, obj_fi, tstamp) VALUES (%s, %s, %s)",
168 array('integer', 'integer', 'integer'),
169 array($next_id, $this->getId(), time())
170 );
171 }
172 }
173
174 public function delete(): bool
175 {
176 $remove = parent::delete();
177 // always call parent delete function first!!
178 if (!$remove) {
179 return false;
180 }
181
182 // delete all related questions
183 $this->deleteAllData();
184
185 // delete meta data
186 $this->deleteMetaData();
187
188 return true;
189 }
190
191 public function deleteAllData(): void
192 {
193 $ilDB = $this->db;
194 $result = $ilDB->queryF(
195 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
196 array('integer'),
197 array($this->getId())
198 );
199 $found_questions = array();
200 while ($row = $ilDB->fetchAssoc($result)) {
201 $this->removeQuestion($row["question_id"]);
202 }
203
204 // delete export files
205 $spl_data_dir = ilFileUtils::getDataDir() . "/spl_data";
206 $directory = $spl_data_dir . "/spl_" . $this->getId();
207 if (is_dir($directory)) {
208 ilFileUtils::delDir($directory);
209 }
210 }
211
215 public function removeQuestion(int $question_id): void
216 {
217 if ($question_id < 1) {
218 return;
219 }
220 $question = SurveyQuestion::_instanciateQuestion($question_id);
221 $question->delete($question_id);
222 }
223
227 public function getQuestiontype(
228 int $question_id
229 ): ?string {
230 $ilDB = $this->db;
231 if ($question_id < 1) {
232 return null;
233 }
234 $result = $ilDB->queryF(
235 "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",
236 array('integer'),
237 array($question_id)
238 );
239 if ($result->numRows() === 1) {
240 $data = $ilDB->fetchAssoc($result);
241 return $data["type_tag"];
242 } else {
243 return null;
244 }
245 }
246
252 public function isInUse(int $question_id): ?array
253 {
254 $ilDB = $this->db;
255 // check out the already answered questions
256 $result = $ilDB->queryF(
257 "SELECT answer_id FROM svy_answer WHERE question_fi = %s",
258 array('integer'),
259 array($question_id)
260 );
261 $answered = $result->numRows();
262
263 // check out the questions inserted in surveys
264 $result = $ilDB->queryF(
265 "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",
266 array('integer'),
267 array($question_id)
268 );
269 $inserted = $result->numRows();
270 if (($inserted + $answered) === 0) {
271 return null;
272 }
273 $result_array = array();
274 while ($row = $ilDB->fetchObject($result)) {
275 $result_array[] = $row;
276 }
277 return $result_array;
278 }
279
283 public function paste(int $question_id): void
284 {
285 $this->duplicateQuestion($question_id, $this->getId());
286 }
287
292 public function getQuestionsInfo(
293 array $question_array
294 ): array {
295 $ilDB = $this->db;
296 $result_array = array();
297 $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'));
298 while ($row = $ilDB->fetchAssoc($result)) {
299 if ($row["plugin"]) {
300 continue;
301 } else {
302 $result_array[] = $row;
303 }
304 }
305 return $result_array;
306 }
307
311 public function duplicateQuestion(
312 int $question_id,
313 int $obj_id = 0
314 ): void {
315 $ilUser = $this->user;
316 $question = SurveyQuestion::_instanciateQuestion($question_id);
317 $suffix = "";
318 $counter = 1;
319 while ($question->questionTitleExists($question->getTitle() . $suffix, $obj_id)) {
320 $counter++;
321 if ($counter > 1) {
322 $suffix = " ($counter)";
323 }
324 }
325 if ($obj_id) {
326 $question->setObjId($obj_id);
327 }
328 $max_len = 195;
329 if (strlen($question->getTitle() . $suffix) > $max_len) {
330 $title = substr($question->getTitle(), 0, $max_len - strlen($suffix)) . $suffix;
331 } else {
332 $title = $question->getTitle() . $suffix;
333 }
334 $question->duplicate(false, $title, $ilUser->fullname, $ilUser->id);
335 }
336
341 public function getQuestionsData(
342 array $arrFilter
343 ): array {
344 $ilDB = $this->db;
345 $where = "";
346 if (count($arrFilter) > 0) {
347 foreach ($arrFilter as $key => $value) {
348 $arrFilter[$key] = str_replace('%', '', $value);
349 }
350 if (array_key_exists('title', $arrFilter) && strlen($arrFilter['title'] ?? "")) {
351 $where .= " AND " . $ilDB->like('svy_question.title', 'text', "%%" . $arrFilter['title'] . "%%");
352 }
353 if (array_key_exists('description', $arrFilter) && strlen($arrFilter['description'] ?? "")) {
354 $where .= " AND " . $ilDB->like('svy_question.description', 'text', "%%" . $arrFilter['description'] . "%%");
355 }
356 if (array_key_exists('author', $arrFilter) && strlen($arrFilter['author'] ?? "")) {
357 $where .= " AND " . $ilDB->like('svy_question.author', 'text', "%%" . $arrFilter['author'] . "%%");
358 }
359 if (array_key_exists('type', $arrFilter) && strlen($arrFilter['type'] ?? "")) {
360 $where .= " AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter['type'], 'text');
361 }
362 }
363 $query_result = $ilDB->queryF(
364 "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,
365 array('integer'),
366 array($this->getId())
367 );
368 $rows = array();
369 if ($query_result->numRows()) {
370 while ($row = $ilDB->fetchAssoc($query_result)) {
371 if ($row["plugin"]) {
372 continue;
373 } else {
374 $rows[] = $row;
375 }
376 }
377 }
378 return $rows;
379 }
380
386 public function createExportDirectory(): void
387 {
388 $spl_data_dir = ilFileUtils::getDataDir() . "/spl_data";
389 ilFileUtils::makeDir($spl_data_dir);
390 if (!is_writable($spl_data_dir)) {
391 throw new ilSurveyException("Survey Questionpool Data Directory (" . $spl_data_dir . ") not writeable.");
392 }
393
394 // create learning module directory (data_dir/lm_data/lm_<id>)
395 $spl_dir = $spl_data_dir . "/spl_" . $this->getId();
396 ilFileUtils::makeDir($spl_dir);
397 if (!is_dir($spl_dir)) {
398 throw new ilSurveyException("Creation of Survey Questionpool Directory failed.");
399 }
400 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
401 $export_dir = $spl_dir . "/export";
402 ilFileUtils::makeDir($export_dir);
403 if (!is_dir($export_dir)) {
404 throw new ilSurveyException("Creation of Survey Questionpool Export Directory failed.");
405 }
406 }
407
411 public function getExportDirectory(): string
412 {
413 $export_dir = ilFileUtils::getDataDir() . "/spl_data" . "/spl_" . $this->getId() . "/export";
414 return $export_dir;
415 }
416
420 public function getExportFiles(string $dir): array
421 {
422 // quit if import dir not available
423 if (!is_dir($dir) or
424 !is_writable($dir)) {
425 return array();
426 }
427
428 // open directory
429 $dir = dir($dir);
430
431 // initialize array
432 $file = array();
433
434 // get files and save the in the array
435 while ($entry = $dir->read()) {
436 if ($entry !== "." &&
437 $entry !== ".." &&
438 preg_match("/^[0-9]{10}__[0-9]+__(spl_)*[0-9]+\.[A-Za-z]{3}$/", $entry)) {
439 $file[] = $entry;
440 }
441 }
442
443 // close import directory
444 $dir->close();
445 // sort files
446 sort($file);
447
448 return $file;
449 }
450
456 public function createImportDirectory(): void
457 {
458 $spl_data_dir = ilFileUtils::getDataDir() . "/spl_data";
459 ilFileUtils::makeDir($spl_data_dir);
460
461 if (!is_writable($spl_data_dir)) {
462 throw new ilSurveyException("Survey Questionpool Data Directory (" . $spl_data_dir . ") not writeable.");
463 }
464
465 // create test directory (data_dir/spl_data/spl_<id>)
466 $spl_dir = $spl_data_dir . "/spl_" . $this->getId();
467 ilFileUtils::makeDir($spl_dir);
468 if (!is_dir($spl_dir)) {
469 throw new ilSurveyException("Creation of Survey Questionpool Directory failed.");
470 }
471
472 // create import subdirectory (data_dir/spl_data/spl_<id>/import)
473 $import_dir = $spl_dir . "/import";
474 ilFileUtils::makeDir($import_dir);
475 if (!is_dir($import_dir)) {
476 throw new ilSurveyException("Creation of Survey Questionpool Import Directory failed.");
477 }
478 }
479
480 public function getImportDirectory(): string
481 {
482 return ilFileUtils::getDataDir() . "/spl_data" .
483 "/spl_" . $this->getId() . "/import";
484 }
485
490 public function toXML(?array $questions): string
491 {
492 if (is_null($questions) || count($questions) === 0) {
493 $questions = $this->getQuestions();
494 }
495 $a_xml_writer = new ilXmlWriter();
496 // set xml header
497 $a_xml_writer->xmlHeader();
498 $attrs = array(
499 "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
500 "xsi:noNamespaceSchemaLocation" => "https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
501 );
502 $a_xml_writer->xmlStartTag("surveyobject", $attrs);
503 $attrs = array(
504 "id" => "qpl_" . $this->getId(),
505 "label" => $this->getTitle()
506 );
507 $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
508 $a_xml_writer->xmlElement("dummy", null, "dummy");
509
510 $a_xml_writer->xmlEndTag("surveyquestions");
511 $a_xml_writer->xmlEndTag("surveyobject");
512
513 $xml = $a_xml_writer->xmlDumpMem(false);
514
515 $questionxml = "";
516 foreach ($questions as $key => $value) {
517 $questiontype = $this->getQuestiontype($value);
518 SurveyQuestion::_includeClass($questiontype);
519 $question = new $questiontype();
520 $question->loadFromDb($value);
521 $questionxml .= $question->toXML(false);
522 }
523
524 $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
525 return $xml;
526 }
527
528 public function toXmlForExport(): string
529 {
530 $questions = $this->getQuestions();
531 $a_xml_writer = new ilXmlWriter();
532 $attrs = array(
533 "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
534 "xsi:noNamespaceSchemaLocation" => "https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
535 );
536 $a_xml_writer->xmlStartTag("surveyobject", $attrs);
537 $attrs = array(
538 "id" => "qpl_" . $this->getId(),
539 "label" => $this->getTitle()
540 );
541 $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
542 $a_xml_writer->xmlElement("dummy", null, "dummy");
543 $a_xml_writer->xmlEndTag("surveyquestions");
544 $a_xml_writer->xmlEndTag("surveyobject");
545 $xml = $a_xml_writer->xmlDumpMem(false);
546 $questionxml = "";
547 foreach ($questions as $key => $value) {
548 $questiontype = $this->getQuestiontype($value);
549 SurveyQuestion::_includeClass($questiontype);
550 $question = new $questiontype();
551 $question->loadFromDb($value);
552 $questionxml .= $question->toXML(false);
553 }
554 $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
555 return $xml;
556 }
557
558 public function getQuestions(): array
559 {
560 $ilDB = $this->db;
561 $questions = array();
562 $result = $ilDB->queryF(
563 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
564 array('integer'),
565 array($this->getId())
566 );
567 if ($result->numRows()) {
568 while ($row = $ilDB->fetchAssoc($result)) {
569 $questions[] = $row["question_id"];
570 }
571 }
572 return $questions;
573 }
574
580 public function importObject(
581 string $source,
582 bool $spl_exists = false
583 ): void {
584 if (is_file($source)) {
585 $isZip = (strcmp(strtolower(substr($source, -3)), 'zip') === 0);
586 if ($isZip) {
587 // unzip file
588 $this->domain->resources()->zip()->unzipFile($source);
589
590 // determine filenames of xml files
591 $subdir = basename($source, ".zip");
592 $source = dirname($source) . "/" . $subdir . "/" . $subdir . ".xml";
593 }
594
595 $fh = fopen($source, 'rb') or die("");
596 $xml = fread($fh, filesize($source));
597 fclose($fh) or die("");
598 if ($isZip) {
599 $subdir = basename($source, ".zip");
600 if (is_dir(dirname($source) . "/" . $subdir)) {
601 ilFileUtils::delDir(dirname($source) . "/" . $subdir);
602 }
603 }
604 if (strpos($xml, "questestinterop") > 0) {
605 throw new ilInvalidSurveyImportFileException("Unsupported survey version (< 3.8) found.");
606 }
607
608 // survey questions for ILIAS >= 3.8
609 $import = new SurveyImportParser($this->getId(), "", $spl_exists);
610 $import->setXMLContent($xml);
611 $import->startParsing();
612 }
613 }
614
615 public static function _lookupOnline(int $a_obj_id): bool
616 {
617 return !self::getOfflineStatus($a_obj_id);
618 }
619
624 public static function _isWriteable(
625 int $object_id
626 ): bool {
627 global $DIC;
628
629 $rbacsystem = $DIC->rbac()->system();
630 $refs = ilObject::_getAllReferences($object_id);
631 $result = false;
632 foreach ($refs as $ref) {
633 if ($rbacsystem->checkAccess("write", $ref) && (ilObject::_hasUntrashedReference($object_id))) {
634 $result = true;
635 }
636 }
637 return $result;
638 }
639
644 public static function _getQuestiontypes(): array
645 {
646 global $DIC;
647
648 $ilDB = $DIC->database();
649 $lng = $DIC->language();
650
651 $lng->loadLanguageModule("survey");
652 $types = array();
653 $query_result = $ilDB->query("SELECT * FROM svy_qtype ORDER BY type_tag");
654 while ($row = $ilDB->fetchAssoc($query_result)) {
655 //array_push($questiontypes, $row["type_tag"]);
656 if ((int) $row["plugin"] === 0) {
657 $types[$lng->txt($row["type_tag"])] = $row;
658 }
659 }
660 ksort($types);
661
662
663 // #14263 - default sorting
664
665 $default_sorting = array_flip(array(
666 "SurveySingleChoiceQuestion",
667 "SurveyMultipleChoiceQuestion",
668 "SurveyMatrixQuestion",
669 "SurveyMetricQuestion",
670 "SurveyTextQuestion"
671 ));
672
673 $sorted = array();
674 $idx = count($default_sorting);
675 foreach ($types as $caption => $item) {
676 $type = $item["type_tag"];
677 $item["caption"] = $caption;
678
679 // default
680 if (array_key_exists($type, $default_sorting)) {
681 $sorted[$default_sorting[$type]] = $item;
682 }
683 // plugin (append alphabetically sorted)
684 else {
685 $sorted[$idx] = $item;
686 $idx++;
687 }
688 }
689 ksort($sorted);
690
691 // redo captions as index
692 $types = array();
693 foreach ($sorted as $item) {
694 $types[$item["caption"]] = $item;
695 }
696
697 return $types;
698 }
699
700 public static function _getQuestionClasses(): array
701 {
702 $classes = array_map(
703 static function (array $c): string {
704 return $c["type_tag"];
705 },
706 self::_getQuestiontypes()
707 );
708 return $classes;
709 }
710
714 public static function _getQuestionTypeTranslations(): array
715 {
716 global $DIC;
717
718 $ilDB = $DIC->database();
719 $lng = $DIC->language();
720
721 $component_factory = $DIC["component.factory"];
722
723 $lng->loadLanguageModule("survey");
724 $result = $ilDB->query("SELECT * FROM svy_qtype");
725 $types = array();
726 while ($row = $ilDB->fetchAssoc($result)) {
727 if ((int) $row["plugin"] === 0) {
728 $types[$row['type_tag']] = $lng->txt($row["type_tag"]);
729 }
730 }
731 ksort($types);
732 return $types;
733 }
734
739 public static function _getAvailableQuestionpools(
740 bool $use_object_id = false,
741 bool $could_be_offline = false,
742 bool $showPath = false,
743 string $permission = "read"
744 ): array {
745 global $DIC;
746
747 $ilUser = $DIC->user();
748 global $DIC;
749
750 $ilDB = $DIC->database();
751
752 $result_array = array();
753 $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
754 $titles = ilObject::_prepareCloneSelection($qpls, "spl", $showPath);
755 $allqpls = array();
756 $result = $ilDB->query("SELECT sq.obj_fi, od.offline as offline FROM svy_qpl sq JOIN object_data od ON (sq.obj_fi = od.obj_id) WHERE sq.obj_fi > 0 AND sq.tstamp > 0 AND NOT(od.offline = 1)");
757 while ($row = $ilDB->fetchAssoc($result)) {
758 $allqpls[$row['obj_fi']] = !($row['offline']);
759 }
760 foreach ($qpls as $ref_id) {
762 if ($could_be_offline || ($allqpls[$obj_id] ?? 0) == 1) {
763 if ($use_object_id) {
764 $result_array[$obj_id] = $titles[$ref_id];
765 } else {
766 $result_array[(int) $ref_id] = $titles[$ref_id];
767 }
768 }
769 }
770 return $result_array;
771 }
772
779 public function getQuestionInfos(array $question_ids): array
780 {
781 $ilDB = $this->db;
782
783 $found = array();
784 $query_result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
785 "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
786 "AND svy_question.tstamp > 0 AND " . $ilDB->in('svy_question.question_id', $question_ids, false, 'integer') . " " .
787 "ORDER BY svy_question.title");
788 if ($query_result->numRows() > 0) {
789 while ($data = $ilDB->fetchAssoc($query_result)) {
790 if (in_array($data["question_id"], $question_ids)) {
791 $found[] = array('id' => $data["question_id"],
792 'title' => $data["title"],
793 'description' => $data["description"],
794 'type_tag' => $data["type_tag"]
795 );
796 }
797 }
798 }
799 return $found;
800 }
801
805 public function purgeQuestions(): void
806 {
807 $ilDB = $this->db;
808 $ilUser = $this->user;
809
810 $result = $ilDB->queryF(
811 "SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
812 array("integer", "integer"),
813 array($ilUser->getId(), 0)
814 );
815 while ($data = $ilDB->fetchAssoc($result)) {
816 $this->removeQuestion($data["question_id"]);
817 }
818 }
819
824 public function copyToClipboard(
825 int $question_id
826 ): void {
827 $this->edit_manager->addQuestionToClipboard($question_id, "copy");
828 }
829
833 public function moveToClipboard(
834 int $question_id
835 ): void {
836 $this->edit_manager->addQuestionToClipboard($question_id, "move");
837 }
838
842 public function pasteFromClipboard(): void
843 {
844 $ilDB = $this->db;
845
846 $qentries = $this->edit_manager->getQuestionsFromClipboard();
847 if (count($qentries) > 0) {
848 foreach ($qentries as $question_object) {
849 if (strcmp($question_object["action"], "move") === 0) {
850 $result = $ilDB->queryF(
851 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
852 array('integer'),
853 array($question_object["question_id"])
854 );
855 if ($result->numRows() === 1) {
856 $row = $ilDB->fetchAssoc($result);
857 $source_questionpool = $row["obj_fi"];
858 if ($this->getId() != $source_questionpool) {
859 // change the questionpool id in the qpl_questions table
860 $affectedRows = $ilDB->manipulateF(
861 "UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
862 array('integer','integer'),
863 array($this->getId(), $question_object["question_id"])
864 );
865
866 // move question data to the new target directory
867 $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
868 if (is_dir($source_path)) {
869 $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/";
870 if (!is_dir($target_path)) {
871 ilFileUtils::makeDirParents($target_path);
872 }
873 ilFileUtils::rename($source_path, $target_path . $question_object["question_id"]);
874 }
875 } else {
876 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("spl_move_same_pool"), true);
877 return;
878 }
879 }
880 } else {
881 $this->copyQuestion($question_object["question_id"], $this->getId());
882 }
883 }
884 }
885 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("spl_paste_success"), true);
886 $this->edit_manager->clearClipboardQuestions();
887 }
888
892 public function setObligatoryStates(
893 array $obligatory_questions
894 ): void {
895 $ilDB = $this->db;
896 foreach ($this->getQuestions() as $question_id) {
897 $status = (int) (isset($obligatory_questions["$question_id"]));
898
899 $ilDB->manipulate("UPDATE svy_question" .
900 " SET obligatory = " . $ilDB->quote($status, "integer") .
901 " WHERE question_id = " . $ilDB->quote($question_id, "integer"));
902 }
903 }
904}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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 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...
Class ilObjSurveyQuestionPool.
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
__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.
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.
paste(int $question_id)
Pastes a duplicate of a question in the question pool.
User class.
Class ilObject Basic functions for all objects.
static _lookupObjectId(int $ref_id)
cloneMetaData(ilObject $target_obj)
Copy meta data.
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...
const CLIENT_WEB_DIR
Definition: constants.php:47
$c
Definition: deliver.php:25
Readable part of repository interface to ilComponentDataDB.
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$counter