ILIAS  Release_4_1_x_branch Revision 61804
 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 
147  private $arrData;
148 
159  function SurveyQuestion
160  (
161  $title = "",
162  $description = "",
163  $author = "",
164  $questiontext = "",
165  $owner = -1
166  )
167  {
168  global $ilias;
169  global $lng;
170  global $tpl;
171 
172  $this->ilias =& $ilias;
173  $this->lng =& $lng;
174  $this->tpl =& $tpl;
175  $this->complete =
176  $this->title = $title;
177  $this->description = $description;
178  $this->questiontext = $questiontext;
179  $this->author = $author;
180  $this->cumulated = array();
181  if (!$this->author)
182  {
183  $this->author = $this->ilias->account->fullname;
184  }
185  $this->owner = $owner;
186  if ($this->owner == -1)
187  {
188  $this->owner = $this->ilias->account->id;
189  }
190  $this->id = -1;
191  $this->survey_id = -1;
192  $this->obligatory = 1;
193  $this->orientation = 0;
194  $this->materials = array();
195  $this->material = array();
196  $this->arrData = array();
197  register_shutdown_function(array(&$this, '_SurveyQuestion'));
198  }
199 
200  function _SurveyQuestion()
201  {
202  }
203 
210  function setComplete($a_complete)
211  {
212  $this->complete = ($a_complete) ? 1 : 0;
213  }
214 
221  function isComplete()
222  {
223  return 0;
224  }
225 
234  function questionTitleExists($title, $questionpool_object = "")
235  {
236  global $ilDB;
237 
238  $refwhere = "";
239  if (strcmp($questionpool_object, "") != 0)
240  {
241  $refwhere = sprintf(" AND obj_fi = %s",
242  $ilDB->quote($questionpool_object, 'integer')
243  );
244  }
245  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE title = %s$refwhere",
246  array('text'),
247  array($title)
248  );
249  return ($result->numRows() > 0) ? true : false;
250  }
251 
259  function setTitle($title = "")
260  {
261  $this->title = $title;
262  }
263 
271  function setObligatory($obligatory = 1)
272  {
273  $this->obligatory = ($obligatory) ? 1 : 0;
274  }
275 
284  {
285  $this->orientation = ($orientation) ? $orientation : 0;
286  }
287 
295  function setId($id = -1)
296  {
297  $this->id = $id;
298  }
299 
307  function setSurveyId($id = -1)
308  {
309  $this->survey_id = $id;
310  }
311 
319  function setDescription($description = "")
320  {
321  $this->description = $description;
322  }
323 
324 
333  function addMaterials($materials_file, $materials_name="")
334  {
335  if (empty($materials_name))
336  {
337  $materials_name = $materials_file;
338  }
339  if ((!empty($materials_name))&&(!array_key_exists($materials_name, $this->materials)))
340  {
341  $this->materials[$materials_name] = $materials_file;
342  }
343  }
344 
352  function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
353  {
354  if (!empty($materials_filename))
355  {
356  include_once "./Services/Utilities/classes/class.ilUtil.php";
357  $materialspath = $this->getMaterialsPath();
358  if (!file_exists($materialspath))
359  {
360  ilUtil::makeDirParents($materialspath);
361  }
362  //if (!move_uploaded_file($materials_tempfilename, $materialspath . $materials_filename))
363  if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
364  $materialspath.$materials_filename))
365  {
366  print "image not uploaded!!!! ";
367  }
368  else
369  {
370  $this->addMaterials($materials_filename, $materials_name);
371  }
372  }
373  }
374 
382  function deleteMaterial($materials_name = "")
383  {
384  foreach ($this->materials as $key => $value)
385  {
386  if (strcmp($key, $materials_name)==0)
387  {
388  if (file_exists($this->getMaterialsPath().$value))
389  {
390  unlink($this->getMaterialsPath().$value);
391  }
392  unset($this->materials[$key]);
393  }
394  }
395  }
396 
403  function flushMaterials()
404  {
405  $this->materials = array();
406  }
407 
415  function setAuthor($author = "")
416  {
417  if (!$author)
418  {
419  $author = $this->ilias->account->fullname;
420  }
421  $this->author = $author;
422  }
423 
432  {
433  $this->questiontext = $questiontext;
434  }
435 
443  function setOwner($owner = "")
444  {
445  $this->owner = $owner;
446  }
447 
455  function getTitle()
456  {
457  return $this->title;
458  }
459 
467  function getId()
468  {
469  return $this->id;
470  }
471 
478  public function getObligatory($survey_id = "")
479  {
480  if ($survey_id > 0)
481  {
482  global $ilDB;
483 
484  $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s AND question_fi = %s",
485  array('integer', 'integer'),
486  array($survey_id, $this->getId())
487  );
488  if ($result->numRows())
489  {
490  $row = $ilDB->fetchAssoc($result);
491  return ($row["obligatory"]) ? 1 : 0;
492  }
493  else
494  {
495  return ($this->obligatory) ? 1 : 0;
496  }
497  }
498  else
499  {
500  return ($this->obligatory) ? 1 : 0;
501  }
502  }
503 
511  function getSurveyId()
512  {
513  return $this->survey_id;
514  }
515 
523  function getOrientation()
524  {
525  switch ($this->orientation)
526  {
527  case 0:
528  case 1:
529  case 2:
530  break;
531  default:
532  $this->orientation = 0;
533  break;
534  }
535  return $this->orientation;
536  }
537 
538 
546  function getDescription()
547  {
548  return (strlen($this->description)) ? $this->description : NULL;
549  }
550 
558  function getAuthor()
559  {
560  return (strlen($this->author)) ? $this->author : NULL;
561  }
562 
570  function getOwner()
571  {
572  return $this->owner;
573  }
574 
582  function getQuestiontext()
583  {
584  return (strlen($this->questiontext)) ? $this->questiontext : NULL;
585  }
586 
594  function getObjId() {
595  return $this->obj_id;
596  }
597 
605  function setObjId($obj_id = 0)
606  {
607  $this->obj_id = $obj_id;
608  }
609 
615  function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
616  {
617  if ($this->getId() <= 0)
618  {
619  // The question has not been saved. It cannot be duplicated
620  return;
621  }
622  // duplicate the question in database
623  $clone = $this;
624  $original_id = $this->getId();
625  $clone->setId(-1);
626  if ($title)
627  {
628  $clone->setTitle($title);
629  }
630  if ($author)
631  {
632  $clone->setAuthor($author);
633  }
634  if ($owner)
635  {
636  $clone->setOwner($owner);
637  }
638  if ($for_survey)
639  {
640  $clone->saveToDb($original_id);
641  }
642  else
643  {
644  $clone->saveToDb();
645  }
646  // duplicate the materials
647  $clone->duplicateMaterials($original_id);
648  // copy XHTML media objects
649  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
650  return $clone->getId();
651  }
652 
658  function copyObject($target_questionpool, $title = "")
659  {
660  if ($this->getId() <= 0)
661  {
662  // The question has not been saved. It cannot be copied
663  return;
664  }
665  $clone = $this;
666  $original_id = SurveyQuestion::_getOriginalId($this->getId());
667  $clone->setId(-1);
668  $source_questionpool = $this->getObjId();
669  $clone->setObjId($target_questionpool);
670  if ($title)
671  {
672  $clone->setTitle($title);
673  }
674 
675  $clone->saveToDb();
676 
677  // duplicate the materials
678  $clone->duplicateMaterials($original_id);
679  // copy XHTML media objects
680  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
681  return $clone->getId();
682  }
683 
691  {
692  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
693  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
694  foreach ($mobs as $mob)
695  {
696  ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
697  }
698  }
699 
706  function loadFromDb($question_id)
707  {
708  global $ilDB;
709 
710  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
711  array('integer'),
712  array($this->getId())
713  );
714  $this->material = array();
715  if ($result->numRows())
716  {
717  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
718  while ($row = $ilDB->fetchAssoc($result))
719  {
720  $mat = new ilSurveyMaterial();
721  $mat->type = $row['material_type'];
722  $mat->internal_link = $row['internal_link'];
723  $mat->title = $row['material_title'];
724  $mat->import_id = $row['import_id'];
725  $mat->text_material = $row['text_material'];
726  $mat->external_link = $row['external_link'];
727  $mat->file_material = $row['file_material'];
728  array_push($this->material, $mat);
729  }
730  }
731  }
732 
739  function _isComplete($question_id)
740  {
741  global $ilDB;
742 
743  $result = $ilDB->queryF("SELECT complete FROM svy_question WHERE question_id = %s",
744  array('integer'),
745  array($question_id)
746  );
747  if ($result->numRows())
748  {
749  $row = $ilDB->fetchAssoc($result);
750  if ($row["complete"] == 1)
751  {
752  return TRUE;
753  }
754  }
755  return FALSE;
756  }
757 
763  function saveCompletionStatus($original_id = "")
764  {
765  global $ilDB;
766 
767  $question_id = $this->getId();
768  if (strlen($original_id))
769  {
770  $question_id = $original_id;
771  }
772 
773  if ($this->getId() > 0)
774  {
775  // update existing dataset
776  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
777  array('text', 'integer', 'integer'),
778  array($this->isComplete(), time(), $question_id)
779  );
780  }
781  }
782 
789  function saveToDb($original_id = "")
790  {
791  global $ilDB;
792 
793  // cleanup RTE images which are not inserted into the question text
794  include_once("./Services/RTE/classes/class.ilRTE.php");
795  ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
796  $affectedRows = 0;
797  if ($this->getId() == -1)
798  {
799  // Write new dataset
800  $next_id = $ilDB->nextId('svy_question');
801  $affectedRows = $ilDB->insert("svy_question", array(
802  "question_id" => array("integer", $next_id),
803  "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
804  "obj_fi" => array("integer", $this->getObjId()),
805  "owner_fi" => array("integer", $this->getOwner()),
806  "title" => array("text", $this->getTitle()),
807  "label" => array("text", (strlen($this->label)) ? $this->label : null),
808  "description" => array("text", $this->getDescription()),
809  "author" => array("text", $this->getAuthor()),
810  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
811  "obligatory" => array("text", $this->getObligatory()),
812  "complete" => array("text", $this->isComplete()),
813  "created" => array("text", time()),
814  "original_id" => array("integer", ($original_id) ? $original_id : NULL),
815  "tstamp" => array("integer", time())
816  ));
817  $this->setId($next_id);
818  }
819  else
820  {
821  // update existing dataset
822  $affectedRows = $ilDB->update("svy_question", array(
823  "title" => array("text", $this->getTitle()),
824  "label" => array("text", (strlen($this->label)) ? $this->label : null),
825  "description" => array("text", $this->getDescription()),
826  "author" => array("text", $this->getAuthor()),
827  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
828  "obligatory" => array("text", $this->getObligatory()),
829  "complete" => array("text", $this->isComplete()),
830  "tstamp" => array("integer", time())
831  ), array(
832  "question_id" => array("integer", $this->getId())
833  ));
834  }
835  return $affectedRows;
836  }
837 
841  public function saveMaterial()
842  {
843  global $ilDB;
844 
845  include_once "./Services/COPage/classes/class.ilInternalLink.php";
846  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
847  array('integer'),
848  array($this->getId())
849  );
851 
852  foreach ($this->material as $material)
853  {
854  $next_id = $ilDB->nextId('svy_material');
855  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material " .
856  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
857  "text_material, external_link, file_material, material_type) ".
858  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
859  array('integer','integer','text','text','text','integer','text','text','text','integer'),
860  array(
861  $next_id, $this->getId(), $material->internal_link, $material->import_id,
862  $material->title, time(), $material->text_material, $material->external_link,
863  $material->file_material, $material->type)
864  );
865  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches))
866  {
867  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
868  }
869  }
870  }
871 
878  public function createNewQuestion()
879  {
880  global $ilDB, $ilUser;
881 
882  $obj_id = ($this->getObjId() <= 0) ? (ilObject::_lookupObjId((strlen($_GET["ref_id"])) ? $_GET["ref_id"] : $_POST["sel_qpl"])) : $this->getObjId();
883  if ($obj_id > 0)
884  {
885  $next_id = $ilDB->nextId('svy_question');
886  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_question (question_id, questiontype_fi, " .
887  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
888  "created, original_id, tstamp) VALUES " .
889  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
890  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
891  'text', 'text', 'integer', 'integer', 'integer'),
892  array(
893  $next_id,
894  $this->getQuestionTypeID(),
895  $obj_id,
896  $this->getOwner(),
897  NULL,
898  NULL,
899  $this->getAuthor(),
900  NULL,
901  "1",
902  "0",
903  time(),
904  NULL,
905  0
906  )
907  );
908  $this->setId($next_id);
909  }
910  return $this->getId();
911  }
912 
919  function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
920  {
921  }
922 
929  function getImagePath()
930  {
931  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
932  }
933 
940  function getMaterialsPath()
941  {
942  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
943  }
944 
951  function getImagePathWeb()
952  {
953  include_once "./Services/Utilities/classes/class.ilUtil.php";
954  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
956  }
957 
965  {
966  include_once "./Services/Utilities/classes/class.ilUtil.php";
967  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
969  }
970 
979  function saveCategoryToDb($categorytext, $neutral = 0)
980  {
981  global $ilUser, $ilDB;
982 
983  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
984  array('text','text','integer'),
985  array($categorytext, $neutral, $ilUser->getId())
986  );
987  $insert = FALSE;
988  $returnvalue = "";
989  if ($result->numRows())
990  {
991  $insert = TRUE;
992  while ($row = $ilDB->fetchAssoc($result))
993  {
994  if (strcmp($row["title"], $categorytext) == 0)
995  {
996  $returnvalue = $row["category_id"];
997  $insert = FALSE;
998  }
999  }
1000  }
1001  else
1002  {
1003  $insert = TRUE;
1004  }
1005  if ($insert)
1006  {
1007  $next_id = $ilDB->nextId('svy_category');
1008  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
1009  array('integer','text','text','integer','integer'),
1010  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
1011  );
1012  $returnvalue = $next_id;
1013  }
1014  return $returnvalue;
1015  }
1016 
1023  function deleteAdditionalTableData($question_id)
1024  {
1025  global $ilDB;
1026  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1027  array('integer'),
1028  array($question_id)
1029  );
1030  }
1031 
1038  function delete($question_id)
1039  {
1040  global $ilDB;
1041 
1042  if ($question_id < 1) return;
1043 
1044  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1045  array('integer'),
1046  array($question_id)
1047  );
1048  if ($result->numRows() == 1)
1049  {
1050  $row = $ilDB->fetchAssoc($result);
1051  $obj_id = $row["obj_fi"];
1052  }
1053  else
1054  {
1055  return;
1056  }
1057 
1058  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_answer WHERE question_fi = %s",
1059  array('integer'),
1060  array($question_id)
1061  );
1062 
1063  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE question_fi = %s",
1064  array('integer'),
1065  array($question_id)
1066  );
1067 
1068  $result = $ilDB->queryF("SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1069  array('integer'),
1070  array($question_id)
1071  );
1072  while ($row = $ilDB->fetchObject($result))
1073  {
1074  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE constraint_id = %s",
1075  array('integer'),
1076  array($row->constraint_fi)
1077  );
1078  }
1079 
1080  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1081  array('integer'),
1082  array($question_id)
1083  );
1084 
1085  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1086  array('integer'),
1087  array($question_id)
1088  );
1089  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_oblig WHERE question_fi = %s",
1090  array('integer'),
1091  array($question_id)
1092  );
1093  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_svy_qst WHERE question_fi = %s",
1094  array('integer'),
1095  array($question_id)
1096  );
1097  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
1098  array('integer'),
1099  array($question_id)
1100  );
1101  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_question WHERE question_id = %s",
1102  array('integer'),
1103  array($question_id)
1104  );
1105 
1106  $this->deleteAdditionalTableData($question_id);
1107 
1108  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1109  array('integer'),
1110  array($question_id)
1111  );
1112  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1113  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1114 
1115  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1116  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
1117  {
1118  include_once "./Services/Utilities/classes/class.ilUtil.php";
1119  ilUtil::delDir($directory);
1120  }
1121 
1122  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1123  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1124  // remaining usages are not in text anymore -> delete them
1125  // and media objects (note: delete method of ilObjMediaObject
1126  // checks whether object is used in another context; if yes,
1127  // the object is not deleted!)
1128  foreach($mobs as $mob)
1129  {
1130  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1131  $mob_obj =& new ilObjMediaObject($mob);
1132  $mob_obj->delete();
1133  }
1134  }
1135 
1143  function _getQuestionType($question_id)
1144  {
1145  global $ilDB;
1146 
1147  if ($question_id < 1) return "";
1148 
1149  $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",
1150  array('integer'),
1151  array($question_id)
1152  );
1153  if ($result->numRows() == 1)
1154  {
1155  $data = $ilDB->fetchAssoc($result);
1156  return $data["type_tag"];
1157  }
1158  else
1159  {
1160  return "";
1161  }
1162  }
1163 
1171  function _getTitle($question_id)
1172  {
1173  global $ilDB;
1174 
1175  if ($question_id < 1) return "";
1176 
1177  $result = $ilDB->queryF("SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1178  array('integer'),
1179  array($question_id)
1180  );
1181  if ($result->numRows() == 1)
1182  {
1183  $data = $ilDB->fetchAssoc($result);
1184  return $data["title"];
1185  }
1186  else
1187  {
1188  return "";
1189  }
1190  }
1191 
1199  function _getOriginalId($question_id)
1200  {
1201  global $ilDB;
1202  $result = $ilDB->queryF("SELECT * FROM svy_question WHERE question_id = %s",
1203  array('integer'),
1204  array($question_id)
1205  );
1206  if ($result->numRows() > 0)
1207  {
1208  $row = $ilDB->fetchAssoc($result);
1209  if ($row["original_id"] > 0)
1210  {
1211  return $row["original_id"];
1212  }
1213  else
1214  {
1215  return $row["question_id"];
1216  }
1217  }
1218  else
1219  {
1220  return "";
1221  }
1222  }
1223 
1224  function syncWithOriginal()
1225  {
1226  global $ilDB;
1227 
1228  if ($this->getOriginalId())
1229  {
1230  $id = $this->getId();
1231  $original = $this->getOriginalId();
1232 
1233  $this->setId($this->getOriginalId());
1234  $this->setOriginalId(NULL);
1235  $this->saveToDb();
1236 
1237  $this->setId($id);
1238  $this->setOriginalId($original);
1239 
1240  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1241  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1242  array('integer'),
1243  array($this->getOriginalId())
1244  );
1245  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1246  if (strlen($this->material["internal_link"]))
1247  {
1248  $next_id = $ilDB->nextId('svy_material');
1249  $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)",
1250  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1251  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1252  );
1253  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
1254  {
1255  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1256  }
1257  }
1258  }
1259  }
1260 
1267  function getPhrase($phrase_id)
1268  {
1269  global $ilDB;
1270 
1271  $result = $ilDB->queryF("SELECT title FROM svy_phrase WHERE phrase_id = %s",
1272  array('integer'),
1273  array($phrase_id)
1274  );
1275  if ($row = $ilDB->fetchAssoc($result))
1276  {
1277  return $row["title"];
1278  }
1279  return "";
1280  }
1281 
1290  {
1291  global $ilUser, $ilDB;
1292 
1293  $result = $ilDB->queryF("SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1294  array('text', 'integer'),
1295  array($title, $ilUser->getId())
1296  );
1297  return ($result->numRows() == 0) ? false : true;
1298  }
1299 
1307  function _questionExists($question_id)
1308  {
1309  global $ilDB;
1310 
1311  if ($question_id < 1)
1312  {
1313  return false;
1314  }
1315 
1316  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE question_id = %s",
1317  array('integer'),
1318  array($question_id)
1319  );
1320  return ($result->numRows() == 1) ? true : false;
1321  }
1322 
1323  function addInternalLink($material_id, $title = "")
1324  {
1325  if (strlen($material_id))
1326  {
1327  if (strcmp($material_title, "") == 0)
1328  {
1329  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1330  {
1331  $type = $matches[1];
1332  $target_id = $matches[2];
1333  $material_title = $this->lng->txt("obj_$type") . ": ";
1334  switch ($type)
1335  {
1336  case "lm":
1337  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1338  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1339  $cont_obj = $cont_obj_gui->object;
1340  $material_title .= $cont_obj->getTitle();
1341  break;
1342  case "pg":
1343  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1344  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1346  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1347  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1348  $cont_obj = $cont_obj_gui->object;
1349  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1350  $material_title .= $pg_obj->getTitle();
1351  break;
1352  case "st":
1353  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1354  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1356  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1357  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1358  $cont_obj = $cont_obj_gui->object;
1359  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1360  $material_title .= $st_obj->getTitle();
1361  break;
1362  case "git":
1363  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1364  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1365  break;
1366  case "mob":
1367  break;
1368  }
1369  }
1370  }
1371  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1372  $mat = new ilSurveyMaterial();
1373  $mat->type = 0;
1374  $mat->internal_link = $material_id;
1375  $mat->title = $material_title;
1376  $this->addMaterial($mat);
1377  $this->saveMaterial();
1378  }
1379  }
1380 
1386  public function deleteMaterials($a_array)
1387  {
1388  foreach ($a_array as $idx)
1389  {
1390  unset($this->material[$idx]);
1391  }
1392  $this->material = array_values($this->material);
1393  $this->saveMaterial();
1394  }
1395 
1402  function duplicateMaterials($question_id)
1403  {
1404  foreach ($this->materials as $filename)
1405  {
1406  $materialspath = $this->getMaterialsPath();
1407  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1408  if (!file_exists($materialspath))
1409  {
1410  include_once "./Services/Utilities/classes/class.ilUtil.php";
1411  ilUtil::makeDirParents($materialspath);
1412  }
1413  if (!copy($materialspath_original . $filename, $materialspath . $filename))
1414  {
1415  print "material could not be duplicated!!!! ";
1416  }
1417  }
1418  }
1419 
1420  public function addMaterial($obj_material)
1421  {
1422  array_push($this->material, $obj_material);
1423  }
1424 
1432  function setMaterial($material_id = "", $is_import = false, $material_title = "")
1433  {
1434  if (strcmp($material_id, "") != 0)
1435  {
1436  $import_id = "";
1437  if ($is_import)
1438  {
1439  $import_id = $material_id;
1440  $material_id = $this->_resolveInternalLink($import_id);
1441  }
1442  if (strcmp($material_title, "") == 0)
1443  {
1444  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1445  {
1446  $type = $matches[1];
1447  $target_id = $matches[2];
1448  $material_title = $this->lng->txt("obj_$type") . ": ";
1449  switch ($type)
1450  {
1451  case "lm":
1452  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1453  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1454  $cont_obj = $cont_obj_gui->object;
1455  $material_title .= $cont_obj->getTitle();
1456  break;
1457  case "pg":
1458  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1459  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1461  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1462  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1463  $cont_obj = $cont_obj_gui->object;
1464  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1465  $material_title .= $pg_obj->getTitle();
1466  break;
1467  case "st":
1468  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1469  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1471  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1472  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1473  $cont_obj = $cont_obj_gui->object;
1474  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1475  $material_title .= $st_obj->getTitle();
1476  break;
1477  case "git":
1478  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1479  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1480  break;
1481  case "mob":
1482  break;
1483  }
1484  }
1485  }
1486  $this->material = array(
1487  "internal_link" => $material_id,
1488  "import_id" => $import_id,
1489  "title" => $material_title
1490  );
1491  }
1492  $this->saveMaterial();
1493  }
1494 
1495  function _resolveInternalLink($internal_link)
1496  {
1497  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
1498  {
1499  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1500  include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1501  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1502  switch ($matches[2])
1503  {
1504  case "lm":
1505  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1506  break;
1507  case "pg":
1508  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1509  break;
1510  case "st":
1511  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1512  break;
1513  case "git":
1514  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1515  break;
1516  case "mob":
1517  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1518  break;
1519  }
1520  if (strcmp($resolved_link, "") == 0)
1521  {
1522  $resolved_link = $internal_link;
1523  }
1524  }
1525  else
1526  {
1527  $resolved_link = $internal_link;
1528  }
1529  return $resolved_link;
1530  }
1531 
1532  function _resolveIntLinks($question_id)
1533  {
1534  global $ilDB;
1535  $resolvedlinks = 0;
1536  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1537  array('integer'),
1538  array($question_id)
1539  );
1540  if ($result->numRows())
1541  {
1542  while ($row = $ilDB->fetchAssoc($result))
1543  {
1544  $internal_link = $row["internal_link"];
1545  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1546  $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
1547  if (strcmp($internal_link, $resolved_link) != 0)
1548  {
1549  // internal link was resolved successfully
1550  $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1551  array('text', 'integer', 'integer'),
1552  array($resolved_link, time(), $row["material_id"])
1553  );
1554  $resolvedlinks++;
1555  }
1556  }
1557  }
1558  if ($resolvedlinks)
1559  {
1560  // there are resolved links -> reenter theses links to the database
1561 
1562  // delete all internal links from the database
1563  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1564  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1565 
1566  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1567  array('integer'),
1568  array($question_id)
1569  );
1570  if ($result->numRows())
1571  {
1572  while ($row = $ilDB->fetchAssoc($result))
1573  {
1574  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
1575  {
1576  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1577  }
1578  }
1579  }
1580  }
1581  }
1582 
1583  function _getInternalLinkHref($target = "")
1584  {
1585  global $ilDB;
1586  $linktypes = array(
1587  "lm" => "LearningModule",
1588  "pg" => "PageObject",
1589  "st" => "StructureObject",
1590  "git" => "GlossaryItem",
1591  "mob" => "MediaObject"
1592  );
1593  $href = "";
1594  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
1595  {
1596  $type = $matches[1];
1597  $target_id = $matches[2];
1598  include_once "./Services/Utilities/classes/class.ilUtil.php";
1599  switch($linktypes[$matches[1]])
1600  {
1601  case "LearningModule":
1602  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1603  break;
1604  case "PageObject":
1605  case "StructureObject":
1606  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1607  break;
1608  case "GlossaryItem":
1609  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1610  break;
1611  case "MediaObject":
1612  $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;
1613  break;
1614  }
1615  }
1616  return $href;
1617  }
1618 
1627  function _isWriteable($question_id, $user_id)
1628  {
1629  global $ilDB;
1630 
1631  if (($question_id < 1) || ($user_id < 1))
1632  {
1633  return false;
1634  }
1635 
1636  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1637  array('integer'),
1638  array($question_id)
1639  );
1640  if ($result->numRows() == 1)
1641  {
1642  $row = $ilDB->fetchAssoc($result);
1643  $qpl_object_id = $row["obj_fi"];
1644  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1645  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1646  }
1647  else
1648  {
1649  return false;
1650  }
1651  }
1652 
1660  {
1661  global $ilDB;
1662  $result = $ilDB->queryF("SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1663  array('text'),
1664  array($this->getQuestionType())
1665  );
1666  if ($result->numRows() == 1)
1667  {
1668  $row = $ilDB->fetchAssoc($result);
1669  return $row["questiontype_id"];
1670  }
1671  else
1672  {
1673  return 0;
1674  }
1675  }
1676 
1683  function getQuestionType()
1684  {
1685  return "";
1686  }
1687 
1695  static function _includeClass($question_type, $gui = 0)
1696  {
1697  $type = $question_type;
1698  if ($gui) $type .= "GUI";
1699  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type.".php"))
1700  {
1701  include_once "./Modules/SurveyQuestionPool/classes/class.".$type.".php";
1702  return true;
1703  }
1704  else
1705  {
1706  global $ilPluginAdmin;
1707  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1708  foreach ($pl_names as $pl_name)
1709  {
1710  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1711  if (strcmp($pl->getQuestionType(), $question_type) == 0)
1712  {
1713  $pl->includeClass("class.".$type.".php");
1714  return true;
1715  }
1716  }
1717  }
1718  return false;
1719  }
1720 
1727  static function _getQuestionTypeName($type_tag)
1728  {
1729  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type_tag.".php"))
1730  {
1731  global $lng;
1732  return $lng->txt($type_tag);
1733  }
1734  else
1735  {
1736  global $ilPluginAdmin;
1737  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1738  foreach ($pl_names as $pl_name)
1739  {
1740  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1741  if (strcmp($pl->getQuestionType(), $type_tag) == 0)
1742  {
1743  return $pl->getQuestionTypeTranslation();
1744  }
1745  }
1746  }
1747  return "";
1748  }
1749 
1750 
1758  function &_instanciateQuestion($question_id)
1759  {
1760  $question_type = SurveyQuestion::_getQuestionType($question_id);
1761  SurveyQuestion::_includeClass($question_type);
1762  $question = new $question_type();
1763  $question->loadFromDb($question_id);
1764  return $question;
1765  }
1766 
1774  function &_instanciateQuestionGUI($question_id)
1775  {
1776  $question_type = SurveyQuestion::_getQuestionType($question_id);
1777  SurveyQuestion::_includeClass($question_type, 1);
1778  $guitype = $question_type . "GUI";
1779  $question = new $guitype($question_id);
1780  return $question;
1781  }
1782 
1791  function isHTML($a_text)
1792  {
1793  if (preg_match("/<[^>]*?>/", $a_text))
1794  {
1795  return TRUE;
1796  }
1797  else
1798  {
1799  return FALSE;
1800  }
1801  }
1802 
1810  function QTIMaterialToString($a_material)
1811  {
1812  $result = "";
1813  for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
1814  {
1815  $material = $a_material->getMaterial($i);
1816  if (strcmp($material["type"], "mattext") == 0)
1817  {
1818  $result .= $material["material"]->getContent();
1819  }
1820  if (strcmp($material["type"], "matimage") == 0)
1821  {
1822  $matimage = $material["material"];
1823  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
1824  {
1825  // import an mediaobject which was inserted using tiny mce
1826  if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
1827  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1828  }
1829  }
1830  }
1831  return $result;
1832  }
1833 
1842  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $a_attrs = null)
1843  {
1844  include_once "./Services/RTE/classes/class.ilRTE.php";
1845  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1846 
1847  $a_xml_writer->xmlStartTag("material");
1848  $attrs = array(
1849  "type" => "text/plain"
1850  );
1851  if ($this->isHTML($a_material))
1852  {
1853  $attrs["type"] = "text/xhtml";
1854  }
1855  if (is_array($a_attrs))
1856  {
1857  $attrs = array_merge($attrs, $a_attrs);
1858  }
1859  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1860 
1861  if ($add_mobs)
1862  {
1863  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1864  foreach ($mobs as $mob)
1865  {
1866  $mob_obj =& new ilObjMediaObject($mob);
1867  $imgattrs = array(
1868  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1869  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
1870  );
1871  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
1872  }
1873  }
1874  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
1875  }
1876 
1883  function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
1884  {
1885  include_once "./Services/Utilities/classes/class.ilUtil.php";
1886  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1887  }
1888 
1897  {
1898  return array();
1899  }
1900 
1901 
1908  function addUserSpecificResultsExportTitles(&$a_array, $a_export_label = "")
1909  {
1910  switch($a_export_label)
1911  {
1912  case "label_only":
1913  array_push($a_array, $this->label ? $this->label : $this->title);
1914  break;
1915 
1916  case "title_only":
1917  array_push($a_array, $this->title);
1918  break;
1919 
1920  default:
1921  array_push($a_array, $this->label ? $this->title.' - '.$this->label : $this->title);
1922  break;
1923  }
1924  }
1925 
1933  function addUserSpecificResultsData(&$a_array, &$resultset)
1934  {
1935  // overwrite in inherited classes
1936  }
1937 
1946  {
1947  // overwrite in inherited classes
1948  return array();
1949  }
1950 
1957  function &getWorkingDataFromUserInput($post_data)
1958  {
1959  // overwrite in inherited classes
1960  $data = array();
1961  return $data;
1962  }
1963 
1972  function importAdditionalMetadata($a_meta)
1973  {
1974  // overwrite in inherited classes
1975  }
1976 
1983  function importResponses($a_data)
1984  {
1985  // overwrite in inherited classes
1986  }
1987 
1994  function importAdjectives($a_data)
1995  {
1996  // overwrite in inherited classes
1997  }
1998 
2005  function importMatrix($a_data)
2006  {
2007  // overwrite in inherited classes
2008  }
2009 
2021  function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
2022  {
2023  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
2024  $column = 0;
2025  switch ($export_label)
2026  {
2027  case 'label_only':
2028  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2029  break;
2030  case 'title_only':
2031  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2032  break;
2033  default:
2034  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2035  $column++;
2036  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2037  break;
2038  }
2039  $column++;
2040  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getQuestiontext()));
2041  $column++;
2042  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->lng->txt($eval_data["QUESTION_TYPE"])));
2043  $column++;
2044  $worksheet->write($row, $column, $eval_data["USERS_ANSWERED"]);
2045  $column++;
2046  $worksheet->write($row, $column, $eval_data["USERS_SKIPPED"]);
2047  $column++;
2048  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
2049  $column++;
2050  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE"]));
2051  $column++;
2052  $worksheet->write($row, $column, $eval_data["MODE_NR_OF_SELECTIONS"]);
2053  $column++;
2054  $worksheet->write($row, $column, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
2055  $column++;
2056  $worksheet->write($row, $column, $eval_data["ARITHMETIC_MEAN"]);
2057  return $row + 1;
2058  }
2059 
2071  function &setExportCumulatedCVS(&$eval_data, $export_label)
2072  {
2073  $csvrow = array();
2074  switch ($export_label)
2075  {
2076  case 'label_only':
2077  array_push($csvrow, $this->label);
2078  break;
2079  case 'title_only':
2080  array_push($csvrow, $this->getTitle());
2081  break;
2082  default:
2083  array_push($csvrow, $this->getTitle());
2084  array_push($csvrow, $this->label);
2085  break;
2086  }
2087  array_push($csvrow, $this->getQuestiontext());
2088  array_push($csvrow, $this->lng->txt($eval_data["QUESTION_TYPE"]));
2089  array_push($csvrow, $eval_data["USERS_ANSWERED"]);
2090  array_push($csvrow, $eval_data["USERS_SKIPPED"]);
2091  array_push($csvrow, $eval_data["MODE"]);
2092  array_push($csvrow, $eval_data["MODE_NR_OF_SELECTIONS"]);
2093  array_push($csvrow, $eval_data["MEDIAN"]);
2094  array_push($csvrow, $eval_data["ARITHMETIC_MEAN"]);
2095  $result = array();
2096  array_push($result, $csvrow);
2097  return $result;
2098  }
2099 
2109  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
2110  {
2111  // overwrite in inherited classes
2112  }
2113 
2121  {
2122  // overwrite in inherited classes
2123  return FALSE;
2124  }
2125 
2133  {
2134  // overwrite in inherited classes
2135  return array();
2136  }
2137 
2143  public function getPreconditionOptions()
2144  {
2145  // overwrite in inherited classes
2146  }
2147 
2156  {
2157  // overwrite in inherited classes
2158  return $value;
2159  }
2160 
2167  public function getPreconditionSelectValue($default = "", $title, $variable)
2168  {
2169  // overwrite in inherited classes
2170  return null;
2171  }
2172 
2181  function outChart($survey_id, $type = "")
2182  {
2183  // overwrite in inherited classes
2184  }
2185 
2186  function setOriginalId($original_id)
2187  {
2188  $this->original_id = $original_id;
2189  }
2190 
2191  function getOriginalId()
2192  {
2193  return $this->original_id;
2194  }
2195 
2201  public function saveRandomData($active_id)
2202  {
2203  // do nothing, overwrite in parent classes
2204  }
2205 
2206  public function getMaterial()
2207  {
2208  return $this->material;
2209  }
2210 
2211  public function setSubtype($a_subtype)
2212  {
2213  // do nothing
2214  }
2215 
2216  public function getSubtype()
2217  {
2218  // do nothing
2219  return null;
2220  }
2221 
2223  {
2224  if (count($this->cumulated) == 0)
2225  {
2226  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
2228  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
2229  }
2230  return $this->cumulated;
2231  }
2232 
2238  public function getCumulatedResultData($survey_id, $counter)
2239  {
2241  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->getQuestiontext());
2242  $maxlen = 37;
2243  include_once "./Services/Utilities/classes/class.ilStr.php";
2244  if (ilStr::strlen($questiontext) > $maxlen + 3)
2245  {
2246  $questiontext = ilStr::substr($questiontext, 0, $maxlen) . "...";
2247  }
2248  $result = array(
2249  'counter' => $counter,
2250  'title' => $this->getTitle(),
2251  'question' => $questiontext,
2252  'users_answered' => $cumulated['USERS_ANSWERED'],
2253  'users_skipped' => $cumulated['USERS_SKIPPED'],
2254  'question_type' => $this->lng->txt($cumulated["QUESTION_TYPE"]),
2255  'mode' => $cumulated["MODE"],
2256  'mode_nr_of_selections' => $cumulated["MODE_NR_OF_SELECTIONS"],
2257  'median' => $cumulated["MEDIAN"],
2258  'arithmetic_mean' => $cumulated["ARITHMETIC_MEAN"]
2259  );
2260  return $result;
2261  }
2262 
2266  public function __get($value)
2267  {
2268  switch ($value)
2269  {
2270  default:
2271  if (array_key_exists($value, $this->arrData))
2272  {
2273  return $this->arrData[$value];
2274  }
2275  else
2276  {
2277  return null;
2278  }
2279  break;
2280  }
2281  }
2282 
2286  public function __set($key, $value)
2287  {
2288  switch ($key)
2289  {
2290  default:
2291  $this->arrData[$key] = $value;
2292  break;
2293  }
2294  }
2295 }
2296 ?>