ILIAS  release_4-3 Revision
 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(), false);
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("integer", 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 
836  // #12420
837  $set = $ilDB->query("SELECT survey_id FROM svy_svy".
838  " WHERE obj_fi = ".$ilDB->quote($this->getObjId(), "integer"));
839  $survey_fi = $ilDB->fetchAssoc($set);
840  $survey_fi = $survey_fi["survey_id"];
841 
842  // pool?
843  if($survey_fi)
844  {
845  $set = $ilDB->query("SELECT obligatory FROM svy_qst_oblig".
846  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
847  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
848  $has_obligatory_states_entry = (bool)$ilDB->numRows($set);
849  $is_obligatory = $ilDB->fetchAssoc($set);
850  $is_obligatory = (bool)$is_obligatory["obligatory"];
851 
852  if(!$this->getObligatory())
853  {
854  if($has_obligatory_states_entry)
855  {
856  $ilDB->manipulate("DELETE FROM svy_qst_oblig".
857  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
858  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
859  }
860  }
861  else if($this->getObligatory())
862  {
863  if(!$has_obligatory_states_entry)
864  {
865  // ilObjSurvey::setObligatoryStates()
866  $next_id = $ilDB->nextId('svy_qst_oblig');
867  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " .
868  "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
869  array('integer','integer','integer','text','integer'),
870  array($next_id, $survey_fi, $this->getId(), 1, time())
871  );
872  }
873  else if(!$is_obligatory)
874  {
875  $ilDB->manipulate("UPDATE svy_qst_oblig".
876  " SET obligatory = ".$ilDB->quote(1, "integer").
877  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
878  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
879  }
880  }
881  }
882 
883  return $affectedRows;
884  }
885 
889  public function saveMaterial()
890  {
891  global $ilDB;
892 
893  include_once "./Services/COPage/classes/class.ilInternalLink.php";
894  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
895  array('integer'),
896  array($this->getId())
897  );
899 
900  foreach ($this->material as $material)
901  {
902  $next_id = $ilDB->nextId('svy_material');
903  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material " .
904  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
905  "text_material, external_link, file_material, material_type) ".
906  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
907  array('integer','integer','text','text','text','integer','text','text','text','integer'),
908  array(
909  $next_id, $this->getId(), $material->internal_link, $material->import_id,
910  $material->title, time(), $material->text_material, $material->external_link,
911  $material->file_material, $material->type)
912  );
913  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches))
914  {
915  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
916  }
917  }
918  }
919 
926  public function createNewQuestion()
927  {
928  global $ilDB, $ilUser;
929 
930  $obj_id = ($this->getObjId() <= 0) ? (ilObject::_lookupObjId((strlen($_GET["ref_id"])) ? $_GET["ref_id"] : $_POST["sel_qpl"])) : $this->getObjId();
931  if ($obj_id > 0)
932  {
933  $next_id = $ilDB->nextId('svy_question');
934  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_question (question_id, questiontype_fi, " .
935  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
936  "created, original_id, tstamp) VALUES " .
937  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
938  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
939  'text', 'text', 'integer', 'integer', 'integer'),
940  array(
941  $next_id,
942  $this->getQuestionTypeID(),
943  $obj_id,
944  $this->getOwner(),
945  NULL,
946  NULL,
947  $this->getAuthor(),
948  NULL,
949  "1",
950  "0",
951  time(),
952  NULL,
953  0
954  )
955  );
956  $this->setId($next_id);
957  }
958  return $this->getId();
959  }
960 
967  function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
968  {
969  }
970 
977  function getImagePath()
978  {
979  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
980  }
981 
988  function getMaterialsPath()
989  {
990  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
991  }
992 
999  function getImagePathWeb()
1000  {
1001  include_once "./Services/Utilities/classes/class.ilUtil.php";
1002  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
1004  }
1005 
1013  {
1014  include_once "./Services/Utilities/classes/class.ilUtil.php";
1015  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
1017  }
1018 
1027  function saveCategoryToDb($categorytext, $neutral = 0)
1028  {
1029  global $ilUser, $ilDB;
1030 
1031  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
1032  array('text','text','integer'),
1033  array($categorytext, $neutral, $ilUser->getId())
1034  );
1035  $insert = FALSE;
1036  $returnvalue = "";
1037  if ($result->numRows())
1038  {
1039  $insert = TRUE;
1040  while ($row = $ilDB->fetchAssoc($result))
1041  {
1042  if (strcmp($row["title"], $categorytext) == 0)
1043  {
1044  $returnvalue = $row["category_id"];
1045  $insert = FALSE;
1046  }
1047  }
1048  }
1049  else
1050  {
1051  $insert = TRUE;
1052  }
1053  if ($insert)
1054  {
1055  $next_id = $ilDB->nextId('svy_category');
1056  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
1057  array('integer','text','text','integer','integer'),
1058  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
1059  );
1060  $returnvalue = $next_id;
1061  }
1062  return $returnvalue;
1063  }
1064 
1071  function deleteAdditionalTableData($question_id)
1072  {
1073  global $ilDB;
1074  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1075  array('integer'),
1076  array($question_id)
1077  );
1078  }
1079 
1086  function delete($question_id)
1087  {
1088  global $ilDB;
1089 
1090  if ($question_id < 1) return;
1091 
1092  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1093  array('integer'),
1094  array($question_id)
1095  );
1096  if ($result->numRows() == 1)
1097  {
1098  $row = $ilDB->fetchAssoc($result);
1099  $obj_id = $row["obj_fi"];
1100  }
1101  else
1102  {
1103  return;
1104  }
1105 
1106  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_answer WHERE question_fi = %s",
1107  array('integer'),
1108  array($question_id)
1109  );
1110 
1111  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE question_fi = %s",
1112  array('integer'),
1113  array($question_id)
1114  );
1115 
1116  $result = $ilDB->queryF("SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1117  array('integer'),
1118  array($question_id)
1119  );
1120  while ($row = $ilDB->fetchObject($result))
1121  {
1122  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE constraint_id = %s",
1123  array('integer'),
1124  array($row->constraint_fi)
1125  );
1126  }
1127 
1128  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1129  array('integer'),
1130  array($question_id)
1131  );
1132 
1133  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1134  array('integer'),
1135  array($question_id)
1136  );
1137  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_oblig WHERE question_fi = %s",
1138  array('integer'),
1139  array($question_id)
1140  );
1141  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_svy_qst WHERE question_fi = %s",
1142  array('integer'),
1143  array($question_id)
1144  );
1145  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
1146  array('integer'),
1147  array($question_id)
1148  );
1149  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_question WHERE question_id = %s",
1150  array('integer'),
1151  array($question_id)
1152  );
1153 
1154  $this->deleteAdditionalTableData($question_id);
1155 
1156  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1157  array('integer'),
1158  array($question_id)
1159  );
1160  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1161  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1162 
1163  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1164  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
1165  {
1166  include_once "./Services/Utilities/classes/class.ilUtil.php";
1167  ilUtil::delDir($directory);
1168  }
1169 
1170  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1171  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1172  // remaining usages are not in text anymore -> delete them
1173  // and media objects (note: delete method of ilObjMediaObject
1174  // checks whether object is used in another context; if yes,
1175  // the object is not deleted!)
1176  foreach($mobs as $mob)
1177  {
1178  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1179  $mob_obj =& new ilObjMediaObject($mob);
1180  $mob_obj->delete();
1181  }
1182 
1183  // #12772 - untie question copies from pool question
1184  $ilDB->manipulate("UPDATE svy_question".
1185  " SET original_id = NULL".
1186  " WHERE original_id = ".$ilDB->quote($question_id, "integer"));
1187  }
1188 
1196  function _getQuestionType($question_id)
1197  {
1198  global $ilDB;
1199 
1200  if ($question_id < 1) return "";
1201 
1202  $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",
1203  array('integer'),
1204  array($question_id)
1205  );
1206  if ($result->numRows() == 1)
1207  {
1208  $data = $ilDB->fetchAssoc($result);
1209  return $data["type_tag"];
1210  }
1211  else
1212  {
1213  return "";
1214  }
1215  }
1216 
1224  function _getTitle($question_id)
1225  {
1226  global $ilDB;
1227 
1228  if ($question_id < 1) return "";
1229 
1230  $result = $ilDB->queryF("SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1231  array('integer'),
1232  array($question_id)
1233  );
1234  if ($result->numRows() == 1)
1235  {
1236  $data = $ilDB->fetchAssoc($result);
1237  return $data["title"];
1238  }
1239  else
1240  {
1241  return "";
1242  }
1243  }
1244 
1252  function _getOriginalId($question_id, $a_return_question_id_if_no_original = true)
1253  {
1254  global $ilDB;
1255  $result = $ilDB->queryF("SELECT * FROM svy_question WHERE question_id = %s",
1256  array('integer'),
1257  array($question_id)
1258  );
1259  if ($result->numRows() > 0)
1260  {
1261  $row = $ilDB->fetchAssoc($result);
1262  if ($row["original_id"] > 0)
1263  {
1264  return $row["original_id"];
1265  }
1266  else if((bool)$a_return_question_id_if_no_original) // #12419
1267  {
1268  return $row["question_id"];
1269  }
1270  }
1271  else
1272  {
1273  return "";
1274  }
1275  }
1276 
1277  function syncWithOriginal()
1278  {
1279  global $ilDB;
1280 
1281  if ($this->getOriginalId())
1282  {
1283  $id = $this->getId();
1284  $original = $this->getOriginalId();
1285 
1286  $this->setId($this->getOriginalId());
1287  $this->setOriginalId(NULL);
1288  $this->saveToDb();
1289 
1290  $this->setId($id);
1291  $this->setOriginalId($original);
1292 
1293  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1294  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1295  array('integer'),
1296  array($this->getOriginalId())
1297  );
1298  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1299  if (strlen($this->material["internal_link"]))
1300  {
1301  $next_id = $ilDB->nextId('svy_material');
1302  $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)",
1303  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1304  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1305  );
1306  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
1307  {
1308  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1309  }
1310  }
1311  }
1312  }
1313 
1320  function getPhrase($phrase_id)
1321  {
1322  global $ilDB;
1323 
1324  $result = $ilDB->queryF("SELECT title FROM svy_phrase WHERE phrase_id = %s",
1325  array('integer'),
1326  array($phrase_id)
1327  );
1328  if ($row = $ilDB->fetchAssoc($result))
1329  {
1330  return $row["title"];
1331  }
1332  return "";
1333  }
1334 
1343  {
1344  global $ilUser, $ilDB;
1345 
1346  $result = $ilDB->queryF("SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1347  array('text', 'integer'),
1348  array($title, $ilUser->getId())
1349  );
1350  return ($result->numRows() == 0) ? false : true;
1351  }
1352 
1360  function _questionExists($question_id)
1361  {
1362  global $ilDB;
1363 
1364  if ($question_id < 1)
1365  {
1366  return false;
1367  }
1368 
1369  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE question_id = %s",
1370  array('integer'),
1371  array($question_id)
1372  );
1373  return ($result->numRows() == 1) ? true : false;
1374  }
1375 
1376  function addInternalLink($material_id, $title = "")
1377  {
1378  if (strlen($material_id))
1379  {
1380  if (strcmp($material_title, "") == 0)
1381  {
1382  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1383  {
1384  $type = $matches[1];
1385  $target_id = $matches[2];
1386  $material_title = $this->lng->txt("obj_$type") . ": ";
1387  switch ($type)
1388  {
1389  case "lm":
1390  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1391  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1392  $cont_obj = $cont_obj_gui->object;
1393  $material_title .= $cont_obj->getTitle();
1394  break;
1395  case "pg":
1396  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1397  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1399  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1400  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1401  $cont_obj = $cont_obj_gui->object;
1402  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1403  $material_title .= $pg_obj->getTitle();
1404  break;
1405  case "st":
1406  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1407  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1409  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1410  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1411  $cont_obj = $cont_obj_gui->object;
1412  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1413  $material_title .= $st_obj->getTitle();
1414  break;
1415  case "git":
1416  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1417  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1418  break;
1419  case "mob":
1420  break;
1421  }
1422  }
1423  }
1424  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1425  $mat = new ilSurveyMaterial();
1426  $mat->type = 0;
1427  $mat->internal_link = $material_id;
1428  $mat->title = $material_title;
1429  $this->addMaterial($mat);
1430  $this->saveMaterial();
1431  }
1432  }
1433 
1439  public function deleteMaterials($a_array)
1440  {
1441  foreach ($a_array as $idx)
1442  {
1443  unset($this->material[$idx]);
1444  }
1445  $this->material = array_values($this->material);
1446  $this->saveMaterial();
1447  }
1448 
1455  function duplicateMaterials($question_id)
1456  {
1457  foreach ($this->materials as $filename)
1458  {
1459  $materialspath = $this->getMaterialsPath();
1460  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1461  if (!file_exists($materialspath))
1462  {
1463  include_once "./Services/Utilities/classes/class.ilUtil.php";
1464  ilUtil::makeDirParents($materialspath);
1465  }
1466  if (!copy($materialspath_original . $filename, $materialspath . $filename))
1467  {
1468  print "material could not be duplicated!!!! ";
1469  }
1470  }
1471  }
1472 
1473  public function addMaterial($obj_material)
1474  {
1475  array_push($this->material, $obj_material);
1476  }
1477 
1485  function setMaterial($material_id = "", $is_import = false, $material_title = "")
1486  {
1487  if (strcmp($material_id, "") != 0)
1488  {
1489  $import_id = "";
1490  if ($is_import)
1491  {
1492  $import_id = $material_id;
1493  $material_id = $this->_resolveInternalLink($import_id);
1494  }
1495  if (strcmp($material_title, "") == 0)
1496  {
1497  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1498  {
1499  $type = $matches[1];
1500  $target_id = $matches[2];
1501  $material_title = $this->lng->txt("obj_$type") . ": ";
1502  switch ($type)
1503  {
1504  case "lm":
1505  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1506  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1507  $cont_obj = $cont_obj_gui->object;
1508  $material_title .= $cont_obj->getTitle();
1509  break;
1510  case "pg":
1511  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1512  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1514  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1515  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1516  $cont_obj = $cont_obj_gui->object;
1517  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1518  $material_title .= $pg_obj->getTitle();
1519  break;
1520  case "st":
1521  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1522  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1524  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1525  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1526  $cont_obj = $cont_obj_gui->object;
1527  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1528  $material_title .= $st_obj->getTitle();
1529  break;
1530  case "git":
1531  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1532  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1533  break;
1534  case "mob":
1535  break;
1536  }
1537  }
1538  }
1539  $this->material = array(
1540  "internal_link" => $material_id,
1541  "import_id" => $import_id,
1542  "title" => $material_title
1543  );
1544  }
1545  $this->saveMaterial();
1546  }
1547 
1548  function _resolveInternalLink($internal_link)
1549  {
1550  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
1551  {
1552  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1553  include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1554  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1555  switch ($matches[2])
1556  {
1557  case "lm":
1558  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1559  break;
1560  case "pg":
1561  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1562  break;
1563  case "st":
1564  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1565  break;
1566  case "git":
1567  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1568  break;
1569  case "mob":
1570  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1571  break;
1572  }
1573  if (strcmp($resolved_link, "") == 0)
1574  {
1575  $resolved_link = $internal_link;
1576  }
1577  }
1578  else
1579  {
1580  $resolved_link = $internal_link;
1581  }
1582  return $resolved_link;
1583  }
1584 
1585  function _resolveIntLinks($question_id)
1586  {
1587  global $ilDB;
1588  $resolvedlinks = 0;
1589  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1590  array('integer'),
1591  array($question_id)
1592  );
1593  if ($result->numRows())
1594  {
1595  while ($row = $ilDB->fetchAssoc($result))
1596  {
1597  $internal_link = $row["internal_link"];
1598  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1599  $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
1600  if (strcmp($internal_link, $resolved_link) != 0)
1601  {
1602  // internal link was resolved successfully
1603  $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1604  array('text', 'integer', 'integer'),
1605  array($resolved_link, time(), $row["material_id"])
1606  );
1607  $resolvedlinks++;
1608  }
1609  }
1610  }
1611  if ($resolvedlinks)
1612  {
1613  // there are resolved links -> reenter theses links to the database
1614 
1615  // delete all internal links from the database
1616  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1617  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1618 
1619  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1620  array('integer'),
1621  array($question_id)
1622  );
1623  if ($result->numRows())
1624  {
1625  while ($row = $ilDB->fetchAssoc($result))
1626  {
1627  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
1628  {
1629  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1630  }
1631  }
1632  }
1633  }
1634  }
1635 
1636  function _getInternalLinkHref($target = "")
1637  {
1638  global $ilDB;
1639  $linktypes = array(
1640  "lm" => "LearningModule",
1641  "pg" => "PageObject",
1642  "st" => "StructureObject",
1643  "git" => "GlossaryItem",
1644  "mob" => "MediaObject"
1645  );
1646  $href = "";
1647  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
1648  {
1649  $type = $matches[1];
1650  $target_id = $matches[2];
1651  include_once "./Services/Utilities/classes/class.ilUtil.php";
1652  switch($linktypes[$matches[1]])
1653  {
1654  case "LearningModule":
1655  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1656  break;
1657  case "PageObject":
1658  case "StructureObject":
1659  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1660  break;
1661  case "GlossaryItem":
1662  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1663  break;
1664  case "MediaObject":
1665  $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;
1666  break;
1667  }
1668  }
1669  return $href;
1670  }
1671 
1680  function _isWriteable($question_id, $user_id)
1681  {
1682  global $ilDB;
1683 
1684  if (($question_id < 1) || ($user_id < 1))
1685  {
1686  return false;
1687  }
1688 
1689  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1690  array('integer'),
1691  array($question_id)
1692  );
1693  if ($result->numRows() == 1)
1694  {
1695  $row = $ilDB->fetchAssoc($result);
1696  $qpl_object_id = $row["obj_fi"];
1697  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1698  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1699  }
1700  else
1701  {
1702  return false;
1703  }
1704  }
1705 
1713  {
1714  global $ilDB;
1715  $result = $ilDB->queryF("SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1716  array('text'),
1717  array($this->getQuestionType())
1718  );
1719  if ($result->numRows() == 1)
1720  {
1721  $row = $ilDB->fetchAssoc($result);
1722  return $row["questiontype_id"];
1723  }
1724  else
1725  {
1726  return 0;
1727  }
1728  }
1729 
1736  function getQuestionType()
1737  {
1738  return "";
1739  }
1740 
1748  static function _includeClass($question_type, $gui = 0)
1749  {
1750  $type = $question_type;
1751  if ($gui) $type .= "GUI";
1752  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type.".php"))
1753  {
1754  include_once "./Modules/SurveyQuestionPool/classes/class.".$type.".php";
1755  return true;
1756  }
1757  else
1758  {
1759  global $ilPluginAdmin;
1760  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1761  foreach ($pl_names as $pl_name)
1762  {
1763  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1764  if (strcmp($pl->getQuestionType(), $question_type) == 0)
1765  {
1766  $pl->includeClass("class.".$type.".php");
1767  return true;
1768  }
1769  }
1770  }
1771  return false;
1772  }
1773 
1780  static function _getQuestionTypeName($type_tag)
1781  {
1782  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type_tag.".php"))
1783  {
1784  global $lng;
1785  return $lng->txt($type_tag);
1786  }
1787  else
1788  {
1789  global $ilPluginAdmin;
1790  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1791  foreach ($pl_names as $pl_name)
1792  {
1793  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1794  if (strcmp($pl->getQuestionType(), $type_tag) == 0)
1795  {
1796  return $pl->getQuestionTypeTranslation();
1797  }
1798  }
1799  }
1800  return "";
1801  }
1802 
1803 
1811  function &_instanciateQuestion($question_id)
1812  {
1813  $question_type = SurveyQuestion::_getQuestionType($question_id);
1814  SurveyQuestion::_includeClass($question_type);
1815  $question = new $question_type();
1816  $question->loadFromDb($question_id);
1817  return $question;
1818  }
1819 
1827  function &_instanciateQuestionGUI($question_id)
1828  {
1829  $question_type = SurveyQuestion::_getQuestionType($question_id);
1830  SurveyQuestion::_includeClass($question_type, 1);
1831  $guitype = $question_type . "GUI";
1832  $question = new $guitype($question_id);
1833  return $question;
1834  }
1835 
1844  function isHTML($a_text)
1845  {
1846  if (preg_match("/<[^>]*?>/", $a_text))
1847  {
1848  return TRUE;
1849  }
1850  else
1851  {
1852  return FALSE;
1853  }
1854  }
1855 
1863  function QTIMaterialToString($a_material)
1864  {
1865  $result = "";
1866  for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
1867  {
1868  $material = $a_material->getMaterial($i);
1869  if (strcmp($material["type"], "mattext") == 0)
1870  {
1871  $result .= $material["material"]->getContent();
1872  }
1873  if (strcmp($material["type"], "matimage") == 0)
1874  {
1875  $matimage = $material["material"];
1876  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
1877  {
1878  // import an mediaobject which was inserted using tiny mce
1879  if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
1880  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1881  }
1882  }
1883  }
1884  return $result;
1885  }
1886 
1895  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $a_attrs = null)
1896  {
1897  include_once "./Services/RTE/classes/class.ilRTE.php";
1898  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1899 
1900  $a_xml_writer->xmlStartTag("material");
1901  $attrs = array(
1902  "type" => "text/plain"
1903  );
1904  if ($this->isHTML($a_material))
1905  {
1906  $attrs["type"] = "text/xhtml";
1907  }
1908  if (is_array($a_attrs))
1909  {
1910  $attrs = array_merge($attrs, $a_attrs);
1911  }
1912  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1913 
1914  if ($add_mobs)
1915  {
1916  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1917  foreach ($mobs as $mob)
1918  {
1919  $mob_obj =& new ilObjMediaObject($mob);
1920  $imgattrs = array(
1921  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1922  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
1923  );
1924  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
1925  }
1926  }
1927  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
1928  }
1929 
1936  function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
1937  {
1938  include_once "./Services/Utilities/classes/class.ilUtil.php";
1939  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1940  }
1941 
1950  {
1951  return array();
1952  }
1953 
1960  function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true)
1961  {
1962  if(!$a_use_label)
1963  {
1964  $title = $this->title;
1965  }
1966  else
1967  {
1968  if($a_substitute)
1969  {
1970  $title = $this->label ? $this->label : $this->title;
1971  }
1972  else
1973  {
1974  $title = $this->label;
1975  }
1976  }
1977 
1978  array_push($a_array, $title);
1979  return $title;
1980  }
1981 
1989  function addUserSpecificResultsData(&$a_array, &$resultset)
1990  {
1991  // overwrite in inherited classes
1992  }
1993 
2002  {
2003  // overwrite in inherited classes
2004  return array();
2005  }
2006 
2013  function &getWorkingDataFromUserInput($post_data)
2014  {
2015  // overwrite in inherited classes
2016  $data = array();
2017  return $data;
2018  }
2019 
2028  function importAdditionalMetadata($a_meta)
2029  {
2030  // overwrite in inherited classes
2031  }
2032 
2039  function importResponses($a_data)
2040  {
2041  // overwrite in inherited classes
2042  }
2043 
2050  function importAdjectives($a_data)
2051  {
2052  // overwrite in inherited classes
2053  }
2054 
2061  function importMatrix($a_data)
2062  {
2063  // overwrite in inherited classes
2064  }
2065 
2077  function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
2078  {
2079  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
2080  $column = 0;
2081  switch ($export_label)
2082  {
2083  case 'label_only':
2084  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2085  break;
2086  case 'title_only':
2087  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2088  break;
2089  default:
2090  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2091  $column++;
2092  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2093  break;
2094  }
2095  $column++;
2096  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text(strip_tags($this->getQuestiontext()))); // #12942
2097  $column++;
2098  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->lng->txt($eval_data["QUESTION_TYPE"])));
2099  $column++;
2100  $worksheet->write($row, $column, $eval_data["USERS_ANSWERED"]);
2101  $column++;
2102  $worksheet->write($row, $column, $eval_data["USERS_SKIPPED"]);
2103  $column++;
2104  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
2105  $column++;
2106  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE"]));
2107  $column++;
2108  $worksheet->write($row, $column, $eval_data["MODE_NR_OF_SELECTIONS"]);
2109  $column++;
2110  $worksheet->write($row, $column, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
2111  $column++;
2112  $worksheet->write($row, $column, $eval_data["ARITHMETIC_MEAN"]);
2113  return $row + 1;
2114  }
2115 
2127  function &setExportCumulatedCVS(&$eval_data, $export_label)
2128  {
2129  $csvrow = array();
2130  switch ($export_label)
2131  {
2132  case 'label_only':
2133  array_push($csvrow, $this->label);
2134  break;
2135  case 'title_only':
2136  array_push($csvrow, $this->getTitle());
2137  break;
2138  default:
2139  array_push($csvrow, $this->getTitle());
2140  array_push($csvrow, $this->label);
2141  break;
2142  }
2143  array_push($csvrow, strip_tags($this->getQuestiontext())); // #12942
2144  array_push($csvrow, $this->lng->txt($eval_data["QUESTION_TYPE"]));
2145  array_push($csvrow, $eval_data["USERS_ANSWERED"]);
2146  array_push($csvrow, $eval_data["USERS_SKIPPED"]);
2147  array_push($csvrow, $eval_data["MODE"]);
2148  array_push($csvrow, $eval_data["MODE_NR_OF_SELECTIONS"]);
2149  array_push($csvrow, $eval_data["MEDIAN"]);
2150  array_push($csvrow, $eval_data["ARITHMETIC_MEAN"]);
2151  $result = array();
2152  array_push($result, $csvrow);
2153  return $result;
2154  }
2155 
2165  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
2166  {
2167  // overwrite in inherited classes
2168  }
2169 
2177  {
2178  // overwrite in inherited classes
2179  return FALSE;
2180  }
2181 
2189  {
2190  // overwrite in inherited classes
2191  return array();
2192  }
2193 
2199  public function getPreconditionOptions()
2200  {
2201  // overwrite in inherited classes
2202  }
2203 
2212  {
2213  // overwrite in inherited classes
2214  return $value;
2215  }
2216 
2223  public function getPreconditionSelectValue($default = "", $title, $variable)
2224  {
2225  // overwrite in inherited classes
2226  return null;
2227  }
2228 
2237  function outChart($survey_id, $type = "")
2238  {
2239  // overwrite in inherited classes
2240  }
2241 
2242  function setOriginalId($original_id)
2243  {
2244  $this->original_id = $original_id;
2245  }
2246 
2247  function getOriginalId()
2248  {
2249  return $this->original_id;
2250  }
2251 
2257  public function saveRandomData($active_id)
2258  {
2259  // do nothing, overwrite in parent classes
2260  }
2261 
2262  public function getMaterial()
2263  {
2264  return $this->material;
2265  }
2266 
2267  public function setSubtype($a_subtype)
2268  {
2269  // do nothing
2270  }
2271 
2272  public function getSubtype()
2273  {
2274  // do nothing
2275  return null;
2276  }
2277 
2279  {
2280  if (count($this->cumulated) == 0)
2281  {
2282  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
2284  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
2285  }
2286  return $this->cumulated;
2287  }
2288 
2294  public function getCumulatedResultData($survey_id, $counter)
2295  {
2297  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->getQuestiontext());
2298 
2299  $maxlen = 75;
2300  include_once "./Services/Utilities/classes/class.ilStr.php";
2301  if (ilStr::strlen($questiontext) > $maxlen + 3)
2302  {
2303  $questiontext = ilStr::substr($questiontext, 0, $maxlen) . "...";
2304  }
2305 
2306  $result = array(
2307  'counter' => $counter,
2308  'title' => $this->getTitle(),
2309  'question' => $questiontext,
2310  'users_answered' => $cumulated['USERS_ANSWERED'],
2311  'users_skipped' => $cumulated['USERS_SKIPPED'],
2312  'question_type' => $this->lng->txt($cumulated["QUESTION_TYPE"]),
2313  'mode' => $cumulated["MODE"],
2314  'mode_nr_of_selections' => $cumulated["MODE_NR_OF_SELECTIONS"],
2315  'median' => $cumulated["MEDIAN"],
2316  'arithmetic_mean' => $cumulated["ARITHMETIC_MEAN"]
2317  );
2318  return $result;
2319  }
2320 
2324  public function __get($value)
2325  {
2326  switch ($value)
2327  {
2328  default:
2329  if (array_key_exists($value, $this->arrData))
2330  {
2331  return $this->arrData[$value];
2332  }
2333  else
2334  {
2335  return null;
2336  }
2337  break;
2338  }
2339  }
2340 
2344  public function __set($key, $value)
2345  {
2346  switch ($key)
2347  {
2348  default:
2349  $this->arrData[$key] = $value;
2350  break;
2351  }
2352  }
2353 
2361  public static function _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
2362  {
2363  global $ilDB;
2364 
2365  $ilDB->manipulate("UPDATE svy_question".
2366  " SET original_id = ".$ilDB->quote($a_original_id, "integer").",".
2367  " obj_fi = ".$ilDB->quote($a_object_id, "integer").
2368  " WHERE question_id = ".$ilDB->quote($a_question_id, "integer"));
2369  }
2370 
2371  public function getCopyIds($a_group_by_survey = false)
2372  {
2373  global $ilDB;
2374 
2375  $set = $ilDB->query("SELECT q.question_id,s.obj_fi".
2376  " FROM svy_question q".
2377  " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)".
2378  " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)".
2379  " WHERE original_id = ".$ilDB->quote($this->getId(), "integer"));
2380  $res = array();
2381  while($row = $ilDB->fetchAssoc($set))
2382  {
2383  if(!$a_group_by_survey)
2384  {
2385  $res[] = $row["question_id"];
2386  }
2387  else
2388  {
2389  $res[$row["obj_fi"]][] = $row["question_id"];
2390  }
2391  }
2392  return $res;
2393  }
2394 
2395  public function hasCopies()
2396  {
2397  return (bool)sizeof($this->getCopyIds());
2398  }
2399 }
2400 ?>