ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
157  function SurveyQuestion
158  (
159  $title = "",
160  $description = "",
161  $author = "",
162  $questiontext = "",
163  $owner = -1
164  )
165  {
166  global $ilias;
167  global $lng;
168  global $tpl;
169 
170  $this->ilias =& $ilias;
171  $this->lng =& $lng;
172  $this->tpl =& $tpl;
173  $this->complete =
174  $this->title = $title;
175  $this->description = $description;
176  $this->questiontext = $questiontext;
177  $this->author = $author;
178  $this->cumulated = array();
179  if (!$this->author)
180  {
181  $this->author = $this->ilias->account->fullname;
182  }
183  $this->owner = $owner;
184  if ($this->owner == -1)
185  {
186  $this->owner = $this->ilias->account->id;
187  }
188  $this->id = -1;
189  $this->survey_id = -1;
190  $this->obligatory = 1;
191  $this->orientation = 0;
192  $this->materials = array();
193  $this->material = array();
194  $this->arrData = array();
195  register_shutdown_function(array(&$this, '_SurveyQuestion'));
196  }
197 
198  function _SurveyQuestion()
199  {
200  }
201 
208  function setComplete($a_complete)
209  {
210  $this->complete = ($a_complete) ? 1 : 0;
211  }
212 
219  function isComplete()
220  {
221  return 0;
222  }
223 
232  function questionTitleExists($title, $questionpool_object = "")
233  {
234  global $ilDB;
235 
236  $refwhere = "";
237  if (strcmp($questionpool_object, "") != 0)
238  {
239  $refwhere = sprintf(" AND obj_fi = %s",
240  $ilDB->quote($questionpool_object, 'integer')
241  );
242  }
243  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE title = %s$refwhere",
244  array('text'),
245  array($title)
246  );
247  return ($result->numRows() > 0) ? true : false;
248  }
249 
257  function setTitle($title = "")
258  {
259  $this->title = $title;
260  }
261 
269  function setObligatory($obligatory = 1)
270  {
271  $this->obligatory = ($obligatory) ? 1 : 0;
272  }
273 
281  function setOrientation($orientation = 0)
282  {
283  $this->orientation = ($orientation) ? $orientation : 0;
284  }
285 
293  function setId($id = -1)
294  {
295  $this->id = $id;
296  }
297 
305  function setSurveyId($id = -1)
306  {
307  $this->survey_id = $id;
308  }
309 
317  function setDescription($description = "")
318  {
319  $this->description = $description;
320  }
321 
322 
331  function addMaterials($materials_file, $materials_name="")
332  {
333  if (empty($materials_name))
334  {
335  $materials_name = $materials_file;
336  }
337  if ((!empty($materials_name))&&(!array_key_exists($materials_name, $this->materials)))
338  {
339  $this->materials[$materials_name] = $materials_file;
340  }
341  }
342 
350  function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
351  {
352  if (!empty($materials_filename))
353  {
354  include_once "./Services/Utilities/classes/class.ilUtil.php";
355  $materialspath = $this->getMaterialsPath();
356  if (!file_exists($materialspath))
357  {
358  ilUtil::makeDirParents($materialspath);
359  }
360  if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
361  $materialspath.$materials_filename))
362  {
363  print "image not uploaded!!!! ";
364  }
365  else
366  {
367  $this->addMaterials($materials_filename, $materials_name);
368  }
369  }
370  }
371 
379  function deleteMaterial($materials_name = "")
380  {
381  foreach ($this->materials as $key => $value)
382  {
383  if (strcmp($key, $materials_name)==0)
384  {
385  if (file_exists($this->getMaterialsPath().$value))
386  {
387  unlink($this->getMaterialsPath().$value);
388  }
389  unset($this->materials[$key]);
390  }
391  }
392  }
393 
400  function flushMaterials()
401  {
402  $this->materials = array();
403  }
404 
412  function setAuthor($author = "")
413  {
414  if (!$author)
415  {
416  $author = $this->ilias->account->fullname;
417  }
418  $this->author = $author;
419  }
420 
428  function setQuestiontext($questiontext = "")
429  {
430  $this->questiontext = $questiontext;
431  }
432 
440  function setOwner($owner = "")
441  {
442  $this->owner = $owner;
443  }
444 
452  function getTitle()
453  {
454  return $this->title;
455  }
456 
457  function getLabel()
458  {
459  return $this->label;
460  }
461 
469  function getId()
470  {
471  return $this->id;
472  }
473 
480  public function getObligatory($survey_id = "")
481  {
482  if ($survey_id > 0)
483  {
484  global $ilDB;
485 
486  $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s AND question_fi = %s",
487  array('integer', 'integer'),
488  array($survey_id, $this->getId())
489  );
490  if ($result->numRows())
491  {
492  $row = $ilDB->fetchAssoc($result);
493  return ($row["obligatory"]) ? 1 : 0;
494  }
495  else
496  {
497  return ($this->obligatory) ? 1 : 0;
498  }
499  }
500  else
501  {
502  return ($this->obligatory) ? 1 : 0;
503  }
504  }
505 
513  function getSurveyId()
514  {
515  return $this->survey_id;
516  }
517 
525  function getOrientation()
526  {
527  switch ($this->orientation)
528  {
529  case 0:
530  case 1:
531  case 2:
532  break;
533  default:
534  $this->orientation = 0;
535  break;
536  }
537  return $this->orientation;
538  }
539 
540 
548  function getDescription()
549  {
550  return (strlen($this->description)) ? $this->description : NULL;
551  }
552 
560  function getAuthor()
561  {
562  return (strlen($this->author)) ? $this->author : NULL;
563  }
564 
572  function getOwner()
573  {
574  return $this->owner;
575  }
576 
584  function getQuestiontext()
585  {
586  return (strlen($this->questiontext)) ? $this->questiontext : NULL;
587  }
588 
596  function getObjId() {
597  return $this->obj_id;
598  }
599 
607  function setObjId($obj_id = 0)
608  {
609  $this->obj_id = $obj_id;
610  }
611 
617  function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
618  {
619  if ($this->getId() <= 0)
620  {
621  // The question has not been saved. It cannot be duplicated
622  return;
623  }
624  // duplicate the question in database
625  $clone = $this;
626  $original_id = $this->getId();
627  $clone->setId(-1);
628  if ($title)
629  {
630  $clone->setTitle($title);
631  }
632  if ($author)
633  {
634  $clone->setAuthor($author);
635  }
636  if ($owner)
637  {
638  $clone->setOwner($owner);
639  }
640  if ($for_survey)
641  {
642  $clone->saveToDb($original_id);
643  }
644  else
645  {
646  $clone->saveToDb();
647  }
648  // duplicate the materials
649  $clone->duplicateMaterials($original_id);
650  // copy XHTML media objects
651  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
652  return $clone->getId();
653  }
654 
660  function copyObject($target_questionpool, $title = "")
661  {
662  if ($this->getId() <= 0)
663  {
664  // The question has not been saved. It cannot be copied
665  return;
666  }
667  $clone = $this;
668  $original_id = SurveyQuestion::_getOriginalId($this->getId(), false);
669  $clone->setId(-1);
670  $source_questionpool = $this->getObjId();
671  $clone->setObjId($target_questionpool);
672  if ($title)
673  {
674  $clone->setTitle($title);
675  }
676 
677  $clone->saveToDb();
678 
679  // duplicate the materials
680  $clone->duplicateMaterials($original_id);
681  // copy XHTML media objects
682  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
683  return $clone->getId();
684  }
685 
693  {
694  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
695  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
696  foreach ($mobs as $mob)
697  {
698  ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
699  }
700  }
701 
708  function loadFromDb($question_id)
709  {
710  global $ilDB;
711 
712  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
713  array('integer'),
714  array($this->getId())
715  );
716  $this->material = array();
717  if ($result->numRows())
718  {
719  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
720  while ($row = $ilDB->fetchAssoc($result))
721  {
722  $mat = new ilSurveyMaterial();
723  $mat->type = $row['material_type'];
724  $mat->internal_link = $row['internal_link'];
725  $mat->title = $row['material_title'];
726  $mat->import_id = $row['import_id'];
727  $mat->text_material = $row['text_material'];
728  $mat->external_link = $row['external_link'];
729  $mat->file_material = $row['file_material'];
730  array_push($this->material, $mat);
731  }
732  }
733  }
734 
741  function _isComplete($question_id)
742  {
743  global $ilDB;
744 
745  $result = $ilDB->queryF("SELECT complete FROM svy_question WHERE question_id = %s",
746  array('integer'),
747  array($question_id)
748  );
749  if ($result->numRows())
750  {
751  $row = $ilDB->fetchAssoc($result);
752  if ($row["complete"] == 1)
753  {
754  return TRUE;
755  }
756  }
757  return FALSE;
758  }
759 
765  function saveCompletionStatus($original_id = "")
766  {
767  global $ilDB;
768 
769  $question_id = $this->getId();
770  if (strlen($original_id))
771  {
772  $question_id = $original_id;
773  }
774 
775  if ($this->getId() > 0)
776  {
777  // update existing dataset
778  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
779  array('text', 'integer', 'integer'),
780  array($this->isComplete(), time(), $question_id)
781  );
782  }
783  }
784 
791  function saveToDb($original_id = "")
792  {
793  global $ilDB;
794 
795  // cleanup RTE images which are not inserted into the question text
796  include_once("./Services/RTE/classes/class.ilRTE.php");
797  ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
798  $affectedRows = 0;
799  if ($this->getId() == -1)
800  {
801  // Write new dataset
802  $next_id = $ilDB->nextId('svy_question');
803  $affectedRows = $ilDB->insert("svy_question", array(
804  "question_id" => array("integer", $next_id),
805  "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
806  "obj_fi" => array("integer", $this->getObjId()),
807  "owner_fi" => array("integer", $this->getOwner()),
808  "title" => array("text", $this->getTitle()),
809  "label" => array("text", (strlen($this->label)) ? $this->label : null),
810  "description" => array("text", $this->getDescription()),
811  "author" => array("text", $this->getAuthor()),
812  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
813  "obligatory" => array("text", $this->getObligatory()),
814  "complete" => array("text", $this->isComplete()),
815  "created" => array("integer", time()),
816  "original_id" => array("integer", ($original_id) ? $original_id : NULL),
817  "tstamp" => array("integer", time())
818  ));
819  $this->setId($next_id);
820  }
821  else
822  {
823  // update existing dataset
824  $affectedRows = $ilDB->update("svy_question", array(
825  "title" => array("text", $this->getTitle()),
826  "label" => array("text", (strlen($this->label)) ? $this->label : null),
827  "description" => array("text", $this->getDescription()),
828  "author" => array("text", $this->getAuthor()),
829  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
830  "obligatory" => array("text", $this->getObligatory()),
831  "complete" => array("text", $this->isComplete()),
832  "tstamp" => array("integer", time())
833  ), array(
834  "question_id" => array("integer", $this->getId())
835  ));
836  }
837 
838  $set = $ilDB->query("SELECT survey_fi FROM svy_svy_qst".
839  " WHERE question_fi = ".$ilDB->quote($this->getId(), "integer"));
840  $survey_fi = $ilDB->fetchAssoc($set);
841  $survey_fi = $survey_fi["survey_fi"];
842 
843  if($survey_fi)
844  {
845  $set = $ilDB->query("SELECT obligatory FROM svy_qst_oblig".
846  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
847  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
848  $has_obligatory_states_entry = (bool)$ilDB->numRows($set);
849  $is_obligatory = $ilDB->fetchAssoc($set);
850  $is_obligatory = (bool)$is_obligatory["obligatory"];
851 
852  if(!$this->getObligatory())
853  {
854  if($has_obligatory_states_entry)
855  {
856  $ilDB->manipulate("DELETE FROM svy_qst_oblig".
857  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
858  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
859  }
860  }
861  else if($this->getObligatory())
862  {
863  if(!$has_obligatory_states_entry)
864  {
865  // ilObjSurvey::setObligatoryStates()
866  $next_id = $ilDB->nextId('svy_qst_oblig');
867  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " .
868  "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
869  array('integer','integer','integer','text','integer'),
870  array($next_id, $survey_fi, $this->getId(), 1, time())
871  );
872  }
873  else if(!$is_obligatory)
874  {
875  $ilDB->manipulate("UPDATE svy_qst_oblig".
876  " SET obligatory = ".$ilDB->quote(1, "integer").
877  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
878  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
879  }
880  }
881  }
882 
883  return $affectedRows;
884  }
885 
889  public function saveMaterial()
890  {
891  global $ilDB;
892 
893  include_once "./Services/Link/classes/class.ilInternalLink.php";
894  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
895  array('integer'),
896  array($this->getId())
897  );
899 
900  foreach ($this->material as $material)
901  {
902  $next_id = $ilDB->nextId('svy_material');
903  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material " .
904  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
905  "text_material, external_link, file_material, material_type) ".
906  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
907  array('integer','integer','text','text','text','integer','text','text','text','integer'),
908  array(
909  $next_id, $this->getId(), $material->internal_link, $material->import_id,
910  $material->title, time(), $material->text_material, $material->external_link,
911  $material->file_material, $material->type)
912  );
913  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches))
914  {
915  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
916  }
917  }
918  }
919 
926  public function createNewQuestion()
927  {
928  global $ilDB;
929 
930  $obj_id = $this->getObjId();
931  if ($obj_id > 0)
932  {
933  $next_id = $ilDB->nextId('svy_question');
934  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_question (question_id, questiontype_fi, " .
935  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
936  "created, original_id, tstamp) VALUES " .
937  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
938  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
939  'text', 'text', 'integer', 'integer', 'integer'),
940  array(
941  $next_id,
942  $this->getQuestionTypeID(),
943  $obj_id,
944  $this->getOwner(),
945  NULL,
946  NULL,
947  $this->getAuthor(),
948  NULL,
949  "1",
950  "0",
951  time(),
952  NULL,
953  0
954  )
955  );
956  $this->setId($next_id);
957  }
958  return $this->getId();
959  }
960 
967  function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
968  {
969  }
970 
977  function getImagePath()
978  {
979  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
980  }
981 
988  function getMaterialsPath()
989  {
990  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
991  }
992 
999  function getImagePathWeb()
1000  {
1001  include_once "./Services/Utilities/classes/class.ilUtil.php";
1002  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
1004  }
1005 
1013  {
1014  include_once "./Services/Utilities/classes/class.ilUtil.php";
1015  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
1017  }
1018 
1027  function saveCategoryToDb($categorytext, $neutral = 0)
1028  {
1029  global $ilUser, $ilDB;
1030 
1031  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
1032  array('text','text','integer'),
1033  array($categorytext, $neutral, $ilUser->getId())
1034  );
1035  $insert = FALSE;
1036  $returnvalue = "";
1037  if ($result->numRows())
1038  {
1039  $insert = TRUE;
1040  while ($row = $ilDB->fetchAssoc($result))
1041  {
1042  if (strcmp($row["title"], $categorytext) == 0)
1043  {
1044  $returnvalue = $row["category_id"];
1045  $insert = FALSE;
1046  }
1047  }
1048  }
1049  else
1050  {
1051  $insert = TRUE;
1052  }
1053  if ($insert)
1054  {
1055  $next_id = $ilDB->nextId('svy_category');
1056  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
1057  array('integer','text','text','integer','integer'),
1058  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
1059  );
1060  $returnvalue = $next_id;
1061  }
1062  return $returnvalue;
1063  }
1064 
1071  function deleteAdditionalTableData($question_id)
1072  {
1073  global $ilDB;
1074  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1075  array('integer'),
1076  array($question_id)
1077  );
1078  }
1079 
1086  function delete($question_id)
1087  {
1088  global $ilDB;
1089 
1090  if ($question_id < 1) return;
1091 
1092  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1093  array('integer'),
1094  array($question_id)
1095  );
1096  if ($result->numRows() == 1)
1097  {
1098  $row = $ilDB->fetchAssoc($result);
1099  $obj_id = $row["obj_fi"];
1100  }
1101  else
1102  {
1103  return;
1104  }
1105 
1106  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_answer WHERE question_fi = %s",
1107  array('integer'),
1108  array($question_id)
1109  );
1110 
1111  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE question_fi = %s",
1112  array('integer'),
1113  array($question_id)
1114  );
1115 
1116  $result = $ilDB->queryF("SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1117  array('integer'),
1118  array($question_id)
1119  );
1120  while ($row = $ilDB->fetchObject($result))
1121  {
1122  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE constraint_id = %s",
1123  array('integer'),
1124  array($row->constraint_fi)
1125  );
1126  }
1127 
1128  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1129  array('integer'),
1130  array($question_id)
1131  );
1132 
1133  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1134  array('integer'),
1135  array($question_id)
1136  );
1137  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_oblig WHERE question_fi = %s",
1138  array('integer'),
1139  array($question_id)
1140  );
1141  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_svy_qst WHERE question_fi = %s",
1142  array('integer'),
1143  array($question_id)
1144  );
1145  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
1146  array('integer'),
1147  array($question_id)
1148  );
1149  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_question WHERE question_id = %s",
1150  array('integer'),
1151  array($question_id)
1152  );
1153 
1154  $this->deleteAdditionalTableData($question_id);
1155 
1156  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1157  array('integer'),
1158  array($question_id)
1159  );
1160  include_once "./Services/Link/classes/class.ilInternalLink.php";
1161  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1162 
1163  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1164  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
1165  {
1166  include_once "./Services/Utilities/classes/class.ilUtil.php";
1167  ilUtil::delDir($directory);
1168  }
1169 
1170  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1171  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1172  // remaining usages are not in text anymore -> delete them
1173  // and media objects (note: delete method of ilObjMediaObject
1174  // checks whether object is used in another context; if yes,
1175  // the object is not deleted!)
1176  foreach($mobs as $mob)
1177  {
1178  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1179  $mob_obj =& new ilObjMediaObject($mob);
1180  $mob_obj->delete();
1181  }
1182 
1183  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1184  ilSurveySkill::handleQuestionDeletion($question_id, $obj_id);
1185 
1186  // #12772 - untie question copies from pool question
1187  $ilDB->manipulate("UPDATE svy_question".
1188  " SET original_id = NULL".
1189  " WHERE original_id = ".$ilDB->quote($question_id, "integer"));
1190  }
1191 
1199  function _getQuestionType($question_id)
1200  {
1201  global $ilDB;
1202 
1203  if ($question_id < 1) return "";
1204 
1205  $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",
1206  array('integer'),
1207  array($question_id)
1208  );
1209  if ($result->numRows() == 1)
1210  {
1211  $data = $ilDB->fetchAssoc($result);
1212  return $data["type_tag"];
1213  }
1214  else
1215  {
1216  return "";
1217  }
1218  }
1219 
1227  function _getTitle($question_id)
1228  {
1229  global $ilDB;
1230 
1231  if ($question_id < 1) return "";
1232 
1233  $result = $ilDB->queryF("SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1234  array('integer'),
1235  array($question_id)
1236  );
1237  if ($result->numRows() == 1)
1238  {
1239  $data = $ilDB->fetchAssoc($result);
1240  return $data["title"];
1241  }
1242  else
1243  {
1244  return "";
1245  }
1246  }
1247 
1255  function _getOriginalId($question_id, $a_return_question_id_if_no_original = true)
1256  {
1257  global $ilDB;
1258  $result = $ilDB->queryF("SELECT * FROM svy_question WHERE question_id = %s",
1259  array('integer'),
1260  array($question_id)
1261  );
1262  if ($result->numRows() > 0)
1263  {
1264  $row = $ilDB->fetchAssoc($result);
1265  if ($row["original_id"] > 0)
1266  {
1267  return $row["original_id"];
1268  }
1269  else if((bool)$a_return_question_id_if_no_original) // #12419
1270  {
1271  return $row["question_id"];
1272  }
1273  }
1274  else
1275  {
1276  return "";
1277  }
1278  }
1279 
1280  function syncWithOriginal()
1281  {
1282  global $ilDB;
1283 
1284  if ($this->getOriginalId())
1285  {
1286  $id = $this->getId();
1287  $original = $this->getOriginalId();
1288 
1289  $this->setId($this->getOriginalId());
1290  $this->setOriginalId(NULL);
1291  $this->saveToDb();
1292 
1293  $this->setId($id);
1294  $this->setOriginalId($original);
1295 
1296  include_once "./Services/Link/classes/class.ilInternalLink.php";
1297  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1298  array('integer'),
1299  array($this->getOriginalId())
1300  );
1301  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1302  if (strlen($this->material["internal_link"]))
1303  {
1304  $next_id = $ilDB->nextId('svy_material');
1305  $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)",
1306  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1307  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1308  );
1309  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
1310  {
1311  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1312  }
1313  }
1314  }
1315  }
1316 
1323  function getPhrase($phrase_id)
1324  {
1325  global $ilDB;
1326 
1327  $result = $ilDB->queryF("SELECT title FROM svy_phrase WHERE phrase_id = %s",
1328  array('integer'),
1329  array($phrase_id)
1330  );
1331  if ($row = $ilDB->fetchAssoc($result))
1332  {
1333  return $row["title"];
1334  }
1335  return "";
1336  }
1337 
1345  function phraseExists($title)
1346  {
1347  global $ilUser, $ilDB;
1348 
1349  $result = $ilDB->queryF("SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1350  array('text', 'integer'),
1351  array($title, $ilUser->getId())
1352  );
1353  return ($result->numRows() == 0) ? false : true;
1354  }
1355 
1363  function _questionExists($question_id)
1364  {
1365  global $ilDB;
1366 
1367  if ($question_id < 1)
1368  {
1369  return false;
1370  }
1371 
1372  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE question_id = %s",
1373  array('integer'),
1374  array($question_id)
1375  );
1376  return ($result->numRows() == 1) ? true : false;
1377  }
1378 
1379  function addInternalLink($material_id, $title = "")
1380  {
1381  if (strlen($material_id))
1382  {
1383  if (strcmp($material_title, "") == 0)
1384  {
1385  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1386  {
1387  $type = $matches[1];
1388  $target_id = $matches[2];
1389  $material_title = $this->lng->txt("obj_$type") . ": ";
1390  switch ($type)
1391  {
1392  case "lm":
1393  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1394  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1395  $cont_obj = $cont_obj_gui->object;
1396  $material_title .= $cont_obj->getTitle();
1397  break;
1398  case "pg":
1399  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1400  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1402  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1403  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1404  $cont_obj = $cont_obj_gui->object;
1405  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1406  $material_title .= $pg_obj->getTitle();
1407  break;
1408  case "st":
1409  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1410  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1412  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1413  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1414  $cont_obj = $cont_obj_gui->object;
1415  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1416  $material_title .= $st_obj->getTitle();
1417  break;
1418  case "git":
1419  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1420  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1421  break;
1422  case "mob":
1423  break;
1424  }
1425  }
1426  }
1427  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1428  $mat = new ilSurveyMaterial();
1429  $mat->type = 0;
1430  $mat->internal_link = $material_id;
1431  $mat->title = $material_title;
1432  $this->addMaterial($mat);
1433  $this->saveMaterial();
1434  }
1435  }
1436 
1442  public function deleteMaterials($a_array)
1443  {
1444  foreach ($a_array as $idx)
1445  {
1446  unset($this->material[$idx]);
1447  }
1448  $this->material = array_values($this->material);
1449  $this->saveMaterial();
1450  }
1451 
1458  function duplicateMaterials($question_id)
1459  {
1460  foreach ($this->materials as $filename)
1461  {
1462  $materialspath = $this->getMaterialsPath();
1463  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1464  if (!file_exists($materialspath))
1465  {
1466  include_once "./Services/Utilities/classes/class.ilUtil.php";
1467  ilUtil::makeDirParents($materialspath);
1468  }
1469  if (!copy($materialspath_original . $filename, $materialspath . $filename))
1470  {
1471  print "material could not be duplicated!!!! ";
1472  }
1473  }
1474  }
1475 
1476  public function addMaterial($obj_material)
1477  {
1478  array_push($this->material, $obj_material);
1479  }
1480 
1488  function setMaterial($material_id = "", $is_import = false, $material_title = "")
1489  {
1490  if (strcmp($material_id, "") != 0)
1491  {
1492  $import_id = "";
1493  if ($is_import)
1494  {
1495  $import_id = $material_id;
1496  $material_id = $this->_resolveInternalLink($import_id);
1497  }
1498  if (strcmp($material_title, "") == 0)
1499  {
1500  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1501  {
1502  $type = $matches[1];
1503  $target_id = $matches[2];
1504  $material_title = $this->lng->txt("obj_$type") . ": ";
1505  switch ($type)
1506  {
1507  case "lm":
1508  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1509  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1510  $cont_obj = $cont_obj_gui->object;
1511  $material_title .= $cont_obj->getTitle();
1512  break;
1513  case "pg":
1514  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1515  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1517  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1518  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1519  $cont_obj = $cont_obj_gui->object;
1520  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1521  $material_title .= $pg_obj->getTitle();
1522  break;
1523  case "st":
1524  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1525  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1527  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1528  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1529  $cont_obj = $cont_obj_gui->object;
1530  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1531  $material_title .= $st_obj->getTitle();
1532  break;
1533  case "git":
1534  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1535  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1536  break;
1537  case "mob":
1538  break;
1539  }
1540  }
1541  }
1542  $this->material = array(
1543  "internal_link" => $material_id,
1544  "import_id" => $import_id,
1545  "title" => $material_title
1546  );
1547  }
1548  $this->saveMaterial();
1549  }
1550 
1551  function _resolveInternalLink($internal_link)
1552  {
1553  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
1554  {
1555  include_once "./Services/Link/classes/class.ilInternalLink.php";
1556  include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1557  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1558  switch ($matches[2])
1559  {
1560  case "lm":
1561  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1562  break;
1563  case "pg":
1564  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1565  break;
1566  case "st":
1567  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1568  break;
1569  case "git":
1570  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1571  break;
1572  case "mob":
1573  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1574  break;
1575  }
1576  if (strcmp($resolved_link, "") == 0)
1577  {
1578  $resolved_link = $internal_link;
1579  }
1580  }
1581  else
1582  {
1583  $resolved_link = $internal_link;
1584  }
1585  return $resolved_link;
1586  }
1587 
1588  function _resolveIntLinks($question_id)
1589  {
1590  global $ilDB;
1591  $resolvedlinks = 0;
1592  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1593  array('integer'),
1594  array($question_id)
1595  );
1596  if ($result->numRows())
1597  {
1598  while ($row = $ilDB->fetchAssoc($result))
1599  {
1600  $internal_link = $row["internal_link"];
1601  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1602  $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
1603  if (strcmp($internal_link, $resolved_link) != 0)
1604  {
1605  // internal link was resolved successfully
1606  $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1607  array('text', 'integer', 'integer'),
1608  array($resolved_link, time(), $row["material_id"])
1609  );
1610  $resolvedlinks++;
1611  }
1612  }
1613  }
1614  if ($resolvedlinks)
1615  {
1616  // there are resolved links -> reenter theses links to the database
1617 
1618  // delete all internal links from the database
1619  include_once "./Services/Link/classes/class.ilInternalLink.php";
1620  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1621 
1622  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1623  array('integer'),
1624  array($question_id)
1625  );
1626  if ($result->numRows())
1627  {
1628  while ($row = $ilDB->fetchAssoc($result))
1629  {
1630  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
1631  {
1632  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1633  }
1634  }
1635  }
1636  }
1637  }
1638 
1639  function _getInternalLinkHref($target = "", $a_parent_ref_id = null)
1640  {
1641  global $ilDB;
1642  $linktypes = array(
1643  "lm" => "LearningModule",
1644  "pg" => "PageObject",
1645  "st" => "StructureObject",
1646  "git" => "GlossaryItem",
1647  "mob" => "MediaObject"
1648  );
1649  $href = "";
1650  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
1651  {
1652  $type = $matches[1];
1653  $target_id = $matches[2];
1654  include_once "./Services/Utilities/classes/class.ilUtil.php";
1655  switch($linktypes[$matches[1]])
1656  {
1657  case "LearningModule":
1658  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1659  break;
1660  case "PageObject":
1661  case "StructureObject":
1662  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1663  break;
1664  case "GlossaryItem":
1665  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1666  break;
1667  case "MediaObject":
1668  $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;
1669  break;
1670  }
1671  }
1672  return $href;
1673  }
1674 
1683  function _isWriteable($question_id, $user_id)
1684  {
1685  global $ilDB;
1686 
1687  if (($question_id < 1) || ($user_id < 1))
1688  {
1689  return false;
1690  }
1691 
1692  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1693  array('integer'),
1694  array($question_id)
1695  );
1696  if ($result->numRows() == 1)
1697  {
1698  $row = $ilDB->fetchAssoc($result);
1699  $qpl_object_id = $row["obj_fi"];
1700  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1701  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1702  }
1703  else
1704  {
1705  return false;
1706  }
1707  }
1708 
1716  {
1717  global $ilDB;
1718  $result = $ilDB->queryF("SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1719  array('text'),
1720  array($this->getQuestionType())
1721  );
1722  if ($result->numRows() == 1)
1723  {
1724  $row = $ilDB->fetchAssoc($result);
1725  return $row["questiontype_id"];
1726  }
1727  else
1728  {
1729  return 0;
1730  }
1731  }
1732 
1739  function getQuestionType()
1740  {
1741  return "";
1742  }
1743 
1751  static function _includeClass($question_type, $gui = 0)
1752  {
1753  $type = $question_type;
1754  if ($gui) $type .= "GUI";
1755  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type.".php"))
1756  {
1757  include_once "./Modules/SurveyQuestionPool/classes/class.".$type.".php";
1758  return true;
1759  }
1760  else
1761  {
1762  global $ilPluginAdmin;
1763  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1764  foreach ($pl_names as $pl_name)
1765  {
1766  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1767  if (strcmp($pl->getQuestionType(), $question_type) == 0)
1768  {
1769  $pl->includeClass("class.".$type.".php");
1770  return true;
1771  }
1772  }
1773  }
1774  return false;
1775  }
1776 
1783  static function _getQuestionTypeName($type_tag)
1784  {
1785  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type_tag.".php"))
1786  {
1787  global $lng;
1788  return $lng->txt($type_tag);
1789  }
1790  else
1791  {
1792  global $ilPluginAdmin;
1793  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1794  foreach ($pl_names as $pl_name)
1795  {
1796  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1797  if (strcmp($pl->getQuestionType(), $type_tag) == 0)
1798  {
1799  return $pl->getQuestionTypeTranslation();
1800  }
1801  }
1802  }
1803  return "";
1804  }
1805 
1806 
1814  function &_instanciateQuestion($question_id)
1815  {
1816  $question_type = SurveyQuestion::_getQuestionType($question_id);
1817  if($question_type)
1818  {
1819  SurveyQuestion::_includeClass($question_type);
1820  $question = new $question_type();
1821  $question->loadFromDb($question_id);
1822  return $question;
1823  }
1824  }
1825 
1833  function &_instanciateQuestionGUI($question_id)
1834  {
1835  $question_type = SurveyQuestion::_getQuestionType($question_id);
1836  if($question_type)
1837  {
1838  SurveyQuestion::_includeClass($question_type, 1);
1839  $guitype = $question_type . "GUI";
1840  $question = new $guitype($question_id);
1841  return $question;
1842  }
1843  }
1844 
1853  function isHTML($a_text)
1854  {
1855  if (preg_match("/<[^>]*?>/", $a_text))
1856  {
1857  return TRUE;
1858  }
1859  else
1860  {
1861  return FALSE;
1862  }
1863  }
1864 
1872  function QTIMaterialToString($a_material)
1873  {
1874  $result = "";
1875  for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
1876  {
1877  $material = $a_material->getMaterial($i);
1878  if (strcmp($material["type"], "mattext") == 0)
1879  {
1880  $result .= $material["material"]->getContent();
1881  }
1882  if (strcmp($material["type"], "matimage") == 0)
1883  {
1884  $matimage = $material["material"];
1885  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
1886  {
1887  // import an mediaobject which was inserted using tiny mce
1888  if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
1889  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1890  }
1891  }
1892  }
1893  return $result;
1894  }
1895 
1904  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $a_attrs = null)
1905  {
1906  include_once "./Services/RTE/classes/class.ilRTE.php";
1907  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1908 
1909  $a_xml_writer->xmlStartTag("material");
1910  $attrs = array(
1911  "type" => "text/plain"
1912  );
1913  if ($this->isHTML($a_material))
1914  {
1915  $attrs["type"] = "text/xhtml";
1916  }
1917  if (is_array($a_attrs))
1918  {
1919  $attrs = array_merge($attrs, $a_attrs);
1920  }
1921  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1922 
1923  if ($add_mobs)
1924  {
1925  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1926  foreach ($mobs as $mob)
1927  {
1928  $mob_obj =& new ilObjMediaObject($mob);
1929  $imgattrs = array(
1930  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1931  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle(),
1932  "type" => "spl:html",
1933  "id" => $this->getId()
1934  );
1935  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
1936  }
1937  }
1938  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
1939  }
1940 
1947  function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
1948  {
1949  include_once "./Services/Utilities/classes/class.ilUtil.php";
1950  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1951  }
1952 
1961  {
1962  return array();
1963  }
1964 
1971  function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true)
1972  {
1973  if(!$a_use_label)
1974  {
1975  $title = $this->title;
1976  }
1977  else
1978  {
1979  if($a_substitute)
1980  {
1981  $title = $this->label ? $this->label : $this->title;
1982  }
1983  else
1984  {
1985  $title = $this->label;
1986  }
1987  }
1988 
1989  array_push($a_array, $title);
1990  return $title;
1991  }
1992 
2000  function addUserSpecificResultsData(&$a_array, &$resultset)
2001  {
2002  // overwrite in inherited classes
2003  }
2004 
2012  function &getUserAnswers($survey_id)
2013  {
2014  // overwrite in inherited classes
2015  return array();
2016  }
2017 
2024  function &getWorkingDataFromUserInput($post_data)
2025  {
2026  // overwrite in inherited classes
2027  $data = array();
2028  return $data;
2029  }
2030 
2039  function importAdditionalMetadata($a_meta)
2040  {
2041  // overwrite in inherited classes
2042  }
2043 
2050  function importResponses($a_data)
2051  {
2052  // overwrite in inherited classes
2053  }
2054 
2061  function importAdjectives($a_data)
2062  {
2063  // overwrite in inherited classes
2064  }
2065 
2072  function importMatrix($a_data)
2073  {
2074  // overwrite in inherited classes
2075  }
2076 
2088  function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
2089  {
2090  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
2091  $column = 0;
2092  switch ($export_label)
2093  {
2094  case 'label_only':
2095  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2096  break;
2097  case 'title_only':
2098  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2099  break;
2100  default:
2101  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2102  $column++;
2103  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2104  break;
2105  }
2106  $column++;
2107  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text(strip_tags($this->getQuestiontext()))); // #12942
2108  $column++;
2109  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->lng->txt($eval_data["QUESTION_TYPE"])));
2110  $column++;
2111  $worksheet->write($row, $column, $eval_data["USERS_ANSWERED"]);
2112  $column++;
2113  $worksheet->write($row, $column, $eval_data["USERS_SKIPPED"]);
2114  $column++;
2115  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
2116  $column++;
2117  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE"]));
2118  $column++;
2119  $worksheet->write($row, $column, $eval_data["MODE_NR_OF_SELECTIONS"]);
2120  $column++;
2121  $worksheet->write($row, $column, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
2122  $column++;
2123  $worksheet->write($row, $column, $eval_data["ARITHMETIC_MEAN"]);
2124  return $row + 1;
2125  }
2126 
2138  function &setExportCumulatedCVS(&$eval_data, $export_label)
2139  {
2140  $csvrow = array();
2141  switch ($export_label)
2142  {
2143  case 'label_only':
2144  array_push($csvrow, $this->label);
2145  break;
2146  case 'title_only':
2147  array_push($csvrow, $this->getTitle());
2148  break;
2149  default:
2150  array_push($csvrow, $this->getTitle());
2151  array_push($csvrow, $this->label);
2152  break;
2153  }
2154  array_push($csvrow, strip_tags($this->getQuestiontext())); // #12942
2155  array_push($csvrow, $this->lng->txt($eval_data["QUESTION_TYPE"]));
2156  array_push($csvrow, $eval_data["USERS_ANSWERED"]);
2157  array_push($csvrow, $eval_data["USERS_SKIPPED"]);
2158  array_push($csvrow, $eval_data["MODE"]);
2159  array_push($csvrow, $eval_data["MODE_NR_OF_SELECTIONS"]);
2160  array_push($csvrow, str_replace("<br />", " ", $eval_data["MEDIAN"])); // #17214
2161  array_push($csvrow, $eval_data["ARITHMETIC_MEAN"]);
2162  $result = array();
2163  array_push($result, $csvrow);
2164  return $result;
2165  }
2166 
2176  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
2177  {
2178  // overwrite in inherited classes
2179  }
2180 
2188  {
2189  // overwrite in inherited classes
2190  return FALSE;
2191  }
2192 
2200  {
2201  // overwrite in inherited classes
2202  return array();
2203  }
2204 
2210  public function getPreconditionOptions()
2211  {
2212  // overwrite in inherited classes
2213  }
2214 
2223  {
2224  // overwrite in inherited classes
2225  return $value;
2226  }
2227 
2234  public function getPreconditionSelectValue($default = "", $title, $variable)
2235  {
2236  // overwrite in inherited classes
2237  return null;
2238  }
2239 
2248  function outChart($survey_id, $type = "")
2249  {
2250  // overwrite in inherited classes
2251  }
2252 
2253  function setOriginalId($original_id)
2254  {
2255  $this->original_id = $original_id;
2256  }
2257 
2258  function getOriginalId()
2259  {
2260  return $this->original_id;
2261  }
2262 
2268  public function saveRandomData($active_id)
2269  {
2270  // do nothing, overwrite in parent classes
2271  }
2272 
2273  public function getMaterial()
2274  {
2275  return $this->material;
2276  }
2277 
2278  public function setSubtype($a_subtype)
2279  {
2280  // do nothing
2281  }
2282 
2283  public function getSubtype()
2284  {
2285  // do nothing
2286  return null;
2287  }
2288 
2289  protected function &calculateCumulatedResults($survey_id, $finished_ids)
2290  {
2291  if (count($this->cumulated) == 0)
2292  {
2293  if(!$finished_ids)
2294  {
2295  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
2296  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
2297  }
2298  else
2299  {
2300  $nr_of_users = sizeof($finished_ids);
2301  }
2302  if($nr_of_users)
2303  {
2304  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
2305  }
2306  }
2307  return $this->cumulated;
2308  }
2309 
2315  public function getCumulatedResultData($survey_id, $counter, $finished_ids)
2316  {
2317  $cumulated =& $this->calculateCumulatedResults($survey_id, $finished_ids);
2318  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->getQuestiontext());
2319 
2320  $maxlen = 75;
2321  include_once "./Services/Utilities/classes/class.ilStr.php";
2322  if (ilStr::strlen($questiontext) > $maxlen + 3)
2323  {
2324  $questiontext = ilStr::substr($questiontext, 0, $maxlen) . "...";
2325  }
2326 
2327  $result = array(
2328  'counter' => $counter,
2329  'title' => $counter.'. '.$this->getTitle(),
2330  'question' => $questiontext,
2331  'users_answered' => $cumulated['USERS_ANSWERED'],
2332  'users_skipped' => $cumulated['USERS_SKIPPED'],
2333  'question_type' => $this->lng->txt($cumulated["QUESTION_TYPE"]),
2334  'mode' => $cumulated["MODE"],
2335  'mode_nr_of_selections' => $cumulated["MODE_NR_OF_SELECTIONS"],
2336  'median' => $cumulated["MEDIAN"],
2337  'arithmetic_mean' => $cumulated["ARITHMETIC_MEAN"]
2338  );
2339  return $result;
2340  }
2341 
2345  public function __get($value)
2346  {
2347  switch ($value)
2348  {
2349  default:
2350  if (array_key_exists($value, $this->arrData))
2351  {
2352  return $this->arrData[$value];
2353  }
2354  else
2355  {
2356  return null;
2357  }
2358  break;
2359  }
2360  }
2361 
2365  public function __set($key, $value)
2366  {
2367  switch ($key)
2368  {
2369  default:
2370  $this->arrData[$key] = $value;
2371  break;
2372  }
2373  }
2374 
2382  public static function _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
2383  {
2384  global $ilDB;
2385 
2386  $ilDB->manipulate("UPDATE svy_question".
2387  " SET original_id = ".$ilDB->quote($a_original_id, "integer").",".
2388  " obj_fi = ".$ilDB->quote($a_object_id, "integer").
2389  " WHERE question_id = ".$ilDB->quote($a_question_id, "integer"));
2390  }
2391 
2392  public function getCopyIds($a_group_by_survey = false)
2393  {
2394  global $ilDB;
2395 
2396  $set = $ilDB->query("SELECT q.question_id,s.obj_fi".
2397  " FROM svy_question q".
2398  " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)".
2399  " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)".
2400  " WHERE original_id = ".$ilDB->quote($this->getId(), "integer"));
2401  $res = array();
2402  while($row = $ilDB->fetchAssoc($set))
2403  {
2404  if(!$a_group_by_survey)
2405  {
2406  $res[] = $row["question_id"];
2407  }
2408  else
2409  {
2410  $res[$row["obj_fi"]][] = $row["question_id"];
2411  }
2412  }
2413  return $res;
2414  }
2415 
2416  public function hasCopies()
2417  {
2418  return (bool)sizeof($this->getCopyIds());
2419  }
2420 
2421  public function getSkippedValue()
2422  {
2423  include_once "Modules/Survey/classes/class.ilObjSurvey.php";
2425  }
2426 
2427  public static function _lookupSurveyObjId($a_question_id)
2428  {
2429  global $ilDB;
2430 
2431  $set = $ilDB->query("SELECT svy_svy.obj_fi FROM svy_svy_qst".
2432  " JOIN svy_svy ON (svy_svy.survey_id = svy_svy_qst.survey_fi)".
2433  " WHERE svy_svy_qst.question_fi = ".$ilDB->quote($a_question_id, "integer"));
2434  $row = $ilDB->fetchAssoc($set);
2435  if($ilDB->numRows($set))
2436  {
2437  return $row["obj_fi"];
2438  }
2439  }
2440 
2447  static function lookupObjFi($a_qid)
2448  {
2449  global $ilDB;
2450 
2451  $set = $ilDB->query("SELECT obj_fi FROM svy_question ".
2452  " WHERE question_id = ".$ilDB->quote($a_qid, "integer")
2453  );
2454  $rec = $ilDB->fetchAssoc($set);
2455  return $rec["obj_fi"];
2456  }
2457 
2458 }
2459 ?>
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.
_isWriteable($object_id, $user_id)
Returns true, if the question pool is writeable by a given user.
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
addMaterials($materials_file, $materials_name="")
Sets the materials uri.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
_questionExists($question_id)
Returns true if the question already exists in 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
outChart($survey_id, $type="")
Creates an image visualising the results of the question.
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)
_getTitle($question_id)
Returns the question title of a question with a given id.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
getMaterialsPath()
Returns the materials path for web accessable materials of a question.
static getSurveySkippedValue()
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.
_convert_text($a_text, $a_target="has been removed")
_resolveInternalLink($internal_link)
importMatrix($a_data)
Import matrix rows from the question import file.
deleteMaterial($materials_name="")
Deletes a materials uri with a given name.
_getQuestionDataArray($id)
Returns the question data fields from the database.
importAdjectives($a_data)
Import bipolar adjectives from the question import file.
getMaterialsPathWeb()
Returns the web image path for web accessable images of a question.
setId($id=-1)
Sets the id of the SurveyQuestion object.
flushMaterials()
Deletes all materials uris.
duplicate($for_survey=true, $title="", $author="", $owner="")
Duplicates a survey question.
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.
usableForPrecondition()
Returns if the question is usable for preconditions.
$target_id
Definition: goto.php:88
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
Survey material class.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
static lookupObjFi($a_qid)
Lookip obj fi.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
_cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
synchronises appearances of media objects in $a_text with media object usage table ...
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.
_removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
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)
& getUserAnswers($survey_id)
Returns an array containing all answers to this question in a given survey.
setOriginalId($original_id)
getOwner()
Gets the creator/owner ID of the SurveyQuestion object.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
& _instanciateQuestionGUI($question_id)
Creates an instance of a question GUI with a given question id.
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
$data
_resolveIntLinks($question_id)
Class ilLMPageObject.
& calculateCumulatedResults($survey_id, $finished_ids)
$mobs
getId()
Gets the id of the SurveyQuestion object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
const ILIAS_ABSOLUTE_PATH
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
_lookupContObjID($a_id)
get learning module / digibook id for lm object
getCumulatedResultData($survey_id, $counter, $finished_ids)
Creates a the cumulated results data for the question.
const IL_COMP_MODULE
redirection script todo: (a better solution should control the processing via a xml file) ...
getAvailableRelations()
Returns the available relations for the question.
Class ilObjMediaObject.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
static removeTrailingPathSeparators($path)
setSurveyId($id=-1)
Sets the survey id of the SurveyQuestion object.
$filename
Definition: buildRTE.php:89
addInternalLink($material_id, $title="")
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
isComplete()
Returns 1, if a question is complete for use.
_getIdForImportId($a_import_id)
get current object id for import id (static)
saveWorkingData($limit_to=LIMIT_NO_LIMIT)
Saves the learners input of the question to the database.
_getOriginalId($question_id, $a_return_question_id_if_no_original=true)
Returns the original id of a question.
getImagePath()
Returns the image path for web accessable images of a question.
setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
Creates the Excel output for the cumulated results of this question.
Class ilStructreObject.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
const LIMIT_NO_LIMIT
Assessment constants.
deleteMaterials($a_array)
Deletes materials.
global $ilUser
Definition: imgupload.php:15
_getQuestionType($question_id)
Returns the question type of a question with a given id.
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.
_isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
copyObject($target_questionpool, $title="")
Copies an assOrderingQuestion object.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
_getInternalLinkHref($target="", $a_parent_ref_id=null)
getDescription()
Gets the description string of the SurveyQuestion object.
getObjId()
Get the reference id of the container object.
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.
_getNrOfParticipants($survey_id)
Returns the number of participants for a survey.
isHTML($a_text)
Checks if a given string contains HTML or not.
__get($value)
Object getter.
& _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
_isComplete($question_id)
Checks whether the question is complete or not.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$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...
& setExportCumulatedCVS(&$eval_data, $export_label)
Creates the CSV output for the cumulated results of this question.
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.
addUserSpecificResultsExportTitles(&$a_array, $a_use_label=false, $a_substitute=true)
Adds the entries for the title row of the user specific results.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
questionTitleExists($title, $questionpool_object="")
Returns TRUE if the question title exists in the database.