ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyQuestion.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
35 {
41  var $id;
42 
48  var $title;
61  var $owner;
62 
69  var $author;
70 
77 
84 
90  var $obj_id;
91 
98 
105 
111  var $ilias;
112 
118  var $tpl;
119 
125  var $lng;
126 
133 
136 
140  protected $cumulated;
141 
145  private $arrData;
146 
157  function SurveyQuestion
158  (
159  $title = "",
160  $description = "",
161  $author = "",
162  $questiontext = "",
163  $owner = -1
164  )
165  {
166  global $ilias;
167  global $lng;
168  global $tpl;
169 
170  $this->ilias =& $ilias;
171  $this->lng =& $lng;
172  $this->tpl =& $tpl;
173  $this->complete =
174  $this->title = $title;
175  $this->description = $description;
176  $this->questiontext = $questiontext;
177  $this->author = $author;
178  $this->cumulated = array();
179  if (!$this->author)
180  {
181  $this->author = $this->ilias->account->fullname;
182  }
183  $this->owner = $owner;
184  if ($this->owner == -1)
185  {
186  $this->owner = $this->ilias->account->id;
187  }
188  $this->id = -1;
189  $this->survey_id = -1;
190  $this->obligatory = 1;
191  $this->orientation = 0;
192  $this->materials = array();
193  $this->material = array();
194  $this->arrData = array();
195  register_shutdown_function(array(&$this, '_SurveyQuestion'));
196  }
197 
198  function _SurveyQuestion()
199  {
200  }
201 
208  function setComplete($a_complete)
209  {
210  $this->complete = ($a_complete) ? 1 : 0;
211  }
212 
219  function isComplete()
220  {
221  return 0;
222  }
223 
232  function questionTitleExists($title, $questionpool_object = "")
233  {
234  global $ilDB;
235 
236  $refwhere = "";
237  if (strcmp($questionpool_object, "") != 0)
238  {
239  $refwhere = sprintf(" AND obj_fi = %s",
240  $ilDB->quote($questionpool_object, 'integer')
241  );
242  }
243  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE title = %s$refwhere",
244  array('text'),
245  array($title)
246  );
247  return ($result->numRows() > 0) ? true : false;
248  }
249 
257  function setTitle($title = "")
258  {
259  $this->title = $title;
260  }
261 
269  function setObligatory($obligatory = 1)
270  {
271  $this->obligatory = ($obligatory) ? 1 : 0;
272  }
273 
282  {
283  $this->orientation = ($orientation) ? $orientation : 0;
284  }
285 
293  function setId($id = -1)
294  {
295  $this->id = $id;
296  }
297 
305  function setSurveyId($id = -1)
306  {
307  $this->survey_id = $id;
308  }
309 
317  function setDescription($description = "")
318  {
319  $this->description = $description;
320  }
321 
322 
331  function addMaterials($materials_file, $materials_name="")
332  {
333  if (empty($materials_name))
334  {
335  $materials_name = $materials_file;
336  }
337  if ((!empty($materials_name))&&(!array_key_exists($materials_name, $this->materials)))
338  {
339  $this->materials[$materials_name] = $materials_file;
340  }
341  }
342 
350  function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
351  {
352  if (!empty($materials_filename))
353  {
354  include_once "./Services/Utilities/classes/class.ilUtil.php";
355  $materialspath = $this->getMaterialsPath();
356  if (!file_exists($materialspath))
357  {
358  ilUtil::makeDirParents($materialspath);
359  }
360  //if (!move_uploaded_file($materials_tempfilename, $materialspath . $materials_filename))
361  if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
362  $materialspath.$materials_filename))
363  {
364  print "image not uploaded!!!! ";
365  }
366  else
367  {
368  $this->addMaterials($materials_filename, $materials_name);
369  }
370  }
371  }
372 
380  function deleteMaterial($materials_name = "")
381  {
382  foreach ($this->materials as $key => $value)
383  {
384  if (strcmp($key, $materials_name)==0)
385  {
386  if (file_exists($this->getMaterialsPath().$value))
387  {
388  unlink($this->getMaterialsPath().$value);
389  }
390  unset($this->materials[$key]);
391  }
392  }
393  }
394 
401  function flushMaterials()
402  {
403  $this->materials = array();
404  }
405 
413  function setAuthor($author = "")
414  {
415  if (!$author)
416  {
417  $author = $this->ilias->account->fullname;
418  }
419  $this->author = $author;
420  }
421 
430  {
431  $this->questiontext = $questiontext;
432  }
433 
441  function setOwner($owner = "")
442  {
443  $this->owner = $owner;
444  }
445 
453  function getTitle()
454  {
455  return $this->title;
456  }
457 
465  function getId()
466  {
467  return $this->id;
468  }
469 
476  public function getObligatory($survey_id = "")
477  {
478  if ($survey_id > 0)
479  {
480  global $ilDB;
481 
482  $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s AND question_fi = %s",
483  array('integer', 'integer'),
484  array($survey_id, $this->getId())
485  );
486  if ($result->numRows())
487  {
488  $row = $ilDB->fetchAssoc($result);
489  return ($row["obligatory"]) ? 1 : 0;
490  }
491  else
492  {
493  return ($this->obligatory) ? 1 : 0;
494  }
495  }
496  else
497  {
498  return ($this->obligatory) ? 1 : 0;
499  }
500  }
501 
509  function getSurveyId()
510  {
511  return $this->survey_id;
512  }
513 
521  function getOrientation()
522  {
523  switch ($this->orientation)
524  {
525  case 0:
526  case 1:
527  case 2:
528  break;
529  default:
530  $this->orientation = 0;
531  break;
532  }
533  return $this->orientation;
534  }
535 
536 
544  function getDescription()
545  {
546  return (strlen($this->description)) ? $this->description : NULL;
547  }
548 
556  function getAuthor()
557  {
558  return (strlen($this->author)) ? $this->author : NULL;
559  }
560 
568  function getOwner()
569  {
570  return $this->owner;
571  }
572 
580  function getQuestiontext()
581  {
582  return (strlen($this->questiontext)) ? $this->questiontext : NULL;
583  }
584 
592  function getObjId() {
593  return $this->obj_id;
594  }
595 
603  function setObjId($obj_id = 0)
604  {
605  $this->obj_id = $obj_id;
606  }
607 
613  function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
614  {
615  if ($this->getId() <= 0)
616  {
617  // The question has not been saved. It cannot be duplicated
618  return;
619  }
620  // duplicate the question in database
621  $clone = $this;
622  $original_id = $this->getId();
623  $clone->setId(-1);
624  if ($title)
625  {
626  $clone->setTitle($title);
627  }
628  if ($author)
629  {
630  $clone->setAuthor($author);
631  }
632  if ($owner)
633  {
634  $clone->setOwner($owner);
635  }
636  if ($for_survey)
637  {
638  $clone->saveToDb($original_id);
639  }
640  else
641  {
642  $clone->saveToDb();
643  }
644  // duplicate the materials
645  $clone->duplicateMaterials($original_id);
646  // copy XHTML media objects
647  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
648  return $clone->getId();
649  }
650 
656  function copyObject($target_questionpool, $title = "")
657  {
658  if ($this->getId() <= 0)
659  {
660  // The question has not been saved. It cannot be copied
661  return;
662  }
663  $clone = $this;
664  $original_id = SurveyQuestion::_getOriginalId($this->getId(), false);
665  $clone->setId(-1);
666  $source_questionpool = $this->getObjId();
667  $clone->setObjId($target_questionpool);
668  if ($title)
669  {
670  $clone->setTitle($title);
671  }
672 
673  $clone->saveToDb();
674 
675  // duplicate the materials
676  $clone->duplicateMaterials($original_id);
677  // copy XHTML media objects
678  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
679  return $clone->getId();
680  }
681 
689  {
690  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
691  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
692  foreach ($mobs as $mob)
693  {
694  ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
695  }
696  }
697 
704  function loadFromDb($question_id)
705  {
706  global $ilDB;
707 
708  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
709  array('integer'),
710  array($this->getId())
711  );
712  $this->material = array();
713  if ($result->numRows())
714  {
715  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
716  while ($row = $ilDB->fetchAssoc($result))
717  {
718  $mat = new ilSurveyMaterial();
719  $mat->type = $row['material_type'];
720  $mat->internal_link = $row['internal_link'];
721  $mat->title = $row['material_title'];
722  $mat->import_id = $row['import_id'];
723  $mat->text_material = $row['text_material'];
724  $mat->external_link = $row['external_link'];
725  $mat->file_material = $row['file_material'];
726  array_push($this->material, $mat);
727  }
728  }
729  }
730 
737  function _isComplete($question_id)
738  {
739  global $ilDB;
740 
741  $result = $ilDB->queryF("SELECT complete FROM svy_question WHERE question_id = %s",
742  array('integer'),
743  array($question_id)
744  );
745  if ($result->numRows())
746  {
747  $row = $ilDB->fetchAssoc($result);
748  if ($row["complete"] == 1)
749  {
750  return TRUE;
751  }
752  }
753  return FALSE;
754  }
755 
761  function saveCompletionStatus($original_id = "")
762  {
763  global $ilDB;
764 
765  $question_id = $this->getId();
766  if (strlen($original_id))
767  {
768  $question_id = $original_id;
769  }
770 
771  if ($this->getId() > 0)
772  {
773  // update existing dataset
774  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET complete = %s, tstamp = %s WHERE question_id = %s",
775  array('text', 'integer', 'integer'),
776  array($this->isComplete(), time(), $question_id)
777  );
778  }
779  }
780 
787  function saveToDb($original_id = "")
788  {
789  global $ilDB;
790 
791  // cleanup RTE images which are not inserted into the question text
792  include_once("./Services/RTE/classes/class.ilRTE.php");
793  ilRTE::_cleanupMediaObjectUsage($this->getQuestiontext(), "spl:html", $this->getId());
794  $affectedRows = 0;
795  if ($this->getId() == -1)
796  {
797  // Write new dataset
798  $next_id = $ilDB->nextId('svy_question');
799  $affectedRows = $ilDB->insert("svy_question", array(
800  "question_id" => array("integer", $next_id),
801  "questiontype_fi" => array("integer", $this->getQuestionTypeID()),
802  "obj_fi" => array("integer", $this->getObjId()),
803  "owner_fi" => array("integer", $this->getOwner()),
804  "title" => array("text", $this->getTitle()),
805  "label" => array("text", (strlen($this->label)) ? $this->label : null),
806  "description" => array("text", $this->getDescription()),
807  "author" => array("text", $this->getAuthor()),
808  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
809  "obligatory" => array("text", $this->getObligatory()),
810  "complete" => array("text", $this->isComplete()),
811  "created" => array("integer", time()),
812  "original_id" => array("integer", ($original_id) ? $original_id : NULL),
813  "tstamp" => array("integer", time())
814  ));
815  $this->setId($next_id);
816  }
817  else
818  {
819  // update existing dataset
820  $affectedRows = $ilDB->update("svy_question", array(
821  "title" => array("text", $this->getTitle()),
822  "label" => array("text", (strlen($this->label)) ? $this->label : null),
823  "description" => array("text", $this->getDescription()),
824  "author" => array("text", $this->getAuthor()),
825  "questiontext" => array("clob", ilRTE::_replaceMediaObjectImageSrc($this->getQuestiontext(), 0)),
826  "obligatory" => array("text", $this->getObligatory()),
827  "complete" => array("text", $this->isComplete()),
828  "tstamp" => array("integer", time())
829  ), array(
830  "question_id" => array("integer", $this->getId())
831  ));
832  }
833 
834  // #12420
835  $set = $ilDB->query("SELECT survey_id FROM svy_svy".
836  " WHERE obj_fi = ".$ilDB->quote($this->getObjId(), "integer"));
837  $survey_fi = $ilDB->fetchAssoc($set);
838  $survey_fi = $survey_fi["survey_id"];
839 
840  // pool?
841  if($survey_fi)
842  {
843  $set = $ilDB->query("SELECT obligatory FROM svy_qst_oblig".
844  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
845  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
846  $has_obligatory_states_entry = (bool)$ilDB->numRows($set);
847  $is_obligatory = $ilDB->fetchAssoc($set);
848  $is_obligatory = (bool)$is_obligatory["obligatory"];
849 
850  if(!$this->getObligatory())
851  {
852  if($has_obligatory_states_entry)
853  {
854  $ilDB->manipulate("DELETE FROM svy_qst_oblig".
855  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
856  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
857  }
858  }
859  else if($this->getObligatory())
860  {
861  if(!$has_obligatory_states_entry)
862  {
863  // ilObjSurvey::setObligatoryStates()
864  $next_id = $ilDB->nextId('svy_qst_oblig');
865  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " .
866  "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
867  array('integer','integer','integer','text','integer'),
868  array($next_id, $survey_fi, $this->getId(), 1, time())
869  );
870  }
871  else if(!$is_obligatory)
872  {
873  $ilDB->manipulate("UPDATE svy_qst_oblig".
874  " SET obligatory = ".$ilDB->quote(1, "integer").
875  " WHERE survey_fi = ".$ilDB->quote($survey_fi, "integer").
876  " AND question_fi = ".$ilDB->quote($this->getId(), "integer"));
877  }
878  }
879  }
880 
881  return $affectedRows;
882  }
883 
887  public function saveMaterial()
888  {
889  global $ilDB;
890 
891  include_once "./Services/COPage/classes/class.ilInternalLink.php";
892  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
893  array('integer'),
894  array($this->getId())
895  );
897 
898  foreach ($this->material as $material)
899  {
900  $next_id = $ilDB->nextId('svy_material');
901  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_material " .
902  "(material_id, question_fi, internal_link, import_id, material_title, tstamp," .
903  "text_material, external_link, file_material, material_type) ".
904  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
905  array('integer','integer','text','text','text','integer','text','text','text','integer'),
906  array(
907  $next_id, $this->getId(), $material->internal_link, $material->import_id,
908  $material->title, time(), $material->text_material, $material->external_link,
909  $material->file_material, $material->type)
910  );
911  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $material->internal_link, $matches))
912  {
913  ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
914  }
915  }
916  }
917 
924  public function createNewQuestion()
925  {
926  global $ilDB;
927 
928  $obj_id = $this->getObjId();
929  if ($obj_id > 0)
930  {
931  $next_id = $ilDB->nextId('svy_question');
932  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_question (question_id, questiontype_fi, " .
933  "obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, " .
934  "created, original_id, tstamp) VALUES " .
935  "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
936  array('integer', 'integer', 'integer', 'integer', 'text', 'text', 'text', 'text',
937  'text', 'text', 'integer', 'integer', 'integer'),
938  array(
939  $next_id,
940  $this->getQuestionTypeID(),
941  $obj_id,
942  $this->getOwner(),
943  NULL,
944  NULL,
945  $this->getAuthor(),
946  NULL,
947  "1",
948  "0",
949  time(),
950  NULL,
951  0
952  )
953  );
954  $this->setId($next_id);
955  }
956  return $this->getId();
957  }
958 
965  function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
966  {
967  }
968 
975  function getImagePath()
976  {
977  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
978  }
979 
986  function getMaterialsPath()
987  {
988  return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
989  }
990 
997  function getImagePathWeb()
998  {
999  include_once "./Services/Utilities/classes/class.ilUtil.php";
1000  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
1002  }
1003 
1011  {
1012  include_once "./Services/Utilities/classes/class.ilUtil.php";
1013  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
1015  }
1016 
1025  function saveCategoryToDb($categorytext, $neutral = 0)
1026  {
1027  global $ilUser, $ilDB;
1028 
1029  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
1030  array('text','text','integer'),
1031  array($categorytext, $neutral, $ilUser->getId())
1032  );
1033  $insert = FALSE;
1034  $returnvalue = "";
1035  if ($result->numRows())
1036  {
1037  $insert = TRUE;
1038  while ($row = $ilDB->fetchAssoc($result))
1039  {
1040  if (strcmp($row["title"], $categorytext) == 0)
1041  {
1042  $returnvalue = $row["category_id"];
1043  $insert = FALSE;
1044  }
1045  }
1046  }
1047  else
1048  {
1049  $insert = TRUE;
1050  }
1051  if ($insert)
1052  {
1053  $next_id = $ilDB->nextId('svy_category');
1054  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, neutral, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
1055  array('integer','text','text','integer','integer'),
1056  array($next_id, $categorytext, $neutral, $ilUser->getId(), time())
1057  );
1058  $returnvalue = $next_id;
1059  }
1060  return $returnvalue;
1061  }
1062 
1069  function deleteAdditionalTableData($question_id)
1070  {
1071  global $ilDB;
1072  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
1073  array('integer'),
1074  array($question_id)
1075  );
1076  }
1077 
1084  function delete($question_id)
1085  {
1086  global $ilDB;
1087 
1088  if ($question_id < 1) return;
1089 
1090  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1091  array('integer'),
1092  array($question_id)
1093  );
1094  if ($result->numRows() == 1)
1095  {
1096  $row = $ilDB->fetchAssoc($result);
1097  $obj_id = $row["obj_fi"];
1098  }
1099  else
1100  {
1101  return;
1102  }
1103 
1104  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_answer WHERE question_fi = %s",
1105  array('integer'),
1106  array($question_id)
1107  );
1108 
1109  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE question_fi = %s",
1110  array('integer'),
1111  array($question_id)
1112  );
1113 
1114  $result = $ilDB->queryF("SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s",
1115  array('integer'),
1116  array($question_id)
1117  );
1118  while ($row = $ilDB->fetchObject($result))
1119  {
1120  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_constraint WHERE constraint_id = %s",
1121  array('integer'),
1122  array($row->constraint_fi)
1123  );
1124  }
1125 
1126  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_constraint WHERE question_fi = %s",
1127  array('integer'),
1128  array($question_id)
1129  );
1130 
1131  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qblk_qst WHERE question_fi = %s",
1132  array('integer'),
1133  array($question_id)
1134  );
1135  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_oblig WHERE question_fi = %s",
1136  array('integer'),
1137  array($question_id)
1138  );
1139  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_svy_qst WHERE question_fi = %s",
1140  array('integer'),
1141  array($question_id)
1142  );
1143  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
1144  array('integer'),
1145  array($question_id)
1146  );
1147  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_question WHERE question_id = %s",
1148  array('integer'),
1149  array($question_id)
1150  );
1151 
1152  $this->deleteAdditionalTableData($question_id);
1153 
1154  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1155  array('integer'),
1156  array($question_id)
1157  );
1158  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1159  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1160 
1161  $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
1162  if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
1163  {
1164  include_once "./Services/Utilities/classes/class.ilUtil.php";
1165  ilUtil::delDir($directory);
1166  }
1167 
1168  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1169  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
1170  // remaining usages are not in text anymore -> delete them
1171  // and media objects (note: delete method of ilObjMediaObject
1172  // checks whether object is used in another context; if yes,
1173  // the object is not deleted!)
1174  foreach($mobs as $mob)
1175  {
1176  ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
1177  $mob_obj =& new ilObjMediaObject($mob);
1178  $mob_obj->delete();
1179  }
1180 
1181  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1183 
1184  // #12772 - untie question copies from pool question
1185  $ilDB->manipulate("UPDATE svy_question".
1186  " SET original_id = NULL".
1187  " WHERE original_id = ".$ilDB->quote($question_id, "integer"));
1188  }
1189 
1197  function _getQuestionType($question_id)
1198  {
1199  global $ilDB;
1200 
1201  if ($question_id < 1) return "";
1202 
1203  $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",
1204  array('integer'),
1205  array($question_id)
1206  );
1207  if ($result->numRows() == 1)
1208  {
1209  $data = $ilDB->fetchAssoc($result);
1210  return $data["type_tag"];
1211  }
1212  else
1213  {
1214  return "";
1215  }
1216  }
1217 
1225  function _getTitle($question_id)
1226  {
1227  global $ilDB;
1228 
1229  if ($question_id < 1) return "";
1230 
1231  $result = $ilDB->queryF("SELECT title FROM svy_question WHERE svy_question.question_id = %s",
1232  array('integer'),
1233  array($question_id)
1234  );
1235  if ($result->numRows() == 1)
1236  {
1237  $data = $ilDB->fetchAssoc($result);
1238  return $data["title"];
1239  }
1240  else
1241  {
1242  return "";
1243  }
1244  }
1245 
1253  function _getOriginalId($question_id, $a_return_question_id_if_no_original = true)
1254  {
1255  global $ilDB;
1256  $result = $ilDB->queryF("SELECT * FROM svy_question WHERE question_id = %s",
1257  array('integer'),
1258  array($question_id)
1259  );
1260  if ($result->numRows() > 0)
1261  {
1262  $row = $ilDB->fetchAssoc($result);
1263  if ($row["original_id"] > 0)
1264  {
1265  return $row["original_id"];
1266  }
1267  else if((bool)$a_return_question_id_if_no_original) // #12419
1268  {
1269  return $row["question_id"];
1270  }
1271  }
1272  else
1273  {
1274  return "";
1275  }
1276  }
1277 
1278  function syncWithOriginal()
1279  {
1280  global $ilDB;
1281 
1282  if ($this->getOriginalId())
1283  {
1284  $id = $this->getId();
1285  $original = $this->getOriginalId();
1286 
1287  $this->setId($this->getOriginalId());
1288  $this->setOriginalId(NULL);
1289  $this->saveToDb();
1290 
1291  $this->setId($id);
1292  $this->setOriginalId($original);
1293 
1294  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1295  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_material WHERE question_fi = %s",
1296  array('integer'),
1297  array($this->getOriginalId())
1298  );
1299  ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
1300  if (strlen($this->material["internal_link"]))
1301  {
1302  $next_id = $ilDB->nextId('svy_material');
1303  $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)",
1304  array('integer', 'integer', 'text', 'text', 'text', 'integer'),
1305  array($next_id, $this->getOriginalId(), $this->material["internal_link"], $this->material["import_id"], $this->material["title"], time())
1306  );
1307  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
1308  {
1309  ilInternalLink::_saveLink("sqst", $this->getOriginalId(), $matches[2], $matches[3], $matches[1]);
1310  }
1311  }
1312  }
1313  }
1314 
1321  function getPhrase($phrase_id)
1322  {
1323  global $ilDB;
1324 
1325  $result = $ilDB->queryF("SELECT title FROM svy_phrase WHERE phrase_id = %s",
1326  array('integer'),
1327  array($phrase_id)
1328  );
1329  if ($row = $ilDB->fetchAssoc($result))
1330  {
1331  return $row["title"];
1332  }
1333  return "";
1334  }
1335 
1344  {
1345  global $ilUser, $ilDB;
1346 
1347  $result = $ilDB->queryF("SELECT phrase_id FROM svy_phrase WHERE title = %s AND owner_fi = %s",
1348  array('text', 'integer'),
1349  array($title, $ilUser->getId())
1350  );
1351  return ($result->numRows() == 0) ? false : true;
1352  }
1353 
1361  function _questionExists($question_id)
1362  {
1363  global $ilDB;
1364 
1365  if ($question_id < 1)
1366  {
1367  return false;
1368  }
1369 
1370  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE question_id = %s",
1371  array('integer'),
1372  array($question_id)
1373  );
1374  return ($result->numRows() == 1) ? true : false;
1375  }
1376 
1377  function addInternalLink($material_id, $title = "")
1378  {
1379  if (strlen($material_id))
1380  {
1381  if (strcmp($material_title, "") == 0)
1382  {
1383  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1384  {
1385  $type = $matches[1];
1386  $target_id = $matches[2];
1387  $material_title = $this->lng->txt("obj_$type") . ": ";
1388  switch ($type)
1389  {
1390  case "lm":
1391  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1392  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1393  $cont_obj = $cont_obj_gui->object;
1394  $material_title .= $cont_obj->getTitle();
1395  break;
1396  case "pg":
1397  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1398  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1400  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1401  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1402  $cont_obj = $cont_obj_gui->object;
1403  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1404  $material_title .= $pg_obj->getTitle();
1405  break;
1406  case "st":
1407  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1408  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1410  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1411  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1412  $cont_obj = $cont_obj_gui->object;
1413  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1414  $material_title .= $st_obj->getTitle();
1415  break;
1416  case "git":
1417  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1418  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1419  break;
1420  case "mob":
1421  break;
1422  }
1423  }
1424  }
1425  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyMaterial.php";
1426  $mat = new ilSurveyMaterial();
1427  $mat->type = 0;
1428  $mat->internal_link = $material_id;
1429  $mat->title = $material_title;
1430  $this->addMaterial($mat);
1431  $this->saveMaterial();
1432  }
1433  }
1434 
1440  public function deleteMaterials($a_array)
1441  {
1442  foreach ($a_array as $idx)
1443  {
1444  unset($this->material[$idx]);
1445  }
1446  $this->material = array_values($this->material);
1447  $this->saveMaterial();
1448  }
1449 
1456  function duplicateMaterials($question_id)
1457  {
1458  foreach ($this->materials as $filename)
1459  {
1460  $materialspath = $this->getMaterialsPath();
1461  $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
1462  if (!file_exists($materialspath))
1463  {
1464  include_once "./Services/Utilities/classes/class.ilUtil.php";
1465  ilUtil::makeDirParents($materialspath);
1466  }
1467  if (!copy($materialspath_original . $filename, $materialspath . $filename))
1468  {
1469  print "material could not be duplicated!!!! ";
1470  }
1471  }
1472  }
1473 
1474  public function addMaterial($obj_material)
1475  {
1476  array_push($this->material, $obj_material);
1477  }
1478 
1486  function setMaterial($material_id = "", $is_import = false, $material_title = "")
1487  {
1488  if (strcmp($material_id, "") != 0)
1489  {
1490  $import_id = "";
1491  if ($is_import)
1492  {
1493  $import_id = $material_id;
1494  $material_id = $this->_resolveInternalLink($import_id);
1495  }
1496  if (strcmp($material_title, "") == 0)
1497  {
1498  if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
1499  {
1500  $type = $matches[1];
1501  $target_id = $matches[2];
1502  $material_title = $this->lng->txt("obj_$type") . ": ";
1503  switch ($type)
1504  {
1505  case "lm":
1506  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1507  $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
1508  $cont_obj = $cont_obj_gui->object;
1509  $material_title .= $cont_obj->getTitle();
1510  break;
1511  case "pg":
1512  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
1513  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1515  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1516  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1517  $cont_obj = $cont_obj_gui->object;
1518  $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
1519  $material_title .= $pg_obj->getTitle();
1520  break;
1521  case "st":
1522  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
1523  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1525  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1526  $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
1527  $cont_obj = $cont_obj_gui->object;
1528  $st_obj =& new ilStructureObject($cont_obj, $target_id);
1529  $material_title .= $st_obj->getTitle();
1530  break;
1531  case "git":
1532  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1533  $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
1534  break;
1535  case "mob":
1536  break;
1537  }
1538  }
1539  }
1540  $this->material = array(
1541  "internal_link" => $material_id,
1542  "import_id" => $import_id,
1543  "title" => $material_title
1544  );
1545  }
1546  $this->saveMaterial();
1547  }
1548 
1549  function _resolveInternalLink($internal_link)
1550  {
1551  if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
1552  {
1553  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1554  include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
1555  include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
1556  switch ($matches[2])
1557  {
1558  case "lm":
1559  $resolved_link = ilLMObject::_getIdForImportId($internal_link);
1560  break;
1561  case "pg":
1562  $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
1563  break;
1564  case "st":
1565  $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
1566  break;
1567  case "git":
1568  $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
1569  break;
1570  case "mob":
1571  $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
1572  break;
1573  }
1574  if (strcmp($resolved_link, "") == 0)
1575  {
1576  $resolved_link = $internal_link;
1577  }
1578  }
1579  else
1580  {
1581  $resolved_link = $internal_link;
1582  }
1583  return $resolved_link;
1584  }
1585 
1586  function _resolveIntLinks($question_id)
1587  {
1588  global $ilDB;
1589  $resolvedlinks = 0;
1590  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1591  array('integer'),
1592  array($question_id)
1593  );
1594  if ($result->numRows())
1595  {
1596  while ($row = $ilDB->fetchAssoc($result))
1597  {
1598  $internal_link = $row["internal_link"];
1599  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1600  $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
1601  if (strcmp($internal_link, $resolved_link) != 0)
1602  {
1603  // internal link was resolved successfully
1604  $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s",
1605  array('text', 'integer', 'integer'),
1606  array($resolved_link, time(), $row["material_id"])
1607  );
1608  $resolvedlinks++;
1609  }
1610  }
1611  }
1612  if ($resolvedlinks)
1613  {
1614  // there are resolved links -> reenter theses links to the database
1615 
1616  // delete all internal links from the database
1617  include_once "./Services/COPage/classes/class.ilInternalLink.php";
1618  ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
1619 
1620  $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s",
1621  array('integer'),
1622  array($question_id)
1623  );
1624  if ($result->numRows())
1625  {
1626  while ($row = $ilDB->fetchAssoc($result))
1627  {
1628  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
1629  {
1630  ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
1631  }
1632  }
1633  }
1634  }
1635  }
1636 
1637  function _getInternalLinkHref($target = "", $a_parent_ref_id = null)
1638  {
1639  global $ilDB;
1640  $linktypes = array(
1641  "lm" => "LearningModule",
1642  "pg" => "PageObject",
1643  "st" => "StructureObject",
1644  "git" => "GlossaryItem",
1645  "mob" => "MediaObject"
1646  );
1647  $href = "";
1648  if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
1649  {
1650  $type = $matches[1];
1651  $target_id = $matches[2];
1652  include_once "./Services/Utilities/classes/class.ilUtil.php";
1653  switch($linktypes[$matches[1]])
1654  {
1655  case "LearningModule":
1656  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1657  break;
1658  case "PageObject":
1659  case "StructureObject":
1660  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1661  break;
1662  case "GlossaryItem":
1663  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
1664  break;
1665  case "MediaObject":
1666  $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/ilias.php?baseClass=ilLMPresentationGUI&obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=".$a_parent_ref_id."&mob_id=".$target_id;
1667  break;
1668  }
1669  }
1670  return $href;
1671  }
1672 
1681  function _isWriteable($question_id, $user_id)
1682  {
1683  global $ilDB;
1684 
1685  if (($question_id < 1) || ($user_id < 1))
1686  {
1687  return false;
1688  }
1689 
1690  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1691  array('integer'),
1692  array($question_id)
1693  );
1694  if ($result->numRows() == 1)
1695  {
1696  $row = $ilDB->fetchAssoc($result);
1697  $qpl_object_id = $row["obj_fi"];
1698  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1699  return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
1700  }
1701  else
1702  {
1703  return false;
1704  }
1705  }
1706 
1714  {
1715  global $ilDB;
1716  $result = $ilDB->queryF("SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
1717  array('text'),
1718  array($this->getQuestionType())
1719  );
1720  if ($result->numRows() == 1)
1721  {
1722  $row = $ilDB->fetchAssoc($result);
1723  return $row["questiontype_id"];
1724  }
1725  else
1726  {
1727  return 0;
1728  }
1729  }
1730 
1737  function getQuestionType()
1738  {
1739  return "";
1740  }
1741 
1749  static function _includeClass($question_type, $gui = 0)
1750  {
1751  $type = $question_type;
1752  if ($gui) $type .= "GUI";
1753  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type.".php"))
1754  {
1755  include_once "./Modules/SurveyQuestionPool/classes/class.".$type.".php";
1756  return true;
1757  }
1758  else
1759  {
1760  global $ilPluginAdmin;
1761  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1762  foreach ($pl_names as $pl_name)
1763  {
1764  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1765  if (strcmp($pl->getQuestionType(), $question_type) == 0)
1766  {
1767  $pl->includeClass("class.".$type.".php");
1768  return true;
1769  }
1770  }
1771  }
1772  return false;
1773  }
1774 
1781  static function _getQuestionTypeName($type_tag)
1782  {
1783  if (file_exists("./Modules/SurveyQuestionPool/classes/class.".$type_tag.".php"))
1784  {
1785  global $lng;
1786  return $lng->txt($type_tag);
1787  }
1788  else
1789  {
1790  global $ilPluginAdmin;
1791  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
1792  foreach ($pl_names as $pl_name)
1793  {
1794  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
1795  if (strcmp($pl->getQuestionType(), $type_tag) == 0)
1796  {
1797  return $pl->getQuestionTypeTranslation();
1798  }
1799  }
1800  }
1801  return "";
1802  }
1803 
1804 
1812  function &_instanciateQuestion($question_id)
1813  {
1814  $question_type = SurveyQuestion::_getQuestionType($question_id);
1815  if($question_type)
1816  {
1817  SurveyQuestion::_includeClass($question_type);
1818  $question = new $question_type();
1819  $question->loadFromDb($question_id);
1820  return $question;
1821  }
1822  }
1823 
1831  function &_instanciateQuestionGUI($question_id)
1832  {
1833  $question_type = SurveyQuestion::_getQuestionType($question_id);
1834  if($question_type)
1835  {
1836  SurveyQuestion::_includeClass($question_type, 1);
1837  $guitype = $question_type . "GUI";
1838  $question = new $guitype($question_id);
1839  return $question;
1840  }
1841  }
1842 
1851  function isHTML($a_text)
1852  {
1853  if (preg_match("/<[^>]*?>/", $a_text))
1854  {
1855  return TRUE;
1856  }
1857  else
1858  {
1859  return FALSE;
1860  }
1861  }
1862 
1870  function QTIMaterialToString($a_material)
1871  {
1872  $result = "";
1873  for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
1874  {
1875  $material = $a_material->getMaterial($i);
1876  if (strcmp($material["type"], "mattext") == 0)
1877  {
1878  $result .= $material["material"]->getContent();
1879  }
1880  if (strcmp($material["type"], "matimage") == 0)
1881  {
1882  $matimage = $material["material"];
1883  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
1884  {
1885  // import an mediaobject which was inserted using tiny mce
1886  if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
1887  array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
1888  }
1889  }
1890  }
1891  return $result;
1892  }
1893 
1902  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $a_attrs = null)
1903  {
1904  include_once "./Services/RTE/classes/class.ilRTE.php";
1905  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1906 
1907  $a_xml_writer->xmlStartTag("material");
1908  $attrs = array(
1909  "type" => "text/plain"
1910  );
1911  if ($this->isHTML($a_material))
1912  {
1913  $attrs["type"] = "text/xhtml";
1914  }
1915  if (is_array($a_attrs))
1916  {
1917  $attrs = array_merge($attrs, $a_attrs);
1918  }
1919  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
1920 
1921  if ($add_mobs)
1922  {
1923  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
1924  foreach ($mobs as $mob)
1925  {
1926  $mob_obj =& new ilObjMediaObject($mob);
1927  $imgattrs = array(
1928  "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
1929  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle(),
1930  "type" => "spl:html",
1931  "id" => $this->getId()
1932  );
1933  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
1934  }
1935  }
1936  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
1937  }
1938 
1945  function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
1946  {
1947  include_once "./Services/Utilities/classes/class.ilUtil.php";
1948  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
1949  }
1950 
1959  {
1960  return array();
1961  }
1962 
1969  function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true)
1970  {
1971  if(!$a_use_label)
1972  {
1973  $title = $this->title;
1974  }
1975  else
1976  {
1977  if($a_substitute)
1978  {
1979  $title = $this->label ? $this->label : $this->title;
1980  }
1981  else
1982  {
1983  $title = $this->label;
1984  }
1985  }
1986 
1987  array_push($a_array, $title);
1988  return $title;
1989  }
1990 
1998  function addUserSpecificResultsData(&$a_array, &$resultset)
1999  {
2000  // overwrite in inherited classes
2001  }
2002 
2011  {
2012  // overwrite in inherited classes
2013  return array();
2014  }
2015 
2022  function &getWorkingDataFromUserInput($post_data)
2023  {
2024  // overwrite in inherited classes
2025  $data = array();
2026  return $data;
2027  }
2028 
2037  function importAdditionalMetadata($a_meta)
2038  {
2039  // overwrite in inherited classes
2040  }
2041 
2048  function importResponses($a_data)
2049  {
2050  // overwrite in inherited classes
2051  }
2052 
2059  function importAdjectives($a_data)
2060  {
2061  // overwrite in inherited classes
2062  }
2063 
2070  function importMatrix($a_data)
2071  {
2072  // overwrite in inherited classes
2073  }
2074 
2086  function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
2087  {
2088  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
2089  $column = 0;
2090  switch ($export_label)
2091  {
2092  case 'label_only':
2093  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2094  break;
2095  case 'title_only':
2096  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2097  break;
2098  default:
2099  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
2100  $column++;
2101  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
2102  break;
2103  }
2104  $column++;
2105  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text(strip_tags($this->getQuestiontext()))); // #12942
2106  $column++;
2107  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->lng->txt($eval_data["QUESTION_TYPE"])));
2108  $column++;
2109  $worksheet->write($row, $column, $eval_data["USERS_ANSWERED"]);
2110  $column++;
2111  $worksheet->write($row, $column, $eval_data["USERS_SKIPPED"]);
2112  $column++;
2113  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
2114  $column++;
2115  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["MODE"]));
2116  $column++;
2117  $worksheet->write($row, $column, $eval_data["MODE_NR_OF_SELECTIONS"]);
2118  $column++;
2119  $worksheet->write($row, $column, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
2120  $column++;
2121  $worksheet->write($row, $column, $eval_data["ARITHMETIC_MEAN"]);
2122  return $row + 1;
2123  }
2124 
2136  function &setExportCumulatedCVS(&$eval_data, $export_label)
2137  {
2138  $csvrow = array();
2139  switch ($export_label)
2140  {
2141  case 'label_only':
2142  array_push($csvrow, $this->label);
2143  break;
2144  case 'title_only':
2145  array_push($csvrow, $this->getTitle());
2146  break;
2147  default:
2148  array_push($csvrow, $this->getTitle());
2149  array_push($csvrow, $this->label);
2150  break;
2151  }
2152  array_push($csvrow, strip_tags($this->getQuestiontext())); // #12942
2153  array_push($csvrow, $this->lng->txt($eval_data["QUESTION_TYPE"]));
2154  array_push($csvrow, $eval_data["USERS_ANSWERED"]);
2155  array_push($csvrow, $eval_data["USERS_SKIPPED"]);
2156  array_push($csvrow, $eval_data["MODE"]);
2157  array_push($csvrow, $eval_data["MODE_NR_OF_SELECTIONS"]);
2158  array_push($csvrow, $eval_data["MEDIAN"]);
2159  array_push($csvrow, $eval_data["ARITHMETIC_MEAN"]);
2160  $result = array();
2161  array_push($result, $csvrow);
2162  return $result;
2163  }
2164 
2174  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
2175  {
2176  // overwrite in inherited classes
2177  }
2178 
2186  {
2187  // overwrite in inherited classes
2188  return FALSE;
2189  }
2190 
2198  {
2199  // overwrite in inherited classes
2200  return array();
2201  }
2202 
2208  public function getPreconditionOptions()
2209  {
2210  // overwrite in inherited classes
2211  }
2212 
2221  {
2222  // overwrite in inherited classes
2223  return $value;
2224  }
2225 
2232  public function getPreconditionSelectValue($default = "", $title, $variable)
2233  {
2234  // overwrite in inherited classes
2235  return null;
2236  }
2237 
2246  function outChart($survey_id, $type = "")
2247  {
2248  // overwrite in inherited classes
2249  }
2250 
2251  function setOriginalId($original_id)
2252  {
2253  $this->original_id = $original_id;
2254  }
2255 
2256  function getOriginalId()
2257  {
2258  return $this->original_id;
2259  }
2260 
2266  public function saveRandomData($active_id)
2267  {
2268  // do nothing, overwrite in parent classes
2269  }
2270 
2271  public function getMaterial()
2272  {
2273  return $this->material;
2274  }
2275 
2276  public function setSubtype($a_subtype)
2277  {
2278  // do nothing
2279  }
2280 
2281  public function getSubtype()
2282  {
2283  // do nothing
2284  return null;
2285  }
2286 
2287  protected function &calculateCumulatedResults($survey_id, $finished_ids)
2288  {
2289  if (count($this->cumulated) == 0)
2290  {
2291  if(!$finished_ids)
2292  {
2293  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
2295  }
2296  else
2297  {
2298  $nr_of_users = sizeof($finished_ids);
2299  }
2300  if($nr_of_users)
2301  {
2302  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
2303  }
2304  }
2305  return $this->cumulated;
2306  }
2307 
2313  public function getCumulatedResultData($survey_id, $counter, $finished_ids)
2314  {
2315  $cumulated =& $this->calculateCumulatedResults($survey_id, $finished_ids);
2316  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->getQuestiontext());
2317 
2318  $maxlen = 75;
2319  include_once "./Services/Utilities/classes/class.ilStr.php";
2320  if (ilStr::strlen($questiontext) > $maxlen + 3)
2321  {
2322  $questiontext = ilStr::substr($questiontext, 0, $maxlen) . "...";
2323  }
2324 
2325  $result = array(
2326  'counter' => $counter,
2327  'title' => $counter.'. '.$this->getTitle(),
2328  'question' => $questiontext,
2329  'users_answered' => $cumulated['USERS_ANSWERED'],
2330  'users_skipped' => $cumulated['USERS_SKIPPED'],
2331  'question_type' => $this->lng->txt($cumulated["QUESTION_TYPE"]),
2332  'mode' => $cumulated["MODE"],
2333  'mode_nr_of_selections' => $cumulated["MODE_NR_OF_SELECTIONS"],
2334  'median' => $cumulated["MEDIAN"],
2335  'arithmetic_mean' => $cumulated["ARITHMETIC_MEAN"]
2336  );
2337  return $result;
2338  }
2339 
2343  public function __get($value)
2344  {
2345  switch ($value)
2346  {
2347  default:
2348  if (array_key_exists($value, $this->arrData))
2349  {
2350  return $this->arrData[$value];
2351  }
2352  else
2353  {
2354  return null;
2355  }
2356  break;
2357  }
2358  }
2359 
2363  public function __set($key, $value)
2364  {
2365  switch ($key)
2366  {
2367  default:
2368  $this->arrData[$key] = $value;
2369  break;
2370  }
2371  }
2372 
2380  public static function _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
2381  {
2382  global $ilDB;
2383 
2384  $ilDB->manipulate("UPDATE svy_question".
2385  " SET original_id = ".$ilDB->quote($a_original_id, "integer").",".
2386  " obj_fi = ".$ilDB->quote($a_object_id, "integer").
2387  " WHERE question_id = ".$ilDB->quote($a_question_id, "integer"));
2388  }
2389 
2390  public function getCopyIds($a_group_by_survey = false)
2391  {
2392  global $ilDB;
2393 
2394  $set = $ilDB->query("SELECT q.question_id,s.obj_fi".
2395  " FROM svy_question q".
2396  " JOIN svy_svy_qst sq ON (sq.question_fi = q.question_id)".
2397  " JOIN svy_svy s ON (s.survey_id = sq.survey_fi)".
2398  " WHERE original_id = ".$ilDB->quote($this->getId(), "integer"));
2399  $res = array();
2400  while($row = $ilDB->fetchAssoc($set))
2401  {
2402  if(!$a_group_by_survey)
2403  {
2404  $res[] = $row["question_id"];
2405  }
2406  else
2407  {
2408  $res[$row["obj_fi"]][] = $row["question_id"];
2409  }
2410  }
2411  return $res;
2412  }
2413 
2414  public function hasCopies()
2415  {
2416  return (bool)sizeof($this->getCopyIds());
2417  }
2418 
2419  public function getSkippedValue()
2420  {
2421  include_once "Modules/Survey/classes/class.ilObjSurvey.php";
2423  }
2424 }
2425 ?>