ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyQuestion.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
25 
37 {
43  var $id;
44 
50  var $title;
63  var $owner;
64 
71  var $author;
72 
79 
86 
92  var $obj_id;
93 
100 
107 
113  var $ilias;
114 
120  var $tpl;
121 
127  var $lng;
128 
135 
138 
142  protected $cumulated;
143 
154  function SurveyQuestion
155  (
156  $title = "",
157  $description = "",
158  $author = "",
159  $questiontext = "",
160  $owner = -1
161  )
162  {
163  global $ilias;
164  global $lng;
165  global $tpl;
166 
167  $this->ilias =& $ilias;
168  $this->lng =& $lng;
169  $this->tpl =& $tpl;
170  $this->complete =
171  $this->title = $title;
172  $this->description = $description;
173  $this->questiontext = $questiontext;
174  $this->author = $author;
175  $this->cumulated = array();
176  if (!$this->author)
177  {
178  $this->author = $this->ilias->account->fullname;
179  }
180  $this->owner = $owner;
181  if ($this->owner == -1)
182  {
183  $this->owner = $this->ilias->account->id;
184  }
185  $this->id = -1;
186  $this->survey_id = -1;
187  $this->obligatory = 1;
188  $this->orientation = 0;
189  $this->materials = array();
190  $this->material = array();
191  register_shutdown_function(array(&$this, '_SurveyQuestion'));
192  }
193 
194  function _SurveyQuestion()
195  {
196  }
197 
204  function setComplete($a_complete)
205  {
206  $this->complete = ($a_complete) ? 1 : 0;
207  }
208 
215  function isComplete()
216  {
217  return 0;
218  }
219 
228  function questionTitleExists($title, $questionpool_object = "")
229  {
230  global $ilDB;
231 
232  $refwhere = "";
233  if (strcmp($questionpool_object, "") != 0)
234  {
235  $refwhere = sprintf(" AND obj_fi = %s",
236  $ilDB->quote($questionpool_object, 'integer')
237  );
238  }
239  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE title = %s$refwhere",
240  array('text'),
241  array($title)
242  );
243  return ($result->numRows() > 0) ? true : false;
244  }
245 
253  function setTitle($title = "")
254  {
255  $this->title = $title;
256  }
257 
265  function setObligatory($obligatory = 1)
266  {
267  $this->obligatory = ($obligatory) ? 1 : 0;
268  }
269 
278  {
279  $this->orientation = ($orientation) ? $orientation : 0;
280  }
281 
289  function setId($id = -1)
290  {
291  $this->id = $id;
292  }
293 
301  function setSurveyId($id = -1)
302  {
303  $this->survey_id = $id;
304  }
305 
313  function setDescription($description = "")
314  {
315  $this->description = $description;
316  }
317 
318 
327  function addMaterials($materials_file, $materials_name="")
328  {
329  if (empty($materials_name))
330  {
331  $materials_name = $materials_file;
332  }
333  if ((!empty($materials_name))&&(!array_key_exists($materials_name, $this->materials)))
334  {
335  $this->materials[$materials_name] = $materials_file;
336  }
337  }
338 
346  function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
347  {
348  if (!empty($materials_filename))
349  {
350  include_once "./Services/Utilities/classes/class.ilUtil.php";
351  $materialspath = $this->getMaterialsPath();
352  if (!file_exists($materialspath))
353  {
354  ilUtil::makeDirParents($materialspath);
355  }
356  //if (!move_uploaded_file($materials_tempfilename, $materialspath . $materials_filename))
357  if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
358  $materialspath.$materials_filename))
359  {
360  print "image not uploaded!!!! ";
361  }
362  else
363  {
364  $this->addMaterials($materials_filename, $materials_name);
365  }
366  }
367  }
368 
376  function deleteMaterial($materials_name = "")
377  {
378  foreach ($this->materials as $key => $value)
379  {
380  if (strcmp($key, $materials_name)==0)
381  {
382  if (file_exists($this->getMaterialsPath().$value))
383  {
384  unlink($this->getMaterialsPath().$value);
385  }
386  unset($this->materials[$key]);
387  }
388  }
389  }
390 
397  function flushMaterials()
398  {
399  $this->materials = array();
400  }
401 
409  function setAuthor($author = "")
410  {
411  if (!$author)
412  {
413  $author = $this->ilias->account->fullname;
414  }
415  $this->author = $author;
416  }
417 
426  {
427  $this->questiontext = $questiontext;
428  }
429 
437  function setOwner($owner = "")
438  {
439  $this->owner = $owner;
440  }
441 
449  function getTitle()
450  {
451  return $this->title;
452  }
453 
461  function getId()
462  {
463  return $this->id;
464  }
465 
472  public function getObligatory($survey_id = "")
473  {
474  if ($survey_id > 0)
475  {
476  global $ilDB;
477 
478  $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s AND question_fi = %s",
479  array('integer', 'integer'),
480  array($survey_id, $this->getId())
481  );
482  if ($result->numRows())
483  {
484  $row = $ilDB->fetchAssoc($result);
485  return ($row["obligatory"]) ? 1 : 0;
486  }
487  else
488  {
489  return ($this->obligatory) ? 1 : 0;
490  }
491  }
492  else
493  {
494  return ($this->obligatory) ? 1 : 0;
495  }
496  }
497 
505  function getSurveyId()
506  {
507  return $this->survey_id;
508  }
509 
517  function getOrientation()
518  {
519  switch ($this->orientation)
520  {
521  case 0:
522  case 1:
523  case 2:
524  break;
525  default:
526  $this->orientation = 0;
527  break;
528  }
529  return $this->orientation;
530  }
531 
532 
540  function getDescription()
541  {
542  return (strlen($this->description)) ? $this->description : NULL;
543  }
544 
552  function getAuthor()
553  {
554  return (strlen($this->author)) ? $this->author : NULL;
555  }
556 
564  function getOwner()
565  {
566  return $this->owner;
567  }
568 
576  function getQuestiontext()
577  {
578  return (strlen($this->questiontext)) ? $this->questiontext : NULL;
579  }
580 
588  function getObjId() {
589  return $this->obj_id;
590  }
591 
599  function setObjId($obj_id = 0)
600  {
601  $this->obj_id = $obj_id;
602  }
603 
609  function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
610  {
611  if ($this->getId() <= 0)
612  {
613  // The question has not been saved. It cannot be duplicated
614  return;
615  }
616  // duplicate the question in database
617  $clone = $this;
618  $original_id = $this->getId();
619  $clone->setId(-1);
620  if ($title)
621  {
622  $clone->setTitle($title);
623  }
624  if ($author)
625  {
626  $clone->setAuthor($author);
627  }
628  if ($owner)
629  {
630  $clone->setOwner($owner);
631  }
632  if ($for_survey)
633  {
634  $clone->saveToDb($original_id);
635  }
636  else
637  {
638  $clone->saveToDb();
639  }
640  // duplicate the materials
641  $clone->duplicateMaterials($original_id);
642  // copy XHTML media objects
643  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
644  return $clone->getId();
645  }
646 
652  function copyObject($target_questionpool, $title = "")
653  {
654  if ($this->getId() <= 0)
655  {
656  // The question has not been saved. It cannot be copied
657  return;
658  }
659  $clone = $this;
660  $original_id = SurveyQuestion::_getOriginalId($this->getId());
661  $clone->setId(-1);
662  $source_questionpool = $this->getObjId();
663  $clone->setObjId($target_questionpool);
664  if ($title)
665  {
666  $clone->setTitle($title);
667  }
668 
669  $clone->saveToDb();
670 
671  // duplicate the materials
672  $clone->duplicateMaterials($original_id);
673  // copy XHTML media objects
674  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
675  return $clone->getId();
676  }
677 
685  {
686  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
687  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
688  foreach ($mobs as $mob)
689  {
690  ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
691  }
692  }
693 
700  function loadFromDb($question_id)
701  {
702  global $ilDB;
703 
704  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
705  array('integer'),
706  array($this->getId())
707  );
708  $this->material = array();
709  if ($result->numRows())
710  {
711  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
712  while ($row = $ilDB->fetchAssoc($result))
713  {
714  $mat = new ilSurveyMaterial();
715  $mat->type = $row['material_type'];
716  $mat->internal_link = $row['internal_link'];
717  $mat->title = $row['material_title'];
718  $mat->import_id = $row['import_id'];
719  $mat->text_material = $row['text_material'];
720  $mat->external_link = $row['external_link'];
721  $mat->file_material = $row['file_material'];
722  array_push($this->material, $mat);
723  }
724  }
725  }
726 
733  function _isComplete($question_id)
734  {
735  global $ilDB;
736 
737  $result = $ilDB->queryF("SELECT complete FROM svy_question WHERE question_id = %s",
738  array('integer'),
739  array($question_id)
740  );
741  if ($result->numRows())
742  {
743  $row = $ilDB->fetchAssoc($result);
744  if ($row["complete"] == 1)
745  {
746  return TRUE;
747  }
748  }
749  return FALSE;
750  }
751 
757  function saveCompletionStatus($original_id = "")
758  {
759  global $ilDB;
760 
761  $question_id = $this->getId();
762  if (strlen($original_id))
763  {
764  $question_id = $original_id;
765  }
766 
767  if ($this->getId() > 0)
768  {
769  // update existing dataset
770  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
771  array('text', 'integer', 'integer'),
772  array($this->isComplete(), time(), $question_id)
773  );
774  }
775  }
776 
783  function saveToDb($original_id = "")
784  {
785  global $ilDB;
786 
787  // cleanup RTE images which are not inserted into the question text
788  include_once("./Services/RTE/classes/class.ilRTE.php");
789  ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
790  $affectedRows = 0;
791  if ($this->getId() == -1)
792  {
793  // Write new dataset
794  $next_id = $ilDB->nextId('svy_question');
795  $affectedRows = $ilDB->insert("svy_question", array(
796  "question_id" => array("integer", $next_id),
797  "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
798  "obj_fi" => array("integer", $this->getObjId()),
799  "owner_fi" => array("integer", $this->getOwner()),
800  "title" => array("text", $this->getTitle()),
801  "description" => array("text", $this->getDescription()),
802  "author" => array("text", $this->getAuthor()),
803  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
804  "obligatory" => array("text", $this->getObligatory()),
805  "complete" => array("text", $this->isComplete()),
806  "created" => array("integer", time()),
807  "original_id" => array("integer", ($original_id) ? $original_id : NULL),
808  "tstamp" => array("integer", time())
809  ));
810  $this->setId($next_id);
811  }
812  else
813  {
814  // update existing dataset
815  $affectedRows = $ilDB->update("svy_question", array(
816  "title" => array("text", $this->getTitle()),
817  "description" => array("text", $this->getDescription()),
818  "author" => array("text", $this->getAuthor()),
819  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
820  "obligatory" => array("text", $this->getObligatory()),
821  "complete" => array("text", $this->isComplete()),
822  "tstamp" => array("integer", time())
823  ), array(
824  "question_id" => array("integer", $this->getId())
825  ));
826  }
827  return $affectedRows;
828  }
829 
833  public function saveMaterial()
834  {
835  global $ilDB;
836 
837  include_once "./Services/COPage/classes/class.ilInternalLink.php";
838  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
839  array('integer'),
840  array($this->getId())
841  );
843 
844  foreach ($this->material as $material)
845  {
846  $next_id = $ilDB->nextId('svy_material');
847  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material " .
848  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
849  "text_material, external_link, file_material, material_type) ".
850  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
851  array('integer','integer','text','text','text','integer','text','text','text','integer'),
852  array(
853  $next_id, $this->getId(), $material->internal_link, $material->import_id,
854  $material->title, time(), $material->text_material, $material->external_link,
855  $material->file_material, $material->type)
856  );
857  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches))
858  {
859  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
860  }
861  }
862  }
863 
870  public function createNewQuestion()
871  {
872  global $ilDB, $ilUser;
873 
874  $obj_id = ($this->getObjId() <= 0) ? (ilObject::_lookupObjId((strlen($_GET["ref_id"])) ? $_GET["ref_id"] : $_POST["sel_qpl"])) : $this->getObjId();
875  if ($obj_id > 0)
876  {
877  $next_id = $ilDB->nextId('svy_question');
878  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_question (question_id, questiontype_fi, " .
879  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
880  "created, original_id, tstamp) VALUES " .
881  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
882  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
883  'text', 'text', 'integer', 'integer', 'integer'),
884  array(
885  $next_id,
886  $this->getQuestionTypeID(),
887  $obj_id,
888  $this->getOwner(),
889  NULL,
890  NULL,
891  $this->getAuthor(),
892  NULL,
893  "1",
894  "0",
895  time(),
896  NULL,
897  0
898  )
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  include_once "./Services/Utilities/classes/class.ilUtil.php";
946  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
948  }
949 
957  {
958  include_once "./Services/Utilities/classes/class.ilUtil.php";
959  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
961  }
962 
971  function saveCategoryToDb($categorytext, $neutral = 0)
972  {
973  global $ilUser, $ilDB;
974 
975  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
976  array('text','text','integer'),
977  array($categorytext, $neutral, $ilUser->getId())
978  );
979  $insert = FALSE;
980  $returnvalue = "";
981  if ($result->numRows())
982  {
983  $insert = TRUE;
984  while ($row = $ilDB->fetchAssoc($result))
985  {
986  if (strcmp($row["title"], $categorytext) == 0)
987  {
988  $returnvalue = $row["category_id"];
989  $insert = FALSE;
990  }
991  }
992  }
993  else
994  {
995  $insert = TRUE;
996  }
997  if ($insert)
998  {
999  $next_id = $ilDB->nextId('svy_category');
1000  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
1001  array('integer','text','text','integer','integer'),
1002  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
1003  );
1004  $returnvalue = $next_id;
1005  }
1006  return $returnvalue;
1007  }
1008 
1015  function deleteAdditionalTableData($question_id)
1016  {
1017  global $ilDB;
1018  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1019  array('integer'),
1020  array($question_id)
1021  );
1022  }
1023 
1030  function delete($question_id)
1031  {
1032  global $ilDB;
1033 
1034  if ($question_id < 1) return;
1035 
1036  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1037  array('integer'),
1038  array($question_id)
1039  );
1040  if ($result->numRows() == 1)
1041  {
1042  $row = $ilDB->fetchAssoc($result);
1043  $obj_id = $row["obj_fi"];
1044  }
1045  else
1046  {
1047  return;
1048  }
1049 
1050  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_answer WHERE question_fi = %s",
1051  array('integer'),
1052  array($question_id)
1053  );
1054 
1055  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE question_fi = %s",
1056  array('integer'),
1057  array($question_id)
1058  );
1059 
1060  $result = $ilDB->queryF("SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1061  array('integer'),
1062  array($question_id)
1063  );
1064  while ($row = $ilDB->fetchObject($result))
1065  {
1066  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE constraint_id = %s",
1067  array('integer'),
1068  array($row->constraint_fi)
1069  );
1070  }
1071 
1072  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1073  array('integer'),
1074  array($question_id)
1075  );
1076 
1077  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1078  array('integer'),
1079  array($question_id)
1080  );
1081  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_oblig WHERE question_fi = %s",
1082  array('integer'),
1083  array($question_id)
1084  );
1085  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_svy_qst WHERE question_fi = %s",
1086  array('integer'),
1087  array($question_id)
1088  );
1089  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
1090  array('integer'),
1091  array($question_id)
1092  );
1093  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_question WHERE question_id = %s",
1094  array('integer'),
1095  array($question_id)
1096  );
1097 
1098  $this->deleteAdditionalTableData($question_id);
1099 
1100  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1101  array('integer'),
1102  array($question_id)
1103  );
1104  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1105  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1106 
1107  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1108  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
1109  {
1110  include_once "./Services/Utilities/classes/class.ilUtil.php";
1111  ilUtil::delDir($directory);
1112  }
1113 
1114  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1115  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1116  // remaining usages are not in text anymore -> delete them
1117  // and media objects (note: delete method of ilObjMediaObject
1118  // checks whether object is used in another context; if yes,
1119  // the object is not deleted!)
1120  foreach($mobs as $mob)
1121  {
1122  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1123  $mob_obj =& new ilObjMediaObject($mob);
1124  $mob_obj->delete();
1125  }
1126  }
1127 
1135  function _getQuestionType($question_id)
1136  {
1137  global $ilDB;
1138 
1139  if ($question_id < 1) return "";
1140 
1141  $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",
1142  array('integer'),
1143  array($question_id)
1144  );
1145  if ($result->numRows() == 1)
1146  {
1147  $data = $ilDB->fetchAssoc($result);
1148  return $data["type_tag"];
1149  }
1150  else
1151  {
1152  return "";
1153  }
1154  }
1155 
1163  function _getTitle($question_id)
1164  {
1165  global $ilDB;
1166 
1167  if ($question_id < 1) return "";
1168 
1169  $result = $ilDB->queryF("SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1170  array('integer'),
1171  array($question_id)
1172  );
1173  if ($result->numRows() == 1)
1174  {
1175  $data = $ilDB->fetchAssoc($result);
1176  return $data["title"];
1177  }
1178  else
1179  {
1180  return "";
1181  }
1182  }
1183 
1191  function _getOriginalId($question_id)
1192  {
1193  global $ilDB;
1194  $result = $ilDB->queryF("SELECT * FROM svy_question WHERE question_id = %s",
1195  array('integer'),
1196  array($question_id)
1197  );
1198  if ($result->numRows() > 0)
1199  {
1200  $row = $ilDB->fetchAssoc($result);
1201  if ($row["original_id"] > 0)
1202  {
1203  return $row["original_id"];
1204  }
1205  else
1206  {
1207  return $row["question_id"];
1208  }
1209  }
1210  else
1211  {
1212  return "";
1213  }
1214  }
1215 
1216  function syncWithOriginal()
1217  {
1218  global $ilDB;
1219 
1220  if ($this->getOriginalId())
1221  {
1222  $id = $this->getId();
1223  $original = $this->getOriginalId();
1224 
1225  $this->setId($this->getOriginalId());
1226  $this->setOriginalId(NULL);
1227  $this->saveToDb();
1228 
1229  $this->setId($id);
1230  $this->setOriginalId($original);
1231 
1232  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1233  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1234  array('integer'),
1235  array($this->getOriginalId())
1236  );
1237  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1238  if (strlen($this->material["internal_link"]))
1239  {
1240  $next_id = $ilDB->nextId('svy_material');
1241  $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)",
1242  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1243  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1244  );
1245  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
1246  {
1247  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1248  }
1249  }
1250  }
1251  }
1252 
1259  function getPhrase($phrase_id)
1260  {
1261  global $ilDB;
1262 
1263  $result = $ilDB->queryF("SELECT title FROM svy_phrase WHERE phrase_id = %s",
1264  array('integer'),
1265  array($phrase_id)
1266  );
1267  if ($row = $ilDB->fetchAssoc($result))
1268  {
1269  return $row["title"];
1270  }
1271  return "";
1272  }
1273 
1282  {
1283  global $ilUser, $ilDB;
1284 
1285  $result = $ilDB->queryF("SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1286  array('text', 'integer'),
1287  array($title, $ilUser->getId())
1288  );
1289  return ($result->numRows() == 0) ? false : true;
1290  }
1291 
1299  function _questionExists($question_id)
1300  {
1301  global $ilDB;
1302 
1303  if ($question_id < 1)
1304  {
1305  return false;
1306  }
1307 
1308  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE question_id = %s",
1309  array('integer'),
1310  array($question_id)
1311  );
1312  return ($result->numRows() == 1) ? true : false;
1313  }
1314 
1315  function addInternalLink($material_id, $title = "")
1316  {
1317  if (strlen($material_id))
1318  {
1319  if (strcmp($material_title, "") == 0)
1320  {
1321  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1322  {
1323  $type = $matches[1];
1324  $target_id = $matches[2];
1325  $material_title = $this->lng->txt("obj_$type") . ": ";
1326  switch ($type)
1327  {
1328  case "lm":
1329  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1330  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1331  $cont_obj = $cont_obj_gui->object;
1332  $material_title .= $cont_obj->getTitle();
1333  break;
1334  case "pg":
1335  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1336  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1338  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1339  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1340  $cont_obj = $cont_obj_gui->object;
1341  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1342  $material_title .= $pg_obj->getTitle();
1343  break;
1344  case "st":
1345  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1346  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1348  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1349  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1350  $cont_obj = $cont_obj_gui->object;
1351  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1352  $material_title .= $st_obj->getTitle();
1353  break;
1354  case "git":
1355  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1356  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1357  break;
1358  case "mob":
1359  break;
1360  }
1361  }
1362  }
1363  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1364  $mat = new ilSurveyMaterial();
1365  $mat->type = 0;
1366  $mat->internal_link = $material_id;
1367  $mat->title = $material_title;
1368  $this->addMaterial($mat);
1369  $this->saveMaterial();
1370  }
1371  }
1372 
1378  public function deleteMaterials($a_array)
1379  {
1380  foreach ($a_array as $idx)
1381  {
1382  unset($this->material[$idx]);
1383  }
1384  $this->material = array_values($this->material);
1385  $this->saveMaterial();
1386  }
1387 
1394  function duplicateMaterials($question_id)
1395  {
1396  foreach ($this->materials as $filename)
1397  {
1398  $materialspath = $this->getMaterialsPath();
1399  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1400  if (!file_exists($materialspath))
1401  {
1402  include_once "./Services/Utilities/classes/class.ilUtil.php";
1403  ilUtil::makeDirParents($materialspath);
1404  }
1405  if (!copy($materialspath_original . $filename, $materialspath . $filename))
1406  {
1407  print "material could not be duplicated!!!! ";
1408  }
1409  }
1410  }
1411 
1412  public function addMaterial($obj_material)
1413  {
1414  array_push($this->material, $obj_material);
1415  }
1416 
1424  function setMaterial($material_id = "", $is_import = false, $material_title = "")
1425  {
1426  if (strcmp($material_id, "") != 0)
1427  {
1428  $import_id = "";
1429  if ($is_import)
1430  {
1431  $import_id = $material_id;
1432  $material_id = $this->_resolveInternalLink($import_id);
1433  }
1434  if (strcmp($material_title, "") == 0)
1435  {
1436  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1437  {
1438  $type = $matches[1];
1439  $target_id = $matches[2];
1440  $material_title = $this->lng->txt("obj_$type") . ": ";
1441  switch ($type)
1442  {
1443  case "lm":
1444  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1445  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1446  $cont_obj = $cont_obj_gui->object;
1447  $material_title .= $cont_obj->getTitle();
1448  break;
1449  case "pg":
1450  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1451  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1453  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1454  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1455  $cont_obj = $cont_obj_gui->object;
1456  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1457  $material_title .= $pg_obj->getTitle();
1458  break;
1459  case "st":
1460  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1461  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1463  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1464  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1465  $cont_obj = $cont_obj_gui->object;
1466  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1467  $material_title .= $st_obj->getTitle();
1468  break;
1469  case "git":
1470  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1471  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1472  break;
1473  case "mob":
1474  break;
1475  }
1476  }
1477  }
1478  $this->material = array(
1479  "internal_link" => $material_id,
1480  "import_id" => $import_id,
1481  "title" => $material_title
1482  );
1483  }
1484  $this->saveMaterial();
1485  }
1486 
1487  function _resolveInternalLink($internal_link)
1488  {
1489  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
1490  {
1491  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1492  include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1493  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1494  switch ($matches[2])
1495  {
1496  case "lm":
1497  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1498  break;
1499  case "pg":
1500  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1501  break;
1502  case "st":
1503  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1504  break;
1505  case "git":
1506  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1507  break;
1508  case "mob":
1509  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1510  break;
1511  }
1512  if (strcmp($resolved_link, "") == 0)
1513  {
1514  $resolved_link = $internal_link;
1515  }
1516  }
1517  else
1518  {
1519  $resolved_link = $internal_link;
1520  }
1521  return $resolved_link;
1522  }
1523 
1524  function _resolveIntLinks($question_id)
1525  {
1526  global $ilDB;
1527  $resolvedlinks = 0;
1528  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1529  array('integer'),
1530  array($question_id)
1531  );
1532  if ($result->numRows())
1533  {
1534  while ($row = $ilDB->fetchAssoc($result))
1535  {
1536  $internal_link = $row["internal_link"];
1537  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1538  $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
1539  if (strcmp($internal_link, $resolved_link) != 0)
1540  {
1541  // internal link was resolved successfully
1542  $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1543  array('text', 'integer', 'integer'),
1544  array($resolved_link, time(), $row["material_id"])
1545  );
1546  $resolvedlinks++;
1547  }
1548  }
1549  }
1550  if ($resolvedlinks)
1551  {
1552  // there are resolved links -> reenter theses links to the database
1553 
1554  // delete all internal links from the database
1555  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1556  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1557 
1558  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1559  array('integer'),
1560  array($question_id)
1561  );
1562  if ($result->numRows())
1563  {
1564  while ($row = $ilDB->fetchAssoc($result))
1565  {
1566  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
1567  {
1568  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1569  }
1570  }
1571  }
1572  }
1573  }
1574 
1575  function _getInternalLinkHref($target = "")
1576  {
1577  global $ilDB;
1578  $linktypes = array(
1579  "lm" => "LearningModule",
1580  "pg" => "PageObject",
1581  "st" => "StructureObject",
1582  "git" => "GlossaryItem",
1583  "mob" => "MediaObject"
1584  );
1585  $href = "";
1586  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
1587  {
1588  $type = $matches[1];
1589  $target_id = $matches[2];
1590  include_once "./Services/Utilities/classes/class.ilUtil.php";
1591  switch($linktypes[$matches[1]])
1592  {
1593  case "LearningModule":
1594  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1595  break;
1596  case "PageObject":
1597  case "StructureObject":
1598  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1599  break;
1600  case "GlossaryItem":
1601  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1602  break;
1603  case "MediaObject":
1604  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/ilias.php?baseClass=ilLMPresentationGUI&obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=".$_GET["ref_id"]."&mob_id=".$target_id;
1605  break;
1606  }
1607  }
1608  return $href;
1609  }
1610 
1619  function _isWriteable($question_id, $user_id)
1620  {
1621  global $ilDB;
1622 
1623  if (($question_id < 1) || ($user_id < 1))
1624  {
1625  return false;
1626  }
1627 
1628  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1629  array('integer'),
1630  array($question_id)
1631  );
1632  if ($result->numRows() == 1)
1633  {
1634  $row = $ilDB->fetchAssoc($result);
1635  $qpl_object_id = $row["obj_fi"];
1636  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1637  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1638  }
1639  else
1640  {
1641  return false;
1642  }
1643  }
1644 
1652  {
1653  global $ilDB;
1654  $result = $ilDB->queryF("SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1655  array('text'),
1656  array($this->getQuestionType())
1657  );
1658  if ($result->numRows() == 1)
1659  {
1660  $row = $ilDB->fetchAssoc($result);
1661  return $row["questiontype_id"];
1662  }
1663  else
1664  {
1665  return 0;
1666  }
1667  }
1668 
1675  function getQuestionType()
1676  {
1677  return "";
1678  }
1679 
1687  static function _includeClass($question_type, $gui = 0)
1688  {
1689  $type = $question_type;
1690  if ($gui) $type .= "GUI";
1691  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type.".php"))
1692  {
1693  include_once "./Modules/SurveyQuestionPool/classes/class.".$type.".php";
1694  return true;
1695  }
1696  else
1697  {
1698  global $ilPluginAdmin;
1699  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1700  foreach ($pl_names as $pl_name)
1701  {
1702  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1703  if (strcmp($pl->getQuestionType(), $question_type) == 0)
1704  {
1705  $pl->includeClass("class.".$type.".php");
1706  return true;
1707  }
1708  }
1709  }
1710  return false;
1711  }
1712 
1719  static function _getQuestionTypeName($type_tag)
1720  {
1721  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type_tag.".php"))
1722  {
1723  global $lng;
1724  return $lng->txt($type_tag);
1725  }
1726  else
1727  {
1728  global $ilPluginAdmin;
1729  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1730  foreach ($pl_names as $pl_name)
1731  {
1732  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1733  if (strcmp($pl->getQuestionType(), $type_tag) == 0)
1734  {
1735  return $pl->getQuestionTypeTranslation();
1736  }
1737  }
1738  }
1739  return "";
1740  }
1741 
1742 
1750  function &_instanciateQuestion($question_id)
1751  {
1752  $question_type = SurveyQuestion::_getQuestionType($question_id);
1753  SurveyQuestion::_includeClass($question_type);
1754  $question = new $question_type();
1755  $question->loadFromDb($question_id);
1756  return $question;
1757  }
1758 
1766  function &_instanciateQuestionGUI($question_id)
1767  {
1768  $question_type = SurveyQuestion::_getQuestionType($question_id);
1769  SurveyQuestion::_includeClass($question_type, 1);
1770  $guitype = $question_type . "GUI";
1771  $question = new $guitype($question_id);
1772  return $question;
1773  }
1774 
1783  function isHTML($a_text)
1784  {
1785  if (preg_match("/<[^>]*?>/", $a_text))
1786  {
1787  return TRUE;
1788  }
1789  else
1790  {
1791  return FALSE;
1792  }
1793  }
1794 
1802  function QTIMaterialToString($a_material)
1803  {
1804  $result = "";
1805  for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
1806  {
1807  $material = $a_material->getMaterial($i);
1808  if (strcmp($material["type"], "mattext") == 0)
1809  {
1810  $result .= $material["material"]->getContent();
1811  }
1812  if (strcmp($material["type"], "matimage") == 0)
1813  {
1814  $matimage = $material["material"];
1815  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
1816  {
1817  // import an mediaobject which was inserted using tiny mce
1818  if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
1819  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1820  }
1821  }
1822  }
1823  return $result;
1824  }
1825 
1834  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE)
1835  {
1836  include_once "./Services/RTE/classes/class.ilRTE.php";
1837  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1838 
1839  $a_xml_writer->xmlStartTag("material");
1840  $attrs = array(
1841  "type" => "text/plain"
1842  );
1843  if ($this->isHTML($a_material))
1844  {
1845  $attrs["type"] = "text/xhtml";
1846  }
1847  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1848 
1849  if ($add_mobs)
1850  {
1851  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1852  foreach ($mobs as $mob)
1853  {
1854  $mob_obj =& new ilObjMediaObject($mob);
1855  $imgattrs = array(
1856  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1857  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
1858  );
1859  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
1860  }
1861  }
1862  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
1863  }
1864 
1871  function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
1872  {
1873  include_once "./Services/Utilities/classes/class.ilUtil.php";
1874  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1875  }
1876 
1885  {
1886  return array();
1887  }
1888 
1889 
1897  {
1898  array_push($a_array, $this->getTitle());
1899  }
1900 
1908  function addUserSpecificResultsData(&$a_array, &$resultset)
1909  {
1910  // overwrite in inherited classes
1911  }
1912 
1921  {
1922  // overwrite in inherited classes
1923  return array();
1924  }
1925 
1932  function &getWorkingDataFromUserInput($post_data)
1933  {
1934  // overwrite in inherited classes
1935  $data = array();
1936  return $data;
1937  }
1938 
1947  function importAdditionalMetadata($a_meta)
1948  {
1949  // overwrite in inherited classes
1950  }
1951 
1958  function importResponses($a_data)
1959  {
1960  // overwrite in inherited classes
1961  }
1962 
1969  function importAdjectives($a_data)
1970  {
1971  // overwrite in inherited classes
1972  }
1973 
1980  function importMatrix($a_data)
1981  {
1982  // overwrite in inherited classes
1983  }
1984 
1996  function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row)
1997  {
1998  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1999  $worksheet->writeString($row, 0, ilExcelUtils::_convert_text($this->getTitle()));
2000  $worksheet->writeString($row, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
2001  $worksheet->writeString($row, 2, ilExcelUtils::_convert_text($this->lng->txt($eval_data["QUESTION_TYPE"])));
2002  $worksheet->write($row, 3, $eval_data["USERS_ANSWERED"]);
2003  $worksheet->write($row, 4, $eval_data["USERS_SKIPPED"]);
2004  $worksheet->write($row, 5, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
2005  $worksheet->write($row, 6, ilExcelUtils::_convert_text($eval_data["MODE"]));
2006  $worksheet->write($row, 7, $eval_data["MODE_NR_OF_SELECTIONS"]);
2007  $worksheet->write($row, 8, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
2008  $worksheet->write($row, 9, $eval_data["ARITHMETIC_MEAN"]);
2009  return $row + 1;
2010  }
2011 
2023  function &setExportCumulatedCVS(&$eval_data)
2024  {
2025  $csvrow = array();
2026  array_push($csvrow, $this->getTitle());
2027  array_push($csvrow, $this->getQuestiontext());
2028  array_push($csvrow, $this->lng->txt($eval_data["QUESTION_TYPE"]));
2029  array_push($csvrow, $eval_data["USERS_ANSWERED"]);
2030  array_push($csvrow, $eval_data["USERS_SKIPPED"]);
2031  array_push($csvrow, $eval_data["MODE"]);
2032  array_push($csvrow, $eval_data["MODE_NR_OF_SELECTIONS"]);
2033  array_push($csvrow, $eval_data["MEDIAN"]);
2034  array_push($csvrow, $eval_data["ARITHMETIC_MEAN"]);
2035  $result = array();
2036  array_push($result, $csvrow);
2037  return $result;
2038  }
2039 
2049  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
2050  {
2051  // overwrite in inherited classes
2052  }
2053 
2061  {
2062  // overwrite in inherited classes
2063  return FALSE;
2064  }
2065 
2073  {
2074  // overwrite in inherited classes
2075  return array();
2076  }
2077 
2084  function getPreconditionSelectValue($default = "")
2085  {
2086  // overwrite in inherited classes
2087  }
2088 
2097  {
2098  // overwrite in inherited classes
2099  return $value;
2100  }
2101 
2110  function outChart($survey_id, $type = "")
2111  {
2112  // overwrite in inherited classes
2113  }
2114 
2115  function setOriginalId($original_id)
2116  {
2117  $this->original_id = $original_id;
2118  }
2119 
2120  function getOriginalId()
2121  {
2122  return $this->original_id;
2123  }
2124 
2130  public function saveRandomData($active_id)
2131  {
2132  // do nothing, overwrite in parent classes
2133  }
2134 
2135  public function getMaterial()
2136  {
2137  return $this->material;
2138  }
2139 
2140  public function setSubtype($a_subtype)
2141  {
2142  // do nothing
2143  }
2144 
2145  public function getSubtype()
2146  {
2147  // do nothing
2148  return null;
2149  }
2150 
2152  {
2153  if (count($this->cumulated) == 0)
2154  {
2155  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
2157  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
2158  }
2159  return $this->cumulated;
2160  }
2161 
2167  public function getCumulatedResultData($survey_id, $counter)
2168  {
2170  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->getQuestiontext());
2171  $maxlen = 37;
2172  include_once "./Services/Utilities/classes/class.ilStr.php";
2173  if (ilStr::strlen($questiontext) > $maxlen + 3)
2174  {
2175  $questiontext = ilStr::substr($questiontext, 0, $maxlen) . "...";
2176  }
2177  $result = array(
2178  'counter' => $counter,
2179  'title' => $this->getTitle(),
2180  'question' => $questiontext,
2181  'users_answered' => $cumulated['USERS_ANSWERED'],
2182  'users_skipped' => $cumulated['USERS_SKIPPED'],
2183  'question_type' => $this->lng->txt($cumulated["QUESTION_TYPE"]),
2184  'mode' => $cumulated["MODE"],
2185  'mode_nr_of_selections' => $cumulated["MODE_NR_OF_SELECTIONS"],
2186  'median' => $cumulated["MEDIAN"],
2187  'arithmetic_mean' => $cumulated["ARITHMETIC_MEAN"]
2188  );
2189  return $result;
2190  }
2191 }
2192 ?>