ILIAS  release_8 Revision v8.24
class.SurveyQuestion.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ?int $original_id;
28 protected \ILIAS\SurveyQuestionPool\Editing\EditSessionRepository $edit_manager;
29 protected ilObjUser $user;
30 protected ilDBInterface $db;
31 public int $id;
32 public string $title;
33 public string $description;
34 public int $owner;
35 public string $author;
36 public array $materials;
37 public int $survey_id;
38 public int $obj_id;
39 public string $questiontext;
40 public bool $obligatory;
42 public int $orientation; // 0 = vertical, 1 = horizontal
44 public array $material;
45 public bool $complete;
46 protected array $cumulated;
47 private array $arrData; // question data
48 protected ilLogger $log;
49
50 protected \ILIAS\SurveyQuestionPool\Export\ImportSessionRepository $import_manager;
51
52 public function __construct(
53 string $title = "",
54 string $description = "",
55 string $author = "",
56 string $questiontext = "",
57 int $owner = -1
58 ) {
59 global $DIC;
60
61 $this->user = $DIC->user();
62 $this->db = $DIC->database();
63 $lng = $DIC->language();
64 $ilUser = $DIC->user();
65
66 $this->lng = $lng;
67 $this->complete = 0;
68 $this->title = $title;
69 $this->description = $description;
70 $this->questiontext = $questiontext;
71 $this->author = $author;
72 $this->cumulated = array();
73 if (!$this->author) {
74 $this->author = $ilUser->fullname;
75 }
76 $this->owner = $owner;
77 if ($this->owner === -1) {
78 $this->owner = $ilUser->getId();
79 }
80 $this->id = -1;
81 $this->survey_id = -1;
82 $this->obligatory = 1;
83 $this->orientation = 0;
84 $this->materials = array();
85 $this->material = array();
86 $this->arrData = array();
87
88 $this->log = ilLoggerFactory::getLogger('svy');
89 $this->import_manager = $DIC->surveyQuestionPool()
90 ->internal()
91 ->repo()
92 ->import();
93
94 $this->edit_manager = $DIC->surveyQuestionPool()
95 ->internal()
96 ->repo()
97 ->editing();
98 }
99
100 public function setComplete(bool $a_complete): void
101 {
102 $this->complete = $a_complete;
103 }
104
105 public function isComplete(): bool
106 {
107 return false;
108 }
109
110 public function questionTitleExists(
111 string $title,
112 int $questionpool_object = 0
113 ): bool {
114 $ilDB = $this->db;
115
116 $refwhere = "";
117 if ($questionpool_object > 0) {
118 $refwhere = sprintf(
119 " AND obj_fi = %s",
120 $ilDB->quote($questionpool_object, 'integer')
121 );
122 }
123 $result = $ilDB->queryF(
124 "SELECT question_id FROM svy_question WHERE title = %s$refwhere",
125 array('text'),
126 array($title)
127 );
128 return $result->numRows() > 0;
129 }
130
131 public function setTitle(string $title = ""): void
132 {
133 $this->title = $title;
134 }
135
136 public function setObligatory(bool $obligatory = true): void
137 {
138 $this->obligatory = $obligatory;
139 }
140
141 public function setOrientation(int $orientation = 0): void
142 {
143 $this->orientation = $orientation;
144 }
145
146 public function setId(int $id = -1): void
147 {
148 $this->id = $id;
149 }
150
151 public function setSurveyId(int $id = -1): void
152 {
153 $this->survey_id = $id;
154 }
155
156 public function setDescription(string $description = ""): void
157 {
158 $this->description = $description;
159 }
160
161 public function addMaterials(
162 string $materials_file,
163 string $materials_name = ""
164 ): void {
165 if (empty($materials_name)) {
166 $materials_name = $materials_file;
167 }
168 if ((!empty($materials_name)) && (!array_key_exists($materials_name, $this->materials))) {
169 $this->materials[$materials_name] = $materials_file;
170 }
171 }
172
176 public function setMaterialsfile(
177 string $materials_filename,
178 string $materials_tempfilename = "",
179 string $materials_name = ""
180 ): void {
181 if (!empty($materials_filename)) {
182 $materialspath = $this->getMaterialsPath();
183 if (!file_exists($materialspath)) {
184 ilFileUtils::makeDirParents($materialspath);
185 }
187 $materials_tempfilename,
188 $materials_filename,
189 $materialspath . $materials_filename
190 )) {
191 print "image not uploaded!!!! ";
192 } else {
193 $this->addMaterials($materials_filename, $materials_name);
194 }
195 }
196 }
197
198 public function deleteMaterial(
199 string $materials_name = ""
200 ): void {
201 foreach ($this->materials as $key => $value) {
202 if (strcmp($key, $materials_name) === 0) {
203 if (file_exists($this->getMaterialsPath() . $value)) {
204 unlink($this->getMaterialsPath() . $value);
205 }
206 unset($this->materials[$key]);
207 }
208 }
209 }
210
215 public function flushMaterials(): void
216 {
217 $this->materials = array();
218 }
219
220 public function setAuthor(string $author = ""): void
221 {
222 $ilUser = $this->user;
223
224 if (!$author) {
225 $author = $ilUser->fullname;
226 }
227 $this->author = $author;
228 }
229
230 public function setQuestiontext(string $questiontext = ""): void
231 {
232 $this->questiontext = $questiontext;
233 }
234
238 public function setOwner(int $owner = 0): void
239 {
240 $this->owner = $owner;
241 }
242
243 public function getTitle(): string
244 {
245 return $this->title;
246 }
247
248 public function getLabel(): string
249 {
250 return $this->label;
251 }
252
253 public function getId(): int
254 {
255 return $this->id;
256 }
257
258 public function getObligatory(): bool
259 {
260 return $this->obligatory;
261 }
262
263 public function getSurveyId(): int
264 {
265 return $this->survey_id;
266 }
267
271 public function getOrientation(): int
272 {
273 switch ($this->orientation) {
274 case 0:
275 case 1:
276 case 2:
277 break;
278 default:
279 $this->orientation = 0;
280 break;
281 }
282 return $this->orientation;
283 }
284
285
286 public function getDescription(): string
287 {
288 return $this->description;
289 }
290
291 public function getAuthor(): string
292 {
293 return $this->author;
294 }
295
296 public function getOwner(): int
297 {
298 return $this->owner;
299 }
300
301 public function getQuestiontext(): string
302 {
303 return $this->questiontext;
304 }
305
309 public function getObjId(): int
310 {
311 return $this->obj_id;
312 }
313
317 public function setObjId(int $obj_id = 0): void
318 {
319 $this->obj_id = $obj_id;
320 }
321
322 public function duplicate(
323 bool $for_survey = true,
324 string $title = "",
325 string $author = "",
326 int $owner = 0,
327 int $a_survey_id = 0
328 ): ?int {
329 if ($this->getId() <= 0) {
330 // The question has not been saved. It cannot be duplicated
331 return null;
332 }
333 // duplicate the question in database
334 $clone = $this;
335 $original_id = $this->getId();
336 $clone->setId(-1);
337 if ($a_survey_id > 0) {
338 $clone->setObjId($a_survey_id);
339 }
340 if ($title) {
341 $clone->setTitle($title);
342 }
343 if ($author) {
344 $clone->setAuthor($author);
345 }
346 if ($owner) {
347 $clone->setOwner($owner);
348 }
349 if ($for_survey) {
350 $clone->saveToDb($original_id);
351 } else {
352 $clone->saveToDb();
353 }
354 // duplicate the materials
355 $clone->duplicateMaterials($original_id);
356 // copy XHTML media objects
357 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
358 return $clone->getId();
359 }
360
361 public function copyObject(
362 int $target_questionpool,
363 string $title = ""
364 ): ?int {
365 if ($this->getId() <= 0) {
366 // The question has not been saved. It cannot be copied
367 return null;
368 }
369 $clone = $this;
370 $original_id = self::_getOriginalId($this->getId(), false);
371 $clone->setId(-1);
372 $source_questionpool = $this->getObjId();
373 $clone->setObjId($target_questionpool);
374 if ($title) {
375 $clone->setTitle($title);
376 }
377
378 $clone->saveToDb();
379
380 // duplicate the materials
381 $clone->duplicateMaterials($original_id);
382 // copy XHTML media objects
383 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
384 return $clone->getId();
385 }
386
391 int $a_q_id
392 ): void {
393 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
394 foreach ($mobs as $mob) {
395 ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
396 }
397 }
398
403 public function loadFromDb(int $question_id): void
404 {
405 $ilDB = $this->db;
406
407 $result = $ilDB->queryF(
408 "SELECT * FROM svy_material WHERE question_fi = %s",
409 array('integer'),
410 array($this->getId())
411 );
412 $this->material = array();
413 if ($result->numRows()) {
414 while ($row = $ilDB->fetchAssoc($result)) {
415 $mat = new ilSurveyMaterial();
416 $mat->type = (string) $row['material_type'];
417 $mat->internal_link = (string) $row['internal_link'];
418 $mat->title = (string) $row['material_title'];
419 $mat->import_id = (string) $row['import_id'];
420 $mat->text_material = (string) $row['text_material'];
421 $mat->external_link = (string) $row['external_link'];
422 $mat->file_material = (string) $row['file_material'];
423 $this->material[] = $mat;
424 }
425 }
426 }
427
431 public static function _isComplete(int $question_id): bool
432 {
433 global $DIC;
434
435 $ilDB = $DIC->database();
436
437 $result = $ilDB->queryF(
438 "SELECT complete FROM svy_question WHERE question_id = %s",
439 array('integer'),
440 array($question_id)
441 );
442 if ($result->numRows()) {
443 $row = $ilDB->fetchAssoc($result);
444 if ((int) $row["complete"] === 1) {
445 return true;
446 }
447 }
448 return false;
449 }
450
454 public function saveCompletionStatus(
455 int $original_id = 0
456 ): void {
457 $ilDB = $this->db;
458
459 $question_id = $this->getId();
460 if ($original_id > 0) {
461 $question_id = $original_id;
462 }
463
464 if ($this->getId() > 0) {
465 $this->log->debug("UPDATE svy_question question_id=" . $question_id);
466
467 // update existing dataset
468 $affectedRows = $ilDB->manipulateF(
469 "UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
470 array('text', 'integer', 'integer'),
471 array($this->isComplete(), time(), $question_id)
472 );
473 }
474 }
475
479 public function saveToDb(int $original_id = 0): int
480 {
481 $ilDB = $this->db;
482
483 // cleanup RTE images which are not inserted into the question text
484 ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
485 $affectedRows = 0;
486 if ($this->getId() === -1) {
487 // Write new dataset
488 $next_id = $ilDB->nextId('svy_question');
489 $affectedRows = $ilDB->insert("svy_question", array(
490 "question_id" => array("integer", $next_id),
491 "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
492 "obj_fi" => array("integer", $this->getObjId()),
493 "owner_fi" => array("integer", $this->getOwner()),
494 "title" => array("text", $this->getTitle()),
495 "label" => array("text", (strlen($this->label)) ? $this->label : null),
496 "description" => array("text", $this->getDescription()),
497 "author" => array("text", $this->getAuthor()),
498 "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
499 "obligatory" => array("text", $this->getObligatory()),
500 "complete" => array("text", $this->isComplete()),
501 "created" => array("integer", time()),
502 "original_id" => array("integer", ($original_id) ?: null),
503 "tstamp" => array("integer", time())
504 ));
505
506 //$this->log->debug("INSERT: svy_question id=".$next_id." questiontype_fi=".$this->getQuestionTypeID()." obj_fi".$this->getObjId()." title=".$this->getTitle()." ...");
507
508 $this->setId($next_id);
509 } else {
510 // update existing dataset
511 $affectedRows = $ilDB->update("svy_question", array(
512 "title" => array("text", $this->getTitle()),
513 "label" => array("text", (strlen($this->label)) ? $this->label : null),
514 "description" => array("text", $this->getDescription()),
515 "author" => array("text", $this->getAuthor()),
516 "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
517 "obligatory" => array("text", $this->getObligatory()),
518 "complete" => array("text", $this->isComplete()),
519 "tstamp" => array("integer", time())
520 ), array(
521 "question_id" => array("integer", $this->getId())
522 ));
523
524 $this->log->debug("UPDATE svy_question id=" . $this->getId() . " SET: title=" . $this->getTitle() . " ...");
525 }
526 return $affectedRows;
527 }
528
529 public function saveMaterial(): void
530 {
531 $ilDB = $this->db;
532
533 $this->log->debug("DELETE: svy_material question_fi=" . $this->getId());
534
535 $affectedRows = $ilDB->manipulateF(
536 "DELETE FROM svy_material WHERE question_fi = %s",
537 array('integer'),
538 array($this->getId())
539 );
541
542 foreach ($this->material as $material) {
543 $next_id = $ilDB->nextId('svy_material');
544
545 $this->log->debug("INSERT: svy_material question_fi=" . $this->getId());
546
547 $affectedRows = $ilDB->manipulateF(
548 "INSERT INTO svy_material " .
549 "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
550 "text_material, external_link, file_material, material_type) " .
551 "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
552 array('integer','integer','text','text','text','integer','text','text','text','integer'),
553 array(
554 $next_id, $this->getId(), $material->internal_link, $material->import_id,
555 $material->title, time(), $material->text_material, $material->external_link,
556 $material->file_material, $material->type)
557 );
558 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches)) {
559 ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], (int) $matches[3], (int) $matches[1]);
560 }
561 }
562 }
563
569 public function createNewQuestion(): int
570 {
571 $ilDB = $this->db;
572
573 $obj_id = $this->getObjId();
574 if ($obj_id > 0) {
575 $next_id = $ilDB->nextId('svy_question');
576 $affectedRows = $ilDB->manipulateF(
577 "INSERT INTO svy_question (question_id, questiontype_fi, " .
578 "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
579 "created, original_id, tstamp) VALUES " .
580 "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
581 array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
582 'text', 'text', 'integer', 'integer', 'integer'),
583 array(
584 $next_id,
585 $this->getQuestionTypeID(),
586 $obj_id,
587 $this->getOwner(),
588 null,
589 null,
590 $this->getAuthor(),
591 null,
592 "1",
593 "0",
594 time(),
595 null,
596 0
597 )
598 );
599 $this->log->debug("INSERT INTO svy_question question_id= " . $next_id . " questiontype_fi= " . $this->getQuestionTypeID());
600
601 $this->setId($next_id);
602 }
603 return $this->getId();
604 }
605
609 public function getImagePath(): string
610 {
611 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
612 }
613
617 public function getMaterialsPath(): string
618 {
619 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
620 }
621
625 public function getImagePathWeb(): string
626 {
627 $webdir = ilFileUtils::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
628 return str_replace(
631 $webdir
632 );
633 }
634
638 public function getMaterialsPathWeb(): string
639 {
640 $webdir = ilFileUtils::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
641 return str_replace(
644 $webdir
645 );
646 }
647
651 public function saveCategoryToDb(
652 string $categorytext,
653 int $neutral = 0
654 ): int {
655 $ilUser = $this->user;
656 $ilDB = $this->db;
657
658 $result = $ilDB->queryF(
659 "SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
660 array('text','text','integer'),
661 array($categorytext, $neutral, $ilUser->getId())
662 );
663 $insert = false;
664 $returnvalue = "";
665 $insert = true;
666 if ($result->numRows()) {
667 while ($row = $ilDB->fetchAssoc($result)) {
668 if (strcmp($row["title"], $categorytext) === 0) {
669 $returnvalue = $row["category_id"];
670 $insert = false;
671 }
672 }
673 }
674 if ($insert) {
675 $next_id = $ilDB->nextId('svy_category');
676 $affectedRows = $ilDB->manipulateF(
677 "INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
678 array('integer','text','text','integer','integer'),
679 array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
680 );
681
682 $this->log->debug("INSERT INTO svy_category id=" . $next_id);
683
684 $returnvalue = $next_id;
685 }
686 return $returnvalue;
687 }
688
692 public function deleteAdditionalTableData(int $question_id): void
693 {
694 $ilDB = $this->db;
695
696 $this->log->debug("DELETE FROM " . $this->getAdditionalTableName());
697
698 $ilDB->manipulateF(
699 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
700 array('integer'),
701 array($question_id)
702 );
703 }
704
708 public function delete(int $question_id): void
709 {
710 $ilDB = $this->db;
711 $this->log->debug("Question Delete... " . $question_id);
712 if ($question_id < 1) {
713 return;
714 }
715
716 $result = $ilDB->queryF(
717 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
718 array('integer'),
719 array($question_id)
720 );
721 if ($result->numRows() === 1) {
722 $row = $ilDB->fetchAssoc($result);
723 $obj_id = $row["obj_fi"];
724 } else {
725 return;
726 }
727
728 $affectedRows = $ilDB->manipulateF(
729 "DELETE FROM svy_answer WHERE question_fi = %s",
730 array('integer'),
731 array($question_id)
732 );
733
734 $affectedRows = $ilDB->manipulateF(
735 "DELETE FROM svy_constraint WHERE question_fi = %s",
736 array('integer'),
737 array($question_id)
738 );
739
740 $result = $ilDB->queryF(
741 "SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
742 array('integer'),
743 array($question_id)
744 );
745 while ($row = $ilDB->fetchObject($result)) {
746 $affectedRows = $ilDB->manipulateF(
747 "DELETE FROM svy_constraint WHERE constraint_id = %s",
748 array('integer'),
749 array($row->constraint_fi)
750 );
751 }
752
753 $affectedRows = $ilDB->manipulateF(
754 "DELETE FROM svy_qst_constraint WHERE question_fi = %s",
755 array('integer'),
756 array($question_id)
757 );
758 $affectedRows = $ilDB->manipulateF(
759 "DELETE FROM svy_qblk_qst WHERE question_fi = %s",
760 array('integer'),
761 array($question_id)
762 );
763 $affectedRows = $ilDB->manipulateF(
764 "DELETE FROM svy_svy_qst WHERE question_fi = %s",
765 array('integer'),
766 array($question_id)
767 );
768 $affectedRows = $ilDB->manipulateF(
769 "DELETE FROM svy_variable WHERE question_fi = %s",
770 array('integer'),
771 array($question_id)
772 );
773 $affectedRows = $ilDB->manipulateF(
774 "DELETE FROM svy_question WHERE question_id = %s",
775 array('integer'),
776 array($question_id)
777 );
778
779 $this->deleteAdditionalTableData($question_id);
780
781 $affectedRows = $ilDB->manipulateF(
782 "DELETE FROM svy_material WHERE question_fi = %s",
783 array('integer'),
784 array($question_id)
785 );
786
787 $this->log->debug("SET OF DELETES svy_answer, svy_constraint, svy_qst_constraint, svy_qblk_qst, svy_qst_oblig, svy_svy_qst, svy_variable, svy_question, svy_material WHERE question_fi = " . $question_id);
788
789 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
790
791 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
792 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory)) {
793 ilFileUtils::delDir($directory);
794 }
795
796 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
797 // remaining usages are not in text anymore -> delete them
798 // and media objects (note: delete method of ilObjMediaObject
799 // checks whether object is used in another context; if yes,
800 // the object is not deleted!)
801 foreach ($mobs as $mob) {
802 ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
803 $mob_obj = new ilObjMediaObject($mob);
804 $mob_obj->delete();
805 }
806 $this->log->debug("Call ilSurveySkill::handleQuestionDeletion, q id: " . $question_id .
807 ", obj id: " . $obj_id);
808 ilSurveySkill::handleQuestionDeletion($question_id, $obj_id);
809
810 $this->log->debug("UPDATE svy_question");
811
812 // #12772 - untie question copies from pool question
813 $ilDB->manipulate("UPDATE svy_question" .
814 " SET original_id = NULL" .
815 " WHERE original_id = " . $ilDB->quote($question_id, "integer"));
816 }
817
821 public static function _getQuestionType(int $question_id): string
822 {
823 global $DIC;
824
825 $ilDB = $DIC->database();
826
827 if ($question_id < 1) {
828 return "";
829 }
830
831 $result = $ilDB->queryF(
832 "SELECT type_tag FROM svy_question, svy_qtype WHERE svy_question.question_id = %s AND svy_question.questiontype_fi = svy_qtype.questiontype_id",
833 array('integer'),
834 array($question_id)
835 );
836 if ($result->numRows() === 1) {
837 $data = $ilDB->fetchAssoc($result);
838 return $data["type_tag"];
839 } else {
840 return "";
841 }
842 }
843
847 public static function _getTitle(int $question_id): string
848 {
849 global $DIC;
850
851 $ilDB = $DIC->database();
852
853 $result = $ilDB->queryF(
854 "SELECT title FROM svy_question WHERE svy_question.question_id = %s",
855 array('integer'),
856 array($question_id)
857 );
858
859 if ($data = $ilDB->fetchAssoc($result)) {
860 return (string) $data["title"];
861 }
862 return "";
863 }
864
868 public static function _getOriginalId(
869 int $question_id,
870 bool $a_return_question_id_if_no_original = true
871 ): int {
872 global $DIC;
873
874 $ilDB = $DIC->database();
875 $result = $ilDB->queryF(
876 "SELECT * FROM svy_question WHERE question_id = %s",
877 array('integer'),
878 array($question_id)
879 );
880 if ($result->numRows() > 0) {
881 $row = $ilDB->fetchAssoc($result);
882 if ($row["original_id"] > 0) {
883 return (int) $row["original_id"];
884 } elseif ($a_return_question_id_if_no_original) { // #12419
885 return (int) $row["question_id"];
886 }
887 }
888 return 0;
889 }
890
891 public function syncWithOriginal(): void
892 {
893 $ilDB = $this->db;
894
895 if ($this->getOriginalId()) {
896 $id = $this->getId();
897 $original = $this->getOriginalId();
898
899 $this->setId($this->getOriginalId());
900 $this->setOriginalId(null);
901 $this->saveToDb();
902
903 $this->setId($id);
904 $this->setOriginalId($original);
905
906 $this->log->debug("DELETE FROM svy_material WHERE question_fi = " . $this->getOriginalId());
907
908 $affectedRows = $ilDB->manipulateF(
909 "DELETE FROM svy_material WHERE question_fi = %s",
910 array('integer'),
911 array($this->getOriginalId())
912 );
913 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
914 if (strlen($this->material["internal_link"])) {
915 $next_id = $ilDB->nextId('svy_material');
916 $affectedRows = $ilDB->manipulateF(
917 "INSERT INTO svy_material (material_id, question_fi, internal_link, import_id, material_title, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
918 array('integer', 'integer', 'text', 'text', 'text', 'integer'),
919 array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
920 );
921
922 $this->log->debug("INSERT svy_material material_id=" . $next_id . " question_fi=" . $this->getOriginalId());
923
924 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches)) {
925 ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
926 }
927 }
928 }
929 }
930
934 public function getPhrase(int $phrase_id): string
935 {
936 $ilDB = $this->db;
937
938 $result = $ilDB->queryF(
939 "SELECT title FROM svy_phrase WHERE phrase_id = %s",
940 array('integer'),
941 array($phrase_id)
942 );
943 if ($row = $ilDB->fetchAssoc($result)) {
944 return $row["title"];
945 }
946 return "";
947 }
948
952 public function phraseExists(string $title): bool
953 {
954 $ilUser = $this->user;
955 $ilDB = $this->db;
956
957 $result = $ilDB->queryF(
958 "SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
959 array('text', 'integer'),
960 array($title, $ilUser->getId())
961 );
962 return $result->numRows() > 0;
963 }
964
965 public static function _questionExists(int $question_id): bool
966 {
967 global $DIC;
968
969 $ilDB = $DIC->database();
970
971 if ($question_id < 1) {
972 return false;
973 }
974
975 $result = $ilDB->queryF(
976 "SELECT question_id FROM svy_question WHERE question_id = %s",
977 array('integer'),
978 array($question_id)
979 );
980 return $result->numRows() === 1;
981 }
982
983 public function addInternalLink(string $material_id): void
984 {
985 $material_title = "";
986 if ($material_id !== '') {
987 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches)) {
988 $type = $matches[1];
989 $target_id = $matches[2];
990 $material_title = $this->lng->txt("obj_$type") . ": ";
991 switch ($type) {
992 case "lm":
993 $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
994 $cont_obj = $cont_obj_gui->getObject();
995 $material_title .= $cont_obj->getTitle();
996 break;
997
998 case "pg":
1000 $cont_obj_gui = new ilObjLearningModuleGUI("", $lm_id, false);
1002 $cont_obj = $cont_obj_gui->getObject();
1003 $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1004 $material_title .= $pg_obj->getTitle();
1005 break;
1006
1007 case "st":
1009 $cont_obj_gui = new ilObjLearningModuleGUI("", $lm_id, false);
1011 $cont_obj = $cont_obj_gui->getObject();
1012 $st_obj = new ilStructureObject($cont_obj, $target_id);
1013 $material_title .= $st_obj->getTitle();
1014 break;
1015
1016 case "git":
1017 $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1018 break;
1019 case "mob":
1020 break;
1021 }
1022 }
1023
1024 $mat = new ilSurveyMaterial();
1025 $mat->type = 0;
1026 $mat->internal_link = $material_id;
1027 $mat->title = $material_title;
1028 $this->addMaterial($mat);
1029 $this->saveMaterial();
1030 }
1031 }
1032
1036 public function deleteMaterials(array $a_array): void
1037 {
1038 foreach ($a_array as $idx) {
1039 unset($this->material[$idx]);
1040 }
1041 $this->material = array_values($this->material);
1042 $this->saveMaterial();
1043 }
1044
1050 public function duplicateMaterials(int $question_id): void
1051 {
1052 foreach ($this->materials as $filename) {
1053 $materialspath = $this->getMaterialsPath();
1054 $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1055 if (!file_exists($materialspath)) {
1056 ilFileUtils::makeDirParents($materialspath);
1057 }
1058 if (!copy($materialspath_original . $filename, $materialspath . $filename)) {
1059 throw new ilSurveyException("Unable to duplicate materials.");
1060 }
1061 }
1062 }
1063
1064 public function addMaterial(ilSurveyMaterial $obj_material): void
1065 {
1066 $this->material[] = $obj_material;
1067 }
1068
1074 public function setMaterial(
1075 string $material_id = "",
1076 bool $is_import = false,
1077 string $material_title = ""
1078 ): void {
1079 if (strcmp($material_id, "") !== 0) {
1080 $import_id = "";
1081 if ($is_import) {
1082 $import_id = $material_id;
1083 $material_id = self::_resolveInternalLink($import_id);
1084 }
1085 if (strcmp($material_title, "") === 0) {
1086 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches)) {
1087 $type = $matches[1];
1088 $target_id = $matches[2];
1089 $material_title = $this->lng->txt("obj_$type") . ": ";
1090 switch ($type) {
1091 case "lm":
1092 $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1093 $cont_obj = $cont_obj_gui->getObject();
1094 $material_title .= $cont_obj->getTitle();
1095 break;
1096
1097 case "pg":
1099 $cont_obj_gui = new ilObjLearningModuleGUI("", $lm_id, false);
1101 $cont_obj = $cont_obj_gui->getObject();
1102 $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1103 $material_title .= $pg_obj->getTitle();
1104 break;
1105
1106 case "st":
1108 $cont_obj_gui = new ilObjLearningModuleGUI("", $lm_id, false);
1110 $cont_obj = $cont_obj_gui->getObject();
1111 $st_obj = new ilStructureObject($cont_obj, $target_id);
1112 $material_title .= $st_obj->getTitle();
1113 break;
1114
1115 case "git":
1116 $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1117 break;
1118 case "mob":
1119 break;
1120 }
1121 }
1122 }
1123 $this->material = array(
1124 "internal_link" => $material_id,
1125 "import_id" => $import_id,
1126 "title" => $material_title
1127 );
1128 }
1129 $this->saveMaterial();
1130 }
1131
1132 public static function _resolveInternalLink(
1133 string $internal_link
1134 ): string {
1135 $resolved_link = "";
1136 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches)) {
1137 switch ($matches[2]) {
1138 case "lm":
1139 $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1140 break;
1141 case "pg":
1142 $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1143 break;
1144 case "st":
1145 $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1146 break;
1147 case "git":
1148 $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1149 break;
1150 case "mob":
1151 $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1152 break;
1153 }
1154 if (strcmp($resolved_link, "") === 0) {
1155 $resolved_link = $internal_link;
1156 }
1157 } else {
1158 $resolved_link = $internal_link;
1159 }
1160 return $resolved_link;
1161 }
1162
1163 public static function _resolveIntLinks(
1164 int $question_id
1165 ): void {
1166 global $DIC;
1167
1168 $ilDB = $DIC->database();
1169 $resolvedlinks = 0;
1170 $result = $ilDB->queryF(
1171 "SELECT * FROM svy_material WHERE question_fi = %s",
1172 array('integer'),
1173 array($question_id)
1174 );
1175 if ($result->numRows()) {
1176 while ($row = $ilDB->fetchAssoc($result)) {
1177 $internal_link = $row["internal_link"];
1178 $resolved_link = self::_resolveInternalLink($internal_link);
1179 if (strcmp($internal_link, $resolved_link) !== 0) {
1180 // internal link was resolved successfully
1181 $affectedRows = $ilDB->manipulateF(
1182 "UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1183 array('text', 'integer', 'integer'),
1184 array($resolved_link, time(), $row["material_id"])
1185 );
1186 $resolvedlinks++;
1187 }
1188 }
1189 }
1190 if ($resolvedlinks) {
1191 // there are resolved links -> reenter theses links to the database
1192
1193 // delete all internal links from the database
1194 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1195
1196 $result = $ilDB->queryF(
1197 "SELECT * FROM svy_material WHERE question_fi = %s",
1198 array('integer'),
1199 array($question_id)
1200 );
1201 if ($result->numRows()) {
1202 while ($row = $ilDB->fetchAssoc($result)) {
1203 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches)) {
1204 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1205 }
1206 }
1207 }
1208 }
1209 }
1210
1211 public static function _getInternalLinkHref(
1212 string $target = "",
1213 int $a_parent_ref_id = null
1214 ): string {
1215 $linktypes = array(
1216 "lm" => "LearningModule",
1217 "pg" => "PageObject",
1218 "st" => "StructureObject",
1219 "git" => "GlossaryItem",
1220 "mob" => "MediaObject"
1221 );
1222 $href = "";
1223 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches)) {
1224 $type = $matches[1];
1225 $target_id = $matches[2];
1226 switch ($linktypes[$matches[1]]) {
1227 case "StructureObject":
1228 case "PageObject":
1229 case "GlossaryItem":
1230 case "LearningModule":
1231 $href = ilFileUtils::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1232 break;
1233 case "MediaObject":
1235 ILIAS_HTTP_PATH
1236 ) . "/ilias.php?baseClass=ilLMPresentationGUI&obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=" . $a_parent_ref_id . "&mob_id=" . $target_id;
1237 break;
1238 }
1239 }
1240 return $href;
1241 }
1242
1246 public static function _isWriteable(
1247 int $question_id,
1248 int $user_id
1249 ): bool {
1250 global $DIC;
1251
1252 $ilDB = $DIC->database();
1253
1254 if (($question_id < 1) || ($user_id < 1)) {
1255 return false;
1256 }
1257
1258 $result = $ilDB->queryF(
1259 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
1260 array('integer'),
1261 array($question_id)
1262 );
1263 if ($result->numRows() === 1) {
1264 $row = $ilDB->fetchAssoc($result);
1265 $qpl_object_id = $row["obj_fi"];
1266 return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id);
1267 }
1268
1269 return false;
1270 }
1271
1272 public function getQuestionTypeID(): int
1273 {
1274 $ilDB = $this->db;
1275 $result = $ilDB->queryF(
1276 "SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1277 array('text'),
1278 array($this->getQuestionType())
1279 );
1280 if ($result->numRows() === 1) {
1281 $row = $ilDB->fetchAssoc($result);
1282 return (int) $row["questiontype_id"];
1283 }
1284
1285 return 0;
1286 }
1287
1288 public function getQuestionType(): string
1289 {
1290 return "";
1291 }
1292
1297 public static function _includeClass(
1298 string $question_type,
1299 int $gui = 0
1300 ): bool {
1301 $type = $question_type;
1302 if ($gui === 1) {
1303 $type .= "GUI";
1304 } elseif ($gui === 2) {
1305 $type .= "Evaluation";
1306 }
1307 if (file_exists("./Modules/SurveyQuestionPool/Questions/class." . $type . ".php")) {
1308 return true;
1309 } else {
1310 global $DIC;
1311
1312 $component_factory = $DIC["component.factory"];
1313 foreach ($component_factory->getActivePluginsInSlot("svyq") as $pl) {
1314 if (strcmp($pl->getQuestionType(), $question_type) === 0) {
1315 return true;
1316 }
1317 }
1318 }
1319 return false;
1320 }
1321
1326 public static function _getQuestionTypeName(
1327 string $type_tag
1328 ): string {
1329 global $DIC;
1330
1331 if (file_exists("./Modules/SurveyQuestionPool/Questions/class." . $type_tag . ".php")) {
1332 $lng = $DIC->language();
1333 return $lng->txt($type_tag);
1334 } else {
1335 $component_factory = $DIC["component.factory"];
1336 foreach ($component_factory->getActivePluginsInSlot("svyq") as $pl) {
1337 if (strcmp($pl->getQuestionType(), $type_tag) === 0) {
1338 return $pl->getQuestionTypeTranslation();
1339 }
1340 }
1341 }
1342 return "";
1343 }
1344
1345
1349 public static function _instanciateQuestion(int $question_id): ?SurveyQuestion
1350 {
1351 $question_type = self::_getQuestionType($question_id);
1352 if ($question_type) {
1353 self::_includeClass($question_type);
1354 $question = new $question_type();
1355 $question->loadFromDb($question_id);
1356 return $question;
1357 }
1358 return null;
1359 }
1360
1364 public static function _instanciateQuestionGUI(
1365 int $question_id
1366 ): ?SurveyQuestionGUI {
1367 $question_type = self::_getQuestionType($question_id);
1368 if ($question_type) {
1369 self::_includeClass($question_type, 1);
1370 $guitype = $question_type . "GUI";
1371 $question = new $guitype($question_id);
1372 return $question;
1373 }
1374 return null;
1375 }
1376
1377 public static function _instanciateQuestionEvaluation(
1378 int $question_id,
1379 array $a_finished_ids = null
1381 $question = self::_instanciateQuestion($question_id);
1382 if (is_null($a_finished_ids)) {
1383 $a_finished_ids = [];
1384 }
1385 if ($question) {
1386 $question_type = self::_getQuestionType($question_id);
1387 self::_includeClass($question_type, 2);
1388 $class = $question_type . "Evaluation";
1389 $ev = new $class($question, $a_finished_ids);
1390 return $ev;
1391 }
1392 return null;
1393 }
1394
1398 public function isHTML(string $a_text): bool
1399 {
1400 if (preg_match("/<[^>]*?>/", $a_text)) {
1401 return true;
1402 }
1403
1404 return false;
1405 }
1406
1410 public function QTIMaterialToString(ilQTIMaterial $a_material): string
1411 {
1412 $svy_log = ilLoggerFactory::getLogger("svy");
1413 $svy_log->debug("material count: " . $a_material->getMaterialCount());
1414
1415 $result = "";
1416 for ($i = 0; $i < $a_material->getMaterialCount(); $i++) {
1417 $material = $a_material->getMaterial($i);
1418 if (strcmp($material["type"], "mattext") === 0) {
1419 $result .= $material["material"]->getContent();
1420 }
1421 if (strcmp($material["type"], "matimage") === 0) {
1422 $matimage = $material["material"];
1423 if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches)) {
1424 // import an mediaobject which was inserted using tiny mce
1425 $this->import_manager->addMob(
1426 $matimage->getLabel(),
1427 $matimage->getUri()
1428 );
1429 }
1430 }
1431 }
1432 return $result;
1433 }
1434
1438 public function addMaterialTag(
1439 ilXmlWriter $a_xml_writer,
1440 string $a_material,
1441 bool $close_material_tag = true,
1442 bool $add_mobs = true,
1443 ?array $a_attrs = null
1444 ): void {
1445 $a_xml_writer->xmlStartTag("material");
1446 $attrs = array(
1447 "type" => "text/plain"
1448 );
1449 if ($this->isHTML($a_material)) {
1450 $attrs["type"] = "text/xhtml";
1451 }
1452 if (is_array($a_attrs)) {
1453 $attrs = array_merge($attrs, $a_attrs);
1454 }
1455 $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1456
1457 if ($add_mobs) {
1458 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1459 foreach ($mobs as $mob) {
1460 $mob_obj = new ilObjMediaObject($mob);
1461 $imgattrs = array(
1462 "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1463 "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle(),
1464 "type" => "spl:html",
1465 "id" => $this->getId()
1466 );
1467 $a_xml_writer->xmlElement("matimage", $imgattrs, null);
1468 }
1469 }
1470 if ($close_material_tag) {
1471 $a_xml_writer->xmlEndTag("material");
1472 }
1473 }
1474
1478 public function prepareTextareaOutput(
1479 string $txt_output,
1480 bool $prepare_for_latex_output = false
1481 ): string {
1482 return ilLegacyFormElementsUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1483 }
1484
1488 public function getQuestionDataArray(int $id): array
1489 {
1490 return array();
1491 }
1492
1497 public function getWorkingDataFromUserInput(array $post_data): array
1498 {
1499 // overwrite in inherited classes
1500 $data = array();
1501 return $data;
1502 }
1503
1509 public function importAdditionalMetadata(array $a_meta): void
1510 {
1511 // overwrite in inherited classes
1512 }
1513
1517 public function importResponses(array $a_data): void
1518 {
1519 // overwrite in inherited classes
1520 }
1521
1525 public function importAdjectives(array $a_data): void
1526 {
1527 // overwrite in inherited classes
1528 }
1529
1533 public function importMatrix(array $a_data): void
1534 {
1535 // overwrite in inherited classes
1536 }
1537
1541 public function usableForPrecondition(): bool
1542 {
1543 // overwrite in inherited classes
1544 return false;
1545 }
1546
1550 public function getAvailableRelations(): array
1551 {
1552 // overwrite in inherited classes
1553 return array();
1554 }
1555
1559 public function getPreconditionOptions(): array
1560 {
1561 // overwrite in inherited classes
1562 return [];
1563 }
1564
1570 public function getPreconditionValueOutput(string $value): string
1571 {
1572 // overwrite in inherited classes
1573 return $value;
1574 }
1575
1580 string $default,
1581 string $title,
1582 string $variable
1583 ): ?ilFormPropertyGUI {
1584 // overwrite in inherited classes
1585 return null;
1586 }
1587
1588 public function setOriginalId(?int $original_id): void
1589 {
1590 $this->original_id = $original_id;
1591 }
1592
1593 public function getOriginalId(): ?int
1594 {
1595 return $this->original_id;
1596 }
1597
1598 public function getMaterial(): array
1599 {
1600 return $this->material;
1601 }
1602
1603 public function setSubtype(int $a_subtype): void
1604 {
1605 // do nothing
1606 }
1607
1608 public function getSubtype(): ?int
1609 {
1610 // do nothing
1611 return null;
1612 }
1613
1614 public function __get(string $value): ?string
1615 {
1616 switch ($value) {
1617 default:
1618 if (array_key_exists($value, $this->arrData)) {
1619 return (string) $this->arrData[$value];
1620 }
1621
1622 return null;
1623 }
1624 }
1625
1626 public function __set(string $key, string $value): void
1627 {
1628 switch ($key) {
1629 default:
1630 $this->arrData[$key] = $value;
1631 break;
1632 }
1633 }
1634
1638 public static function _changeOriginalId(
1639 int $a_question_id,
1640 int $a_original_id,
1641 int $a_object_id
1642 ): void {
1643 global $DIC;
1644
1645 $ilDB = $DIC->database();
1646
1647 $ilDB->manipulate("UPDATE svy_question" .
1648 " SET original_id = " . $ilDB->quote($a_original_id, "integer") . "," .
1649 " obj_fi = " . $ilDB->quote($a_object_id, "integer") .
1650 " WHERE question_id = " . $ilDB->quote($a_question_id, "integer"));
1651 }
1652
1653 public function getCopyIds(
1654 bool $a_group_by_survey = false
1655 ): array {
1656 $ilDB = $this->db;
1657
1658 $set = $ilDB->query("SELECT q.question_id,s.obj_fi" .
1659 " FROM svy_question q" .
1660 " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)" .
1661 " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)" .
1662 " WHERE original_id = " . $ilDB->quote($this->getId(), "integer"));
1663 $res = array();
1664 while ($row = $ilDB->fetchAssoc($set)) {
1665 if (!$a_group_by_survey) {
1666 $res[] = (int) $row["question_id"];
1667 } else {
1668 $res[$row["obj_fi"]][] = (int) $row["question_id"];
1669 }
1670 }
1671 return $res;
1672 }
1673
1674 public function hasCopies(): bool
1675 {
1676 return (bool) count($this->getCopyIds());
1677 }
1678
1679 public static function _lookupSurveyObjId(
1680 int $a_question_id
1681 ): ?int {
1682 global $DIC;
1683
1684 $ilDB = $DIC->database();
1685
1686 $set = $ilDB->query("SELECT svy_svy.obj_fi FROM svy_svy_qst" .
1687 " JOIN svy_svy ON (svy_svy.survey_id = svy_svy_qst.survey_fi)" .
1688 " WHERE svy_svy_qst.question_fi = " . $ilDB->quote($a_question_id, "integer"));
1689 $row = $ilDB->fetchAssoc($set);
1690 if ($ilDB->numRows($set)) {
1691 return (int) $row["obj_fi"];
1692 }
1693 return null;
1694 }
1695
1696 public static function lookupObjFi(
1697 int $a_qid
1698 ): ?int {
1699 global $DIC;
1700
1701 $ilDB = $DIC->database();
1702
1703 $set = $ilDB->query(
1704 "SELECT obj_fi FROM svy_question " .
1705 " WHERE question_id = " . $ilDB->quote($a_qid, "integer")
1706 );
1707 if ($rec = $ilDB->fetchAssoc($set)) {
1708 return (int) $rec["obj_fi"];
1709 }
1710 return null;
1711 }
1712
1717 public function stripSlashesAddSpaceFallback(string $a_str): string
1718 {
1719 $str = ilUtil::stripSlashes($a_str);
1720 if ($str !== $a_str) {
1721 $str = ilUtil::stripSlashes(str_replace("<", "< ", $a_str));
1722 }
1723 return $str;
1724 }
1725
1729 public static function getMaxSumScore(int $survey_id): int
1730 {
1731 return 0;
1732 }
1733}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$filename
Definition: buildRTE.php:78
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 ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importMatrix(array $a_data)
Import matrix rows from the question import file.
static getMaxSumScore(int $survey_id)
Get max sum score for specific survey (and this question type)
static _getTitle(int $question_id)
Returns the question title of a question with a given id.
copyObject(int $target_questionpool, string $title="")
ILIAS SurveyQuestionPool Editing EditSessionRepository $edit_manager
static _getOriginalId(int $question_id, bool $a_return_question_id_if_no_original=true)
Returns the original id of a question.
getCopyIds(bool $a_group_by_survey=false)
static _getInternalLinkHref(string $target="", int $a_parent_ref_id=null)
getQuestionDataArray(int $id)
Returns the question data.
stripSlashesAddSpaceFallback(string $a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
getObjId()
Get the reference(?) id of the container object.
setTitle(string $title="")
ILIAS SurveyQuestionPool Export ImportSessionRepository $import_manager
duplicateMaterials(int $question_id)
Duplicates the materials of a question.
deleteMaterials(array $a_array)
copyXHTMLMediaObjectsOfQuestion(int $a_q_id)
Copy media object usages from other question.
deleteAdditionalTableData(int $question_id)
Deletes datasets from the additional question table in the database.
static _resolveIntLinks(int $question_id)
static _resolveInternalLink(string $internal_link)
loadFromDb(int $question_id)
load question data into object note: this base implementation only loads the material data
static _lookupSurveyObjId(int $a_question_id)
createNewQuestion()
Creates a new question with a 0 timestamp when a new question is created This assures that an ID is g...
setMaterialsfile(string $materials_filename, string $materials_tempfilename="", string $materials_name="")
Uploads and adds a material.
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag an creates a text string.
getMaterialsPath()
Returns the materials path for web accessible materials of a question.
duplicate(bool $for_survey=true, string $title="", string $author="", int $owner=0, int $a_survey_id=0)
getPreconditionSelectValue(string $default, string $title, string $variable)
Creates a form property for the precondition value.
importResponses(array $a_data)
Import response data from the question import file.
getWorkingDataFromUserInput(array $post_data)
Creates the user data of the svy_answer table from the POST data.
getMaterialsPathWeb()
Returns the web image path for web accessable images of a question.
getImagePath()
Returns the image path for web accessible images of a question.
saveCategoryToDb(string $categorytext, int $neutral=0)
Saves a category to the database.
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.
deleteMaterial(string $materials_name="")
__set(string $key, string $value)
importAdditionalMetadata(array $a_meta)
Import additional meta data from the question import file.
setQuestiontext(string $questiontext="")
static _instanciateQuestionEvaluation(int $question_id, array $a_finished_ids=null)
setSubtype(int $a_subtype)
setDescription(string $description="")
static _isWriteable(int $question_id, int $user_id)
is question writeable by a certain user
static _includeClass(string $question_type, int $gui=0)
Include the php class file for a given question type.
getPreconditionOptions()
Returns the options for preconditions.
static _changeOriginalId(int $a_question_id, int $a_original_id, int $a_object_id)
Change original id of existing question in db.
saveToDb(int $original_id=0)
Saves a SurveyQuestion object to a database.
static lookupObjFi(int $a_qid)
addMaterial(ilSurveyMaterial $obj_material)
phraseExists(string $title)
Returns true if the phrase title already exists for the current user(!)
getPhrase(int $phrase_id)
Returns a phrase title for phrase id.
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
setOrientation(int $orientation=0)
static _questionExists(int $question_id)
static _getQuestionType(int $question_id)
Returns the question type of a question with a given id.
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1)
setOwner(int $owner=0)
static _instanciateQuestion(int $question_id)
Get question object.
getAvailableRelations()
Returns the available relations for the question.
addMaterials(string $materials_file, string $materials_name="")
setComplete(bool $a_complete)
setOriginalId(?int $original_id)
static _instanciateQuestionGUI(int $question_id)
Get question gui object.
usableForPrecondition()
Returns if the question is usable for preconditions.
getPreconditionValueOutput(string $value)
Returns the output for a precondition value.
flushMaterials()
Deletes all materials uris.
prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false)
Prepares string for a text area output in surveys.
static _isComplete(int $question_id)
Checks whether the question is complete or not.
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database.
isHTML(string $a_text)
setObligatory(bool $obligatory=true)
getImagePathWeb()
Returns the web image path for web accessible images of a question.
setAuthor(string $author="")
importAdjectives(array $a_data)
Import bipolar adjectives from the question import file.
addMaterialTag(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true, ?array $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
questionTitleExists(string $title, int $questionpool_object=0)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static removeTrailingPathSeparators(string $path)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
This class represents a property in a property form.
static _lookGlossaryTerm(int $term_id)
get glossary term
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _getIdForImportId(string $a_import_id)
get current object id for import id (static)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Class ilObjContentObjectGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
static _removeUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Remove usage of mob in another container.
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
static _isWriteable(int $object_id)
Returns true, if the question pool is writeable for the current user.
User class.
getMaterial(int $a_index)
static _cleanupMediaObjectUsage(string $a_text, string $a_usage_type, int $a_usage_id)
Synchronises appearances of media objects in $a_text with media object usage table.
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static handleQuestionDeletion(int $a_question_id, int $a_obj_id)
Remove question skill assignment.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
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
const IL_INST_ID
Definition: constants.php:40
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$mobs
Definition: imgupload.php:70
$ilUser
Definition: imgupload.php:34
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$i
Definition: metadata.php:41
string $key
Consumer key/client ID value.
Definition: System.php:193
$type
$lng