ILIAS  Release_4_0_x_branch Revision 61816
 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  if (array_key_exists('title', $arrFilter) && strlen($arrFilter['title']))
515  {
516  $where .= " AND " . $ilDB->like('svy_question.title', 'text', "%%" . $arrFilter['title'] . "%%");
517  }
518  if (array_key_exists('description', $arrFilter) && strlen($arrFilter['description']))
519  {
520  $where .= " AND " . $ilDB->like('svy_question.description', 'text', "%%" . $arrFilter['description'] . "%%");
521  }
522  if (array_key_exists('author', $arrFilter) && strlen($arrFilter['author']))
523  {
524  $where .= " AND " . $ilDB->like('svy_question.author', 'text', "%%" . $arrFilter['author'] . "%%");
525  }
526  if (array_key_exists('type', $arrFilter) && strlen($arrFilter['type']))
527  {
528  $where .= " AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter['type'], 'text');
529  }
530  }
531  $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,
532  array('integer'),
533  array($this->getId())
534  );
535  $rows = array();
536  if ($query_result->numRows())
537  {
538  while ($row = $ilDB->fetchAssoc($query_result))
539  {
540  if ($row["plugin"])
541  {
542  if ($this->isPluginActive($row["type_tag"]))
543  {
544  array_push($rows, $row);
545  }
546  }
547  else
548  {
549  array_push($rows, $row);
550  }
551  }
552  }
553  return $rows;
554  }
555 
562  {
563  include_once "./Services/Utilities/classes/class.ilUtil.php";
564  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
565  ilUtil::makeDir($spl_data_dir);
566  if(!is_writable($spl_data_dir))
567  {
568  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
569  .") not writeable.",$this->ilias->error_obj->FATAL);
570  }
571 
572  // create learning module directory (data_dir/lm_data/lm_<id>)
573  $spl_dir = $spl_data_dir."/spl_".$this->getId();
574  ilUtil::makeDir($spl_dir);
575  if(!@is_dir($spl_dir))
576  {
577  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
578  }
579  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
580  $export_dir = $spl_dir."/export";
581  ilUtil::makeDir($export_dir);
582  if(!@is_dir($export_dir))
583  {
584  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
585  }
586  }
587 
592  {
593  include_once "./Services/Utilities/classes/class.ilUtil.php";
594  $export_dir = ilUtil::getDataDir()."/spl_data"."/spl_".$this->getId()."/export";
595  return $export_dir;
596  }
597 
602  {
603  // quit if import dir not available
604  if (!@is_dir($dir) or
605  !is_writeable($dir))
606  {
607  return array();
608  }
609 
610  // open directory
611  $dir = dir($dir);
612 
613  // initialize array
614  $file = array();
615 
616  // get files and save the in the array
617  while ($entry = $dir->read())
618  {
619  if ($entry != "." and
620  $entry != ".." and
621  substr($entry, -4) == ".xml" and
622  ereg("^[0-9]{10}_{2}[0-9]+_{2}(spl__)*[0-9]+\.xml\$", $entry))
623  {
624  $file[] = $entry;
625  }
626  }
627 
628  // close import directory
629  $dir->close();
630  // sort files
631  sort ($file);
632  reset ($file);
633 
634  return $file;
635  }
636 
643  {
644  include_once "./Services/Utilities/classes/class.ilUtil.php";
645  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
646  ilUtil::makeDir($spl_data_dir);
647 
648  if(!is_writable($spl_data_dir))
649  {
650  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
651  .") not writeable.",$this->ilias->error_obj->FATAL);
652  }
653 
654  // create test directory (data_dir/spl_data/spl_<id>)
655  $spl_dir = $spl_data_dir."/spl_".$this->getId();
656  ilUtil::makeDir($spl_dir);
657  if(!@is_dir($spl_dir))
658  {
659  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
660  }
661 
662  // create import subdirectory (data_dir/spl_data/spl_<id>/import)
663  $import_dir = $spl_dir."/import";
664  ilUtil::makeDir($import_dir);
665  if(!@is_dir($import_dir))
666  {
667  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
668  }
669  }
670 
675  {
676  include_once "./Services/Utilities/classes/class.ilUtil.php";
677  $import_dir = ilUtil::getDataDir()."/spl_data".
678  "/spl_".$this->getId()."/import";
679  if(@is_dir($import_dir))
680  {
681  return $import_dir;
682  }
683  else
684  {
685  return false;
686  }
687  }
688 
692  function toXML($questions)
693  {
694  if (!is_array($questions))
695  {
696  $questions =& $this->getQuestions();
697  }
698  if (count($questions) == 0)
699  {
700  $questions =& $this->getQuestions();
701  }
702  $xml = "";
703 
704  include_once("./classes/class.ilXmlWriter.php");
705  $a_xml_writer = new ilXmlWriter;
706  // set xml header
707  $a_xml_writer->xmlHeader();
708  $attrs = array(
709  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
710  "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
711  );
712  $a_xml_writer->xmlStartTag("surveyobject", $attrs);
713  $attrs = array(
714  "id" => "qpl_" . $this->getId(),
715  "label" => $this->getTitle()
716  );
717  $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
718  $a_xml_writer->xmlElement("dummy", NULL, "dummy");
719  // add ILIAS specific metadata
720  $a_xml_writer->xmlStartTag("metadata");
721  $a_xml_writer->xmlStartTag("metadatafield");
722  $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
723  include_once "./Services/MetaData/classes/class.ilMD.php";
724  $md = new ilMD($this->getId(),0, $this->getType());
725  $writer = new ilXmlWriter();
726  $md->toXml($writer);
727  $metadata = $writer->xmlDumpMem();
728  $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
729  $a_xml_writer->xmlEndTag("metadatafield");
730  $a_xml_writer->xmlEndTag("metadata");
731 
732  $a_xml_writer->xmlEndTag("surveyquestions");
733  $a_xml_writer->xmlEndTag("surveyobject");
734 
735  $xml = $a_xml_writer->xmlDumpMem(FALSE);
736 
737  $questionxml = "";
738  foreach ($questions as $key => $value)
739  {
740  $questiontype = $this->getQuestiontype($value);
741  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
742  SurveyQuestion::_includeClass($questiontype);
743  $question = new $questiontype();
744  $question->loadFromDb($value);
745  $questionxml .= $question->toXML(false);
746  }
747 
748  $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
749  return $xml;
750  }
751 
752  function &getQuestions()
753  {
754  global $ilDB;
755  $questions = array();
756  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
757  array('integer'),
758  array($this->getId())
759  );
760  if ($result->numRows())
761  {
762  while ($row = $ilDB->fetchAssoc($result))
763  {
764  array_push($questions, $row["question_id"]);
765  }
766  }
767  return $questions;
768  }
769 
776  function importObject($source, $spl_exists = FALSE)
777  {
778  if (is_file($source))
779  {
780  $fh = fopen($source, "r") or die("");
781  $xml = fread($fh, filesize($source));
782  fclose($fh) or die("");
783  if (strpos($xml, "questestinterop") > 0)
784  {
785  // survey questions for ILIAS < 3.8
786  include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php";
787  $import = new SurveyImportParserPre38($this, "", $spl_exists);
788  $import->setXMLContent($xml);
789  $import->startParsing();
790  }
791  else
792  {
793  // survey questions for ILIAS >= 3.8
794  include_once "./Services/Survey/classes/class.SurveyImportParser.php";
795  $import = new SurveyImportParser($this, "", $spl_exists);
796  $import->setXMLContent($xml);
797  $import->startParsing();
798  }
799  }
800  }
801 
809  function setOnline($a_online_status)
810  {
811  switch ($a_online_status)
812  {
813  case 0:
814  case 1:
815  $this->online = $a_online_status;
816  break;
817  default:
818  $this->online = 0;
819  break;
820  }
821  }
822 
823  function getOnline()
824  {
825  if (strcmp($this->online, "") == 0) $this->online = "0";
826  return $this->online;
827  }
828 
829  function _lookupOnline($a_obj_id)
830  {
831  global $ilDB;
832 
833  $result = $ilDB->queryF("SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
834  array('integer'),
835  array($a_obj_id)
836  );
837  if ($result->numRows() == 1)
838  {
839  $row = $ilDB->fetchAssoc($result);
840  return $row["isonline"];
841  }
842  return 0;
843  }
844 
852  function _isWriteable($object_id, $user_id)
853  {
854  global $rbacsystem;
855  global $ilDB;
856 
857  $refs = ilObject::_getAllReferences($object_id);
858  $result = false;
859  foreach ($refs as $ref)
860  {
861  if ($rbacsystem->checkAccess("write", $ref) && (ilObject::_hasUntrashedReference($object_id)))
862  {
863  $result = true;
864  }
865  }
866  return $result;
867  }
868 
875  function &_getQuestiontypes()
876  {
877  global $ilDB;
878  global $lng;
879 
880  $lng->loadLanguageModule("survey");
881  $types = array();
882  $query_result = $ilDB->query("SELECT * FROM svy_qtype ORDER BY type_tag");
883  while ($row = $ilDB->fetchAssoc($query_result))
884  {
885  //array_push($questiontypes, $row["type_tag"]);
886  if ($row["plugin"] == 0)
887  {
888  $types[$lng->txt($row["type_tag"])] = $row;
889  }
890  else
891  {
892  global $ilPluginAdmin;
893  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
894  foreach ($pl_names as $pl_name)
895  {
896  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
897  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
898  {
899  $types[$pl->getQuestionTypeTranslation()] = $row;
900  }
901  }
902  }
903  }
904  ksort($types);
905  return $types;
906  }
907 
908  public static function &_getQuestionTypeTranslations()
909  {
910  global $ilDB;
911  global $lng;
912  global $ilLog;
913  global $ilPluginAdmin;
914 
915  $lng->loadLanguageModule("survey");
916  $result = $ilDB->query("SELECT * FROM svy_qtype");
917  $types = array();
918  while ($row = $ilDB->fetchAssoc($result))
919  {
920  if ($row["plugin"] == 0)
921  {
922  $types[$row['type_tag']] = $lng->txt($row["type_tag"]);
923  }
924  else
925  {
926  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
927  foreach ($pl_names as $pl_name)
928  {
929  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
930  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
931  {
932  $types[$row['type_tag']] = $pl->getQuestionTypeTranslation();
933  }
934  }
935  }
936  }
937  ksort($types);
938  return $types;
939  }
940 
947  function &_getAvailableQuestionpools($use_object_id = FALSE, $could_be_offline = FALSE, $showPath = FALSE, $permission = "read")
948  {
949  global $ilUser;
950  global $ilDB;
951 
952  $result_array = array();
953  $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
954  $titles = ilObject::_prepareCloneSelection($qpls, "spl");
955  $allqpls = array();
956  $result = $ilDB->query("SELECT obj_fi, isonline FROM svy_qpl");
957  while ($row = $ilDB->fetchAssoc($result))
958  {
959  $allqpls[$row['obj_fi']] = $row['isonline'];
960  }
961  foreach ($qpls as $ref_id)
962  {
963  $obj_id = ilObject::_lookupObjectId($ref_id);
964  if (($could_be_offline) || ($allqpls[$obj_id]['isonline'] == 1))
965  {
966  if ($use_object_id)
967  {
968  $result_array[$obj_id] = $titles[$ref_id];
969  }
970  else
971  {
972  $result_array[$ref_id] = $titles[$ref_id];
973  }
974  }
975  }
976  return $result_array;
977  }
978 
985  function isPluginActive($a_pname)
986  {
987  global $ilPluginAdmin;
988  if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $a_pname))
989  {
990  return TRUE;
991  }
992  else
993  {
994  return FALSE;
995  }
996  }
997 
1004  public function getQuestionInfos($question_ids)
1005  {
1006  global $ilDB;
1007 
1008  $found = array();
1009  $query_result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
1010  "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
1011  "AND svy_question.tstamp > 0 AND " . $ilDB->in('svy_question.question_id', $question_ids, false, 'integer') . " " .
1012  "ORDER BY svy_question.title");
1013  if ($query_result->numRows() > 0)
1014  {
1015  while ($data = $ilDB->fetchAssoc($query_result))
1016  {
1017  if (in_array($data["question_id"], $question_ids))
1018  {
1019  array_push($found, array('title' => $data["title"], 'description' => $data["description"], 'type_tag' => $data["type_tag"]));
1020  }
1021  }
1022  }
1023  return $found;
1024  }
1025 
1026  /*
1027  * Remove all questions with tstamp = 0
1028  */
1029  public function purgeQuestions()
1030  {
1031  global $ilDB, $ilUser;
1032 
1033  $result = $ilDB->queryF("SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1034  array("integer", "integer"),
1035  array($ilUser->getId(), 0)
1036  );
1037  while ($data = $ilDB->fetchAssoc($result))
1038  {
1039  $this->removeQuestion($data["question_id"]);
1040  }
1041  }
1042 
1048  public function copyToClipboard($question_id)
1049  {
1050  if (!array_key_exists("spl_clipboard", $_SESSION))
1051  {
1052  $_SESSION["spl_clipboard"] = array();
1053  }
1054  $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
1055  }
1056 
1062  public function moveToClipboard($question_id)
1063  {
1064  if (!array_key_exists("spl_clipboard", $_SESSION))
1065  {
1066  $_SESSION["spl_clipboard"] = array();
1067  }
1068  $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "move");
1069  }
1070 
1074  public function pasteFromClipboard()
1075  {
1076  global $ilDB;
1077 
1078  if (array_key_exists("spl_clipboard", $_SESSION))
1079  {
1080  foreach ($_SESSION["spl_clipboard"] as $question_object)
1081  {
1082  if (strcmp($question_object["action"], "move") == 0)
1083  {
1084  $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s",
1085  array('integer'),
1086  array($question_object["question_id"])
1087  );
1088  if ($result->numRows() == 1)
1089  {
1090  $row = $ilDB->fetchAssoc($result);
1091  $source_questionpool = $row["obj_fi"];
1092  if ($this->getId() != $source_questionpool)
1093  {
1094  // change the questionpool id in the qpl_questions table
1095  $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1096  array('integer','integer'),
1097  array($this->getId(), $question_object["question_id"])
1098  );
1099 
1100  // move question data to the new target directory
1101  $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
1102  if (@is_dir($source_path))
1103  {
1104  $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/";
1105  if (!@is_dir($target_path))
1106  {
1107  include_once "./Services/Utilities/classes/class.ilUtil.php";
1108  ilUtil::makeDirParents($target_path);
1109  }
1110  @rename($source_path, $target_path . $question_object["question_id"]);
1111  }
1112  }
1113  else
1114  {
1115  ilUtil::sendFailure($this->lng->txt("spl_move_same_pool"), true);
1116  return;
1117  }
1118  }
1119  }
1120  else
1121  {
1122  $this->copyQuestion($question_object["question_id"], $this->getId());
1123  }
1124  }
1125  }
1126  ilUtil::sendSuccess($this->lng->txt("spl_paste_success"), true);
1127  unset($_SESSION["spl_clipboard"]);
1128  }
1129 } // END class.ilSurveyObjQuestionPool
1130 ?>