ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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;
64  public $description;
71  public $owner;
72 
79  public $author;
80 
86  public $materials;
87 
93  public $survey_id;
94 
100  public $obj_id;
101 
108 
114  public $obligatory;
115 
121  public $lng;
122 
128  public $orientation;
129 
130  public $material;
131  public $complete;
132 
136  protected $cumulated;
137 
141  private $arrData;
142 
146  protected $log;
147 
158  public function __construct($title = "", $description = "", $author = "", $questiontext = "", $owner = -1)
159  {
160  global $DIC;
161 
162  $this->user = $DIC->user();
163  $this->db = $DIC->database();
164  $lng = $DIC->language();
165  $ilUser = $DIC->user();
166 
167  $this->lng = $lng;
168  $this->complete = 0;
169  $this->title = $title;
170  $this->description = $description;
171  $this->questiontext = $questiontext;
172  $this->author = $author;
173  $this->cumulated = array();
174  if (!$this->author) {
175  $this->author = $ilUser->fullname;
176  }
177  $this->owner = $owner;
178  if ($this->owner == -1) {
179  $this->owner = $ilUser->getId();
180  }
181  $this->id = -1;
182  $this->survey_id = -1;
183  $this->obligatory = 1;
184  $this->orientation = 0;
185  $this->materials = array();
186  $this->material = array();
187  $this->arrData = array();
188 
189  $this->log = ilLoggerFactory::getLogger('svy');
190  }
191 
198  public function setComplete($a_complete)
199  {
200  $this->complete = ($a_complete) ? 1 : 0;
201  }
202 
209  public function isComplete()
210  {
211  return 0;
212  }
213 
222  public function questionTitleExists($title, $questionpool_object = "")
223  {
224  $ilDB = $this->db;
225 
226  $refwhere = "";
227  if (strcmp($questionpool_object, "") != 0) {
228  $refwhere = sprintf(
229  " AND obj_fi = %s",
230  $ilDB->quote($questionpool_object, 'integer')
231  );
232  }
233  $result = $ilDB->queryF(
234  "SELECT question_id FROM svy_question WHERE title = %s$refwhere",
235  array('text'),
236  array($title)
237  );
238  return ($result->numRows() > 0) ? true : false;
239  }
240 
248  public function setTitle($title = "")
249  {
250  $this->title = $title;
251  }
252 
260  public function setObligatory($obligatory = 1)
261  {
262  $this->obligatory = ($obligatory) ? 1 : 0;
263  }
264 
272  public function setOrientation($orientation = 0)
273  {
274  $this->orientation = ($orientation) ? $orientation : 0;
275  }
276 
284  public function setId($id = -1)
285  {
286  $this->id = $id;
287  }
288 
296  public function setSurveyId($id = -1)
297  {
298  $this->survey_id = $id;
299  }
300 
308  public function setDescription($description = "")
309  {
310  $this->description = $description;
311  }
312 
321  public function addMaterials($materials_file, $materials_name = "")
322  {
323  if (empty($materials_name)) {
324  $materials_name = $materials_file;
325  }
326  if ((!empty($materials_name)) && (!array_key_exists($materials_name, $this->materials))) {
327  $this->materials[$materials_name] = $materials_file;
328  }
329  }
330 
338  public function setMaterialsfile($materials_filename, $materials_tempfilename = "", $materials_name = "")
339  {
340  if (!empty($materials_filename)) {
341  $materialspath = $this->getMaterialsPath();
342  if (!file_exists($materialspath)) {
343  ilUtil::makeDirParents($materialspath);
344  }
346  $materials_tempfilename,
347  $materials_filename,
348  $materialspath . $materials_filename
349  )) {
350  print "image not uploaded!!!! ";
351  } else {
352  $this->addMaterials($materials_filename, $materials_name);
353  }
354  }
355  }
356 
364  public function deleteMaterial($materials_name = "")
365  {
366  foreach ($this->materials as $key => $value) {
367  if (strcmp($key, $materials_name) == 0) {
368  if (file_exists($this->getMaterialsPath() . $value)) {
369  unlink($this->getMaterialsPath() . $value);
370  }
371  unset($this->materials[$key]);
372  }
373  }
374  }
375 
382  public function flushMaterials()
383  {
384  $this->materials = array();
385  }
386 
394  public function setAuthor($author = "")
395  {
397 
398  if (!$author) {
399  $author = $ilUser->fullname;
400  }
401  $this->author = $author;
402  }
403 
411  public function setQuestiontext($questiontext = "")
412  {
413  $this->questiontext = $questiontext;
414  }
415 
423  public function setOwner($owner = "")
424  {
425  $this->owner = $owner;
426  }
427 
435  public function getTitle()
436  {
437  return $this->title;
438  }
439 
440  public function getLabel()
441  {
442  return $this->label;
443  }
444 
452  public function getId()
453  {
454  return $this->id;
455  }
456 
463  public function getObligatory($survey_id = "")
464  {
465  return ($this->obligatory) ? 1 : 0;
466  }
467 
475  public function getSurveyId()
476  {
477  return $this->survey_id;
478  }
479 
487  public function getOrientation()
488  {
489  switch ($this->orientation) {
490  case 0:
491  case 1:
492  case 2:
493  break;
494  default:
495  $this->orientation = 0;
496  break;
497  }
498  return $this->orientation;
499  }
500 
501 
509  public function getDescription()
510  {
511  return (strlen($this->description)) ? $this->description : null;
512  }
513 
521  public function getAuthor()
522  {
523  return (strlen($this->author)) ? $this->author : null;
524  }
525 
533  public function getOwner()
534  {
535  return $this->owner;
536  }
537 
545  public function getQuestiontext()
546  {
547  return (strlen($this->questiontext)) ? $this->questiontext : null;
548  }
549 
557  public function getObjId()
558  {
559  return $this->obj_id;
560  }
561 
569  public function setObjId($obj_id = 0)
570  {
571  $this->obj_id = $obj_id;
572  }
573 
579  public function duplicate($for_survey = true, $title = "", $author = "", $owner = "", $a_survey_id = 0)
580  {
581  if ($this->getId() <= 0) {
582  // The question has not been saved. It cannot be duplicated
583  return;
584  }
585  // duplicate the question in database
586  $clone = $this;
587  $original_id = $this->getId();
588  $clone->setId(-1);
589  if ($a_survey_id > 0) {
590  $clone->setObjId($a_survey_id);
591  }
592  if ($title) {
593  $clone->setTitle($title);
594  }
595  if ($author) {
596  $clone->setAuthor($author);
597  }
598  if ($owner) {
599  $clone->setOwner($owner);
600  }
601  if ($for_survey) {
602  $clone->saveToDb($original_id);
603  } else {
604  $clone->saveToDb();
605  }
606  // duplicate the materials
607  $clone->duplicateMaterials($original_id);
608  // copy XHTML media objects
609  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
610  return $clone->getId();
611  }
612 
618  public function copyObject($target_questionpool, $title = "")
619  {
620  if ($this->getId() <= 0) {
621  // The question has not been saved. It cannot be copied
622  return;
623  }
624  $clone = $this;
625  $original_id = self::_getOriginalId($this->getId(), false);
626  $clone->setId(-1);
627  $source_questionpool = $this->getObjId();
628  $clone->setObjId($target_questionpool);
629  if ($title) {
630  $clone->setTitle($title);
631  }
632 
633  $clone->saveToDb();
634 
635  // duplicate the materials
636  $clone->duplicateMaterials($original_id);
637  // copy XHTML media objects
638  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
639  return $clone->getId();
640  }
641 
648  public function copyXHTMLMediaObjectsOfQuestion($a_q_id)
649  {
650  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
651  foreach ($mobs as $mob) {
652  ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
653  }
654  }
655 
662  public function loadFromDb($question_id)
663  {
664  $ilDB = $this->db;
665 
666  $result = $ilDB->queryF(
667  "SELECT * FROM svy_material WHERE question_fi = %s",
668  array('integer'),
669  array($this->getId())
670  );
671  $this->material = array();
672  if ($result->numRows()) {
673  while ($row = $ilDB->fetchAssoc($result)) {
674  $mat = new ilSurveyMaterial();
675  $mat->type = $row['material_type'];
676  $mat->internal_link = $row['internal_link'];
677  $mat->title = $row['material_title'];
678  $mat->import_id = $row['import_id'];
679  $mat->text_material = $row['text_material'];
680  $mat->external_link = $row['external_link'];
681  $mat->file_material = $row['file_material'];
682  array_push($this->material, $mat);
683  }
684  }
685  }
686 
693  public static function _isComplete($question_id)
694  {
695  global $DIC;
696 
697  $ilDB = $DIC->database();
698 
699  $result = $ilDB->queryF(
700  "SELECT complete FROM svy_question WHERE question_id = %s",
701  array('integer'),
702  array($question_id)
703  );
704  if ($result->numRows()) {
705  $row = $ilDB->fetchAssoc($result);
706  if ($row["complete"] == 1) {
707  return true;
708  }
709  }
710  return false;
711  }
712 
718  public function saveCompletionStatus($original_id = "")
719  {
720  $ilDB = $this->db;
721 
722  $question_id = $this->getId();
723  if (strlen($original_id)) {
724  $question_id = $original_id;
725  }
726 
727  if ($this->getId() > 0) {
728  $this->log->debug("UPDATE svy_question question_id=" . $question_id);
729 
730  // update existing dataset
731  $affectedRows = $ilDB->manipulateF(
732  "UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
733  array('text', 'integer', 'integer'),
734  array($this->isComplete(), time(), $question_id)
735  );
736  }
737  }
738 
745  public function saveToDb($original_id = "")
746  {
747  $ilDB = $this->db;
748 
749  // cleanup RTE images which are not inserted into the question text
750  ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
751  $affectedRows = 0;
752  if ($this->getId() == -1) {
753  // Write new dataset
754  $next_id = $ilDB->nextId('svy_question');
755  $affectedRows = $ilDB->insert("svy_question", array(
756  "question_id" => array("integer", $next_id),
757  "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
758  "obj_fi" => array("integer", $this->getObjId()),
759  "owner_fi" => array("integer", $this->getOwner()),
760  "title" => array("text", $this->getTitle()),
761  "label" => array("text", (strlen($this->label)) ? $this->label : null),
762  "description" => array("text", $this->getDescription()),
763  "author" => array("text", $this->getAuthor()),
764  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
765  "obligatory" => array("text", $this->getObligatory()),
766  "complete" => array("text", $this->isComplete()),
767  "created" => array("integer", time()),
768  "original_id" => array("integer", ($original_id) ? $original_id : null),
769  "tstamp" => array("integer", time())
770  ));
771 
772  //$this->log->debug("INSERT: svy_question id=".$next_id." questiontype_fi=".$this->getQuestionTypeID()." obj_fi".$this->getObjId()." title=".$this->getTitle()." ...");
773 
774  $this->setId($next_id);
775  } else {
776  // update existing dataset
777  $affectedRows = $ilDB->update("svy_question", array(
778  "title" => array("text", $this->getTitle()),
779  "label" => array("text", (strlen($this->label)) ? $this->label : null),
780  "description" => array("text", $this->getDescription()),
781  "author" => array("text", $this->getAuthor()),
782  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
783  "obligatory" => array("text", $this->getObligatory()),
784  "complete" => array("text", $this->isComplete()),
785  "tstamp" => array("integer", time())
786  ), array(
787  "question_id" => array("integer", $this->getId())
788  ));
789 
790  $this->log->debug("UPDATE svy_question id=" . $this->getId() . " SET: title=" . $this->getTitle() . " ...");
791  }
792 
793  return $affectedRows;
794  }
795 
799  public function saveMaterial()
800  {
801  $ilDB = $this->db;
802 
803  $this->log->debug("DELETE: svy_material question_fi=" . $this->getId());
804 
805  $affectedRows = $ilDB->manipulateF(
806  "DELETE FROM svy_material WHERE question_fi = %s",
807  array('integer'),
808  array($this->getId())
809  );
811 
812  foreach ($this->material as $material) {
813  $next_id = $ilDB->nextId('svy_material');
814 
815  $this->log->debug("INSERT: svy_material question_fi=" . $this->getId());
816 
817  $affectedRows = $ilDB->manipulateF(
818  "INSERT INTO svy_material " .
819  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
820  "text_material, external_link, file_material, material_type) " .
821  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
822  array('integer','integer','text','text','text','integer','text','text','text','integer'),
823  array(
824  $next_id, $this->getId(), $material->internal_link, $material->import_id,
825  $material->title, time(), $material->text_material, $material->external_link,
826  $material->file_material, $material->type)
827  );
828  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches)) {
829  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
830  }
831  }
832  }
833 
840  public function createNewQuestion()
841  {
842  $ilDB = $this->db;
843 
844  $obj_id = $this->getObjId();
845  if ($obj_id > 0) {
846  $next_id = $ilDB->nextId('svy_question');
847  $affectedRows = $ilDB->manipulateF(
848  "INSERT INTO svy_question (question_id, questiontype_fi, " .
849  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
850  "created, original_id, tstamp) VALUES " .
851  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
852  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
853  'text', 'text', 'integer', 'integer', 'integer'),
854  array(
855  $next_id,
856  $this->getQuestionTypeID(),
857  $obj_id,
858  $this->getOwner(),
859  null,
860  null,
861  $this->getAuthor(),
862  null,
863  "1",
864  "0",
865  time(),
866  null,
867  0
868  )
869  );
870  $this->log->debug("INSERT INTO svy_question question_id= " . $next_id . " questiontype_fi= " . $this->getQuestionTypeID());
871 
872  $this->setId($next_id);
873  }
874  return $this->getId();
875  }
876 
883  public function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
884  {
885  }
886 
893  public function getImagePath()
894  {
895  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
896  }
897 
904  public function getMaterialsPath()
905  {
906  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
907  }
908 
915  public function getImagePathWeb()
916  {
917  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
918  return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
919  }
920 
927  public function getMaterialsPathWeb()
928  {
929  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
930  return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
931  }
932 
941  public function saveCategoryToDb($categorytext, $neutral = 0)
942  {
944  $ilDB = $this->db;
945 
946  $result = $ilDB->queryF(
947  "SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
948  array('text','text','integer'),
949  array($categorytext, $neutral, $ilUser->getId())
950  );
951  $insert = false;
952  $returnvalue = "";
953  if ($result->numRows()) {
954  $insert = true;
955  while ($row = $ilDB->fetchAssoc($result)) {
956  if (strcmp($row["title"], $categorytext) == 0) {
957  $returnvalue = $row["category_id"];
958  $insert = false;
959  }
960  }
961  } else {
962  $insert = true;
963  }
964  if ($insert) {
965  $next_id = $ilDB->nextId('svy_category');
966  $affectedRows = $ilDB->manipulateF(
967  "INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
968  array('integer','text','text','integer','integer'),
969  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
970  );
971 
972  $this->log->debug("INSERT INTO svy_category id=" . $next_id);
973 
974  $returnvalue = $next_id;
975  }
976  return $returnvalue;
977  }
978 
985  public function deleteAdditionalTableData($question_id)
986  {
987  $ilDB = $this->db;
988 
989  $this->log->debug("DELETE FROM " . $this->getAdditionalTableName());
990 
991  $affectedRows = $ilDB->manipulateF(
992  "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
993  array('integer'),
994  array($question_id)
995  );
996  }
997 
1004  public function delete($question_id)
1005  {
1006  $ilDB = $this->db;
1007 
1008  if ($question_id < 1) {
1009  return;
1010  }
1011 
1012  $result = $ilDB->queryF(
1013  "SELECT obj_fi FROM svy_question WHERE question_id = %s",
1014  array('integer'),
1015  array($question_id)
1016  );
1017  if ($result->numRows() == 1) {
1018  $row = $ilDB->fetchAssoc($result);
1019  $obj_id = $row["obj_fi"];
1020  } else {
1021  return;
1022  }
1023 
1024  $affectedRows = $ilDB->manipulateF(
1025  "DELETE FROM svy_answer WHERE question_fi = %s",
1026  array('integer'),
1027  array($question_id)
1028  );
1029 
1030  $affectedRows = $ilDB->manipulateF(
1031  "DELETE FROM svy_constraint WHERE question_fi = %s",
1032  array('integer'),
1033  array($question_id)
1034  );
1035 
1036  $result = $ilDB->queryF(
1037  "SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1038  array('integer'),
1039  array($question_id)
1040  );
1041  while ($row = $ilDB->fetchObject($result)) {
1042  $affectedRows = $ilDB->manipulateF(
1043  "DELETE FROM svy_constraint WHERE constraint_id = %s",
1044  array('integer'),
1045  array($row->constraint_fi)
1046  );
1047  }
1048 
1049  $affectedRows = $ilDB->manipulateF(
1050  "DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1051  array('integer'),
1052  array($question_id)
1053  );
1054  $affectedRows = $ilDB->manipulateF(
1055  "DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1056  array('integer'),
1057  array($question_id)
1058  );
1059  $affectedRows = $ilDB->manipulateF(
1060  "DELETE FROM svy_svy_qst WHERE question_fi = %s",
1061  array('integer'),
1062  array($question_id)
1063  );
1064  $affectedRows = $ilDB->manipulateF(
1065  "DELETE FROM svy_variable WHERE question_fi = %s",
1066  array('integer'),
1067  array($question_id)
1068  );
1069  $affectedRows = $ilDB->manipulateF(
1070  "DELETE FROM svy_question WHERE question_id = %s",
1071  array('integer'),
1072  array($question_id)
1073  );
1074 
1075  $this->deleteAdditionalTableData($question_id);
1076 
1077  $affectedRows = $ilDB->manipulateF(
1078  "DELETE FROM svy_material WHERE question_fi = %s",
1079  array('integer'),
1080  array($question_id)
1081  );
1082 
1083  $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);
1084 
1085  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1086 
1087  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1088  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory)) {
1089  ilUtil::delDir($directory);
1090  }
1091 
1092  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1093  // remaining usages are not in text anymore -> delete them
1094  // and media objects (note: delete method of ilObjMediaObject
1095  // checks whether object is used in another context; if yes,
1096  // the object is not deleted!)
1097  foreach ($mobs as $mob) {
1098  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1099  $mob_obj = new ilObjMediaObject($mob);
1100  $mob_obj->delete();
1101  }
1102 
1104 
1105  $this->log->debug("UPDATE svy_question");
1106 
1107  // #12772 - untie question copies from pool question
1108  $ilDB->manipulate("UPDATE svy_question" .
1109  " SET original_id = NULL" .
1110  " WHERE original_id = " . $ilDB->quote($question_id, "integer"));
1111  }
1112 
1120  public static function _getQuestionType($question_id)
1121  {
1122  global $DIC;
1123 
1124  $ilDB = $DIC->database();
1125 
1126  if ($question_id < 1) {
1127  return "";
1128  }
1129 
1130  $result = $ilDB->queryF(
1131  "SELECT type_tag FROM svy_question, svy_qtype WHERE svy_question.question_id = %s AND svy_question.questiontype_fi = svy_qtype.questiontype_id",
1132  array('integer'),
1133  array($question_id)
1134  );
1135  if ($result->numRows() == 1) {
1136  $data = $ilDB->fetchAssoc($result);
1137  return $data["type_tag"];
1138  } else {
1139  return "";
1140  }
1141  }
1142 
1150  public static function _getTitle($question_id)
1151  {
1152  global $DIC;
1153 
1154  $ilDB = $DIC->database();
1155 
1156  if ($question_id < 1) {
1157  return "";
1158  }
1159 
1160  $result = $ilDB->queryF(
1161  "SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1162  array('integer'),
1163  array($question_id)
1164  );
1165  if ($result->numRows() == 1) {
1166  $data = $ilDB->fetchAssoc($result);
1167  return $data["title"];
1168  } else {
1169  return "";
1170  }
1171  }
1172 
1180  public static function _getOriginalId($question_id, $a_return_question_id_if_no_original = true)
1181  {
1182  global $DIC;
1183 
1184  $ilDB = $DIC->database();
1185  $result = $ilDB->queryF(
1186  "SELECT * FROM svy_question WHERE question_id = %s",
1187  array('integer'),
1188  array($question_id)
1189  );
1190  if ($result->numRows() > 0) {
1191  $row = $ilDB->fetchAssoc($result);
1192  if ($row["original_id"] > 0) {
1193  return $row["original_id"];
1194  } elseif ((bool) $a_return_question_id_if_no_original) { // #12419
1195  return $row["question_id"];
1196  }
1197  } else {
1198  return "";
1199  }
1200  }
1201 
1202  public function syncWithOriginal()
1203  {
1204  $ilDB = $this->db;
1205 
1206  if ($this->getOriginalId()) {
1207  $id = $this->getId();
1208  $original = $this->getOriginalId();
1209 
1210  $this->setId($this->getOriginalId());
1211  $this->setOriginalId(null);
1212  $this->saveToDb();
1213 
1214  $this->setId($id);
1215  $this->setOriginalId($original);
1216 
1217  $this->log->debug("DELETE FROM svy_material WHERE question_fi = " . $this->getOriginalId());
1218 
1219  $affectedRows = $ilDB->manipulateF(
1220  "DELETE FROM svy_material WHERE question_fi = %s",
1221  array('integer'),
1222  array($this->getOriginalId())
1223  );
1224  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1225  if (strlen($this->material["internal_link"])) {
1226  $next_id = $ilDB->nextId('svy_material');
1227  $affectedRows = $ilDB->manipulateF(
1228  "INSERT INTO svy_material (material_id, question_fi, internal_link, import_id, material_title, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
1229  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1230  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1231  );
1232 
1233  $this->log->debug("INSERT svy_material material_id=" . $next_id . " question_fi=" . $this->getOriginalId());
1234 
1235  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches)) {
1236  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1237  }
1238  }
1239  }
1240  }
1241 
1248  public function getPhrase($phrase_id)
1249  {
1250  $ilDB = $this->db;
1251 
1252  $result = $ilDB->queryF(
1253  "SELECT title FROM svy_phrase WHERE phrase_id = %s",
1254  array('integer'),
1255  array($phrase_id)
1256  );
1257  if ($row = $ilDB->fetchAssoc($result)) {
1258  return $row["title"];
1259  }
1260  return "";
1261  }
1262 
1270  public function phraseExists($title)
1271  {
1272  $ilUser = $this->user;
1273  $ilDB = $this->db;
1274 
1275  $result = $ilDB->queryF(
1276  "SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1277  array('text', 'integer'),
1278  array($title, $ilUser->getId())
1279  );
1280  return ($result->numRows() == 0) ? false : true;
1281  }
1282 
1290  public static function _questionExists($question_id)
1291  {
1292  global $DIC;
1293 
1294  $ilDB = $DIC->database();
1295 
1296  if ($question_id < 1) {
1297  return false;
1298  }
1299 
1300  $result = $ilDB->queryF(
1301  "SELECT question_id FROM svy_question WHERE question_id = %s",
1302  array('integer'),
1303  array($question_id)
1304  );
1305  return ($result->numRows() == 1) ? true : false;
1306  }
1307 
1308  public function addInternalLink($material_id, $title = "")
1309  {
1310  if (strlen($material_id)) {
1311  if (strcmp($material_title, "") == 0) {
1312  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches)) {
1313  $type = $matches[1];
1314  $target_id = $matches[2];
1315  $material_title = $this->lng->txt("obj_$type") . ": ";
1316  switch ($type) {
1317  case "lm":
1318  $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1319  $cont_obj = $cont_obj_gui->object;
1320  $material_title .= $cont_obj->getTitle();
1321  break;
1322 
1323  case "pg":
1325  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1326  $cont_obj = $cont_obj_gui->object;
1327  $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1328  $material_title .= $pg_obj->getTitle();
1329  break;
1330 
1331  case "st":
1333  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1334  $cont_obj = $cont_obj_gui->object;
1335  $st_obj = new ilStructureObject($cont_obj, $target_id);
1336  $material_title .= $st_obj->getTitle();
1337  break;
1338 
1339  case "git":
1340  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1341  break;
1342  case "mob":
1343  break;
1344  }
1345  }
1346  }
1347 
1348  $mat = new ilSurveyMaterial();
1349  $mat->type = 0;
1350  $mat->internal_link = $material_id;
1351  $mat->title = $material_title;
1352  $this->addMaterial($mat);
1353  $this->saveMaterial();
1354  }
1355  }
1356 
1362  public function deleteMaterials($a_array)
1363  {
1364  foreach ($a_array as $idx) {
1365  unset($this->material[$idx]);
1366  }
1367  $this->material = array_values($this->material);
1368  $this->saveMaterial();
1369  }
1370 
1377  public function duplicateMaterials($question_id)
1378  {
1379  foreach ($this->materials as $filename) {
1380  $materialspath = $this->getMaterialsPath();
1381  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1382  if (!file_exists($materialspath)) {
1383  ilUtil::makeDirParents($materialspath);
1384  }
1385  if (!copy($materialspath_original . $filename, $materialspath . $filename)) {
1386  print "material could not be duplicated!!!! ";
1387  }
1388  }
1389  }
1390 
1391  public function addMaterial($obj_material)
1392  {
1393  array_push($this->material, $obj_material);
1394  }
1395 
1403  public function setMaterial($material_id = "", $is_import = false, $material_title = "")
1404  {
1405  if (strcmp($material_id, "") != 0) {
1406  $import_id = "";
1407  if ($is_import) {
1408  $import_id = $material_id;
1409  $material_id = self::_resolveInternalLink($import_id);
1410  }
1411  if (strcmp($material_title, "") == 0) {
1412  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches)) {
1413  $type = $matches[1];
1414  $target_id = $matches[2];
1415  $material_title = $this->lng->txt("obj_$type") . ": ";
1416  switch ($type) {
1417  case "lm":
1418  $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1419  $cont_obj = $cont_obj_gui->object;
1420  $material_title .= $cont_obj->getTitle();
1421  break;
1422 
1423  case "pg":
1425  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1426  $cont_obj = $cont_obj_gui->object;
1427  $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1428  $material_title .= $pg_obj->getTitle();
1429  break;
1430 
1431  case "st":
1433  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, false);
1434  $cont_obj = $cont_obj_gui->object;
1435  $st_obj = new ilStructureObject($cont_obj, $target_id);
1436  $material_title .= $st_obj->getTitle();
1437  break;
1438 
1439  case "git":
1440  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1441  break;
1442  case "mob":
1443  break;
1444  }
1445  }
1446  }
1447  $this->material = array(
1448  "internal_link" => $material_id,
1449  "import_id" => $import_id,
1450  "title" => $material_title
1451  );
1452  }
1453  $this->saveMaterial();
1454  }
1455 
1456  public static function _resolveInternalLink($internal_link)
1457  {
1458  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches)) {
1459  switch ($matches[2]) {
1460  case "lm":
1461  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1462  break;
1463  case "pg":
1464  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1465  break;
1466  case "st":
1467  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1468  break;
1469  case "git":
1470  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1471  break;
1472  case "mob":
1473  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1474  break;
1475  }
1476  if (strcmp($resolved_link, "") == 0) {
1477  $resolved_link = $internal_link;
1478  }
1479  } else {
1480  $resolved_link = $internal_link;
1481  }
1482  return $resolved_link;
1483  }
1484 
1485  public static function _resolveIntLinks($question_id)
1486  {
1487  global $DIC;
1488 
1489  $ilDB = $DIC->database();
1490  $resolvedlinks = 0;
1491  $result = $ilDB->queryF(
1492  "SELECT * FROM svy_material WHERE question_fi = %s",
1493  array('integer'),
1494  array($question_id)
1495  );
1496  if ($result->numRows()) {
1497  while ($row = $ilDB->fetchAssoc($result)) {
1498  $internal_link = $row["internal_link"];
1499  $resolved_link = self::_resolveInternalLink($internal_link);
1500  if (strcmp($internal_link, $resolved_link) != 0) {
1501  // internal link was resolved successfully
1502  $affectedRows = $ilDB->manipulateF(
1503  "UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1504  array('text', 'integer', 'integer'),
1505  array($resolved_link, time(), $row["material_id"])
1506  );
1507  $resolvedlinks++;
1508  }
1509  }
1510  }
1511  if ($resolvedlinks) {
1512  // there are resolved links -> reenter theses links to the database
1513 
1514  // delete all internal links from the database
1515  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1516 
1517  $result = $ilDB->queryF(
1518  "SELECT * FROM svy_material WHERE question_fi = %s",
1519  array('integer'),
1520  array($question_id)
1521  );
1522  if ($result->numRows()) {
1523  while ($row = $ilDB->fetchAssoc($result)) {
1524  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches)) {
1525  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1526  }
1527  }
1528  }
1529  }
1530  }
1531 
1532  public static function _getInternalLinkHref($target = "", $a_parent_ref_id = null)
1533  {
1534  global $DIC;
1535 
1536  $ilDB = $DIC->database();
1537  $linktypes = array(
1538  "lm" => "LearningModule",
1539  "pg" => "PageObject",
1540  "st" => "StructureObject",
1541  "git" => "GlossaryItem",
1542  "mob" => "MediaObject"
1543  );
1544  $href = "";
1545  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches)) {
1546  $type = $matches[1];
1547  $target_id = $matches[2];
1548  switch ($linktypes[$matches[1]]) {
1549  case "LearningModule":
1550  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1551  break;
1552  case "PageObject":
1553  case "StructureObject":
1554  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1555  break;
1556  case "GlossaryItem":
1557  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/goto.php?target=" . $type . "_" . $target_id;
1558  break;
1559  case "MediaObject":
1560  $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;
1561  break;
1562  }
1563  }
1564  return $href;
1565  }
1566 
1575  public static function _isWriteable($question_id, $user_id)
1576  {
1577  global $DIC;
1578 
1579  $ilDB = $DIC->database();
1580 
1581  if (($question_id < 1) || ($user_id < 1)) {
1582  return false;
1583  }
1584 
1585  $result = $ilDB->queryF(
1586  "SELECT obj_fi FROM svy_question WHERE question_id = %s",
1587  array('integer'),
1588  array($question_id)
1589  );
1590  if ($result->numRows() == 1) {
1591  $row = $ilDB->fetchAssoc($result);
1592  $qpl_object_id = $row["obj_fi"];
1593  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1594  } else {
1595  return false;
1596  }
1597  }
1598 
1605  public function getQuestionTypeID()
1606  {
1607  $ilDB = $this->db;
1608  $result = $ilDB->queryF(
1609  "SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1610  array('text'),
1611  array($this->getQuestionType())
1612  );
1613  if ($result->numRows() == 1) {
1614  $row = $ilDB->fetchAssoc($result);
1615  return $row["questiontype_id"];
1616  } else {
1617  return 0;
1618  }
1619  }
1620 
1627  public function getQuestionType()
1628  {
1629  return "";
1630  }
1631 
1639  public static function _includeClass($question_type, $gui = 0)
1640  {
1641  $type = $question_type;
1642  if ($gui == 1) {
1643  $type .= "GUI";
1644  } elseif ($gui == 2) {
1645  $type .= "Evaluation";
1646  }
1647  if (file_exists("./Modules/SurveyQuestionPool/Questions/class." . $type . ".php")) {
1648  return true;
1649  } else {
1650  global $DIC;
1651 
1652  $ilPluginAdmin = $DIC["ilPluginAdmin"];
1653  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1654  foreach ($pl_names as $pl_name) {
1655  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1656  if (strcmp($pl->getQuestionType(), $question_type) == 0) {
1657  $pl->includeClass("class." . $type . ".php");
1658  return true;
1659  }
1660  }
1661  }
1662  return false;
1663  }
1664 
1671  public static function _getQuestionTypeName($type_tag)
1672  {
1673  if (file_exists("./Modules/SurveyQuestionPool/Questions/class." . $type_tag . ".php")) {
1674  global $DIC;
1675 
1676  $lng = $DIC->language();
1677  return $lng->txt($type_tag);
1678  } else {
1679  global $DIC;
1680 
1681  $ilPluginAdmin = $DIC["ilPluginAdmin"];
1682  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1683  foreach ($pl_names as $pl_name) {
1684  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1685  if (strcmp($pl->getQuestionType(), $type_tag) == 0) {
1686  return $pl->getQuestionTypeTranslation();
1687  }
1688  }
1689  }
1690  return "";
1691  }
1692 
1693 
1701  public static function _instanciateQuestion($question_id)
1702  {
1703  $question_type = self::_getQuestionType($question_id);
1704  if ($question_type) {
1705  self::_includeClass($question_type);
1706  $question = new $question_type();
1707  $question->loadFromDb($question_id);
1708  return $question;
1709  }
1710  }
1711 
1719  public static function _instanciateQuestionGUI($question_id)
1720  {
1721  $question_type = self::_getQuestionType($question_id);
1722  if ($question_type) {
1723  self::_includeClass($question_type, 1);
1724  $guitype = $question_type . "GUI";
1725  $question = new $guitype($question_id);
1726  return $question;
1727  }
1728  }
1729 
1737  public static function _instanciateQuestionEvaluation($question_id, array $a_finished_ids = null)
1738  {
1739  $question = self::_instanciateQuestion($question_id);
1740  if ($question) {
1741  $question_type = self::_getQuestionType($question_id);
1742  self::_includeClass($question_type, 2);
1743  $class = $question_type . "Evaluation";
1744  $ev = new $class($question, $a_finished_ids);
1745  return $ev;
1746  }
1747  }
1748 
1757  public function isHTML($a_text)
1758  {
1759  if (preg_match("/<[^>]*?>/", $a_text)) {
1760  return true;
1761  } else {
1762  return false;
1763  }
1764  }
1765 
1773  public function QTIMaterialToString($a_material)
1774  {
1775  $svy_log = ilLoggerFactory::getLogger("svy");
1776  $svy_log->debug("material count: " . $a_material->getMaterialCount());
1777 
1778  $result = "";
1779  for ($i = 0; $i < $a_material->getMaterialCount(); $i++) {
1780  $material = $a_material->getMaterial($i);
1781  if (strcmp($material["type"], "mattext") == 0) {
1782  $result .= $material["material"]->getContent();
1783  }
1784  if (strcmp($material["type"], "matimage") == 0) {
1785  $matimage = $material["material"];
1786  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches)) {
1787  // import an mediaobject which was inserted using tiny mce
1788  if (!is_array($_SESSION["import_mob_xhtml"])) {
1789  $_SESSION["import_mob_xhtml"] = array();
1790  }
1791  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1792  }
1793  }
1794  }
1795  return $result;
1796  }
1797 
1805  public function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = true, $add_mobs = true, $a_attrs = null)
1806  {
1807  $a_xml_writer->xmlStartTag("material");
1808  $attrs = array(
1809  "type" => "text/plain"
1810  );
1811  if ($this->isHTML($a_material)) {
1812  $attrs["type"] = "text/xhtml";
1813  }
1814  if (is_array($a_attrs)) {
1815  $attrs = array_merge($attrs, $a_attrs);
1816  }
1817  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1818 
1819  if ($add_mobs) {
1820  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1821  foreach ($mobs as $mob) {
1822  $mob_obj = new ilObjMediaObject($mob);
1823  $imgattrs = array(
1824  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1825  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle(),
1826  "type" => "spl:html",
1827  "id" => $this->getId()
1828  );
1829  $a_xml_writer->xmlElement("matimage", $imgattrs, null);
1830  }
1831  }
1832  if ($close_material_tag) {
1833  $a_xml_writer->xmlEndTag("material");
1834  }
1835  }
1836 
1843  public function prepareTextareaOutput($txt_output, $prepare_for_latex_output = false)
1844  {
1845  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1846  }
1847 
1855  public function getQuestionDataArray($id)
1856  {
1857  return array();
1858  }
1859 
1866  public function &getWorkingDataFromUserInput($post_data)
1867  {
1868  // overwrite in inherited classes
1869  $data = array();
1870  return $data;
1871  }
1872 
1881  public function importAdditionalMetadata($a_meta)
1882  {
1883  // overwrite in inherited classes
1884  }
1885 
1892  public function importResponses($a_data)
1893  {
1894  // overwrite in inherited classes
1895  }
1896 
1903  public function importAdjectives($a_data)
1904  {
1905  // overwrite in inherited classes
1906  }
1907 
1914  public function importMatrix($a_data)
1915  {
1916  // overwrite in inherited classes
1917  }
1918 
1925  public function usableForPrecondition()
1926  {
1927  // overwrite in inherited classes
1928  return false;
1929  }
1930 
1937  public function getAvailableRelations()
1938  {
1939  // overwrite in inherited classes
1940  return array();
1941  }
1942 
1948  public function getPreconditionOptions()
1949  {
1950  // overwrite in inherited classes
1951  }
1952 
1960  public function getPreconditionValueOutput($value)
1961  {
1962  // overwrite in inherited classes
1963  return $value;
1964  }
1965 
1972  public function getPreconditionSelectValue($default = "", $title, $variable)
1973  {
1974  // overwrite in inherited classes
1975  return null;
1976  }
1977 
1978  public function setOriginalId($original_id)
1979  {
1980  $this->original_id = $original_id;
1981  }
1982 
1983  public function getOriginalId()
1984  {
1985  return $this->original_id;
1986  }
1987 
1988  public function getMaterial()
1989  {
1990  return $this->material;
1991  }
1992 
1993  public function setSubtype($a_subtype)
1994  {
1995  // do nothing
1996  }
1997 
1998  public function getSubtype()
1999  {
2000  // do nothing
2001  return null;
2002  }
2003 
2007  public function __get($value)
2008  {
2009  switch ($value) {
2010  default:
2011  if (array_key_exists($value, $this->arrData)) {
2012  return $this->arrData[$value];
2013  } else {
2014  return null;
2015  }
2016  break;
2017  }
2018  }
2019 
2023  public function __set($key, $value)
2024  {
2025  switch ($key) {
2026  default:
2027  $this->arrData[$key] = $value;
2028  break;
2029  }
2030  }
2031 
2039  public static function _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
2040  {
2041  global $DIC;
2042 
2043  $ilDB = $DIC->database();
2044 
2045  $ilDB->manipulate("UPDATE svy_question" .
2046  " SET original_id = " . $ilDB->quote($a_original_id, "integer") . "," .
2047  " obj_fi = " . $ilDB->quote($a_object_id, "integer") .
2048  " WHERE question_id = " . $ilDB->quote($a_question_id, "integer"));
2049  }
2050 
2051  public function getCopyIds($a_group_by_survey = false)
2052  {
2053  $ilDB = $this->db;
2054 
2055  $set = $ilDB->query("SELECT q.question_id,s.obj_fi" .
2056  " FROM svy_question q" .
2057  " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)" .
2058  " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)" .
2059  " WHERE original_id = " . $ilDB->quote($this->getId(), "integer"));
2060  $res = array();
2061  while ($row = $ilDB->fetchAssoc($set)) {
2062  if (!$a_group_by_survey) {
2063  $res[] = $row["question_id"];
2064  } else {
2065  $res[$row["obj_fi"]][] = $row["question_id"];
2066  }
2067  }
2068  return $res;
2069  }
2070 
2071  public function hasCopies()
2072  {
2073  return (bool) sizeof($this->getCopyIds());
2074  }
2075 
2076  public static function _lookupSurveyObjId($a_question_id)
2077  {
2078  global $DIC;
2079 
2080  $ilDB = $DIC->database();
2081 
2082  $set = $ilDB->query("SELECT svy_svy.obj_fi FROM svy_svy_qst" .
2083  " JOIN svy_svy ON (svy_svy.survey_id = svy_svy_qst.survey_fi)" .
2084  " WHERE svy_svy_qst.question_fi = " . $ilDB->quote($a_question_id, "integer"));
2085  $row = $ilDB->fetchAssoc($set);
2086  if ($ilDB->numRows($set)) {
2087  return $row["obj_fi"];
2088  }
2089  }
2090 
2097  public static function lookupObjFi($a_qid)
2098  {
2099  global $DIC;
2100 
2101  $ilDB = $DIC->database();
2102 
2103  $set = $ilDB->query(
2104  "SELECT obj_fi FROM svy_question " .
2105  " WHERE question_id = " . $ilDB->quote($a_qid, "integer")
2106  );
2107  $rec = $ilDB->fetchAssoc($set);
2108  return $rec["obj_fi"];
2109  }
2110 
2118  public function stripSlashesAddSpaceFallback($a_str)
2119  {
2120  $str = ilUtil::stripSlashes($a_str);
2121  if ($str != $a_str) {
2122  $str = ilUtil::stripSlashes(str_replace("<", "< ", $a_str));
2123  }
2124  return $str;
2125  }
2126 
2132  public static function getMaxSumScore(int $survey_id) : int
2133  {
2134  return 0;
2135  }
2136 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static _instanciateQuestionGUI($question_id)
Creates an instance of a question GUI with a given question id.
static _resolveInternalLink($internal_link)
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
addMaterials($materials_file, $materials_name="")
Sets the materials uri.
__construct($title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
getAuthor()
Gets the authors name of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
getTitle()
Gets the title string of the SurveyQuestion object.
$data
Definition: storeScorm.php:23
const IL_INST_ID
Definition: constants.php:38
phraseExists($title)
Returns true if the phrase title already exists for the current user.
saveToDb($original_id="")
Saves a SurveyQuestion object to a database.
static handleQuestionDeletion($a_question_id, $a_obj_id)
Remove question skill assignment.
$_SESSION["AccountId"]
$result
$mobs
Definition: imgupload.php:54
getObligatory($survey_id="")
Gets the obligatory state of the question.
QTIMaterialToString($a_material)
Reads an QTI material tag an creates a text string.
$type
static _lookupSurveyObjId($a_question_id)
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
setObligatory($obligatory=1)
Sets the obligatory state of the question.
getMaterialsPath()
Returns the materials path for web accessable materials of a question.
setOrientation($orientation=0)
Sets the orientation of the question output.
__set($key, $value)
Object setter.
copyXHTMLMediaObjectsOfQuestion($a_q_id)
Increases the media object usage counter when a question is duplicated.
importResponses($a_data)
Import response data from the question import file.
importMatrix($a_data)
Import matrix rows from the question import file.
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 _getIdForImportId($a_import_id)
get current object id for import id (static)
static _getTitle($question_id)
Returns the question title of a question with a given id.
static _resolveIntLinks($question_id)
deleteMaterial($materials_name="")
Deletes a materials uri with a given name.
importAdjectives($a_data)
Import bipolar adjectives from the question import file.
getMaterialsPathWeb()
Returns the web image path for web accessable images of a question.
static _isWriteable($object_id, $user_id)
Returns true, if the question pool is writeable by a given user.
setId($id=-1)
Sets the id of the SurveyQuestion object.
flushMaterials()
Deletes all materials uris.
static _isComplete($question_id)
Checks whether the question is complete or not.
static _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
Change original id of existing question in db.
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
static _getQuestionType($question_id)
Returns the question type of a question with a given id.
usableForPrecondition()
Returns if the question is usable for preconditions.
$target_id
Definition: goto.php:51
getQuestionDataArray($id)
Returns the question data fields from the database.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
Survey material class.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static lookupObjFi($a_qid)
Lookip obj fi.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
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($question_id, $user_id)
Returns true if the question is writeable by a certain user.
loadFromDb($question_id)
Loads a SurveyQuestion object from the database.
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...
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
user()
Definition: user.php:4
setComplete($a_complete)
Sets the complete state of the question.
getPreconditionOptions()
Returns the options for preconditions.
setMaterial($material_id="", $is_import=false, $material_title="")
Sets a material link for the question.
getQuestionTypeID()
Returns the question type ID of the question.
addMaterial($obj_material)
setOriginalId($original_id)
duplicate($for_survey=true, $title="", $author="", $owner="", $a_survey_id=0)
Duplicates a survey question.
getOwner()
Gets the creator/owner ID of the SurveyQuestion object.
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
static _getOriginalId($question_id, $a_return_question_id_if_no_original=true)
Returns the original id of a question.
Class ilLMPageObject.
foreach($_POST as $key=> $value) $res
static _instanciateQuestionEvaluation($question_id, array $a_finished_ids=null)
Creates an instance of a question evaluation with a given question id.
getId()
Gets the id of the SurveyQuestion object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getPhrase($phrase_id)
Returns a phrase for a given database id.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
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.
prepareTextareaOutput($txt_output, $prepare_for_latex_output=false)
Prepares a string for a text area output in surveys.
Basic class for all survey question types.
global $DIC
Definition: goto.php:24
saveMaterial()
save material to db
static _questionExists($question_id)
Returns true if the question already exists in the database.
static getMaxSumScore(int $survey_id)
Get max sum score for specific survey (and this question type)
const IL_COMP_MODULE
getAvailableRelations()
Returns the available relations for the question.
Class ilObjMediaObject.
const CLIENT_WEB_DIR
Definition: constants.php:45
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static removeTrailingPathSeparators($path)
static _getInternalLinkHref($target="", $a_parent_ref_id=null)
setSurveyId($id=-1)
Sets the survey id of the SurveyQuestion object.
$filename
Definition: buildRTE.php:89
addInternalLink($material_id, $title="")
isComplete()
Returns 1, if a question is complete for use.
saveWorkingData($limit_to=LIMIT_NO_LIMIT)
Saves the learners input of the question to the database.
getImagePath()
Returns the image path for web accessable images of a question.
Class ilStructreObject.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
const LIMIT_NO_LIMIT
Assessment constants.
deleteMaterials($a_array)
Deletes materials.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
global $ilDB
setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
Sets and uploads the materials uri.
Class ilObjContentObjectGUI.
copyObject($target_questionpool, $title="")
Copies an assOrderingQuestion object.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
static _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
Synchronises appearances of media objects in $a_text with media object usage table.
getDescription()
Gets the description string of the SurveyQuestion object.
static getLogger($a_component_id)
Get component logger.
getObjId()
Get the reference id of the container object.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
$ilUser
Definition: imgupload.php:18
duplicateMaterials($question_id)
Duplicates the materials of a question.
setObjId($obj_id=0)
Set the reference id of the container object.
isHTML($a_text)
Checks if a given string contains HTML or not.
__get($value)
Object getter.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
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.
$arrData
data array containing the question data
static _lookGlossaryTerm($term_id)
get glossary term
getQuestionType()
Returns the question type of the question.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
createNewQuestion()
Creates a new question with a 0 timestamp when a new question is created This assures that an ID is g...
getCopyIds($a_group_by_survey=false)
deleteAdditionalTableData($question_id)
Deletes datasets from the additional question table in the database.
getSurveyId()
Gets the survey id of the SurveyQuestion object.
$i
Definition: metadata.php:24
setTitle($title="")
Sets the title string of the SurveyQuestion object.
questionTitleExists($title, $questionpool_object="")
Returns TRUE if the question title exists in the database.