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