ILIAS  Release_3_10_x_branch Revision 61812
 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 
107  function cloneObject($a_target_id,$a_copy_id = 0)
108  {
109  global $ilLog;
110  $newObj = parent::cloneObject($a_target_id,$a_copy_id);
111  $newObj->setOnline($this->getOnline());
112  $newObj->saveToDb();
113  // clone the questions in the question pool
114  $questions =& $this->getQuestions();
115  foreach ($questions as $question_id)
116  {
117  $newObj->copyQuestion($question_id, $newObj->getId());
118  }
119 
120  // clone meta data
121  include_once "./Services/MetaData/classes/class.ilMD.php";
122  $md = new ilMD($this->getId(),0,$this->getType());
123  $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
124 
125  // update the metadata with the new title of the question pool
126  $newObj->updateMetaData();
127  return $newObj;
128  }
129 
130  function &createQuestion($question_type, $question_id = -1)
131  {
132  if ((!$question_type) and ($question_id > 0))
133  {
134  $question_type = $this->getQuestiontype($question_id);
135  }
136 
137  include_once "./Modules/SurveyQuestionPool/classes/class.".$question_type."GUI.php";
138  $question_type_gui = $question_type . "GUI";
139  $question =& new $question_type_gui();
140 
141  if ($question_id > 0)
142  {
143  $question->object->loadFromDb($question_id);
144  }
145 
146  return $question;
147  }
148 
158  function copyQuestion($question_id, $questionpool_to)
159  {
160  $question_gui =& $this->createQuestion("", $question_id);
161  if ($question_gui->object->getObjId() == $questionpool_to)
162  {
163  // the question is copied into the same question pool
164  $this->duplicateQuestion($question_id);
165  }
166  else
167  {
168  // the question is copied into another question pool
169  $newtitle = $question_gui->object->getTitle();
170  if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to))
171  {
172  $counter = 2;
173  while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() . " ($counter)", $questionpool_to))
174  {
175  $counter++;
176  }
177  $newtitle = $question_gui->object->getTitle() . " ($counter)";
178  }
179  $question_gui->object->copyObject($this->getId(), $newtitle);
180  }
181  }
182 
190  function loadFromDb()
191  {
192  global $ilDB;
193 
194  $query = sprintf("SELECT * FROM survey_questionpool WHERE obj_fi = %s",
195  $ilDB->quote($this->getId() . "")
196  );
197  $result = $ilDB->query($query);
198  if ($result->numRows() == 1)
199  {
200  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
201  $this->setOnline($row["online"]);
202  }
203  }
204 
212  function saveToDb()
213  {
214  global $ilDB;
215 
216  $query = sprintf("SELECT * FROM survey_questionpool WHERE obj_fi = %s",
217  $ilDB->quote($this->getId() . "")
218  );
219  $result = $ilDB->query($query);
220  if ($result->numRows() == 1)
221  {
222  $query = sprintf("UPDATE survey_questionpool SET online = %s WHERE obj_fi = %s",
223  $ilDB->quote($this->getOnline() . ""),
224  $ilDB->quote($this->getId() . "")
225  );
226  $result = $ilDB->query($query);
227  if (PEAR::isError($result))
228  {
229  global $ilias;
230  $ilias->raiseError($result->getMessage());
231  }
232  }
233  else
234  {
235  $query = sprintf("INSERT INTO survey_questionpool (online, obj_fi) VALUES (%s, %s)",
236  $ilDB->quote($this->getOnline() . ""),
237  $ilDB->quote($this->getId() . "")
238  );
239  $result = $ilDB->query($query);
240  if (PEAR::isError($result))
241  {
242  global $ilias;
243  $ilias->raiseError($result->getMessage());
244  }
245  }
246  }
247 
254  function delete()
255  {
256  $remove = parent::delete();
257  // always call parent delete function first!!
258  if (!$remove)
259  {
260  return false;
261  }
262 
263  // delete all related questions
264  $this->deleteAllData();
265 
266  // delete meta data
267  $this->deleteMetaData();
268 
269  return true;
270  }
271 
272  function deleteAllData()
273  {
274  $query = sprintf("SELECT question_id FROM survey_question WHERE obj_fi = %s AND original_id IS NULL",
275  $this->ilias->db->quote($this->getId())
276  );
277  $result = $this->ilias->db->query($query);
278  $found_questions = array();
279  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
280  {
281  $this->removeQuestion($row["question_id"]);
282  }
283 
284  // delete export files
285  include_once "./Services/Utilities/classes/class.ilUtil.php";
286  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
287  $directory = $spl_data_dir."/spl_".$this->getId();
288  if (is_dir($directory))
289  {
290  include_once "./Services/Utilities/classes/class.ilUtil.php";
291  ilUtil::delDir($directory);
292  }
293  }
294 
308  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
309  {
310  global $tree;
311 
312  switch ($a_event)
313  {
314  case "link":
315 
316  //var_dump("<pre>",$a_params,"</pre>");
317  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
318  //exit;
319  break;
320 
321  case "cut":
322 
323  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
324  //exit;
325  break;
326 
327  case "copy":
328 
329  //var_dump("<pre>",$a_params,"</pre>");
330  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
331  //exit;
332  break;
333 
334  case "paste":
335 
336  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
337  //exit;
338  break;
339 
340  case "new":
341 
342  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
343  //exit;
344  break;
345  }
346 
347  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
348  if ($a_node_id==$_GET["ref_id"])
349  {
350  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
351  $parent_type = $parent_obj->getType();
352  if($parent_type == $this->getType())
353  {
354  $a_node_id = (int) $tree->getParentId($a_node_id);
355  }
356  }
357 
358  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
359  }
360 
366  function getTitle()
367  {
368  //return $this->title;
369  return parent::getTitle();
370  }
371 
375  function setTitle($a_title)
376  {
377  parent::setTitle($a_title);
378  }
379 
388  function removeQuestion($question_id)
389  {
390  if ($question_id < 1) return;
391  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
392  $question =& SurveyQuestion::_instanciateQuestion($question_id);
393  $question->delete($question_id);
394  }
395 
405  function getQuestiontype($question_id)
406  {
407  if ($question_id < 1) return;
408  $query = sprintf("SELECT survey_questiontype.type_tag FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id = %s",
409  $this->ilias->db->quote($question_id)
410  );
411  $result = $this->ilias->db->query($query);
412  if ($result->numRows() == 1)
413  {
414  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
415  return $data->type_tag;
416  } else {
417  return;
418  }
419  }
420 
430  function isInUse($question_id)
431  {
432  // check out the already answered questions
433  $query = sprintf("SELECT answer_id FROM survey_answer WHERE question_fi = %s",
434  $this->ilias->db->quote($question_id)
435  );
436  $result = $this->ilias->db->query($query);
437  $answered = $result->numRows();
438 
439  // check out the questions inserted in surveys
440  $query = sprintf("SELECT survey_survey.* FROM survey_survey, survey_survey_question WHERE survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = %s",
441  $this->ilias->db->quote($question_id)
442  );
443  $result = $this->ilias->db->query($query);
444  $inserted = $result->numRows();
445  if (($inserted + $answered) == 0)
446  {
447  return false;
448  }
449  $result_array = array();
450  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
451  {
452  array_push($result_array, $row);
453  }
454  return $result_array;
455  }
456 
465  function paste($question_id)
466  {
467  $this->duplicateQuestion($question_id, $this->getId());
468  }
469 
479  function &getQuestionsInfo($question_array)
480  {
481  $result_array = array();
482  $query = sprintf("SELECT survey_question.*, survey_questiontype.type_tag, survey_questiontype.plugin FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id IN ('%s')",
483  join($question_array, "','")
484  );
485  $result = $this->ilias->db->query($query);
486  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
487  {
488  if ($row["plugin"])
489  {
490  if ($this->isPluginActive($row["type_tag"]))
491  {
492  array_push($result_array, $row);
493  }
494  }
495  else
496  {
497  array_push($result_array, $row);
498  }
499  }
500  return $result_array;
501  }
502 
511  function duplicateQuestion($question_id, $obj_id = "")
512  {
513  global $ilUser;
514  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
515  $question = SurveyQuestion::_instanciateQuestion($question_id);
516  $suffix = "";
517  $counter = 1;
518  while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id))
519  {
520  $counter++;
521  if ($counter > 1) $suffix = " ($counter)";
522  }
523  if ($obj_id)
524  {
525  $question->setObjId($obj_id);
526  }
527  $question->duplicate(false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
528  }
529 
537  function getQuestionsTable($sort, $sortorder, $filter_text, $sel_filter_type, $startrow = 0)
538  {
539  global $ilUser;
540  $where = "";
541  if (strlen($filter_text) > 0)
542  {
543  switch($sel_filter_type)
544  {
545  case "title":
546  $where = " AND survey_question.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
547  break;
548  case "description":
549  $where = " AND survey_question.description LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
550  break;
551  case "author":
552  $where = " AND survey_question.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
553  break;
554  }
555  }
556 
557  // build sort order for sql query
558  $order = "";
559  $images = array();
560  include_once "./Services/Utilities/classes/class.ilUtil.php";
561  switch ($sort)
562  {
563  case "title":
564  $order = " ORDER BY title $sortorder";
565  $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
566  break;
567  case "description":
568  $order = " ORDER BY description $sortorder";
569  $images["description"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
570  break;
571  case "type":
572  $order = " ORDER BY questiontype_id $sortorder";
573  $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
574  break;
575  case "author":
576  $order = " ORDER BY author $sortorder";
577  $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
578  break;
579  case "created":
580  $order = " ORDER BY created $sortorder";
581  $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
582  break;
583  case "updated":
584  $order = " ORDER BY timestamp14 $sortorder";
585  $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
586  break;
587  }
588  $maxentries = $ilUser->prefs["hits_per_page"];
589  if ($maxentries < 1)
590  {
591  $maxentries = 9999;
592  }
593  $query = "SELECT survey_question.question_id, survey_question.TIMESTAMP + 0 AS timestamp14 FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.obj_fi = " . $this->getId() . " AND ISNULL(survey_question.original_id) $where$order$limit";
594  $query_result = $this->ilias->db->query($query);
595  $max = $query_result->numRows();
596  if ($startrow > $max -1)
597  {
598  $startrow = $max - ($max % $maxentries);
599  }
600  else if ($startrow < 0)
601  {
602  $startrow = 0;
603  }
604  $limit = " LIMIT $startrow, $maxentries";
605  $query = "SELECT survey_question.*, survey_question.TIMESTAMP + 0 AS timestamp14, survey_questiontype.type_tag, survey_questiontype.plugin FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.obj_fi = " . $this->getId() . " AND ISNULL(survey_question.original_id) $where$order$limit";
606  $query_result = $this->ilias->db->query($query);
607  $rows = array();
608  if ($query_result->numRows())
609  {
610  while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
611  {
612  if ($row["plugin"])
613  {
614  if ($this->isPluginActive($row["type_tag"]))
615  {
616  array_push($rows, $row);
617  }
618  }
619  else
620  {
621  array_push($rows, $row);
622  }
623  }
624  }
625  $nextrow = $startrow + $maxentries;
626  if ($nextrow > $max - 1)
627  {
628  $nextrow = $startrow;
629  }
630  $prevrow = $startrow - $maxentries;
631  if ($prevrow < 0)
632  {
633  $prevrow = 0;
634  }
635  return array(
636  "rows" => $rows,
637  "images" => $images,
638  "startrow" => $startrow,
639  "nextrow" => $nextrow,
640  "prevrow" => $prevrow,
641  "step" => $maxentries,
642  "rowcount" => $max
643  );
644  }
645 
652  {
653  include_once "./Services/Utilities/classes/class.ilUtil.php";
654  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
655  ilUtil::makeDir($spl_data_dir);
656  if(!is_writable($spl_data_dir))
657  {
658  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
659  .") not writeable.",$this->ilias->error_obj->FATAL);
660  }
661 
662  // create learning module directory (data_dir/lm_data/lm_<id>)
663  $spl_dir = $spl_data_dir."/spl_".$this->getId();
664  ilUtil::makeDir($spl_dir);
665  if(!@is_dir($spl_dir))
666  {
667  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
668  }
669  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
670  $export_dir = $spl_dir."/export";
671  ilUtil::makeDir($export_dir);
672  if(!@is_dir($export_dir))
673  {
674  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
675  }
676  }
677 
682  {
683  include_once "./Services/Utilities/classes/class.ilUtil.php";
684  $export_dir = ilUtil::getDataDir()."/spl_data"."/spl_".$this->getId()."/export";
685  return $export_dir;
686  }
687 
692  {
693  // quit if import dir not available
694  if (!@is_dir($dir) or
695  !is_writeable($dir))
696  {
697  return array();
698  }
699 
700  // open directory
701  $dir = dir($dir);
702 
703  // initialize array
704  $file = array();
705 
706  // get files and save the in the array
707  while ($entry = $dir->read())
708  {
709  if ($entry != "." and
710  $entry != ".." and
711  substr($entry, -4) == ".xml" and
712  ereg("^[0-9]{10}_{2}[0-9]+_{2}(spl__)*[0-9]+\.xml\$", $entry))
713  {
714  $file[] = $entry;
715  }
716  }
717 
718  // close import directory
719  $dir->close();
720  // sort files
721  sort ($file);
722  reset ($file);
723 
724  return $file;
725  }
726 
733  {
734  include_once "./Services/Utilities/classes/class.ilUtil.php";
735  $spl_data_dir = ilUtil::getDataDir()."/spl_data";
736  ilUtil::makeDir($spl_data_dir);
737 
738  if(!is_writable($spl_data_dir))
739  {
740  $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
741  .") not writeable.",$this->ilias->error_obj->FATAL);
742  }
743 
744  // create test directory (data_dir/spl_data/spl_<id>)
745  $spl_dir = $spl_data_dir."/spl_".$this->getId();
746  ilUtil::makeDir($spl_dir);
747  if(!@is_dir($spl_dir))
748  {
749  $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
750  }
751 
752  // create import subdirectory (data_dir/spl_data/spl_<id>/import)
753  $import_dir = $spl_dir."/import";
754  ilUtil::makeDir($import_dir);
755  if(!@is_dir($import_dir))
756  {
757  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
758  }
759  }
760 
765  {
766  include_once "./Services/Utilities/classes/class.ilUtil.php";
767  $import_dir = ilUtil::getDataDir()."/spl_data".
768  "/spl_".$this->getId()."/import";
769  if(@is_dir($import_dir))
770  {
771  return $import_dir;
772  }
773  else
774  {
775  return false;
776  }
777  }
778 
782  function toXML($questions)
783  {
784  if (!is_array($questions))
785  {
786  $questions =& $this->getQuestions();
787  }
788  if (count($questions) == 0)
789  {
790  $questions =& $this->getQuestions();
791  }
792  $xml = "";
793 
794  include_once("./classes/class.ilXmlWriter.php");
795  $a_xml_writer = new ilXmlWriter;
796  // set xml header
797  $a_xml_writer->xmlHeader();
798  $attrs = array(
799  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
800  "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
801  );
802  $a_xml_writer->xmlStartTag("surveyobject", $attrs);
803  $attrs = array(
804  "id" => "qpl_" . $this->getId(),
805  "label" => $this->getTitle()
806  );
807  $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
808  $a_xml_writer->xmlElement("dummy", NULL, "dummy");
809  // add ILIAS specific metadata
810  $a_xml_writer->xmlStartTag("metadata");
811  $a_xml_writer->xmlStartTag("metadatafield");
812  $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
813  include_once "./Services/MetaData/classes/class.ilMD.php";
814  $md = new ilMD($this->getId(),0, $this->getType());
815  $writer = new ilXmlWriter();
816  $md->toXml($writer);
817  $metadata = $writer->xmlDumpMem();
818  $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
819  $a_xml_writer->xmlEndTag("metadatafield");
820  $a_xml_writer->xmlEndTag("metadata");
821 
822  $a_xml_writer->xmlEndTag("surveyquestions");
823  $a_xml_writer->xmlEndTag("surveyobject");
824 
825  $xml = $a_xml_writer->xmlDumpMem(FALSE);
826 
827  $questionxml = "";
828  foreach ($questions as $key => $value)
829  {
830  $questiontype = $this->getQuestiontype($value);
831  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
832  SurveyQuestion::_includeClass($questiontype);
833  $question = new $questiontype();
834  $question->loadFromDb($value);
835  $questionxml .= $question->toXML(false);
836  }
837 
838  $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
839  return $xml;
840  }
841 
842  function &getQuestions()
843  {
844  $questions = array();
845  $query = sprintf("SELECT question_id FROM survey_question WHERE obj_fi = %s AND ISNULL(original_id)",
846  $this->ilias->db->quote($this->getId() . "")
847  );
848  $result = $this->ilias->db->query($query);
849  if ($result->numRows())
850  {
851  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
852  {
853  array_push($questions, $row["question_id"]);
854  }
855  }
856  return $questions;
857  }
858 
867  function importObject($source, $spl_exists = FALSE)
868  {
869  if (is_file($source))
870  {
871  $fh = fopen($source, "r") or die("");
872  $xml = fread($fh, filesize($source));
873  fclose($fh) or die("");
874  if (strpos($xml, "questestinterop") > 0)
875  {
876  // survey questions for ILIAS < 3.8
877  include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php";
878  $import = new SurveyImportParserPre38($this, "", $spl_exists);
879  $import->setXMLContent($xml);
880  $import->startParsing();
881  }
882  else
883  {
884  // survey questions for ILIAS >= 3.8
885  include_once "./Services/Survey/classes/class.SurveyImportParser.php";
886  $import = new SurveyImportParser($this, "", $spl_exists);
887  $import->setXMLContent($xml);
888  $import->startParsing();
889  }
890  }
891  }
892 
902  function setOnline($a_online_status)
903  {
904  switch ($a_online_status)
905  {
906  case 0:
907  case 1:
908  $this->online = $a_online_status;
909  break;
910  default:
911  $this->online = 0;
912  break;
913  }
914  }
915 
916  function getOnline()
917  {
918  if (strcmp($this->online, "") == 0) $this->online = "0";
919  return $this->online;
920  }
921 
922  function _lookupOnline($a_obj_id)
923  {
924  global $ilDB;
925 
926  $query = sprintf("SELECT online FROM survey_questionpool WHERE obj_fi = %s",
927  $ilDB->quote($a_obj_id . "")
928  );
929  $result = $ilDB->query($query);
930  if ($result->numRows() == 1)
931  {
932  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
933  return $row["online"];
934  }
935  return 0;
936  }
937 
947  function _isWriteable($object_id, $user_id)
948  {
949  global $rbacsystem;
950  global $ilDB;
951 
952  $result_array = array();
953  $query = sprintf("SELECT object_data.*, object_data.obj_id, object_reference.ref_id FROM object_data, object_reference WHERE object_data.obj_id = object_reference.obj_id AND object_data.obj_id = %s",
954  $ilDB->quote($object_id . "")
955  );
956  $result = $ilDB->query($query);
957  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
958  {
959  include_once "./classes/class.ilObject.php";
960  if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
961  {
962  return true;
963  }
964  }
965  return false;
966  }
967 
976  function &_getQuestiontypes()
977  {
978  global $ilDB;
979  global $lng;
980 
981  $lng->loadLanguageModule("survey");
982  $types = array();
983  $query = "SELECT * FROM survey_questiontype ORDER BY type_tag";
984  $query_result = $ilDB->query($query);
985  while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
986  {
987  //array_push($questiontypes, $row["type_tag"]);
988  if ($row["plugin"] == 0)
989  {
990  $types[$lng->txt($row["type_tag"])] = $row;
991  }
992  else
993  {
994  global $ilPluginAdmin;
995  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
996  foreach ($pl_names as $pl_name)
997  {
998  $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
999  if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0)
1000  {
1001  $types[$pl->getQuestionTypeTranslation()] = $row;
1002  }
1003  }
1004  }
1005  }
1006  ksort($types);
1007  return $types;
1008  }
1009 
1018  function &_getAvailableQuestionpools($use_object_id = FALSE, $could_be_offline = FALSE, $showPath = FALSE, $permission = "read")
1019  {
1020  global $ilUser;
1021  global $ilDB;
1022 
1023  $result_array = array();
1024  $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
1025  $titles = ilObject::_prepareCloneSelection($qpls, "spl");
1026  if (count($qpls))
1027  {
1028  $query = "";
1029  if ($could_be_offline)
1030  {
1031  $query = sprintf("SELECT object_data.*, object_reference.ref_id FROM object_data, object_reference, survey_questionpool WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') AND survey_questionpool.obj_fi = object_data.obj_id ORDER BY object_data.title",
1032  implode("','", $qpls)
1033  );
1034  }
1035  else
1036  {
1037  $query = sprintf("SELECT object_data.*, object_reference.ref_id FROM object_data, object_reference, survey_questionpool WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') AND survey_questionpool.online = '1' AND survey_questionpool.obj_fi = object_data.obj_id ORDER BY object_data.title",
1038  implode("','", $qpls)
1039  );
1040  }
1041  $result = $ilDB->query($query);
1042  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1043  {
1044  $title = (($showPath) ? $titles[$row["ref_id"]] : $row["title"]);
1045 
1046  if ($use_object_id)
1047  {
1048  $result_array[$row["obj_id"]] = $title;
1049  }
1050  else
1051  {
1052  $result_array[$row["ref_id"]] = $title;
1053  }
1054  }
1055  }
1056  return $result_array;
1057  }
1058 
1065  function isPluginActive($a_pname)
1066  {
1067  global $ilPluginAdmin;
1068  if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $a_pname))
1069  {
1070  return TRUE;
1071  }
1072  else
1073  {
1074  return FALSE;
1075  }
1076  }
1077 } // END class.ilSurveyObjQuestionPool
1078 ?>