ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurveyQuestionPool.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 
34 include_once "./Services/Object/classes/class.ilObject.php";
35 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
36 
38 {
44  var $online;
45 
52  function ilObjSurveyQuestionPool($a_id = 0,$a_call_by_reference = true)
53  {
54  $this->type = "spl";
55  $this->ilObject($a_id,$a_call_by_reference);
56  }
57 
61  function create($a_upload = false)
62  {
64  if(!$a_upload)
65  {
66  $this->createMetaData();
67  }
68  }
69 
76  function update()
77  {
78  $this->updateMetaData();
79  if (!parent::update())
80  {
81  return false;
82  }
83 
84  // put here object specific stuff
85 
86  return true;
87  }
88 
94  function read($a_force_db = false)
95  {
96  parent::read($a_force_db);
97  $this->loadFromDb();
98  }
99 
105  function cloneObject($a_target_id,$a_copy_id = 0)
106  {
107  global $ilLog;
108  $newObj = parent::cloneObject($a_target_id,$a_copy_id);
109  $newObj->setOnline($this->getOnline());
110  $newObj->saveToDb();
111  // clone the questions in the question pool
112  $questions =& $this->getQuestions();
113  foreach ($questions as $question_id)
114  {
115  $newObj->copyQuestion($question_id, $newObj->getId());
116  }
117 
118  // clone meta data
119  include_once "./Services/MetaData/classes/class.ilMD.php";
120  $md = new ilMD($this->getId(),0,$this->getType());
121  $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
122 
123  // update the metadata with the new title of the question pool
124  $newObj->updateMetaData();
125  return $newObj;
126  }
127 
128  function &createQuestion($question_type, $question_id = -1)
129  {
130  if ((!$question_type) and ($question_id > 0))
131  {
132  $question_type = $this->getQuestiontype($question_id);
133  }
134 
135  include_once "./Modules/SurveyQuestionPool/classes/class.".$question_type."GUI.php";
136  $question_type_gui = $question_type . "GUI";
137  $question =& new $question_type_gui();
138 
139  if ($question_id > 0)
140  {
141  $question->object->loadFromDb($question_id);
142  }
143 
144  return $question;
145  }
146 
154  function copyQuestion($question_id, $questionpool_to)
155  {
156  $question_gui =& $this->createQuestion("", $question_id);
157  if ($question_gui->object->getObjId() == $questionpool_to)
158  {
159  // the question is copied into the same question pool
160  $this->duplicateQuestion($question_id);
161  }
162  else
163  {
164  // the question is copied into another question pool
165  $newtitle = $question_gui->object->getTitle();
166  if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to))
167  {
168  $counter = 2;
169  while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() . " ($counter)", $questionpool_to))
170  {
171  $counter++;
172  }
173  $newtitle = $question_gui->object->getTitle() . " ($counter)";
174  }
175  $question_gui->object->copyObject($this->getId(), $newtitle);
176  }
177  }
178 
184  function loadFromDb()
185  {
186  global $ilDB;
187 
188  $result = $ilDB->queryF("SELECT * FROM svy_qpl WHERE obj_fi = %s",
189  array('integer'),
190  array($this->getId())
191  );
192  if ($result->numRows() == 1)
193  {
194  $row = $ilDB->fetchAssoc($result);
195  $this->setOnline($row["isonline"]);
196  }
197  }
198 
204  function saveToDb()
205  {
206  global $ilDB;
207 
208  $result = $ilDB->queryF("SELECT * FROM svy_qpl WHERE obj_fi = %s",
209  array('integer'),
210  array($this->getId())
211  );
212  if ($result->numRows() == 1)
213  {
214  $affectedRows = $ilDB->manipulateF("UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
215  array('text','integer','integer'),
216  array($this->getOnline(), time(), $this->getId())
217  );
218  }
219  else
220  {
221  $next_id = $ilDB->nextId('svy_qpl');
222  $query = $ilDB->manipulateF("INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
223  array('integer', 'text', 'integer', 'integer'),
224  array($next_id, $this->getOnline(), $this->getId(), time())
225  );
226  }
227  }
228 
235  function delete()
236  {
237  $remove = parent::delete();
238  // always call parent delete function first!!
239  if (!$remove)
240  {
241  return false;
242  }
243 
244  // delete all related questions
245  $this->deleteAllData();
246 
247  // delete meta data
248  $this->deleteMetaData();
249 
250  return true;
251  }
252 
253  function deleteAllData()
254  {
255  global $ilDB;
256  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
257  array('integer'),
258  array($this->getId())
259  );
260  $found_questions = array();
261  while ($row = $ilDB->fetchAssoc($result))
262  {
263  $this->removeQuestion($row["question_id"]);
264  }
265 
266  // delete export files
267  include_once "./Services/Utilities/classes/class.ilUtil.php";
268  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
269  $directory = $spl_data_dir."/spl_".$this->getId();
270  if (is_dir($directory))
271  {
272  include_once "./Services/Utilities/classes/class.ilUtil.php";
273  ilUtil::delDir($directory);
274  }
275  }
276 
290  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
291  {
292  global $tree;
293 
294  switch ($a_event)
295  {
296  case "link":
297 
298  //var_dump("<pre>",$a_params,"</pre>");
299  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
300  //exit;
301  break;
302 
303  case "cut":
304 
305  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
306  //exit;
307  break;
308 
309  case "copy":
310 
311  //var_dump("<pre>",$a_params,"</pre>");
312  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
313  //exit;
314  break;
315 
316  case "paste":
317 
318  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
319  //exit;
320  break;
321 
322  case "new":
323 
324  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
325  //exit;
326  break;
327  }
328 
329  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
330  if ($a_node_id==$_GET["ref_id"])
331  {
332  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
333  $parent_type = $parent_obj->getType();
334  if($parent_type == $this->getType())
335  {
336  $a_node_id = (int) $tree->getParentId($a_node_id);
337  }
338  }
339 
340  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
341  }
342 
348  function getTitle()
349  {
350  //return $this->title;
351  return parent::getTitle();
352  }
353 
357  function setTitle($a_title)
358  {
359  parent::setTitle($a_title);
360  }
361 
368  function removeQuestion($question_id)
369  {
370  if ($question_id < 1) return;
371  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
372  $question =& SurveyQuestion::_instanciateQuestion($question_id);
373  $question->delete($question_id);
374  }
375 
383  function getQuestiontype($question_id)
384  {
385  global $ilDB;
386  if ($question_id < 1) return;
387  $result = $ilDB->queryF("SELECT svy_qtype.type_tag FROM svy_question, svy_qtype WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.question_id = %s",
388  array('integer'),
389  array($question_id)
390  );
391  if ($result->numRows() == 1)
392  {
393  $data = $ilDB->fetchAssoc($result);
394  return $data["type_tag"];
395  }
396  else
397  {
398  return;
399  }
400  }
401 
409  function isInUse($question_id)
410  {
411  global $ilDB;
412  // check out the already answered questions
413  $result = $ilDB->queryF("SELECT answer_id FROM svy_answer WHERE question_fi = %s",
414  array('integer'),
415  array($question_id)
416  );
417  $answered = $result->numRows();
418 
419  // check out the questions inserted in surveys
420  $result = $ilDB->queryF("SELECT svy_svy.* FROM svy_svy, svy_svy_qst WHERE svy_svy_qst.survey_fi = svy_svy.survey_id AND svy_svy_qst.question_fi = %s",
421  array('integer'),
422  array($question_id)
423  );
424  $inserted = $result->numRows();
425  if (($inserted + $answered) == 0)
426  {
427  return false;
428  }
429  $result_array = array();
430  while ($row = $ilDB->fetchObject($result))
431  {
432  array_push($result_array, $row);
433  }
434  return $result_array;
435  }
436 
443  function paste($question_id)
444  {
445  $this->duplicateQuestion($question_id, $this->getId());
446  }
447 
455  function &getQuestionsInfo($question_array)
456  {
457  global $ilDB;
458  $result_array = array();
459  $result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag, svy_qtype.plugin FROM svy_question, svy_qtype WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.tstamp > 0 AND " . $ilDB->in('svy_question.question_id', $question_array, false, 'integer'));
460  while ($row = $ilDB->fetchAssoc($result))
461  {
462  if ($row["plugin"])
463  {
464  if ($this->isPluginActive($row["type_tag"]))
465  {
466  array_push($result_array, $row);
467  }
468  }
469  else
470  {
471  array_push($result_array, $row);
472  }
473  }
474  return $result_array;
475  }
476 
483  function duplicateQuestion($question_id, $obj_id = "")
484  {
485  global $ilUser;
486  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
487  $question = SurveyQuestion::_instanciateQuestion($question_id);
488  $suffix = "";
489  $counter = 1;
490  while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id))
491  {
492  $counter++;
493  if ($counter > 1) $suffix = " ($counter)";
494  }
495  if ($obj_id)
496  {
497  $question->setObjId($obj_id);
498  }
499  $question->duplicate(false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
500  }
501 
507  function getQuestionsData($arrFilter)
508  {
509  global $ilUser;
510  global $ilDB;
511  $where = "";
512  if (is_array($arrFilter))
513  {
514  foreach ($arrFilter as $key => $value)
515  {
516  $arrFilter[$key] = str_replace('%', '', $arrFilter[$key]);
517  }
518  if (array_key_exists('title', $arrFilter) && strlen($arrFilter['title']))
519  {
520  $where .= " AND " . $ilDB->like('svy_question.title', 'text', "%%" . $arrFilter['title'] . "%%");
521  }
522  if (array_key_exists('description', $arrFilter) && strlen($arrFilter['description']))
523  {
524  $where .= " AND " . $ilDB->like('svy_question.description', 'text', "%%" . $arrFilter['description'] . "%%");
525  }
526  if (array_key_exists('author', $arrFilter) && strlen($arrFilter['author']))
527  {
528  $where .= " AND " . $ilDB->like('svy_question.author', 'text', "%%" . $arrFilter['author'] . "%%");
529  }
530  if (array_key_exists('type', $arrFilter) && strlen($arrFilter['type']))
531  {
532  $where .= " AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter['type'], 'text');
533  }
534  }
535  $query_result = $ilDB->queryF("SELECT svy_question.*, svy_qtype.type_tag, svy_qtype.plugin FROM svy_question, svy_qtype WHERE svy_question.original_id IS NULL AND svy_question.tstamp > 0 AND svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.obj_fi = %s" . $where,
536  array('integer'),
537  array($this->getId())
538  );
539  $rows = array();
540  if ($query_result->numRows())
541  {
542  while ($row = $ilDB->fetchAssoc($query_result))
543  {
544  if ($row["plugin"])
545  {
546  if ($this->isPluginActive($row["type_tag"]))
547  {
548  array_push($rows, $row);
549  }
550  }
551  else
552  {
553  array_push($rows, $row);
554  }
555  }
556  }
557  return $rows;
558  }
559 
566  {
567  include_once "./Services/Utilities/classes/class.ilUtil.php";
568  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
569  ilUtil::makeDir($spl_data_dir);
570  if(!is_writable($spl_data_dir))
571  {
572  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
573  .") not writeable.",$this->ilias->error_obj->FATAL);
574  }
575 
576  // create learning module directory (data_dir/lm_data/lm_<id>)
577  $spl_dir = $spl_data_dir."/spl_".$this->getId();
578  ilUtil::makeDir($spl_dir);
579  if(!@is_dir($spl_dir))
580  {
581  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
582  }
583  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
584  $export_dir = $spl_dir."/export";
585  ilUtil::makeDir($export_dir);
586  if(!@is_dir($export_dir))
587  {
588  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
589  }
590  }
591 
596  {
597  include_once "./Services/Utilities/classes/class.ilUtil.php";
598  $export_dir = ilUtil::getDataDir()."/spl_data"."/spl_".$this->getId()."/export";
599  return $export_dir;
600  }
601 
605  function getExportFiles($dir)
606  {
607  // quit if import dir not available
608  if (!@is_dir($dir) or
609  !is_writeable($dir))
610  {
611  return array();
612  }
613 
614  // open directory
615  $dir = dir($dir);
616 
617  // initialize array
618  $file = array();
619 
620  // get files and save the in the array
621  while ($entry = $dir->read())
622  {
623  if ($entry != "." &&
624  $entry != ".." &&
625  ereg("^[0-9]{10}_{2}[0-9]+_{2}(spl_)*[0-9]+\.[A-Za-z]{3}\$", $entry))
626  {
627  $file[] = $entry;
628  }
629  }
630 
631  // close import directory
632  $dir->close();
633  // sort files
634  sort ($file);
635  reset ($file);
636 
637  return $file;
638  }
639 
646  {
647  include_once "./Services/Utilities/classes/class.ilUtil.php";
648  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
649  ilUtil::makeDir($spl_data_dir);
650 
651  if(!is_writable($spl_data_dir))
652  {
653  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
654  .") not writeable.",$this->ilias->error_obj->FATAL);
655  }
656 
657  // create test directory (data_dir/spl_data/spl_<id>)
658  $spl_dir = $spl_data_dir."/spl_".$this->getId();
659  ilUtil::makeDir($spl_dir);
660  if(!@is_dir($spl_dir))
661  {
662  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
663  }
664 
665  // create import subdirectory (data_dir/spl_data/spl_<id>/import)
666  $import_dir = $spl_dir."/import";
667  ilUtil::makeDir($import_dir);
668  if(!@is_dir($import_dir))
669  {
670  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
671  }
672  }
673 
678  {
679  include_once "./Services/Utilities/classes/class.ilUtil.php";
680  $import_dir = ilUtil::getDataDir()."/spl_data".
681  "/spl_".$this->getId()."/import";
682  if(@is_dir($import_dir))
683  {
684  return $import_dir;
685  }
686  else
687  {
688  return false;
689  }
690  }
691 
695  function toXML($questions)
696  {
697  if (!is_array($questions))
698  {
699  $questions =& $this->getQuestions();
700  }
701  if (count($questions) == 0)
702  {
703  $questions =& $this->getQuestions();
704  }
705  $xml = "";
706 
707  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
708  $a_xml_writer = new ilXmlWriter;
709  // set xml header
710  $a_xml_writer->xmlHeader();
711  $attrs = array(
712  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
713  "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
714  );
715  $a_xml_writer->xmlStartTag("surveyobject", $attrs);
716  $attrs = array(
717  "id" => "qpl_" . $this->getId(),
718  "label" => $this->getTitle(),
719  "online" => $this->getOnline()
720  );
721  $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
722  $a_xml_writer->xmlElement("dummy", NULL, "dummy");
723  // add ILIAS specific metadata
724  $a_xml_writer->xmlStartTag("metadata");
725  $a_xml_writer->xmlStartTag("metadatafield");
726  $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
727  include_once "./Services/MetaData/classes/class.ilMD.php";
728  $md = new ilMD($this->getId(),0, $this->getType());
729  $writer = new ilXmlWriter();
730  $md->toXml($writer);
731  $metadata = $writer->xmlDumpMem();
732  $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
733  $a_xml_writer->xmlEndTag("metadatafield");
734  $a_xml_writer->xmlEndTag("metadata");
735 
736  $a_xml_writer->xmlEndTag("surveyquestions");
737  $a_xml_writer->xmlEndTag("surveyobject");
738 
739  $xml = $a_xml_writer->xmlDumpMem(FALSE);
740 
741  $questionxml = "";
742  foreach ($questions as $key => $value)
743  {
744  $questiontype = $this->getQuestiontype($value);
745  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
746  SurveyQuestion::_includeClass($questiontype);
747  $question = new $questiontype();
748  $question->loadFromDb($value);
749  $questionxml .= $question->toXML(false);
750  }
751 
752  $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
753  return $xml;
754  }
755 
756  function &getQuestions()
757  {
758  global $ilDB;
759  $questions = array();
760  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
761  array('integer'),
762  array($this->getId())
763  );
764  if ($result->numRows())
765  {
766  while ($row = $ilDB->fetchAssoc($result))
767  {
768  array_push($questions, $row["question_id"]);
769  }
770  }
771  return $questions;
772  }
773 
780  function importObject($source, $spl_exists = FALSE)
781  {
782  if (is_file($source))
783  {
784  $isZip = (strcmp(strtolower(substr($source, -3)), 'zip') == 0);
785  if ($isZip)
786  {
787  // unzip file
788  ilUtil::unzip($source);
789 
790  // determine filenames of xml files
791  $subdir = basename($source, ".zip");
792  $source = dirname($source)."/".$subdir."/".$subdir.".xml";
793  }
794 
795  $fh = fopen($source, "r") or die("");
796  $xml = fread($fh, filesize($source));
797  fclose($fh) or die("");
798  if ($isZip)
799  {
800  $subdir = basename($source, ".zip");
801  if (@is_dir(dirname($source)."/".$subdir))
802  {
803  ilUtil::delDir(dirname($source)."/".$subdir);
804  }
805  }
806  if (strpos($xml, "questestinterop") > 0)
807  {
808  // survey questions for ILIAS < 3.8
809  include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php";
810  $import = new SurveyImportParserPre38($this->getId(), "", $spl_exists);
811  $import->setXMLContent($xml);
812  $import->startParsing();
813  }
814  else
815  {
816  // survey questions for ILIAS >= 3.8
817  include_once "./Services/Survey/classes/class.SurveyImportParser.php";
818  $import = new SurveyImportParser($this->getId(), "", $spl_exists);
819  $import->setXMLContent($xml);
820  $import->startParsing();
821  }
822  }
823  }
824 
825  public static function _setOnline($a_obj_id, $a_online_status)
826  {
827  global $ilDB;
828 
829  $status = "0";
830  switch ($a_online_status)
831  {
832  case 0:
833  case 1:
834  $status = "$a_online_status";
835  break;
836  }
837  $affectedRows = $ilDB->manipulateF("UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
838  array('text','integer'),
839  array($status, $a_obj_id)
840  );
841  }
842 
850  function setOnline($a_online_status)
851  {
852  switch ($a_online_status)
853  {
854  case 0:
855  case 1:
856  $this->online = $a_online_status;
857  break;
858  default:
859  $this->online = 0;
860  break;
861  }
862  }
863 
864  function getOnline()
865  {
866  if (strcmp($this->online, "") == 0) $this->online = "0";
867  return $this->online;
868  }
869 
870  function _lookupOnline($a_obj_id)
871  {
872  global $ilDB;
873 
874  $result = $ilDB->queryF("SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
875  array('integer'),
876  array($a_obj_id)
877  );
878  if ($result->numRows() == 1)
879  {
880  $row = $ilDB->fetchAssoc($result);
881  return $row["isonline"];
882  }
883  return 0;
884  }
885 
893  function _isWriteable($object_id, $user_id)
894  {
895  global $rbacsystem;
896  global $ilDB;
897 
898  $refs = ilObject::_getAllReferences($object_id);
899  $result = false;
900  foreach ($refs as $ref)
901  {
902  if ($rbacsystem->checkAccess("write", $ref) && (ilObject::_hasUntrashedReference($object_id)))
903  {
904  $result = true;
905  }
906  }
907  return $result;
908  }
909 
916  function &_getQuestiontypes()
917  {
918  global $ilDB;
919  global $lng;
920 
921  $lng->loadLanguageModule("survey");
922  $types = array();
923  $query_result = $ilDB->query("SELECT * FROM svy_qtype ORDER BY type_tag");
924  while ($row = $ilDB->fetchAssoc($query_result))
925  {
926  //array_push($questiontypes, $row["type_tag"]);
927  if ($row["plugin"] == 0)
928  {
929  $types[$lng->txt($row["type_tag"])] = $row;
930  }
931  else
932  {
933  global $ilPluginAdmin;
934  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
935  foreach ($pl_names as $pl_name)
936  {
937  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
938  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
939  {
940  $types[$pl->getQuestionTypeTranslation()] = $row;
941  }
942  }
943  }
944  }
945  ksort($types);
946  return $types;
947  }
948 
949  public static function &_getQuestionTypeTranslations()
950  {
951  global $ilDB;
952  global $lng;
953  global $ilLog;
954  global $ilPluginAdmin;
955 
956  $lng->loadLanguageModule("survey");
957  $result = $ilDB->query("SELECT * FROM svy_qtype");
958  $types = array();
959  while ($row = $ilDB->fetchAssoc($result))
960  {
961  if ($row["plugin"] == 0)
962  {
963  $types[$row['type_tag']] = $lng->txt($row["type_tag"]);
964  }
965  else
966  {
967  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
968  foreach ($pl_names as $pl_name)
969  {
970  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
971  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
972  {
973  $types[$row['type_tag']] = $pl->getQuestionTypeTranslation();
974  }
975  }
976  }
977  }
978  ksort($types);
979  return $types;
980  }
981 
988  function &_getAvailableQuestionpools($use_object_id = FALSE, $could_be_offline = FALSE, $showPath = FALSE, $permission = "read")
989  {
990  global $ilUser;
991  global $ilDB;
992 
993  $result_array = array();
994  $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
995  $titles = ilObject::_prepareCloneSelection($qpls, "spl", $showPath);
996  $allqpls = array();
997  $result = $ilDB->query("SELECT obj_fi, isonline FROM svy_qpl");
998  while ($row = $ilDB->fetchAssoc($result))
999  {
1000  $allqpls[$row['obj_fi']] = $row['isonline'];
1001  }
1002  foreach ($qpls as $ref_id)
1003  {
1004  $obj_id = ilObject::_lookupObjectId($ref_id);
1005  if (($could_be_offline) || ($allqpls[$obj_id]['isonline'] == 1))
1006  {
1007  if ($use_object_id)
1008  {
1009  $result_array[$obj_id] = $titles[$ref_id];
1010  }
1011  else
1012  {
1013  $result_array[$ref_id] = $titles[$ref_id];
1014  }
1015  }
1016  }
1017  return $result_array;
1018  }
1019 
1026  function isPluginActive($a_pname)
1027  {
1028  global $ilPluginAdmin;
1029  if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $a_pname))
1030  {
1031  return TRUE;
1032  }
1033  else
1034  {
1035  return FALSE;
1036  }
1037  }
1038 
1045  public function getQuestionInfos($question_ids)
1046  {
1047  global $ilDB;
1048 
1049  $found = array();
1050  $query_result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
1051  "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
1052  "AND svy_question.tstamp > 0 AND " . $ilDB->in('svy_question.question_id', $question_ids, false, 'integer') . " " .
1053  "ORDER BY svy_question.title");
1054  if ($query_result->numRows() > 0)
1055  {
1056  while ($data = $ilDB->fetchAssoc($query_result))
1057  {
1058  if (in_array($data["question_id"], $question_ids))
1059  {
1060  array_push($found, array('id' => $data["question_id"],
1061  'title' => $data["title"],
1062  'description' => $data["description"],
1063  'type_tag' => $data["type_tag"]));
1064  }
1065  }
1066  }
1067  return $found;
1068  }
1069 
1070  /*
1071  * Remove all questions with tstamp = 0
1072  */
1073  public function purgeQuestions()
1074  {
1075  global $ilDB, $ilUser;
1076 
1077  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1078  array("integer", "integer"),
1079  array($ilUser->getId(), 0)
1080  );
1081  while ($data = $ilDB->fetchAssoc($result))
1082  {
1083  $this->removeQuestion($data["question_id"]);
1084  }
1085  }
1086 
1092  public function copyToClipboard($question_id)
1093  {
1094  if (!array_key_exists("spl_clipboard", $_SESSION))
1095  {
1096  $_SESSION["spl_clipboard"] = array();
1097  }
1098  $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
1099  }
1100 
1106  public function moveToClipboard($question_id)
1107  {
1108  if (!array_key_exists("spl_clipboard", $_SESSION))
1109  {
1110  $_SESSION["spl_clipboard"] = array();
1111  }
1112  $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "move");
1113  }
1114 
1118  public function pasteFromClipboard()
1119  {
1120  global $ilDB;
1121 
1122  if (array_key_exists("spl_clipboard", $_SESSION))
1123  {
1124  foreach ($_SESSION["spl_clipboard"] as $question_object)
1125  {
1126  if (strcmp($question_object["action"], "move") == 0)
1127  {
1128  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1129  array('integer'),
1130  array($question_object["question_id"])
1131  );
1132  if ($result->numRows() == 1)
1133  {
1134  $row = $ilDB->fetchAssoc($result);
1135  $source_questionpool = $row["obj_fi"];
1136  if ($this->getId() != $source_questionpool)
1137  {
1138  // change the questionpool id in the qpl_questions table
1139  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1140  array('integer','integer'),
1141  array($this->getId(), $question_object["question_id"])
1142  );
1143 
1144  // move question data to the new target directory
1145  $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
1146  if (@is_dir($source_path))
1147  {
1148  $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/";
1149  if (!@is_dir($target_path))
1150  {
1151  include_once "./Services/Utilities/classes/class.ilUtil.php";
1152  ilUtil::makeDirParents($target_path);
1153  }
1154  @rename($source_path, $target_path . $question_object["question_id"]);
1155  }
1156  }
1157  else
1158  {
1159  ilUtil::sendFailure($this->lng->txt("spl_move_same_pool"), true);
1160  return;
1161  }
1162  }
1163  }
1164  else
1165  {
1166  $this->copyQuestion($question_object["question_id"], $this->getId());
1167  }
1168  }
1169  }
1170  ilUtil::sendSuccess($this->lng->txt("spl_paste_success"), true);
1171  unset($_SESSION["spl_clipboard"]);
1172  }
1173 
1180  function setObligatoryStates($obligatory_questions)
1181  {
1182  global $ilDB;
1183 
1184  foreach($this->getQuestions() as $question_id)
1185  {
1186  $status = (int)(in_array($question_id, $obligatory_questions));
1187 
1188  $ilDB->manipulate("UPDATE svy_question".
1189  " SET obligatory = ".$ilDB->quote($status, "integer").
1190  " WHERE question_id = ".$ilDB->quote($question_id, "integer"));
1191  }
1192  }
1193 
1194 } // END class.ilSurveyObjQuestionPool
1195 ?>