ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
41  var $id;
42 
48  var $title;
61  var $owner;
62 
69  var $author;
70 
77 
84 
90  var $obj_id;
91 
98 
105 
111  var $ilias;
112 
118  var $tpl;
119 
125  var $lng;
126 
133 
136 
140  protected $cumulated;
141 
145  private $arrData;
146 
150  protected $log;
151 
162  function __construct($title = "", $description = "", $author = "", $questiontext = "", $owner = -1)
163  {
164  global $ilias, $lng, $tpl;
165 
166  $this->ilias = $ilias;
167  $this->lng = $lng;
168  $this->tpl = $tpl;
169  $this->complete = 0;
170  $this->title = $title;
171  $this->description = $description;
172  $this->questiontext = $questiontext;
173  $this->author = $author;
174  $this->cumulated = array();
175  if (!$this->author)
176  {
177  $this->author = $this->ilias->account->fullname;
178  }
179  $this->owner = $owner;
180  if ($this->owner == -1)
181  {
182  $this->owner = $this->ilias->account->id;
183  }
184  $this->id = -1;
185  $this->survey_id = -1;
186  $this->obligatory = 1;
187  $this->orientation = 0;
188  $this->materials = array();
189  $this->material = array();
190  $this->arrData = array();
191 
192  $this->log = ilLoggerFactory::getLogger('svy');
193  }
194 
201  function setComplete($a_complete)
202  {
203  $this->complete = ($a_complete) ? 1 : 0;
204  }
205 
212  function isComplete()
213  {
214  return 0;
215  }
216 
225  function questionTitleExists($title, $questionpool_object = "")
226  {
227  global $ilDB;
228 
229  $refwhere = "";
230  if (strcmp($questionpool_object, "") != 0)
231  {
232  $refwhere = sprintf(" AND obj_fi = %s",
233  $ilDB->quote($questionpool_object, 'integer')
234  );
235  }
236  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE title = %s$refwhere",
237  array('text'),
238  array($title)
239  );
240  return ($result->numRows() > 0) ? true : false;
241  }
242 
250  function setTitle($title = "")
251  {
252  $this->title = $title;
253  }
254 
262  function setObligatory($obligatory = 1)
263  {
264  $this->obligatory = ($obligatory) ? 1 : 0;
265  }
266 
274  function setOrientation($orientation = 0)
275  {
276  $this->orientation = ($orientation) ? $orientation : 0;
277  }
278 
286  function setId($id = -1)
287  {
288  $this->id = $id;
289  }
290 
298  function setSurveyId($id = -1)
299  {
300  $this->survey_id = $id;
301  }
302 
310  function setDescription($description = "")
311  {
312  $this->description = $description;
313  }
314 
323  function addMaterials($materials_file, $materials_name="")
324  {
325  if (empty($materials_name))
326  {
327  $materials_name = $materials_file;
328  }
329  if ((!empty($materials_name))&&(!array_key_exists($materials_name, $this->materials)))
330  {
331  $this->materials[$materials_name] = $materials_file;
332  }
333  }
334 
342  function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
343  {
344  if (!empty($materials_filename))
345  {
346  $materialspath = $this->getMaterialsPath();
347  if (!file_exists($materialspath))
348  {
349  ilUtil::makeDirParents($materialspath);
350  }
351  if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
352  $materialspath.$materials_filename))
353  {
354  print "image not uploaded!!!! ";
355  }
356  else
357  {
358  $this->addMaterials($materials_filename, $materials_name);
359  }
360  }
361  }
362 
370  function deleteMaterial($materials_name = "")
371  {
372  foreach ($this->materials as $key => $value)
373  {
374  if (strcmp($key, $materials_name)==0)
375  {
376  if (file_exists($this->getMaterialsPath().$value))
377  {
378  unlink($this->getMaterialsPath().$value);
379  }
380  unset($this->materials[$key]);
381  }
382  }
383  }
384 
391  function flushMaterials()
392  {
393  $this->materials = array();
394  }
395 
403  function setAuthor($author = "")
404  {
405  if (!$author)
406  {
407  $author = $this->ilias->account->fullname;
408  }
409  $this->author = $author;
410  }
411 
419  function setQuestiontext($questiontext = "")
420  {
421  $this->questiontext = $questiontext;
422  }
423 
431  function setOwner($owner = "")
432  {
433  $this->owner = $owner;
434  }
435 
443  function getTitle()
444  {
445  return $this->title;
446  }
447 
448  function getLabel()
449  {
450  return $this->label;
451  }
452 
460  function getId()
461  {
462  return $this->id;
463  }
464 
471  public function getObligatory($survey_id = "")
472  {
473  return ($this->obligatory) ? 1 : 0;
474  }
475 
483  function getSurveyId()
484  {
485  return $this->survey_id;
486  }
487 
495  function getOrientation()
496  {
497  switch ($this->orientation)
498  {
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  function getDescription()
519  {
520  return (strlen($this->description)) ? $this->description : NULL;
521  }
522 
530  function getAuthor()
531  {
532  return (strlen($this->author)) ? $this->author : NULL;
533  }
534 
542  function getOwner()
543  {
544  return $this->owner;
545  }
546 
554  function getQuestiontext()
555  {
556  return (strlen($this->questiontext)) ? $this->questiontext : NULL;
557  }
558 
566  function getObjId() {
567  return $this->obj_id;
568  }
569 
577  function setObjId($obj_id = 0)
578  {
579  $this->obj_id = $obj_id;
580  }
581 
587  function duplicate($for_survey = true, $title = "", $author = "", $owner = "", $a_survey_id = 0)
588  {
589  if ($this->getId() <= 0)
590  {
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  {
600  $clone->setObjId($a_survey_id);
601  }
602  if ($title)
603  {
604  $clone->setTitle($title);
605  }
606  if ($author)
607  {
608  $clone->setAuthor($author);
609  }
610  if ($owner)
611  {
612  $clone->setOwner($owner);
613  }
614  if ($for_survey)
615  {
616  $clone->saveToDb($original_id);
617  }
618  else
619  {
620  $clone->saveToDb();
621  }
622  // duplicate the materials
623  $clone->duplicateMaterials($original_id);
624  // copy XHTML media objects
625  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
626  return $clone->getId();
627  }
628 
634  function copyObject($target_questionpool, $title = "")
635  {
636  if ($this->getId() <= 0)
637  {
638  // The question has not been saved. It cannot be copied
639  return;
640  }
641  $clone = $this;
642  $original_id = self::_getOriginalId($this->getId(), false);
643  $clone->setId(-1);
644  $source_questionpool = $this->getObjId();
645  $clone->setObjId($target_questionpool);
646  if ($title)
647  {
648  $clone->setTitle($title);
649  }
650 
651  $clone->saveToDb();
652 
653  // duplicate the materials
654  $clone->duplicateMaterials($original_id);
655  // copy XHTML media objects
656  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
657  return $clone->getId();
658  }
659 
667  {
668  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
669  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
670  foreach ($mobs as $mob)
671  {
672  ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
673  }
674  }
675 
682  function loadFromDb($question_id)
683  {
684  global $ilDB;
685 
686  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
687  array('integer'),
688  array($this->getId())
689  );
690  $this->material = array();
691  if ($result->numRows())
692  {
693  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
694  while ($row = $ilDB->fetchAssoc($result))
695  {
696  $mat = new ilSurveyMaterial();
697  $mat->type = $row['material_type'];
698  $mat->internal_link = $row['internal_link'];
699  $mat->title = $row['material_title'];
700  $mat->import_id = $row['import_id'];
701  $mat->text_material = $row['text_material'];
702  $mat->external_link = $row['external_link'];
703  $mat->file_material = $row['file_material'];
704  array_push($this->material, $mat);
705  }
706  }
707  }
708 
715  static function _isComplete($question_id)
716  {
717  global $ilDB;
718 
719  $result = $ilDB->queryF("SELECT complete FROM svy_question WHERE question_id = %s",
720  array('integer'),
721  array($question_id)
722  );
723  if ($result->numRows())
724  {
725  $row = $ilDB->fetchAssoc($result);
726  if ($row["complete"] == 1)
727  {
728  return TRUE;
729  }
730  }
731  return FALSE;
732  }
733 
739  function saveCompletionStatus($original_id = "")
740  {
741  global $ilDB;
742 
743  $question_id = $this->getId();
744  if (strlen($original_id))
745  {
746  $question_id = $original_id;
747  }
748 
749  if ($this->getId() > 0)
750  {
751  $this->log->debug("UPDATE svy_question question_id=".$question_id);
752 
753  // update existing dataset
754  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
755  array('text', 'integer', 'integer'),
756  array($this->isComplete(), time(), $question_id)
757  );
758  }
759  }
760 
767  function saveToDb($original_id = "")
768  {
769  global $ilDB;
770 
771  // cleanup RTE images which are not inserted into the question text
772  include_once("./Services/RTE/classes/class.ilRTE.php");
773  ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
774  $affectedRows = 0;
775  if ($this->getId() == -1)
776  {
777  // Write new dataset
778  $next_id = $ilDB->nextId('svy_question');
779  $affectedRows = $ilDB->insert("svy_question", array(
780  "question_id" => array("integer", $next_id),
781  "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
782  "obj_fi" => array("integer", $this->getObjId()),
783  "owner_fi" => array("integer", $this->getOwner()),
784  "title" => array("text", $this->getTitle()),
785  "label" => array("text", (strlen($this->label)) ? $this->label : null),
786  "description" => array("text", $this->getDescription()),
787  "author" => array("text", $this->getAuthor()),
788  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
789  "obligatory" => array("text", $this->getObligatory()),
790  "complete" => array("text", $this->isComplete()),
791  "created" => array("integer", time()),
792  "original_id" => array("integer", ($original_id) ? $original_id : NULL),
793  "tstamp" => array("integer", time())
794  ));
795 
796  //$this->log->debug("INSERT: svy_question id=".$next_id." questiontype_fi=".$this->getQuestionTypeID()." obj_fi".$this->getObjId()." title=".$this->getTitle()." ...");
797 
798  $this->setId($next_id);
799  }
800  else
801  {
802  // update existing dataset
803  $affectedRows = $ilDB->update("svy_question", array(
804  "title" => array("text", $this->getTitle()),
805  "label" => array("text", (strlen($this->label)) ? $this->label : null),
806  "description" => array("text", $this->getDescription()),
807  "author" => array("text", $this->getAuthor()),
808  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
809  "obligatory" => array("text", $this->getObligatory()),
810  "complete" => array("text", $this->isComplete()),
811  "tstamp" => array("integer", time())
812  ), array(
813  "question_id" => array("integer", $this->getId())
814  ));
815 
816  $this->log->debug("UPDATE svy_question id=".$this->getId()." SET: title=".$this->getTitle()." ...");
817  }
818 
819  return $affectedRows;
820  }
821 
825  public function saveMaterial()
826  {
827  global $ilDB;
828 
829  include_once "./Services/Link/classes/class.ilInternalLink.php";
830 
831  $this->log->debug("DELETE: svy_material question_fi=".$this->getId());
832 
833  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
834  array('integer'),
835  array($this->getId())
836  );
838 
839  foreach ($this->material as $material)
840  {
841  $next_id = $ilDB->nextId('svy_material');
842 
843  $this->log->debug("INSERT: svy_material question_fi=".$this->getId());
844 
845  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material " .
846  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
847  "text_material, external_link, file_material, material_type) ".
848  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
849  array('integer','integer','text','text','text','integer','text','text','text','integer'),
850  array(
851  $next_id, $this->getId(), $material->internal_link, $material->import_id,
852  $material->title, time(), $material->text_material, $material->external_link,
853  $material->file_material, $material->type)
854  );
855  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches))
856  {
857  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
858  }
859  }
860  }
861 
868  public function createNewQuestion()
869  {
870  global $ilDB;
871 
872  $obj_id = $this->getObjId();
873  if ($obj_id > 0)
874  {
875  $next_id = $ilDB->nextId('svy_question');
876  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_question (question_id, questiontype_fi, " .
877  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
878  "created, original_id, tstamp) VALUES " .
879  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
880  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
881  'text', 'text', 'integer', 'integer', 'integer'),
882  array(
883  $next_id,
884  $this->getQuestionTypeID(),
885  $obj_id,
886  $this->getOwner(),
887  NULL,
888  NULL,
889  $this->getAuthor(),
890  NULL,
891  "1",
892  "0",
893  time(),
894  NULL,
895  0
896  )
897  );
898  $this->log->debug("INSERT INTO svy_question question_id= ".$next_id." questiontype_fi= ".$this->getQuestionTypeID());
899 
900  $this->setId($next_id);
901  }
902  return $this->getId();
903  }
904 
911  function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
912  {
913  }
914 
921  function getImagePath()
922  {
923  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
924  }
925 
932  function getMaterialsPath()
933  {
934  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
935  }
936 
943  function getImagePathWeb()
944  {
945  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
946  return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
947  }
948 
956  {
957  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
958  return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
959  }
960 
969  function saveCategoryToDb($categorytext, $neutral = 0)
970  {
971  global $ilUser, $ilDB;
972 
973  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
974  array('text','text','integer'),
975  array($categorytext, $neutral, $ilUser->getId())
976  );
977  $insert = FALSE;
978  $returnvalue = "";
979  if ($result->numRows())
980  {
981  $insert = TRUE;
982  while ($row = $ilDB->fetchAssoc($result))
983  {
984  if (strcmp($row["title"], $categorytext) == 0)
985  {
986  $returnvalue = $row["category_id"];
987  $insert = FALSE;
988  }
989  }
990  }
991  else
992  {
993  $insert = TRUE;
994  }
995  if ($insert)
996  {
997  $next_id = $ilDB->nextId('svy_category');
998  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
999  array('integer','text','text','integer','integer'),
1000  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
1001  );
1002 
1003  $this->log->debug("INSERT INTO svy_category id=".$next_id);
1004 
1005  $returnvalue = $next_id;
1006  }
1007  return $returnvalue;
1008  }
1009 
1016  function deleteAdditionalTableData($question_id)
1017  {
1018  global $ilDB;
1019 
1020  $this->log->debug("DELETE FROM ".$this->getAdditionalTableName());
1021 
1022  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1023  array('integer'),
1024  array($question_id)
1025  );
1026  }
1027 
1034  function delete($question_id)
1035  {
1036  global $ilDB;
1037 
1038  if ($question_id < 1) return;
1039 
1040  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1041  array('integer'),
1042  array($question_id)
1043  );
1044  if ($result->numRows() == 1)
1045  {
1046  $row = $ilDB->fetchAssoc($result);
1047  $obj_id = $row["obj_fi"];
1048  }
1049  else
1050  {
1051  return;
1052  }
1053 
1054  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_answer WHERE question_fi = %s",
1055  array('integer'),
1056  array($question_id)
1057  );
1058 
1059  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE question_fi = %s",
1060  array('integer'),
1061  array($question_id)
1062  );
1063 
1064  $result = $ilDB->queryF("SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1065  array('integer'),
1066  array($question_id)
1067  );
1068  while ($row = $ilDB->fetchObject($result))
1069  {
1070  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE constraint_id = %s",
1071  array('integer'),
1072  array($row->constraint_fi)
1073  );
1074  }
1075 
1076  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1077  array('integer'),
1078  array($question_id)
1079  );
1080  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1081  array('integer'),
1082  array($question_id)
1083  );
1084  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_svy_qst WHERE question_fi = %s",
1085  array('integer'),
1086  array($question_id)
1087  );
1088  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
1089  array('integer'),
1090  array($question_id)
1091  );
1092  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_question WHERE question_id = %s",
1093  array('integer'),
1094  array($question_id)
1095  );
1096 
1097  $this->deleteAdditionalTableData($question_id);
1098 
1099  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1100  array('integer'),
1101  array($question_id)
1102  );
1103 
1104  $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);
1105 
1106  include_once "./Services/Link/classes/class.ilInternalLink.php";
1107  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1108 
1109  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1110  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
1111  {
1112  ilUtil::delDir($directory);
1113  }
1114 
1115  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1116  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1117  // remaining usages are not in text anymore -> delete them
1118  // and media objects (note: delete method of ilObjMediaObject
1119  // checks whether object is used in another context; if yes,
1120  // the object is not deleted!)
1121  foreach($mobs as $mob)
1122  {
1123  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1124  $mob_obj = new ilObjMediaObject($mob);
1125  $mob_obj->delete();
1126  }
1127 
1128  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1129  ilSurveySkill::handleQuestionDeletion($question_id, $obj_id);
1130 
1131  $this->log->debug("UPDATE svy_question");
1132 
1133  // #12772 - untie question copies from pool question
1134  $ilDB->manipulate("UPDATE svy_question".
1135  " SET original_id = NULL".
1136  " WHERE original_id = ".$ilDB->quote($question_id, "integer"));
1137  }
1138 
1146  static function _getQuestionType($question_id)
1147  {
1148  global $ilDB;
1149 
1150  if ($question_id < 1) return "";
1151 
1152  $result = $ilDB->queryF("SELECT type_tag FROM svy_question, svy_qtype WHERE svy_question.question_id = %s AND svy_question.questiontype_fi = svy_qtype.questiontype_id",
1153  array('integer'),
1154  array($question_id)
1155  );
1156  if ($result->numRows() == 1)
1157  {
1158  $data = $ilDB->fetchAssoc($result);
1159  return $data["type_tag"];
1160  }
1161  else
1162  {
1163  return "";
1164  }
1165  }
1166 
1174  static function _getTitle($question_id)
1175  {
1176  global $ilDB;
1177 
1178  if ($question_id < 1) return "";
1179 
1180  $result = $ilDB->queryF("SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1181  array('integer'),
1182  array($question_id)
1183  );
1184  if ($result->numRows() == 1)
1185  {
1186  $data = $ilDB->fetchAssoc($result);
1187  return $data["title"];
1188  }
1189  else
1190  {
1191  return "";
1192  }
1193  }
1194 
1202  static function _getOriginalId($question_id, $a_return_question_id_if_no_original = true)
1203  {
1204  global $ilDB;
1205  $result = $ilDB->queryF("SELECT * FROM svy_question WHERE question_id = %s",
1206  array('integer'),
1207  array($question_id)
1208  );
1209  if ($result->numRows() > 0)
1210  {
1211  $row = $ilDB->fetchAssoc($result);
1212  if ($row["original_id"] > 0)
1213  {
1214  return $row["original_id"];
1215  }
1216  else if((bool)$a_return_question_id_if_no_original) // #12419
1217  {
1218  return $row["question_id"];
1219  }
1220  }
1221  else
1222  {
1223  return "";
1224  }
1225  }
1226 
1227  function syncWithOriginal()
1228  {
1229  global $ilDB;
1230 
1231  if ($this->getOriginalId())
1232  {
1233  $id = $this->getId();
1234  $original = $this->getOriginalId();
1235 
1236  $this->setId($this->getOriginalId());
1237  $this->setOriginalId(NULL);
1238  $this->saveToDb();
1239 
1240  $this->setId($id);
1241  $this->setOriginalId($original);
1242 
1243  $this->log->debug("DELETE FROM svy_material WHERE question_fi = ".$this->getOriginalId());
1244 
1245  include_once "./Services/Link/classes/class.ilInternalLink.php";
1246  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1247  array('integer'),
1248  array($this->getOriginalId())
1249  );
1250  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1251  if (strlen($this->material["internal_link"]))
1252  {
1253  $next_id = $ilDB->nextId('svy_material');
1254  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material (material_id, question_fi, internal_link, import_id, material_title, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
1255  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1256  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1257  );
1258 
1259  $this->log->debug("INSERT svy_material material_id=".$next_id." question_fi=".$this->getOriginalId());
1260 
1261  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
1262  {
1263  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1264  }
1265  }
1266  }
1267  }
1268 
1275  function getPhrase($phrase_id)
1276  {
1277  global $ilDB;
1278 
1279  $result = $ilDB->queryF("SELECT title FROM svy_phrase WHERE phrase_id = %s",
1280  array('integer'),
1281  array($phrase_id)
1282  );
1283  if ($row = $ilDB->fetchAssoc($result))
1284  {
1285  return $row["title"];
1286  }
1287  return "";
1288  }
1289 
1297  function phraseExists($title)
1298  {
1299  global $ilUser, $ilDB;
1300 
1301  $result = $ilDB->queryF("SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1302  array('text', 'integer'),
1303  array($title, $ilUser->getId())
1304  );
1305  return ($result->numRows() == 0) ? false : true;
1306  }
1307 
1315  static function _questionExists($question_id)
1316  {
1317  global $ilDB;
1318 
1319  if ($question_id < 1)
1320  {
1321  return false;
1322  }
1323 
1324  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE question_id = %s",
1325  array('integer'),
1326  array($question_id)
1327  );
1328  return ($result->numRows() == 1) ? true : false;
1329  }
1330 
1331  function addInternalLink($material_id, $title = "")
1332  {
1333  if (strlen($material_id))
1334  {
1335  if (strcmp($material_title, "") == 0)
1336  {
1337  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1338  {
1339  $type = $matches[1];
1340  $target_id = $matches[2];
1341  $material_title = $this->lng->txt("obj_$type") . ": ";
1342  switch ($type)
1343  {
1344  case "lm":
1345  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1346  $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1347  $cont_obj = $cont_obj_gui->object;
1348  $material_title .= $cont_obj->getTitle();
1349  break;
1350  case "pg":
1351  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1352  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1354  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1355  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, FALSE);
1356  $cont_obj = $cont_obj_gui->object;
1357  $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1358  $material_title .= $pg_obj->getTitle();
1359  break;
1360  case "st":
1361  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1362  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1364  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1365  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, FALSE);
1366  $cont_obj = $cont_obj_gui->object;
1367  $st_obj = new ilStructureObject($cont_obj, $target_id);
1368  $material_title .= $st_obj->getTitle();
1369  break;
1370  case "git":
1371  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1372  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1373  break;
1374  case "mob":
1375  break;
1376  }
1377  }
1378  }
1379  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1380  $mat = new ilSurveyMaterial();
1381  $mat->type = 0;
1382  $mat->internal_link = $material_id;
1383  $mat->title = $material_title;
1384  $this->addMaterial($mat);
1385  $this->saveMaterial();
1386  }
1387  }
1388 
1394  public function deleteMaterials($a_array)
1395  {
1396  foreach ($a_array as $idx)
1397  {
1398  unset($this->material[$idx]);
1399  }
1400  $this->material = array_values($this->material);
1401  $this->saveMaterial();
1402  }
1403 
1410  function duplicateMaterials($question_id)
1411  {
1412  foreach ($this->materials as $filename)
1413  {
1414  $materialspath = $this->getMaterialsPath();
1415  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1416  if (!file_exists($materialspath))
1417  {
1418  ilUtil::makeDirParents($materialspath);
1419  }
1420  if (!copy($materialspath_original . $filename, $materialspath . $filename))
1421  {
1422  print "material could not be duplicated!!!! ";
1423  }
1424  }
1425  }
1426 
1427  public function addMaterial($obj_material)
1428  {
1429  array_push($this->material, $obj_material);
1430  }
1431 
1439  function setMaterial($material_id = "", $is_import = false, $material_title = "")
1440  {
1441  if (strcmp($material_id, "") != 0)
1442  {
1443  $import_id = "";
1444  if ($is_import)
1445  {
1446  $import_id = $material_id;
1447  $material_id = self::_resolveInternalLink($import_id);
1448  }
1449  if (strcmp($material_title, "") == 0)
1450  {
1451  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1452  {
1453  $type = $matches[1];
1454  $target_id = $matches[2];
1455  $material_title = $this->lng->txt("obj_$type") . ": ";
1456  switch ($type)
1457  {
1458  case "lm":
1459  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1460  $cont_obj_gui = new ilObjContentObjectGUI("", $target_id, true);
1461  $cont_obj = $cont_obj_gui->object;
1462  $material_title .= $cont_obj->getTitle();
1463  break;
1464  case "pg":
1465  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1466  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1468  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1469  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, FALSE);
1470  $cont_obj = $cont_obj_gui->object;
1471  $pg_obj = new ilLMPageObject($cont_obj, $target_id);
1472  $material_title .= $pg_obj->getTitle();
1473  break;
1474  case "st":
1475  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1476  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1478  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1479  $cont_obj_gui = new ilObjContentObjectGUI("", $lm_id, FALSE);
1480  $cont_obj = $cont_obj_gui->object;
1481  $st_obj = new ilStructureObject($cont_obj, $target_id);
1482  $material_title .= $st_obj->getTitle();
1483  break;
1484  case "git":
1485  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1486  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1487  break;
1488  case "mob":
1489  break;
1490  }
1491  }
1492  }
1493  $this->material = array(
1494  "internal_link" => $material_id,
1495  "import_id" => $import_id,
1496  "title" => $material_title
1497  );
1498  }
1499  $this->saveMaterial();
1500  }
1501 
1502  static function _resolveInternalLink($internal_link)
1503  {
1504  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
1505  {
1506  include_once "./Services/Link/classes/class.ilInternalLink.php";
1507  include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1508  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1509  switch ($matches[2])
1510  {
1511  case "lm":
1512  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1513  break;
1514  case "pg":
1515  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1516  break;
1517  case "st":
1518  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1519  break;
1520  case "git":
1521  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1522  break;
1523  case "mob":
1524  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1525  break;
1526  }
1527  if (strcmp($resolved_link, "") == 0)
1528  {
1529  $resolved_link = $internal_link;
1530  }
1531  }
1532  else
1533  {
1534  $resolved_link = $internal_link;
1535  }
1536  return $resolved_link;
1537  }
1538 
1539  static function _resolveIntLinks($question_id)
1540  {
1541  global $ilDB;
1542  $resolvedlinks = 0;
1543  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1544  array('integer'),
1545  array($question_id)
1546  );
1547  if ($result->numRows())
1548  {
1549  while ($row = $ilDB->fetchAssoc($result))
1550  {
1551  $internal_link = $row["internal_link"];
1552  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1553  $resolved_link = self::_resolveInternalLink($internal_link);
1554  if (strcmp($internal_link, $resolved_link) != 0)
1555  {
1556  // internal link was resolved successfully
1557  $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1558  array('text', 'integer', 'integer'),
1559  array($resolved_link, time(), $row["material_id"])
1560  );
1561  $resolvedlinks++;
1562  }
1563  }
1564  }
1565  if ($resolvedlinks)
1566  {
1567  // there are resolved links -> reenter theses links to the database
1568 
1569  // delete all internal links from the database
1570  include_once "./Services/Link/classes/class.ilInternalLink.php";
1571  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1572 
1573  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1574  array('integer'),
1575  array($question_id)
1576  );
1577  if ($result->numRows())
1578  {
1579  while ($row = $ilDB->fetchAssoc($result))
1580  {
1581  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
1582  {
1583  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1584  }
1585  }
1586  }
1587  }
1588  }
1589 
1590  static function _getInternalLinkHref($target = "", $a_parent_ref_id = null)
1591  {
1592  global $ilDB;
1593  $linktypes = array(
1594  "lm" => "LearningModule",
1595  "pg" => "PageObject",
1596  "st" => "StructureObject",
1597  "git" => "GlossaryItem",
1598  "mob" => "MediaObject"
1599  );
1600  $href = "";
1601  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
1602  {
1603  $type = $matches[1];
1604  $target_id = $matches[2];
1605  switch($linktypes[$matches[1]])
1606  {
1607  case "LearningModule":
1608  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1609  break;
1610  case "PageObject":
1611  case "StructureObject":
1612  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1613  break;
1614  case "GlossaryItem":
1615  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1616  break;
1617  case "MediaObject":
1618  $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;
1619  break;
1620  }
1621  }
1622  return $href;
1623  }
1624 
1633  static function _isWriteable($question_id, $user_id)
1634  {
1635  global $ilDB;
1636 
1637  if (($question_id < 1) || ($user_id < 1))
1638  {
1639  return false;
1640  }
1641 
1642  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1643  array('integer'),
1644  array($question_id)
1645  );
1646  if ($result->numRows() == 1)
1647  {
1648  $row = $ilDB->fetchAssoc($result);
1649  $qpl_object_id = $row["obj_fi"];
1650  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1651  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1652  }
1653  else
1654  {
1655  return false;
1656  }
1657  }
1658 
1666  {
1667  global $ilDB;
1668  $result = $ilDB->queryF("SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1669  array('text'),
1670  array($this->getQuestionType())
1671  );
1672  if ($result->numRows() == 1)
1673  {
1674  $row = $ilDB->fetchAssoc($result);
1675  return $row["questiontype_id"];
1676  }
1677  else
1678  {
1679  return 0;
1680  }
1681  }
1682 
1689  function getQuestionType()
1690  {
1691  return "";
1692  }
1693 
1701  static function _includeClass($question_type, $gui = 0)
1702  {
1703  $type = $question_type;
1704  if ($gui == 1) $type .= "GUI";
1705  else if ($gui == 2) $type .= "Evaluation";
1706  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type.".php"))
1707  {
1708  include_once "./Modules/SurveyQuestionPool/classes/class.".$type.".php";
1709  return true;
1710  }
1711  else
1712  {
1713  global $ilPluginAdmin;
1714  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1715  foreach ($pl_names as $pl_name)
1716  {
1717  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1718  if (strcmp($pl->getQuestionType(), $question_type) == 0)
1719  {
1720  $pl->includeClass("class.".$type.".php");
1721  return true;
1722  }
1723  }
1724  }
1725  return false;
1726  }
1727 
1734  static function _getQuestionTypeName($type_tag)
1735  {
1736  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type_tag.".php"))
1737  {
1738  global $lng;
1739  return $lng->txt($type_tag);
1740  }
1741  else
1742  {
1743  global $ilPluginAdmin;
1744  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1745  foreach ($pl_names as $pl_name)
1746  {
1747  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1748  if (strcmp($pl->getQuestionType(), $type_tag) == 0)
1749  {
1750  return $pl->getQuestionTypeTranslation();
1751  }
1752  }
1753  }
1754  return "";
1755  }
1756 
1757 
1765  static function _instanciateQuestion($question_id)
1766  {
1767  $question_type = self::_getQuestionType($question_id);
1768  if($question_type)
1769  {
1770  self::_includeClass($question_type);
1771  $question = new $question_type();
1772  $question->loadFromDb($question_id);
1773  return $question;
1774  }
1775  }
1776 
1784  static function _instanciateQuestionGUI($question_id)
1785  {
1786  $question_type = self::_getQuestionType($question_id);
1787  if($question_type)
1788  {
1789  self::_includeClass($question_type, 1);
1790  $guitype = $question_type . "GUI";
1791  $question = new $guitype($question_id);
1792  return $question;
1793  }
1794  }
1795 
1803  static function _instanciateQuestionEvaluation($question_id, array $a_finished_ids = null)
1804  {
1805  $question = self::_instanciateQuestion($question_id);
1806  if($question)
1807  {
1808  $question_type = self::_getQuestionType($question_id);
1809  self::_includeClass($question_type, 2);
1810  $class = $question_type . "Evaluation";
1811  $ev = new $class($question, $a_finished_ids);
1812  return $ev;
1813  }
1814  }
1815 
1824  function isHTML($a_text)
1825  {
1826  if (preg_match("/<[^>]*?>/", $a_text))
1827  {
1828  return TRUE;
1829  }
1830  else
1831  {
1832  return FALSE;
1833  }
1834  }
1835 
1843  function QTIMaterialToString($a_material)
1844  {
1845  $svy_log = ilLoggerFactory::getLogger("svy");
1846  $svy_log->debug("material count: ".$a_material->getMaterialCount());
1847 
1848  $result = "";
1849  for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
1850  {
1851  $material = $a_material->getMaterial($i);
1852  if (strcmp($material["type"], "mattext") == 0)
1853  {
1854  $result .= $material["material"]->getContent();
1855  }
1856  if (strcmp($material["type"], "matimage") == 0)
1857  {
1858  $matimage = $material["material"];
1859  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
1860  {
1861  // import an mediaobject which was inserted using tiny mce
1862  if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
1863  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1864  }
1865  }
1866  }
1867  return $result;
1868  }
1869 
1878  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $a_attrs = null)
1879  {
1880  include_once "./Services/RTE/classes/class.ilRTE.php";
1881  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1882 
1883  $a_xml_writer->xmlStartTag("material");
1884  $attrs = array(
1885  "type" => "text/plain"
1886  );
1887  if ($this->isHTML($a_material))
1888  {
1889  $attrs["type"] = "text/xhtml";
1890  }
1891  if (is_array($a_attrs))
1892  {
1893  $attrs = array_merge($attrs, $a_attrs);
1894  }
1895  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1896 
1897  if ($add_mobs)
1898  {
1899  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1900  foreach ($mobs as $mob)
1901  {
1902  $mob_obj = new ilObjMediaObject($mob);
1903  $imgattrs = array(
1904  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1905  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle(),
1906  "type" => "spl:html",
1907  "id" => $this->getId()
1908  );
1909  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
1910  }
1911  }
1912  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
1913  }
1914 
1921  function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
1922  {
1923  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1924  }
1925 
1933  function getQuestionDataArray($id)
1934  {
1935  return array();
1936  }
1937 
1944  function &getWorkingDataFromUserInput($post_data)
1945  {
1946  // overwrite in inherited classes
1947  $data = array();
1948  return $data;
1949  }
1950 
1959  function importAdditionalMetadata($a_meta)
1960  {
1961  // overwrite in inherited classes
1962  }
1963 
1970  function importResponses($a_data)
1971  {
1972  // overwrite in inherited classes
1973  }
1974 
1981  function importAdjectives($a_data)
1982  {
1983  // overwrite in inherited classes
1984  }
1985 
1992  function importMatrix($a_data)
1993  {
1994  // overwrite in inherited classes
1995  }
1996 
2004  {
2005  // overwrite in inherited classes
2006  return FALSE;
2007  }
2008 
2016  {
2017  // overwrite in inherited classes
2018  return array();
2019  }
2020 
2026  public function getPreconditionOptions()
2027  {
2028  // overwrite in inherited classes
2029  }
2030 
2039  {
2040  // overwrite in inherited classes
2041  return $value;
2042  }
2043 
2050  public function getPreconditionSelectValue($default = "", $title, $variable)
2051  {
2052  // overwrite in inherited classes
2053  return null;
2054  }
2055 
2056  function setOriginalId($original_id)
2057  {
2058  $this->original_id = $original_id;
2059  }
2060 
2061  function getOriginalId()
2062  {
2063  return $this->original_id;
2064  }
2065 
2066  public function getMaterial()
2067  {
2068  return $this->material;
2069  }
2070 
2071  public function setSubtype($a_subtype)
2072  {
2073  // do nothing
2074  }
2075 
2076  public function getSubtype()
2077  {
2078  // do nothing
2079  return null;
2080  }
2081 
2085  public function __get($value)
2086  {
2087  switch ($value)
2088  {
2089  default:
2090  if (array_key_exists($value, $this->arrData))
2091  {
2092  return $this->arrData[$value];
2093  }
2094  else
2095  {
2096  return null;
2097  }
2098  break;
2099  }
2100  }
2101 
2105  public function __set($key, $value)
2106  {
2107  switch ($key)
2108  {
2109  default:
2110  $this->arrData[$key] = $value;
2111  break;
2112  }
2113  }
2114 
2122  public static function _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
2123  {
2124  global $ilDB;
2125 
2126  $ilDB->manipulate("UPDATE svy_question".
2127  " SET original_id = ".$ilDB->quote($a_original_id, "integer").",".
2128  " obj_fi = ".$ilDB->quote($a_object_id, "integer").
2129  " WHERE question_id = ".$ilDB->quote($a_question_id, "integer"));
2130  }
2131 
2132  public function getCopyIds($a_group_by_survey = false)
2133  {
2134  global $ilDB;
2135 
2136  $set = $ilDB->query("SELECT q.question_id,s.obj_fi".
2137  " FROM svy_question q".
2138  " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)".
2139  " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)".
2140  " WHERE original_id = ".$ilDB->quote($this->getId(), "integer"));
2141  $res = array();
2142  while($row = $ilDB->fetchAssoc($set))
2143  {
2144  if(!$a_group_by_survey)
2145  {
2146  $res[] = $row["question_id"];
2147  }
2148  else
2149  {
2150  $res[$row["obj_fi"]][] = $row["question_id"];
2151  }
2152  }
2153  return $res;
2154  }
2155 
2156  public function hasCopies()
2157  {
2158  return (bool)sizeof($this->getCopyIds());
2159  }
2160 
2161  public static function _lookupSurveyObjId($a_question_id)
2162  {
2163  global $ilDB;
2164 
2165  $set = $ilDB->query("SELECT svy_svy.obj_fi FROM svy_svy_qst".
2166  " JOIN svy_svy ON (svy_svy.survey_id = svy_svy_qst.survey_fi)".
2167  " WHERE svy_svy_qst.question_fi = ".$ilDB->quote($a_question_id, "integer"));
2168  $row = $ilDB->fetchAssoc($set);
2169  if($ilDB->numRows($set))
2170  {
2171  return $row["obj_fi"];
2172  }
2173  }
2174 
2181  static function lookupObjFi($a_qid)
2182  {
2183  global $ilDB;
2184 
2185  $set = $ilDB->query("SELECT obj_fi FROM svy_question ".
2186  " WHERE question_id = ".$ilDB->quote($a_qid, "integer")
2187  );
2188  $rec = $ilDB->fetchAssoc($set);
2189  return $rec["obj_fi"];
2190  }
2191 
2200  {
2201  $str = ilUtil::stripSlashes($a_str);
2202  if ($str != $a_str)
2203  {
2204  $str = ilUtil::stripSlashes(str_replace("<", "< ", $a_str));
2205  }
2206  return $str;
2207  }
2208 
2209 
2210 }
2211 ?>
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get plugin object.
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
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.
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...
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
getObligatory($survey_id="")
Gets the obligatory state of the question.
QTIMaterialToString($a_material)
Reads an QTI material tag an creates a text string.
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 _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.
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.
$mobs
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
Basic class for all survey question types.
saveMaterial()
save material to db
static _questionExists($question_id)
Returns true if the question already exists in the database.
const IL_COMP_MODULE
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
getAvailableRelations()
Returns the available relations for the question.
Class ilObjMediaObject.
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)
Create styles array
The data for the language used.
setSurveyId($id=-1)
Sets the survey id of the SurveyQuestion object.
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.
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.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
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.
prepareTextareaOutput($txt_output, $prepare_for_latex_output=FALSE)
Prepares a string for a text area output in surveys.
getSurveyId()
Gets the survey id of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
questionTitleExists($title, $questionpool_object="")
Returns TRUE if the question title exists in the database.
$insert