ILIAS  eassessment Revision 61809
 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 "./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 
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 != "." and
624  $entry != ".." and
625  substr($entry, -4) == ".xml" and
626  ereg("^[0-9]{10}_{2}[0-9]+_{2}(spl__)*[0-9]+\.xml\$", $entry))
627  {
628  $file[] = $entry;
629  }
630  }
631 
632  // close import directory
633  $dir->close();
634  // sort files
635  sort ($file);
636  reset ($file);
637 
638  return $file;
639  }
640 
647  {
648  include_once "./Services/Utilities/classes/class.ilUtil.php";
649  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
650  ilUtil::makeDir($spl_data_dir);
651 
652  if(!is_writable($spl_data_dir))
653  {
654  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
655  .") not writeable.",$this->ilias->error_obj->FATAL);
656  }
657 
658  // create test directory (data_dir/spl_data/spl_<id>)
659  $spl_dir = $spl_data_dir."/spl_".$this->getId();
660  ilUtil::makeDir($spl_dir);
661  if(!@is_dir($spl_dir))
662  {
663  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
664  }
665 
666  // create import subdirectory (data_dir/spl_data/spl_<id>/import)
667  $import_dir = $spl_dir."/import";
668  ilUtil::makeDir($import_dir);
669  if(!@is_dir($import_dir))
670  {
671  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
672  }
673  }
674 
679  {
680  include_once "./Services/Utilities/classes/class.ilUtil.php";
681  $import_dir = ilUtil::getDataDir()."/spl_data".
682  "/spl_".$this->getId()."/import";
683  if(@is_dir($import_dir))
684  {
685  return $import_dir;
686  }
687  else
688  {
689  return false;
690  }
691  }
692 
696  function toXML($questions)
697  {
698  if (!is_array($questions))
699  {
700  $questions =& $this->getQuestions();
701  }
702  if (count($questions) == 0)
703  {
704  $questions =& $this->getQuestions();
705  }
706  $xml = "";
707 
708  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
709  $a_xml_writer = new ilXmlWriter;
710  // set xml header
711  $a_xml_writer->xmlHeader();
712  $attrs = array(
713  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
714  "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
715  );
716  $a_xml_writer->xmlStartTag("surveyobject", $attrs);
717  $attrs = array(
718  "id" => "qpl_" . $this->getId(),
719  "label" => $this->getTitle()
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  $fh = fopen($source, "r") or die("");
785  $xml = fread($fh, filesize($source));
786  fclose($fh) or die("");
787  if (strpos($xml, "questestinterop") > 0)
788  {
789  // survey questions for ILIAS < 3.8
790  include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php";
791  $import = new SurveyImportParserPre38($this, "", $spl_exists);
792  $import->setXMLContent($xml);
793  $import->startParsing();
794  }
795  else
796  {
797  // survey questions for ILIAS >= 3.8
798  include_once "./Services/Survey/classes/class.SurveyImportParser.php";
799  $import = new SurveyImportParser($this, "", $spl_exists);
800  $import->setXMLContent($xml);
801  $import->startParsing();
802  }
803  }
804  }
805 
813  function setOnline($a_online_status)
814  {
815  switch ($a_online_status)
816  {
817  case 0:
818  case 1:
819  $this->online = $a_online_status;
820  break;
821  default:
822  $this->online = 0;
823  break;
824  }
825  }
826 
827  function getOnline()
828  {
829  if (strcmp($this->online, "") == 0) $this->online = "0";
830  return $this->online;
831  }
832 
833  function _lookupOnline($a_obj_id)
834  {
835  global $ilDB;
836 
837  $result = $ilDB->queryF("SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
838  array('integer'),
839  array($a_obj_id)
840  );
841  if ($result->numRows() == 1)
842  {
843  $row = $ilDB->fetchAssoc($result);
844  return $row["isonline"];
845  }
846  return 0;
847  }
848 
856  function _isWriteable($object_id, $user_id)
857  {
858  global $rbacsystem;
859  global $ilDB;
860 
861  $refs = ilObject::_getAllReferences($object_id);
862  $result = false;
863  foreach ($refs as $ref)
864  {
865  if ($rbacsystem->checkAccess("write", $ref) && (ilObject::_hasUntrashedReference($object_id)))
866  {
867  $result = true;
868  }
869  }
870  return $result;
871  }
872 
879  function &_getQuestiontypes()
880  {
881  global $ilDB;
882  global $lng;
883 
884  $lng->loadLanguageModule("survey");
885  $types = array();
886  $query_result = $ilDB->query("SELECT * FROM svy_qtype ORDER BY type_tag");
887  while ($row = $ilDB->fetchAssoc($query_result))
888  {
889  //array_push($questiontypes, $row["type_tag"]);
890  if ($row["plugin"] == 0)
891  {
892  $types[$lng->txt($row["type_tag"])] = $row;
893  }
894  else
895  {
896  global $ilPluginAdmin;
897  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
898  foreach ($pl_names as $pl_name)
899  {
900  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
901  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
902  {
903  $types[$pl->getQuestionTypeTranslation()] = $row;
904  }
905  }
906  }
907  }
908  ksort($types);
909  return $types;
910  }
911 
912  public static function &_getQuestionTypeTranslations()
913  {
914  global $ilDB;
915  global $lng;
916  global $ilLog;
917  global $ilPluginAdmin;
918 
919  $lng->loadLanguageModule("survey");
920  $result = $ilDB->query("SELECT * FROM svy_qtype");
921  $types = array();
922  while ($row = $ilDB->fetchAssoc($result))
923  {
924  if ($row["plugin"] == 0)
925  {
926  $types[$row['type_tag']] = $lng->txt($row["type_tag"]);
927  }
928  else
929  {
930  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
931  foreach ($pl_names as $pl_name)
932  {
933  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
934  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
935  {
936  $types[$row['type_tag']] = $pl->getQuestionTypeTranslation();
937  }
938  }
939  }
940  }
941  ksort($types);
942  return $types;
943  }
944 
951  function &_getAvailableQuestionpools($use_object_id = FALSE, $could_be_offline = FALSE, $showPath = FALSE, $permission = "read")
952  {
953  global $ilUser;
954  global $ilDB;
955 
956  $result_array = array();
957  $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
958  $titles = ilObject::_prepareCloneSelection($qpls, "spl");
959  $allqpls = array();
960  $result = $ilDB->query("SELECT obj_fi, isonline FROM svy_qpl");
961  while ($row = $ilDB->fetchAssoc($result))
962  {
963  $allqpls[$row['obj_fi']] = $row['isonline'];
964  }
965  foreach ($qpls as $ref_id)
966  {
967  $obj_id = ilObject::_lookupObjectId($ref_id);
968  if (($could_be_offline) || ($allqpls[$obj_id]['isonline'] == 1))
969  {
970  if ($use_object_id)
971  {
972  $result_array[$obj_id] = $titles[$ref_id];
973  }
974  else
975  {
976  $result_array[$ref_id] = $titles[$ref_id];
977  }
978  }
979  }
980  return $result_array;
981  }
982 
989  function isPluginActive($a_pname)
990  {
991  global $ilPluginAdmin;
992  if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $a_pname))
993  {
994  return TRUE;
995  }
996  else
997  {
998  return FALSE;
999  }
1000  }
1001 
1008  public function getQuestionInfos($question_ids)
1009  {
1010  global $ilDB;
1011 
1012  $found = array();
1013  $query_result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
1014  "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
1015  "AND svy_question.tstamp > 0 AND " . $ilDB->in('svy_question.question_id', $question_ids, false, 'integer') . " " .
1016  "ORDER BY svy_question.title");
1017  if ($query_result->numRows() > 0)
1018  {
1019  while ($data = $ilDB->fetchAssoc($query_result))
1020  {
1021  if (in_array($data["question_id"], $question_ids))
1022  {
1023  array_push($found, array('title' => $data["title"], 'description' => $data["description"], 'type_tag' => $data["type_tag"]));
1024  }
1025  }
1026  }
1027  return $found;
1028  }
1029 
1030  /*
1031  * Remove all questions with tstamp = 0
1032  */
1033  public function purgeQuestions()
1034  {
1035  global $ilDB, $ilUser;
1036 
1037  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1038  array("integer", "integer"),
1039  array($ilUser->getId(), 0)
1040  );
1041  while ($data = $ilDB->fetchAssoc($result))
1042  {
1043  $this->removeQuestion($data["question_id"]);
1044  }
1045  }
1046 
1052  public function copyToClipboard($question_id)
1053  {
1054  if (!array_key_exists("spl_clipboard", $_SESSION))
1055  {
1056  $_SESSION["spl_clipboard"] = array();
1057  }
1058  $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
1059  }
1060 
1066  public function moveToClipboard($question_id)
1067  {
1068  if (!array_key_exists("spl_clipboard", $_SESSION))
1069  {
1070  $_SESSION["spl_clipboard"] = array();
1071  }
1072  $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "move");
1073  }
1074 
1078  public function pasteFromClipboard()
1079  {
1080  global $ilDB;
1081 
1082  if (array_key_exists("spl_clipboard", $_SESSION))
1083  {
1084  foreach ($_SESSION["spl_clipboard"] as $question_object)
1085  {
1086  if (strcmp($question_object["action"], "move") == 0)
1087  {
1088  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1089  array('integer'),
1090  array($question_object["question_id"])
1091  );
1092  if ($result->numRows() == 1)
1093  {
1094  $row = $ilDB->fetchAssoc($result);
1095  $source_questionpool = $row["obj_fi"];
1096  if ($this->getId() != $source_questionpool)
1097  {
1098  // change the questionpool id in the qpl_questions table
1099  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1100  array('integer','integer'),
1101  array($this->getId(), $question_object["question_id"])
1102  );
1103 
1104  // move question data to the new target directory
1105  $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
1106  if (@is_dir($source_path))
1107  {
1108  $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/";
1109  if (!@is_dir($target_path))
1110  {
1111  include_once "./Services/Utilities/classes/class.ilUtil.php";
1112  ilUtil::makeDirParents($target_path);
1113  }
1114  @rename($source_path, $target_path . $question_object["question_id"]);
1115  }
1116  }
1117  else
1118  {
1119  ilUtil::sendFailure($this->lng->txt("spl_move_same_pool"), true);
1120  return;
1121  }
1122  }
1123  }
1124  else
1125  {
1126  $this->copyQuestion($question_object["question_id"], $this->getId());
1127  }
1128  }
1129  }
1130  ilUtil::sendSuccess($this->lng->txt("spl_paste_success"), true);
1131  unset($_SESSION["spl_clipboard"]);
1132  }
1133 } // END class.ilSurveyObjQuestionPool
1134 ?>