ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.SurveyQuestion.php
Go to the documentation of this file.
1<?php
2 /*
3 +----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +----------------------------------------------------------------------------+
22*/
23
35{
39 protected $user;
40
44 protected $db;
45
51 public $id;
52
58 public $title;
71 public $owner;
72
79 public $author;
80
86 public $materials;
87
93 public $survey_id;
94
100 public $obj_id;
101
108
115
121 public $tpl;
122
128 public $lng;
129
136
137 public $material;
138 public $complete;
139
143 protected $cumulated;
144
148 private $arrData;
149
153 protected $log;
154
165 public function __construct($title = "", $description = "", $author = "", $questiontext = "", $owner = -1)
166 {
167 global $DIC;
168
169 $this->user = $DIC->user();
170 $this->db = $DIC->database();
171 $lng = $DIC->language();
172 $tpl = $DIC["tpl"];
173 $ilUser = $DIC->user();
174
175 $this->lng = $lng;
176 $this->tpl = $tpl;
177 $this->complete = 0;
178 $this->title = $title;
179 $this->description = $description;
180 $this->questiontext = $questiontext;
181 $this->author = $author;
182 $this->cumulated = array();
183 if (!$this->author) {
184 $this->author = $ilUser->fullname;
185 }
186 $this->owner = $owner;
187 if ($this->owner == -1) {
188 $this->owner = $ilUser->getId();
189 }
190 $this->id = -1;
191 $this->survey_id = -1;
192 $this->obligatory = 1;
193 $this->orientation = 0;
194 $this->materials = array();
195 $this->material = array();
196 $this->arrData = array();
197
198 $this->log = ilLoggerFactory::getLogger('svy');
199 }
200
207 public function setComplete($a_complete)
208 {
209 $this->complete = ($a_complete) ? 1 : 0;
210 }
211
218 public function isComplete()
219 {
220 return 0;
221 }
222
231 public function questionTitleExists($title, $questionpool_object = "")
232 {
234
235 $refwhere = "";
236 if (strcmp($questionpool_object, "") != 0) {
237 $refwhere = sprintf(
238 " AND obj_fi = %s",
239 $ilDB->quote($questionpool_object, 'integer')
240 );
241 }
242 $result = $ilDB->queryF(
243 "SELECT question_id FROM svy_question WHERE title = %s$refwhere",
244 array('text'),
245 array($title)
246 );
247 return ($result->numRows() > 0) ? true : false;
248 }
249
257 public function setTitle($title = "")
258 {
259 $this->title = $title;
260 }
261
269 public function setObligatory($obligatory = 1)
270 {
271 $this->obligatory = ($obligatory) ? 1 : 0;
272 }
273
281 public function setOrientation($orientation = 0)
282 {
283 $this->orientation = ($orientation) ? $orientation : 0;
284 }
285
293 public function setId($id = -1)
294 {
295 $this->id = $id;
296 }
297
305 public function setSurveyId($id = -1)
306 {
307 $this->survey_id = $id;
308 }
309
317 public function setDescription($description = "")
318 {
319 $this->description = $description;
320 }
321
330 public function addMaterials($materials_file, $materials_name="")
331 {
332 if (empty($materials_name)) {
333 $materials_name = $materials_file;
334 }
335 if ((!empty($materials_name))&&(!array_key_exists($materials_name, $this->materials))) {
336 $this->materials[$materials_name] = $materials_file;
337 }
338 }
339
347 public function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
348 {
349 if (!empty($materials_filename)) {
350 $materialspath = $this->getMaterialsPath();
351 if (!file_exists($materialspath)) {
352 ilUtil::makeDirParents($materialspath);
353 }
354 if (ilUtil::moveUploadedFile(
355 $materials_tempfilename,
356 $materials_filename,
357 $materialspath . $materials_filename
358 )) {
359 print "image not uploaded!!!! ";
360 } else {
361 $this->addMaterials($materials_filename, $materials_name);
362 }
363 }
364 }
365
373 public function deleteMaterial($materials_name = "")
374 {
375 foreach ($this->materials as $key => $value) {
376 if (strcmp($key, $materials_name)==0) {
377 if (file_exists($this->getMaterialsPath() . $value)) {
378 unlink($this->getMaterialsPath() . $value);
379 }
380 unset($this->materials[$key]);
381 }
382 }
383 }
384
391 public function flushMaterials()
392 {
393 $this->materials = array();
394 }
395
403 public function setAuthor($author = "")
404 {
406
407 if (!$author) {
408 $author = $ilUser->fullname;
409 }
410 $this->author = $author;
411 }
412
420 public function setQuestiontext($questiontext = "")
421 {
422 $this->questiontext = $questiontext;
423 }
424
432 public function setOwner($owner = "")
433 {
434 $this->owner = $owner;
435 }
436
444 public function getTitle()
445 {
446 return $this->title;
447 }
448
449 public function getLabel()
450 {
451 return $this->label;
452 }
453
461 public function getId()
462 {
463 return $this->id;
464 }
465
472 public function getObligatory($survey_id = "")
473 {
474 return ($this->obligatory) ? 1 : 0;
475 }
476
484 public function getSurveyId()
485 {
486 return $this->survey_id;
487 }
488
496 public function getOrientation()
497 {
498 switch ($this->orientation) {
499 case 0:
500 case 1:
501 case 2:
502 break;
503 default:
504 $this->orientation = 0;
505 break;
506 }
507 return $this->orientation;
508 }
509
510
518 public function getDescription()
519 {
520 return (strlen($this->description)) ? $this->description : null;
521 }
522
530 public function getAuthor()
531 {
532 return (strlen($this->author)) ? $this->author : null;
533 }
534
542 public function getOwner()
543 {
544 return $this->owner;
545 }
546
554 public function getQuestiontext()
555 {
556 return (strlen($this->questiontext)) ? $this->questiontext : null;
557 }
558
566 public function getObjId()
567 {
568 return $this->obj_id;
569 }
570
578 public function setObjId($obj_id = 0)
579 {
580 $this->obj_id = $obj_id;
581 }
582
588 public function duplicate($for_survey = true, $title = "", $author = "", $owner = "", $a_survey_id = 0)
589 {
590 if ($this->getId() <= 0) {
591 // The question has not been saved. It cannot be duplicated
592 return;
593 }
594 // duplicate the question in database
595 $clone = $this;
596 $original_id = $this->getId();
597 $clone->setId(-1);
598 if ($a_survey_id > 0) {
599 $clone->setObjId($a_survey_id);
600 }
601 if ($title) {
602 $clone->setTitle($title);
603 }
604 if ($author) {
605 $clone->setAuthor($author);
606 }
607 if ($owner) {
608 $clone->setOwner($owner);
609 }
610 if ($for_survey) {
611 $clone->saveToDb($original_id);
612 } else {
613 $clone->saveToDb();
614 }
615 // duplicate the materials
616 $clone->duplicateMaterials($original_id);
617 // copy XHTML media objects
618 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
619 return $clone->getId();
620 }
621
627 public function copyObject($target_questionpool, $title = "")
628 {
629 if ($this->getId() <= 0) {
630 // The question has not been saved. It cannot be copied
631 return;
632 }
633 $clone = $this;
634 $original_id = self::_getOriginalId($this->getId(), false);
635 $clone->setId(-1);
636 $source_questionpool = $this->getObjId();
637 $clone->setObjId($target_questionpool);
638 if ($title) {
639 $clone->setTitle($title);
640 }
641
642 $clone->saveToDb();
643
644 // duplicate the materials
645 $clone->duplicateMaterials($original_id);
646 // copy XHTML media objects
647 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
648 return $clone->getId();
649 }
650
657 public function copyXHTMLMediaObjectsOfQuestion($a_q_id)
658 {
659 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
660 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
661 foreach ($mobs as $mob) {
662 ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
663 }
664 }
665
672 public function loadFromDb($question_id)
673 {
675
676 $result = $ilDB->queryF(
677 "SELECT * FROM svy_material WHERE question_fi = %s",
678 array('integer'),
679 array($this->getId())
680 );
681 $this->material = array();
682 if ($result->numRows()) {
683 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
684 while ($row = $ilDB->fetchAssoc($result)) {
685 $mat = new ilSurveyMaterial();
686 $mat->type = $row['material_type'];
687 $mat->internal_link = $row['internal_link'];
688 $mat->title = $row['material_title'];
689 $mat->import_id = $row['import_id'];
690 $mat->text_material = $row['text_material'];
691 $mat->external_link = $row['external_link'];
692 $mat->file_material = $row['file_material'];
693 array_push($this->material, $mat);
694 }
695 }
696 }
697
704 public static function _isComplete($question_id)
705 {
706 global $DIC;
707
708 $ilDB = $DIC->database();
709
710 $result = $ilDB->queryF(
711 "SELECT complete FROM svy_question WHERE question_id = %s",
712 array('integer'),
713 array($question_id)
714 );
715 if ($result->numRows()) {
716 $row = $ilDB->fetchAssoc($result);
717 if ($row["complete"] == 1) {
718 return true;
719 }
720 }
721 return false;
722 }
723
729 public function saveCompletionStatus($original_id = "")
730 {
732
733 $question_id = $this->getId();
734 if (strlen($original_id)) {
735 $question_id = $original_id;
736 }
737
738 if ($this->getId() > 0) {
739 $this->log->debug("UPDATE svy_question question_id=" . $question_id);
740
741 // update existing dataset
742 $affectedRows = $ilDB->manipulateF(
743 "UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
744 array('text', 'integer', 'integer'),
745 array($this->isComplete(), time(), $question_id)
746 );
747 }
748 }
749
756 public function saveToDb($original_id = "")
757 {
759
760 // cleanup RTE images which are not inserted into the question text
761 include_once("./Services/RTE/classes/class.ilRTE.php");
762 ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
763 $affectedRows = 0;
764 if ($this->getId() == -1) {
765 // Write new dataset
766 $next_id = $ilDB->nextId('svy_question');
767 $affectedRows = $ilDB->insert("svy_question", array(
768 "question_id" => array("integer", $next_id),
769 "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
770 "obj_fi" => array("integer", $this->getObjId()),
771 "owner_fi" => array("integer", $this->getOwner()),
772 "title" => array("text", $this->getTitle()),
773 "label" => array("text", (strlen($this->label)) ? $this->label : null),
774 "description" => array("text", $this->getDescription()),
775 "author" => array("text", $this->getAuthor()),
776 "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
777 "obligatory" => array("text", $this->getObligatory()),
778 "complete" => array("text", $this->isComplete()),
779 "created" => array("integer", time()),
780 "original_id" => array("integer", ($original_id) ? $original_id : null),
781 "tstamp" => array("integer", time())
782 ));
783
784 //$this->log->debug("INSERT: svy_question id=".$next_id." questiontype_fi=".$this->getQuestionTypeID()." obj_fi".$this->getObjId()." title=".$this->getTitle()." ...");
785
786 $this->setId($next_id);
787 } else {
788 // update existing dataset
789 $affectedRows = $ilDB->update("svy_question", array(
790 "title" => array("text", $this->getTitle()),
791 "label" => array("text", (strlen($this->label)) ? $this->label : null),
792 "description" => array("text", $this->getDescription()),
793 "author" => array("text", $this->getAuthor()),
794 "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
795 "obligatory" => array("text", $this->getObligatory()),
796 "complete" => array("text", $this->isComplete()),
797 "tstamp" => array("integer", time())
798 ), array(
799 "question_id" => array("integer", $this->getId())
800 ));
801
802 $this->log->debug("UPDATE svy_question id=" . $this->getId() . " SET: title=" . $this->getTitle() . " ...");
803 }
804
805 return $affectedRows;
806 }
807
811 public function saveMaterial()
812 {
814
815 include_once "./Services/Link/classes/class.ilInternalLink.php";
816
817 $this->log->debug("DELETE: svy_material question_fi=" . $this->getId());
818
819 $affectedRows = $ilDB->manipulateF(
820 "DELETE FROM svy_material WHERE question_fi = %s",
821 array('integer'),
822 array($this->getId())
823 );
825
826 foreach ($this->material as $material) {
827 $next_id = $ilDB->nextId('svy_material');
828
829 $this->log->debug("INSERT: svy_material question_fi=" . $this->getId());
830
831 $affectedRows = $ilDB->manipulateF(
832 "INSERT INTO svy_material " .
833 "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
834 "text_material, external_link, file_material, material_type) " .
835 "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
836 array('integer','integer','text','text','text','integer','text','text','text','integer'),
837 array(
838 $next_id, $this->getId(), $material->internal_link, $material->import_id,
839 $material->title, time(), $material->text_material, $material->external_link,
840 $material->file_material, $material->type)
841 );
842 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches)) {
843 ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
844 }
845 }
846 }
847
854 public function createNewQuestion()
855 {
857
858 $obj_id = $this->getObjId();
859 if ($obj_id > 0) {
860 $next_id = $ilDB->nextId('svy_question');
861 $affectedRows = $ilDB->manipulateF(
862 "INSERT INTO svy_question (question_id, questiontype_fi, " .
863 "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
864 "created, original_id, tstamp) VALUES " .
865 "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
866 array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
867 'text', 'text', 'integer', 'integer', 'integer'),
868 array(
869 $next_id,
870 $this->getQuestionTypeID(),
871 $obj_id,
872 $this->getOwner(),
873 null,
874 null,
875 $this->getAuthor(),
876 null,
877 "1",
878 "0",
879 time(),
880 null,
881 0
882 )
883 );
884 $this->log->debug("INSERT INTO svy_question question_id= " . $next_id . " questiontype_fi= " . $this->getQuestionTypeID());
885
886 $this->setId($next_id);
887 }
888 return $this->getId();
889 }
890
897 public function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
898 {
899 }
900
907 public function getImagePath()
908 {
909 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
910 }
911
918 public function getMaterialsPath()
919 {
920 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
921 }
922
929 public function getImagePathWeb()
930 {
931 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
932 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
933 }
934
941 public function getMaterialsPathWeb()
942 {
943 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
944 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
945 }
946
955 public function saveCategoryToDb($categorytext, $neutral = 0)
956 {
959
960 $result = $ilDB->queryF(
961 "SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
962 array('text','text','integer'),
963 array($categorytext, $neutral, $ilUser->getId())
964 );
965 $insert = false;
966 $returnvalue = "";
967 if ($result->numRows()) {
968 $insert = true;
969 while ($row = $ilDB->fetchAssoc($result)) {
970 if (strcmp($row["title"], $categorytext) == 0) {
971 $returnvalue = $row["category_id"];
972 $insert = false;
973 }
974 }
975 } else {
976 $insert = true;
977 }
978 if ($insert) {
979 $next_id = $ilDB->nextId('svy_category');
980 $affectedRows = $ilDB->manipulateF(
981 "INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
982 array('integer','text','text','integer','integer'),
983 array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
984 );
985
986 $this->log->debug("INSERT INTO svy_category id=" . $next_id);
987
988 $returnvalue = $next_id;
989 }
990 return $returnvalue;
991 }
992
999 public function deleteAdditionalTableData($question_id)
1000 {
1001 $ilDB = $this->db;
1002
1003 $this->log->debug("DELETE FROM " . $this->getAdditionalTableName());
1004
1005 $affectedRows = $ilDB->manipulateF(
1006 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1007 array('integer'),
1008 array($question_id)
1009 );
1010 }
1011
1018 public function delete($question_id)
1019 {
1020 $ilDB = $this->db;
1021
1022 if ($question_id < 1) {
1023 return;
1024 }
1025
1026 $result = $ilDB->queryF(
1027 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
1028 array('integer'),
1029 array($question_id)
1030 );
1031 if ($result->numRows() == 1) {
1032 $row = $ilDB->fetchAssoc($result);
1033 $obj_id = $row["obj_fi"];
1034 } else {
1035 return;
1036 }
1037
1038 $affectedRows = $ilDB->manipulateF(
1039 "DELETE FROM svy_answer WHERE question_fi = %s",
1040 array('integer'),
1041 array($question_id)
1042 );
1043
1044 $affectedRows = $ilDB->manipulateF(
1045 "DELETE FROM svy_constraint WHERE question_fi = %s",
1046 array('integer'),
1047 array($question_id)
1048 );
1049
1050 $result = $ilDB->queryF(
1051 "SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1052 array('integer'),
1053 array($question_id)
1054 );
1055 while ($row = $ilDB->fetchObject($result)) {
1056 $affectedRows = $ilDB->manipulateF(
1057 "DELETE FROM svy_constraint WHERE constraint_id = %s",
1058 array('integer'),
1059 array($row->constraint_fi)
1060 );
1061 }
1062
1063 $affectedRows = $ilDB->manipulateF(
1064 "DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1065 array('integer'),
1066 array($question_id)
1067 );
1068 $affectedRows = $ilDB->manipulateF(
1069 "DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1070 array('integer'),
1071 array($question_id)
1072 );
1073 $affectedRows = $ilDB->manipulateF(
1074 "DELETE FROM svy_svy_qst WHERE question_fi = %s",
1075 array('integer'),
1076 array($question_id)
1077 );
1078 $affectedRows = $ilDB->manipulateF(
1079 "DELETE FROM svy_variable WHERE question_fi = %s",
1080 array('integer'),
1081 array($question_id)
1082 );
1083 $affectedRows = $ilDB->manipulateF(
1084 "DELETE FROM svy_question WHERE question_id = %s",
1085 array('integer'),
1086 array($question_id)
1087 );
1088
1089 $this->deleteAdditionalTableData($question_id);
1090
1091 $affectedRows = $ilDB->manipulateF(
1092 "DELETE FROM svy_material WHERE question_fi = %s",
1093 array('integer'),
1094 array($question_id)
1095 );
1096
1097 $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);
1098
1099 include_once "./Services/Link/classes/class.ilInternalLink.php";
1100 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1101
1102 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1103 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory)) {
1104 ilUtil::delDir($directory);
1105 }
1106
1107 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1108 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1109 // remaining usages are not in text anymore -> delete them
1110 // and media objects (note: delete method of ilObjMediaObject
1111 // checks whether object is used in another context; if yes,
1112 // the object is not deleted!)
1113 foreach ($mobs as $mob) {
1114 ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1115 $mob_obj = new ilObjMediaObject($mob);
1116 $mob_obj->delete();
1117 }
1118
1119 include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1121
1122 $this->log->debug("UPDATE svy_question");
1123
1124 // #12772 - untie question copies from pool question
1125 $ilDB->manipulate("UPDATE svy_question" .
1126 " SET original_id = NULL" .
1127 " WHERE original_id = " . $ilDB->quote($question_id, "integer"));
1128 }
1129
1137 public static function _getQuestionType($question_id)
1138 {
1139 global $DIC;
1140
1141 $ilDB = $DIC->database();
1142
1143 if ($question_id < 1) {
1144 return "";
1145 }
1146
1147 $result = $ilDB->queryF(
1148 "SELECT type_tag FROM svy_question, svy_qtype WHERE svy_question.question_id = %s AND svy_question.questiontype_fi = svy_qtype.questiontype_id",
1149 array('integer'),
1150 array($question_id)
1151 );
1152 if ($result->numRows() == 1) {
1153 $data = $ilDB->fetchAssoc($result);
1154 return $data["type_tag"];
1155 } else {
1156 return "";
1157 }
1158 }
1159
1167 public static function _getTitle($question_id)
1168 {
1169 global $DIC;
1170
1171 $ilDB = $DIC->database();
1172
1173 if ($question_id < 1) {
1174 return "";
1175 }
1176
1177 $result = $ilDB->queryF(
1178 "SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1179 array('integer'),
1180 array($question_id)
1181 );
1182 if ($result->numRows() == 1) {
1183 $data = $ilDB->fetchAssoc($result);
1184 return $data["title"];
1185 } else {
1186 return "";
1187 }
1188 }
1189
1197 public static function _getOriginalId($question_id, $a_return_question_id_if_no_original = true)
1198 {
1199 global $DIC;
1200
1201 $ilDB = $DIC->database();
1202 $result = $ilDB->queryF(
1203 "SELECT * FROM svy_question WHERE question_id = %s",
1204 array('integer'),
1205 array($question_id)
1206 );
1207 if ($result->numRows() > 0) {
1208 $row = $ilDB->fetchAssoc($result);
1209 if ($row["original_id"] > 0) {
1210 return $row["original_id"];
1211 } elseif ((bool) $a_return_question_id_if_no_original) { // #12419
1212 return $row["question_id"];
1213 }
1214 } else {
1215 return "";
1216 }
1217 }
1218
1219 public function syncWithOriginal()
1220 {
1221 $ilDB = $this->db;
1222
1223 if ($this->getOriginalId()) {
1224 $id = $this->getId();
1225 $original = $this->getOriginalId();
1226
1227 $this->setId($this->getOriginalId());
1228 $this->setOriginalId(null);
1229 $this->saveToDb();
1230
1231 $this->setId($id);
1232 $this->setOriginalId($original);
1233
1234 $this->log->debug("DELETE FROM svy_material WHERE question_fi = " . $this->getOriginalId());
1235
1236 include_once "./Services/Link/classes/class.ilInternalLink.php";
1237 $affectedRows = $ilDB->manipulateF(
1238 "DELETE FROM svy_material WHERE question_fi = %s",
1239 array('integer'),
1240 array($this->getOriginalId())
1241 );
1242 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1243 if (strlen($this->material["internal_link"])) {
1244 $next_id = $ilDB->nextId('svy_material');
1245 $affectedRows = $ilDB->manipulateF(
1246 "INSERT INTO svy_material (material_id, question_fi, internal_link, import_id, material_title, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
1247 array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1248 array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1249 );
1250
1251 $this->log->debug("INSERT svy_material material_id=" . $next_id . " question_fi=" . $this->getOriginalId());
1252
1253 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches)) {
1254 ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1255 }
1256 }
1257 }
1258 }
1259
1266 public function getPhrase($phrase_id)
1267 {
1268 $ilDB = $this->db;
1269
1270 $result = $ilDB->queryF(
1271 "SELECT title FROM svy_phrase WHERE phrase_id = %s",
1272 array('integer'),
1273 array($phrase_id)
1274 );
1275 if ($row = $ilDB->fetchAssoc($result)) {
1276 return $row["title"];
1277 }
1278 return "";
1279 }
1280
1288 public function phraseExists($title)
1289 {
1291 $ilDB = $this->db;
1292
1293 $result = $ilDB->queryF(
1294 "SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1295 array('text', 'integer'),
1296 array($title, $ilUser->getId())
1297 );
1298 return ($result->numRows() == 0) ? false : true;
1299 }
1300
1308 public static function _questionExists($question_id)
1309 {
1310 global $DIC;
1311
1312 $ilDB = $DIC->database();
1313
1314 if ($question_id < 1) {
1315 return false;
1316 }
1317
1318 $result = $ilDB->queryF(
1319 "SELECT question_id FROM svy_question WHERE question_id = %s",
1320 array('integer'),
1321 array($question_id)
1322 );
1323 return ($result->numRows() == 1) ? true : false;
1324 }
1325
1326 public function addInternalLink($material_id, $title = "")
1327 {
1328 if (strlen($material_id)) {
1329 if (strcmp($material_title, "") == 0) {
1330 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches)) {
1331 $type = $matches[1];
1332 $target_id = $matches[2];
1333 $material_title = $this->lng->txt("obj_$type") . ": ";
1334 switch ($type) {
1335 case "lm":
1336 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1337 $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1338 $cont_obj = $cont_obj_gui->object;
1339 $material_title .= $cont_obj->getTitle();
1340 break;
1341 case "pg":
1342 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1343 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1345 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1346 $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1347 $cont_obj = $cont_obj_gui->object;
1348 $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1349 $material_title .= $pg_obj->getTitle();
1350 break;
1351 case "st":
1352 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1353 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1355 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1356 $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1357 $cont_obj = $cont_obj_gui->object;
1358 $st_obj = new ilStructureObject($cont_obj, $target_id);
1359 $material_title .= $st_obj->getTitle();
1360 break;
1361 case "git":
1362 include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1363 $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1364 break;
1365 case "mob":
1366 break;
1367 }
1368 }
1369 }
1370 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1371 $mat = new ilSurveyMaterial();
1372 $mat->type = 0;
1373 $mat->internal_link = $material_id;
1374 $mat->title = $material_title;
1375 $this->addMaterial($mat);
1376 $this->saveMaterial();
1377 }
1378 }
1379
1385 public function deleteMaterials($a_array)
1386 {
1387 foreach ($a_array as $idx) {
1388 unset($this->material[$idx]);
1389 }
1390 $this->material = array_values($this->material);
1391 $this->saveMaterial();
1392 }
1393
1400 public function duplicateMaterials($question_id)
1401 {
1402 foreach ($this->materials as $filename) {
1403 $materialspath = $this->getMaterialsPath();
1404 $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1405 if (!file_exists($materialspath)) {
1406 ilUtil::makeDirParents($materialspath);
1407 }
1408 if (!copy($materialspath_original . $filename, $materialspath . $filename)) {
1409 print "material could not be duplicated!!!! ";
1410 }
1411 }
1412 }
1413
1414 public function addMaterial($obj_material)
1415 {
1416 array_push($this->material, $obj_material);
1417 }
1418
1426 public function setMaterial($material_id = "", $is_import = false, $material_title = "")
1427 {
1428 if (strcmp($material_id, "") != 0) {
1429 $import_id = "";
1430 if ($is_import) {
1431 $import_id = $material_id;
1432 $material_id = self::_resolveInternalLink($import_id);
1433 }
1434 if (strcmp($material_title, "") == 0) {
1435 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches)) {
1436 $type = $matches[1];
1437 $target_id = $matches[2];
1438 $material_title = $this->lng->txt("obj_$type") . ": ";
1439 switch ($type) {
1440 case "lm":
1441 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1442 $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1443 $cont_obj = $cont_obj_gui->object;
1444 $material_title .= $cont_obj->getTitle();
1445 break;
1446 case "pg":
1447 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1448 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1450 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1451 $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1452 $cont_obj = $cont_obj_gui->object;
1453 $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1454 $material_title .= $pg_obj->getTitle();
1455 break;
1456 case "st":
1457 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1458 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1460 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1461 $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1462 $cont_obj = $cont_obj_gui->object;
1463 $st_obj = new ilStructureObject($cont_obj, $target_id);
1464 $material_title .= $st_obj->getTitle();
1465 break;
1466 case "git":
1467 include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1468 $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1469 break;
1470 case "mob":
1471 break;
1472 }
1473 }
1474 }
1475 $this->material = array(
1476 "internal_link" => $material_id,
1477 "import_id" => $import_id,
1478 "title" => $material_title
1479 );
1480 }
1481 $this->saveMaterial();
1482 }
1483
1484 public static function _resolveInternalLink($internal_link)
1485 {
1486 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches)) {
1487 include_once "./Services/Link/classes/class.ilInternalLink.php";
1488 include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1489 include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1490 switch ($matches[2]) {
1491 case "lm":
1492 $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1493 break;
1494 case "pg":
1495 $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1496 break;
1497 case "st":
1498 $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1499 break;
1500 case "git":
1501 $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1502 break;
1503 case "mob":
1504 $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1505 break;
1506 }
1507 if (strcmp($resolved_link, "") == 0) {
1508 $resolved_link = $internal_link;
1509 }
1510 } else {
1511 $resolved_link = $internal_link;
1512 }
1513 return $resolved_link;
1514 }
1515
1516 public static function _resolveIntLinks($question_id)
1517 {
1518 global $DIC;
1519
1520 $ilDB = $DIC->database();
1521 $resolvedlinks = 0;
1522 $result = $ilDB->queryF(
1523 "SELECT * FROM svy_material WHERE question_fi = %s",
1524 array('integer'),
1525 array($question_id)
1526 );
1527 if ($result->numRows()) {
1528 while ($row = $ilDB->fetchAssoc($result)) {
1529 $internal_link = $row["internal_link"];
1530 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1531 $resolved_link = self::_resolveInternalLink($internal_link);
1532 if (strcmp($internal_link, $resolved_link) != 0) {
1533 // internal link was resolved successfully
1534 $affectedRows = $ilDB->manipulateF(
1535 "UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1536 array('text', 'integer', 'integer'),
1537 array($resolved_link, time(), $row["material_id"])
1538 );
1539 $resolvedlinks++;
1540 }
1541 }
1542 }
1543 if ($resolvedlinks) {
1544 // there are resolved links -> reenter theses links to the database
1545
1546 // delete all internal links from the database
1547 include_once "./Services/Link/classes/class.ilInternalLink.php";
1548 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1549
1550 $result = $ilDB->queryF(
1551 "SELECT * FROM svy_material WHERE question_fi = %s",
1552 array('integer'),
1553 array($question_id)
1554 );
1555 if ($result->numRows()) {
1556 while ($row = $ilDB->fetchAssoc($result)) {
1557 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches)) {
1558 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1559 }
1560 }
1561 }
1562 }
1563 }
1564
1565 public static function _getInternalLinkHref($target = "", $a_parent_ref_id = null)
1566 {
1567 global $DIC;
1568
1569 $ilDB = $DIC->database();
1570 $linktypes = array(
1571 "lm" => "LearningModule",
1572 "pg" => "PageObject",
1573 "st" => "StructureObject",
1574 "git" => "GlossaryItem",
1575 "mob" => "MediaObject"
1576 );
1577 $href = "";
1578 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches)) {
1579 $type = $matches[1];
1580 $target_id = $matches[2];
1581 switch ($linktypes[$matches[1]]) {
1582 case "LearningModule":
1583 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1584 break;
1585 case "PageObject":
1586 case "StructureObject":
1587 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1588 break;
1589 case "GlossaryItem":
1590 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1591 break;
1592 case "MediaObject":
1593 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/ilias.php?baseClass=ilLMPresentationGUI&obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=" . $a_parent_ref_id . "&mob_id=" . $target_id;
1594 break;
1595 }
1596 }
1597 return $href;
1598 }
1599
1608 public static function _isWriteable($question_id, $user_id)
1609 {
1610 global $DIC;
1611
1612 $ilDB = $DIC->database();
1613
1614 if (($question_id < 1) || ($user_id < 1)) {
1615 return false;
1616 }
1617
1618 $result = $ilDB->queryF(
1619 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
1620 array('integer'),
1621 array($question_id)
1622 );
1623 if ($result->numRows() == 1) {
1624 $row = $ilDB->fetchAssoc($result);
1625 $qpl_object_id = $row["obj_fi"];
1626 include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1627 return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1628 } else {
1629 return false;
1630 }
1631 }
1632
1639 public function getQuestionTypeID()
1640 {
1641 $ilDB = $this->db;
1642 $result = $ilDB->queryF(
1643 "SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1644 array('text'),
1645 array($this->getQuestionType())
1646 );
1647 if ($result->numRows() == 1) {
1648 $row = $ilDB->fetchAssoc($result);
1649 return $row["questiontype_id"];
1650 } else {
1651 return 0;
1652 }
1653 }
1654
1661 public function getQuestionType()
1662 {
1663 return "";
1664 }
1665
1673 public static function _includeClass($question_type, $gui = 0)
1674 {
1675 $type = $question_type;
1676 if ($gui == 1) {
1677 $type .= "GUI";
1678 } elseif ($gui == 2) {
1679 $type .= "Evaluation";
1680 }
1681 if (file_exists("./Modules/SurveyQuestionPool/classes/class." . $type . ".php")) {
1682 include_once "./Modules/SurveyQuestionPool/classes/class." . $type . ".php";
1683 return true;
1684 } else {
1685 global $DIC;
1686
1687 $ilPluginAdmin = $DIC["ilPluginAdmin"];
1688 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1689 foreach ($pl_names as $pl_name) {
1690 $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1691 if (strcmp($pl->getQuestionType(), $question_type) == 0) {
1692 $pl->includeClass("class." . $type . ".php");
1693 return true;
1694 }
1695 }
1696 }
1697 return false;
1698 }
1699
1706 public static function _getQuestionTypeName($type_tag)
1707 {
1708 if (file_exists("./Modules/SurveyQuestionPool/classes/class." . $type_tag . ".php")) {
1709 global $DIC;
1710
1711 $lng = $DIC->language();
1712 return $lng->txt($type_tag);
1713 } else {
1714 global $DIC;
1715
1716 $ilPluginAdmin = $DIC["ilPluginAdmin"];
1717 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1718 foreach ($pl_names as $pl_name) {
1719 $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1720 if (strcmp($pl->getQuestionType(), $type_tag) == 0) {
1721 return $pl->getQuestionTypeTranslation();
1722 }
1723 }
1724 }
1725 return "";
1726 }
1727
1728
1736 public static function _instanciateQuestion($question_id)
1737 {
1738 $question_type = self::_getQuestionType($question_id);
1739 if ($question_type) {
1740 self::_includeClass($question_type);
1741 $question = new $question_type();
1742 $question->loadFromDb($question_id);
1743 return $question;
1744 }
1745 }
1746
1754 public static function _instanciateQuestionGUI($question_id)
1755 {
1756 $question_type = self::_getQuestionType($question_id);
1757 if ($question_type) {
1758 self::_includeClass($question_type, 1);
1759 $guitype = $question_type . "GUI";
1760 $question = new $guitype($question_id);
1761 return $question;
1762 }
1763 }
1764
1772 public static function _instanciateQuestionEvaluation($question_id, array $a_finished_ids = null)
1773 {
1774 $question = self::_instanciateQuestion($question_id);
1775 if ($question) {
1776 $question_type = self::_getQuestionType($question_id);
1777 self::_includeClass($question_type, 2);
1778 $class = $question_type . "Evaluation";
1779 $ev = new $class($question, $a_finished_ids);
1780 return $ev;
1781 }
1782 }
1783
1792 public function isHTML($a_text)
1793 {
1794 if (preg_match("/<[^>]*?>/", $a_text)) {
1795 return true;
1796 } else {
1797 return false;
1798 }
1799 }
1800
1808 public function QTIMaterialToString($a_material)
1809 {
1810 $svy_log = ilLoggerFactory::getLogger("svy");
1811 $svy_log->debug("material count: " . $a_material->getMaterialCount());
1812
1813 $result = "";
1814 for ($i = 0; $i < $a_material->getMaterialCount(); $i++) {
1815 $material = $a_material->getMaterial($i);
1816 if (strcmp($material["type"], "mattext") == 0) {
1817 $result .= $material["material"]->getContent();
1818 }
1819 if (strcmp($material["type"], "matimage") == 0) {
1820 $matimage = $material["material"];
1821 if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches)) {
1822 // import an mediaobject which was inserted using tiny mce
1823 if (!is_array($_SESSION["import_mob_xhtml"])) {
1824 $_SESSION["import_mob_xhtml"] = array();
1825 }
1826 array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1827 }
1828 }
1829 }
1830 return $result;
1831 }
1832
1841 public function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = true, $add_mobs = true, $a_attrs = null)
1842 {
1843 include_once "./Services/RTE/classes/class.ilRTE.php";
1844 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1845
1846 $a_xml_writer->xmlStartTag("material");
1847 $attrs = array(
1848 "type" => "text/plain"
1849 );
1850 if ($this->isHTML($a_material)) {
1851 $attrs["type"] = "text/xhtml";
1852 }
1853 if (is_array($a_attrs)) {
1854 $attrs = array_merge($attrs, $a_attrs);
1855 }
1856 $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1857
1858 if ($add_mobs) {
1859 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1860 foreach ($mobs as $mob) {
1861 $mob_obj = new ilObjMediaObject($mob);
1862 $imgattrs = array(
1863 "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1864 "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle(),
1865 "type" => "spl:html",
1866 "id" => $this->getId()
1867 );
1868 $a_xml_writer->xmlElement("matimage", $imgattrs, null);
1869 }
1870 }
1871 if ($close_material_tag) {
1872 $a_xml_writer->xmlEndTag("material");
1873 }
1874 }
1875
1882 public function prepareTextareaOutput($txt_output, $prepare_for_latex_output = false)
1883 {
1884 return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1885 }
1886
1894 public function getQuestionDataArray($id)
1895 {
1896 return array();
1897 }
1898
1905 public function &getWorkingDataFromUserInput($post_data)
1906 {
1907 // overwrite in inherited classes
1908 $data = array();
1909 return $data;
1910 }
1911
1920 public function importAdditionalMetadata($a_meta)
1921 {
1922 // overwrite in inherited classes
1923 }
1924
1931 public function importResponses($a_data)
1932 {
1933 // overwrite in inherited classes
1934 }
1935
1942 public function importAdjectives($a_data)
1943 {
1944 // overwrite in inherited classes
1945 }
1946
1953 public function importMatrix($a_data)
1954 {
1955 // overwrite in inherited classes
1956 }
1957
1964 public function usableForPrecondition()
1965 {
1966 // overwrite in inherited classes
1967 return false;
1968 }
1969
1976 public function getAvailableRelations()
1977 {
1978 // overwrite in inherited classes
1979 return array();
1980 }
1981
1987 public function getPreconditionOptions()
1988 {
1989 // overwrite in inherited classes
1990 }
1991
1999 public function getPreconditionValueOutput($value)
2000 {
2001 // overwrite in inherited classes
2002 return $value;
2003 }
2004
2011 public function getPreconditionSelectValue($default = "", $title, $variable)
2012 {
2013 // overwrite in inherited classes
2014 return null;
2015 }
2016
2017 public function setOriginalId($original_id)
2018 {
2019 $this->original_id = $original_id;
2020 }
2021
2022 public function getOriginalId()
2023 {
2024 return $this->original_id;
2025 }
2026
2027 public function getMaterial()
2028 {
2029 return $this->material;
2030 }
2031
2032 public function setSubtype($a_subtype)
2033 {
2034 // do nothing
2035 }
2036
2037 public function getSubtype()
2038 {
2039 // do nothing
2040 return null;
2041 }
2042
2046 public function __get($value)
2047 {
2048 switch ($value) {
2049 default:
2050 if (array_key_exists($value, $this->arrData)) {
2051 return $this->arrData[$value];
2052 } else {
2053 return null;
2054 }
2055 break;
2056 }
2057 }
2058
2062 public function __set($key, $value)
2063 {
2064 switch ($key) {
2065 default:
2066 $this->arrData[$key] = $value;
2067 break;
2068 }
2069 }
2070
2078 public static function _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
2079 {
2080 global $DIC;
2081
2082 $ilDB = $DIC->database();
2083
2084 $ilDB->manipulate("UPDATE svy_question" .
2085 " SET original_id = " . $ilDB->quote($a_original_id, "integer") . "," .
2086 " obj_fi = " . $ilDB->quote($a_object_id, "integer") .
2087 " WHERE question_id = " . $ilDB->quote($a_question_id, "integer"));
2088 }
2089
2090 public function getCopyIds($a_group_by_survey = false)
2091 {
2092 $ilDB = $this->db;
2093
2094 $set = $ilDB->query("SELECT q.question_id,s.obj_fi" .
2095 " FROM svy_question q" .
2096 " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)" .
2097 " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)" .
2098 " WHERE original_id = " . $ilDB->quote($this->getId(), "integer"));
2099 $res = array();
2100 while ($row = $ilDB->fetchAssoc($set)) {
2101 if (!$a_group_by_survey) {
2102 $res[] = $row["question_id"];
2103 } else {
2104 $res[$row["obj_fi"]][] = $row["question_id"];
2105 }
2106 }
2107 return $res;
2108 }
2109
2110 public function hasCopies()
2111 {
2112 return (bool) sizeof($this->getCopyIds());
2113 }
2114
2115 public static function _lookupSurveyObjId($a_question_id)
2116 {
2117 global $DIC;
2118
2119 $ilDB = $DIC->database();
2120
2121 $set = $ilDB->query("SELECT svy_svy.obj_fi FROM svy_svy_qst" .
2122 " JOIN svy_svy ON (svy_svy.survey_id = svy_svy_qst.survey_fi)" .
2123 " WHERE svy_svy_qst.question_fi = " . $ilDB->quote($a_question_id, "integer"));
2124 $row = $ilDB->fetchAssoc($set);
2125 if ($ilDB->numRows($set)) {
2126 return $row["obj_fi"];
2127 }
2128 }
2129
2136 public static function lookupObjFi($a_qid)
2137 {
2138 global $DIC;
2139
2140 $ilDB = $DIC->database();
2141
2142 $set = $ilDB->query(
2143 "SELECT obj_fi FROM svy_question " .
2144 " WHERE question_id = " . $ilDB->quote($a_qid, "integer")
2145 );
2146 $rec = $ilDB->fetchAssoc($set);
2147 return $rec["obj_fi"];
2148 }
2149
2157 public function stripSlashesAddSpaceFallback($a_str)
2158 {
2159 $str = ilUtil::stripSlashes($a_str);
2160 if ($str != $a_str) {
2161 $str = ilUtil::stripSlashes(str_replace("<", "< ", $a_str));
2162 }
2163 return $str;
2164 }
2165}
sprintf('%.4f', $callTime)
$result
user()
Definition: user.php:4
if(! $in) print
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Basic class for all survey question types.
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
setId($id=-1)
Sets the id of the SurveyQuestion object.
static _getTitle($question_id)
Returns the question title of a question with a given id.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
getOwner()
Gets the creator/owner ID of the SurveyQuestion object.
copyXHTMLMediaObjectsOfQuestion($a_q_id)
Increases the media object usage counter when a question is duplicated.
static _questionExists($question_id)
Returns true if the question already exists in the database.
getQuestionType()
Returns the question type of the question.
getObjId()
Get the reference id of the container object.
static _instanciateQuestionGUI($question_id)
Creates an instance of a question GUI with a given question id.
saveWorkingData($limit_to=LIMIT_NO_LIMIT)
Saves the learners input of the question to the database.
$arrData
data array containing the question data
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
getDescription()
Gets the description string of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
getQuestionTypeID()
Returns the question type ID of the question.
setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
Sets and uploads the materials uri.
static lookupObjFi($a_qid)
Lookip obj fi.
importResponses($a_data)
Import response data from the question import file.
static _getOriginalId($question_id, $a_return_question_id_if_no_original=true)
Returns the original id of a question.
addMaterials($materials_file, $materials_name="")
Sets the materials uri.
addMaterial($obj_material)
importAdjectives($a_data)
Import bipolar adjectives from the question import file.
__construct($title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
duplicateMaterials($question_id)
Duplicates the materials of a question.
createNewQuestion()
Creates a new question with a 0 timestamp when a new question is created This assures that an ID is g...
setDescription($description="")
Sets the description string of the SurveyQuestion object.
static _resolveInternalLink($internal_link)
setSurveyId($id=-1)
Sets the survey id of the SurveyQuestion object.
isHTML($a_text)
Checks if a given string contains HTML or not.
addInternalLink($material_id, $title="")
getMaterialsPath()
Returns the materials path for web accessable materials of a question.
phraseExists($title)
Returns true if the phrase title already exists for the current user.
setObjId($obj_id=0)
Set the reference id of the container object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
setMaterial($material_id="", $is_import=false, $material_title="")
Sets a material link for the question.
isComplete()
Returns 1, if a question is complete for use.
getPhrase($phrase_id)
Returns a phrase for a given database id.
static _getInternalLinkHref($target="", $a_parent_ref_id=null)
setOriginalId($original_id)
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getMaterialsPathWeb()
Returns the web image path for web accessable images of a question.
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
QTIMaterialToString($a_material)
Reads an QTI material tag an creates a text string.
getObligatory($survey_id="")
Gets the obligatory state of the question.
getImagePath()
Returns the image path for web accessable images of a question.
deleteMaterial($materials_name="")
Deletes a materials uri with a given name.
setOrientation($orientation=0)
Sets the orientation of the question output.
loadFromDb($question_id)
Loads a SurveyQuestion object from the database.
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
static _resolveIntLinks($question_id)
static _isComplete($question_id)
Checks whether the question is complete or not.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
getTitle()
Gets the title string of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
prepareTextareaOutput($txt_output, $prepare_for_latex_output=false)
Prepares a string for a text area output in surveys.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
questionTitleExists($title, $questionpool_object="")
Returns TRUE if the question title exists in the database.
duplicate($for_survey=true, $title="", $author="", $owner="", $a_survey_id=0)
Duplicates a survey question.
getPreconditionOptions()
Returns the options for preconditions.
saveMaterial()
save material to db
deleteMaterials($a_array)
Deletes materials.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
static _lookupSurveyObjId($a_question_id)
static _getQuestionType($question_id)
Returns the question type of a question with a given id.
static _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
Change original id of existing question in db.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
getSurveyId()
Gets the survey id of the SurveyQuestion object.
saveToDb($original_id="")
Saves a SurveyQuestion object to a database.
getAvailableRelations()
Returns the available relations for the question.
getQuestionDataArray($id)
Returns the question data fields from the database.
$cumulated
An array containing the cumulated results of the question for a given survey.
getOrientation()
Gets the orientation of the question output.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
getCopyIds($a_group_by_survey=false)
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=true, $add_mobs=true, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
usableForPrecondition()
Returns if the question is usable for preconditions.
copyObject($target_questionpool, $title="")
Copies an assOrderingQuestion object.
flushMaterials()
Deletes all materials uris.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
deleteAdditionalTableData($question_id)
Deletes datasets from the additional question table in the database.
static _instanciateQuestionEvaluation($question_id, array $a_finished_ids=null)
Creates an instance of a question evaluation with a given question id.
__set($key, $value)
Object setter.
importMatrix($a_data)
Import matrix rows from the question import file.
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
__get($value)
Object getter.
const IL_COMP_MODULE
static _lookGlossaryTerm($term_id)
get glossary term
static _getIdForImportId($a_import_id)
get current object id for import id (static)
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
Class ilLMPageObject.
static getLogger($a_component_id)
Get component logger.
Class ilObjContentObjectGUI.
Class ilObjMediaObject.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _isWriteable($object_id, $user_id)
Returns true, if the question pool is writeable by a given user.
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get plugin object.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
Synchronises appearances of media objects in $a_text with media object usage table.
Class ilStructreObject.
Survey material class.
static handleQuestionDeletion($a_question_id, $a_obj_id)
Remove question skill assignment.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static prepareTextareaOutput($txt_output, $prepare_for_latex_output=false, $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free,...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static removeTrailingPathSeparators($path)
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
$target_id
Definition: goto.php:49
const LIMIT_NO_LIMIT
Assessment constants.
$type
$insert
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$mobs
$ilUser
Definition: imgupload.php:18