ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
34include_once "./Services/Object/classes/class.ilObject.php";
35
37{
41 protected $user;
42
46 protected $plugin_admin;
47
53 public $online;
54
61 public function __construct($a_id = 0, $a_call_by_reference = true)
62 {
63 global $DIC;
64
65 $this->log = $DIC["ilLog"];
66 $this->db = $DIC->database();
67 $this->user = $DIC->user();
68 $this->plugin_admin = $DIC["ilPluginAdmin"];
69 $this->type = "spl";
70 parent::__construct($a_id, $a_call_by_reference);
71 }
72
76 public function create($a_upload = false)
77 {
78 parent::create();
79 if (!$a_upload) {
80 $this->createMetaData();
81 }
82 }
83
90 public function update()
91 {
92 $this->updateMetaData();
93 if (!parent::update()) {
94 return false;
95 }
96
97 // put here object specific stuff
98
99 return true;
100 }
101
106 public function read()
107 {
108 parent::read();
109 $this->loadFromDb();
110 }
111
117 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
118 {
120 $newObj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
121
122 //copy online status if object is not the root copy object
123 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
124
125 if (!$cp_options->isRootNode($this->getRefId())) {
126 $newObj->setOnline($this->getOnline());
127 }
128
129 $newObj->saveToDb();
130 // clone the questions in the question pool
131 $questions = &$this->getQuestions();
132 foreach ($questions as $question_id) {
133 $newObj->copyQuestion($question_id, $newObj->getId());
134 }
135
136 // clone meta data
137 include_once "./Services/MetaData/classes/class.ilMD.php";
138 $md = new ilMD($this->getId(), 0, $this->getType());
139 $new_md = &$md->cloneMD($newObj->getId(), 0, $newObj->getType());
140
141 // update the metadata with the new title of the question pool
142 $newObj->updateMetaData();
143 return $newObj;
144 }
145
146 public function &createQuestion($question_type, $question_id = -1)
147 {
148 if ((!$question_type) and ($question_id > 0)) {
149 $question_type = $this->getQuestiontype($question_id);
150 }
151
152 include_once "./Modules/SurveyQuestionPool/classes/class." . $question_type . "GUI.php";
153 $question_type_gui = $question_type . "GUI";
154 $question = new $question_type_gui();
155
156 if ($question_id > 0) {
157 $question->object->loadFromDb($question_id);
158 }
159
160 return $question;
161 }
162
170 public function copyQuestion($question_id, $questionpool_to)
171 {
172 $question_gui = &$this->createQuestion("", $question_id);
173 if ($question_gui->object->getObjId() == $questionpool_to) {
174 // the question is copied into the same question pool
175 $this->duplicateQuestion($question_id);
176 } else {
177 // the question is copied into another question pool
178 $newtitle = $question_gui->object->getTitle();
179 if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to)) {
180 $counter = 2;
181 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() . " ($counter)", $questionpool_to)) {
182 $counter++;
183 }
184 $newtitle = $question_gui->object->getTitle() . " ($counter)";
185 }
186 $question_gui->object->copyObject($this->getId(), $newtitle);
187 }
188 }
189
195 public function loadFromDb()
196 {
198
199 $result = $ilDB->queryF(
200 "SELECT * FROM svy_qpl WHERE obj_fi = %s",
201 array('integer'),
202 array($this->getId())
203 );
204 if ($result->numRows() == 1) {
205 $row = $ilDB->fetchAssoc($result);
206 $this->setOnline($row["isonline"]);
207 }
208 }
209
215 public function saveToDb()
216 {
218
220
221 $result = $ilDB->queryF(
222 "SELECT * FROM svy_qpl WHERE obj_fi = %s",
223 array('integer'),
224 array($this->getId())
225 );
226 if ($result->numRows() == 1) {
227 $affectedRows = $ilDB->manipulateF(
228 "UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
229 array('text','integer','integer'),
230 array($this->getOnline(), time(), $this->getId())
231 );
232 } else {
233 $next_id = $ilDB->nextId('svy_qpl');
234 $query = $ilDB->manipulateF(
235 "INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
236 array('integer', 'text', 'integer', 'integer'),
237 array($next_id, $this->getOnline(), $this->getId(), time())
238 );
239 }
240 }
241
248 public function delete()
249 {
250 $remove = parent::delete();
251 // always call parent delete function first!!
252 if (!$remove) {
253 return false;
254 }
255
256 // delete all related questions
257 $this->deleteAllData();
258
259 // delete meta data
260 $this->deleteMetaData();
261
262 return true;
263 }
264
265 public function deleteAllData()
266 {
268 $result = $ilDB->queryF(
269 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
270 array('integer'),
271 array($this->getId())
272 );
273 $found_questions = array();
274 while ($row = $ilDB->fetchAssoc($result)) {
275 $this->removeQuestion($row["question_id"]);
276 }
277
278 // delete export files
279 $spl_data_dir = ilUtil::getDataDir() . "/spl_data";
280 $directory = $spl_data_dir . "/spl_" . $this->getId();
281 if (is_dir($directory)) {
282 ilUtil::delDir($directory);
283 }
284 }
285
292 public function removeQuestion($question_id)
293 {
294 if ($question_id < 1) {
295 return;
296 }
297 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
298 $question = &SurveyQuestion::_instanciateQuestion($question_id);
299 $question->delete($question_id);
300 }
301
309 public function getQuestiontype($question_id)
310 {
312 if ($question_id < 1) {
313 return;
314 }
315 $result = $ilDB->queryF(
316 "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",
317 array('integer'),
318 array($question_id)
319 );
320 if ($result->numRows() == 1) {
321 $data = $ilDB->fetchAssoc($result);
322 return $data["type_tag"];
323 } else {
324 return;
325 }
326 }
327
335 public function isInUse($question_id)
336 {
338 // check out the already answered questions
339 $result = $ilDB->queryF(
340 "SELECT answer_id FROM svy_answer WHERE question_fi = %s",
341 array('integer'),
342 array($question_id)
343 );
344 $answered = $result->numRows();
345
346 // check out the questions inserted in surveys
347 $result = $ilDB->queryF(
348 "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",
349 array('integer'),
350 array($question_id)
351 );
352 $inserted = $result->numRows();
353 if (($inserted + $answered) == 0) {
354 return false;
355 }
356 $result_array = array();
357 while ($row = $ilDB->fetchObject($result)) {
358 array_push($result_array, $row);
359 }
360 return $result_array;
361 }
362
369 public function paste($question_id)
370 {
371 $this->duplicateQuestion($question_id, $this->getId());
372 }
373
381 public function &getQuestionsInfo($question_array)
382 {
384 $result_array = array();
385 $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'));
386 while ($row = $ilDB->fetchAssoc($result)) {
387 if ($row["plugin"]) {
388 if ($this->isPluginActive($row["type_tag"])) {
389 array_push($result_array, $row);
390 }
391 } else {
392 array_push($result_array, $row);
393 }
394 }
395 return $result_array;
396 }
397
404 public function duplicateQuestion($question_id, $obj_id = "")
405 {
407 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
408 $question = SurveyQuestion::_instanciateQuestion($question_id);
409 $suffix = "";
410 $counter = 1;
411 while ($question->questionTitleExists($question->getTitle() . $suffix, $obj_id)) {
412 $counter++;
413 if ($counter > 1) {
414 $suffix = " ($counter)";
415 }
416 }
417 if ($obj_id) {
418 $question->setObjId($obj_id);
419 }
420 $question->duplicate(false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
421 }
422
428 public function getQuestionsData($arrFilter)
429 {
432 $where = "";
433 if (is_array($arrFilter)) {
434 foreach ($arrFilter as $key => $value) {
435 $arrFilter[$key] = str_replace('%', '', $arrFilter[$key]);
436 }
437 if (array_key_exists('title', $arrFilter) && strlen($arrFilter['title'])) {
438 $where .= " AND " . $ilDB->like('svy_question.title', 'text', "%%" . $arrFilter['title'] . "%%");
439 }
440 if (array_key_exists('description', $arrFilter) && strlen($arrFilter['description'])) {
441 $where .= " AND " . $ilDB->like('svy_question.description', 'text', "%%" . $arrFilter['description'] . "%%");
442 }
443 if (array_key_exists('author', $arrFilter) && strlen($arrFilter['author'])) {
444 $where .= " AND " . $ilDB->like('svy_question.author', 'text', "%%" . $arrFilter['author'] . "%%");
445 }
446 if (array_key_exists('type', $arrFilter) && strlen($arrFilter['type'])) {
447 $where .= " AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter['type'], 'text');
448 }
449 }
450 $query_result = $ilDB->queryF(
451 "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,
452 array('integer'),
453 array($this->getId())
454 );
455 $rows = array();
456 if ($query_result->numRows()) {
457 while ($row = $ilDB->fetchAssoc($query_result)) {
458 if ($row["plugin"]) {
459 if ($this->isPluginActive($row["type_tag"])) {
460 array_push($rows, $row);
461 }
462 } else {
463 array_push($rows, $row);
464 }
465 }
466 }
467 return $rows;
468 }
469
477 public function createExportDirectory()
478 {
479 $spl_data_dir = ilUtil::getDataDir() . "/spl_data";
480 ilUtil::makeDir($spl_data_dir);
481 if (!is_writable($spl_data_dir)) {
482 include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
483 throw new ilSurveyException("Survey Questionpool Data Directory (" . $spl_data_dir . ") not writeable.");
484 }
485
486 // create learning module directory (data_dir/lm_data/lm_<id>)
487 $spl_dir = $spl_data_dir . "/spl_" . $this->getId();
488 ilUtil::makeDir($spl_dir);
489 if (!@is_dir($spl_dir)) {
490 include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
491 throw new ilSurveyException("Creation of Survey Questionpool Directory failed.");
492 }
493 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
494 $export_dir = $spl_dir . "/export";
495 ilUtil::makeDir($export_dir);
496 if (!@is_dir($export_dir)) {
497 include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
498 throw new ilSurveyException("Creation of Survey Questionpool Export Directory failed.");
499 }
500 }
501
505 public function getExportDirectory()
506 {
507 $export_dir = ilUtil::getDataDir() . "/spl_data" . "/spl_" . $this->getId() . "/export";
508 return $export_dir;
509 }
510
514 public function getExportFiles($dir)
515 {
516 // quit if import dir not available
517 if (!@is_dir($dir) or
518 !is_writeable($dir)) {
519 return array();
520 }
521
522 // open directory
523 $dir = dir($dir);
524
525 // initialize array
526 $file = array();
527
528 // get files and save the in the array
529 while ($entry = $dir->read()) {
530 if ($entry != "." &&
531 $entry != ".." &&
532 preg_match("/^[0-9]{10}__[0-9]+__(spl_)*[0-9]+\.[A-Za-z]{3}$/", $entry)) {
533 $file[] = $entry;
534 }
535 }
536
537 // close import directory
538 $dir->close();
539 // sort files
540 sort($file);
541 reset($file);
542
543 return $file;
544 }
545
553 public function createImportDirectory()
554 {
555 $spl_data_dir = ilUtil::getDataDir() . "/spl_data";
556 ilUtil::makeDir($spl_data_dir);
557
558 if (!is_writable($spl_data_dir)) {
559 include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
560 throw new ilSurveyException("Survey Questionpool Data Directory (" . $spl_data_dir . ") not writeable.");
561 }
562
563 // create test directory (data_dir/spl_data/spl_<id>)
564 $spl_dir = $spl_data_dir . "/spl_" . $this->getId();
565 ilUtil::makeDir($spl_dir);
566 if (!@is_dir($spl_dir)) {
567 include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
568 throw new ilSurveyException("Creation of Survey Questionpool Directory failed.");
569 }
570
571 // create import subdirectory (data_dir/spl_data/spl_<id>/import)
572 $import_dir = $spl_dir . "/import";
573 ilUtil::makeDir($import_dir);
574 if (!@is_dir($import_dir)) {
575 include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
576 throw new ilSurveyException("Creation of Survey Questionpool Import Directory failed.");
577 }
578 }
579
583 public function getImportDirectory()
584 {
585 $import_dir = ilUtil::getDataDir() . "/spl_data" .
586 "/spl_" . $this->getId() . "/import";
587 if (@is_dir($import_dir)) {
588 return $import_dir;
589 } else {
590 return false;
591 }
592 }
593
597 public function toXML($questions)
598 {
599 if (!is_array($questions)) {
600 $questions = &$this->getQuestions();
601 }
602 if (count($questions) == 0) {
603 $questions = &$this->getQuestions();
604 }
605 $xml = "";
606
607 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
608 $a_xml_writer = new ilXmlWriter;
609 // set xml header
610 $a_xml_writer->xmlHeader();
611 $attrs = array(
612 "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
613 "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
614 );
615 $a_xml_writer->xmlStartTag("surveyobject", $attrs);
616 $attrs = array(
617 "id" => "qpl_" . $this->getId(),
618 "label" => $this->getTitle(),
619 "online" => $this->getOnline()
620 );
621 $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
622 $a_xml_writer->xmlElement("dummy", null, "dummy");
623 // add ILIAS specific metadata
624 $a_xml_writer->xmlStartTag("metadata");
625 $a_xml_writer->xmlStartTag("metadatafield");
626 $a_xml_writer->xmlElement("fieldlabel", null, "SCORM");
627 include_once "./Services/MetaData/classes/class.ilMD.php";
628 $md = new ilMD($this->getId(), 0, $this->getType());
629 $writer = new ilXmlWriter();
630 $md->toXml($writer);
631 $metadata = $writer->xmlDumpMem();
632 $a_xml_writer->xmlElement("fieldentry", null, $metadata);
633 $a_xml_writer->xmlEndTag("metadatafield");
634 $a_xml_writer->xmlEndTag("metadata");
635
636 $a_xml_writer->xmlEndTag("surveyquestions");
637 $a_xml_writer->xmlEndTag("surveyobject");
638
639 $xml = $a_xml_writer->xmlDumpMem(false);
640
641 $questionxml = "";
642 foreach ($questions as $key => $value) {
643 $questiontype = $this->getQuestiontype($value);
644 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
645 SurveyQuestion::_includeClass($questiontype);
646 $question = new $questiontype();
647 $question->loadFromDb($value);
648 $questionxml .= $question->toXML(false);
649 }
650
651 $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
652 return $xml;
653 }
654
655 public function &getQuestions()
656 {
658 $questions = array();
659 $result = $ilDB->queryF(
660 "SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
661 array('integer'),
662 array($this->getId())
663 );
664 if ($result->numRows()) {
665 while ($row = $ilDB->fetchAssoc($result)) {
666 array_push($questions, $row["question_id"]);
667 }
668 }
669 return $questions;
670 }
671
678 public function importObject($source, $spl_exists = false)
679 {
680 if (is_file($source)) {
681 $isZip = (strcmp(strtolower(substr($source, -3)), 'zip') == 0);
682 if ($isZip) {
683 // unzip file
685
686 // determine filenames of xml files
687 $subdir = basename($source, ".zip");
688 $source = dirname($source) . "/" . $subdir . "/" . $subdir . ".xml";
689 }
690
691 $fh = fopen($source, "r") or die("");
692 $xml = fread($fh, filesize($source));
693 fclose($fh) or die("");
694 if ($isZip) {
695 $subdir = basename($source, ".zip");
696 if (@is_dir(dirname($source) . "/" . $subdir)) {
697 ilUtil::delDir(dirname($source) . "/" . $subdir);
698 }
699 }
700 if (strpos($xml, "questestinterop") > 0) {
701 include_once("./Modules/Survey/exceptions/class.ilInvalidSurveyImportFileException.php");
702 throw new ilInvalidSurveyImportFileException("Unsupported survey version (< 3.8) found.");
703 } else {
704 // survey questions for ILIAS >= 3.8
705 include_once "./Services/Survey/classes/class.SurveyImportParser.php";
706 $import = new SurveyImportParser($this->getId(), "", $spl_exists);
707 $import->setXMLContent($xml);
708 $import->startParsing();
709 }
710 }
711 }
712
713 public static function _setOnline($a_obj_id, $a_online_status)
714 {
715 global $DIC;
716
717 $ilDB = $DIC->database();
718
719 $status = "0";
720 switch ($a_online_status) {
721 case 0:
722 case 1:
723 $status = "$a_online_status";
724 break;
725 }
726 $affectedRows = $ilDB->manipulateF(
727 "UPDATE svy_qpl SET isonline = %s WHERE obj_fi = %s",
728 array('text','integer'),
729 array($status, $a_obj_id)
730 );
731 }
732
740 public function setOnline($a_online_status)
741 {
742 switch ($a_online_status) {
743 case 0:
744 case 1:
745 $this->online = $a_online_status;
746 break;
747 default:
748 $this->online = 0;
749 break;
750 }
751 }
752
753 public function getOnline()
754 {
755 if (strcmp($this->online, "") == 0) {
756 $this->online = "0";
757 }
758 return $this->online;
759 }
760
761 public static function _lookupOnline($a_obj_id)
762 {
763 global $DIC;
764
765 $ilDB = $DIC->database();
766
767 $result = $ilDB->queryF(
768 "SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
769 array('integer'),
770 array($a_obj_id)
771 );
772 if ($result->numRows() == 1) {
773 $row = $ilDB->fetchAssoc($result);
774 return $row["isonline"];
775 }
776 return 0;
777 }
778
786 public static function _isWriteable($object_id, $user_id)
787 {
788 global $DIC;
789
790 $rbacsystem = $DIC->rbac()->system();
791 global $DIC;
792
793 $ilDB = $DIC->database();
794
795 $refs = ilObject::_getAllReferences($object_id);
796 $result = false;
797 foreach ($refs as $ref) {
798 if ($rbacsystem->checkAccess("write", $ref) && (ilObject::_hasUntrashedReference($object_id))) {
799 $result = true;
800 }
801 }
802 return $result;
803 }
804
811 public static function _getQuestiontypes()
812 {
813 global $DIC;
814
815 $ilDB = $DIC->database();
816 global $DIC;
817
818 $lng = $DIC->language();
819
820 $lng->loadLanguageModule("survey");
821 $types = array();
822 $query_result = $ilDB->query("SELECT * FROM svy_qtype ORDER BY type_tag");
823 while ($row = $ilDB->fetchAssoc($query_result)) {
824 //array_push($questiontypes, $row["type_tag"]);
825 if ($row["plugin"] == 0) {
826 $types[$lng->txt($row["type_tag"])] = $row;
827 } else {
828 global $DIC;
829
830 $ilPluginAdmin = $DIC["ilPluginAdmin"];
831 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
832 foreach ($pl_names as $pl_name) {
833 $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
834 if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0) {
835 $types[$pl->getQuestionTypeTranslation()] = $row;
836 }
837 }
838 }
839 }
840 ksort($types);
841
842
843 // #14263 - default sorting
844
845 $default_sorting = array_flip(array(
846 "SurveySingleChoiceQuestion",
847 "SurveyMultipleChoiceQuestion",
848 "SurveyMatrixQuestion",
849 "SurveyMetricQuestion",
850 "SurveyTextQuestion"
851 ));
852
853 $sorted = array();
854 $idx = sizeof($default_sorting);
855 foreach ($types as $caption => $item) {
856 $type = $item["type_tag"];
857 $item["caption"] = $caption;
858
859 // default
860 if (array_key_exists($type, $default_sorting)) {
861 $sorted[$default_sorting[$type]] = $item;
862 }
863 // plugin (append alphabetically sorted)
864 else {
865 $sorted[$idx] = $item;
866 $idx++;
867 }
868 }
869 ksort($sorted);
870
871 // redo captions as index
872 $types = array();
873 foreach ($sorted as $item) {
874 $types[$item["caption"]] = $item;
875 }
876
877 return $types;
878 }
879
880 public static function _getQuestionTypeTranslations()
881 {
882 global $DIC;
883
884 $ilDB = $DIC->database();
885 global $DIC;
886
887 $lng = $DIC->language();
888 global $DIC;
889
890 $ilLog = $DIC["ilLog"];
891 global $DIC;
892
893 $ilPluginAdmin = $DIC["ilPluginAdmin"];
894
895 $lng->loadLanguageModule("survey");
896 $result = $ilDB->query("SELECT * FROM svy_qtype");
897 $types = array();
898 while ($row = $ilDB->fetchAssoc($result)) {
899 if ($row["plugin"] == 0) {
900 $types[$row['type_tag']] = $lng->txt($row["type_tag"]);
901 } else {
902 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "SurveyQuestionPool", "svyq");
903 foreach ($pl_names as $pl_name) {
904 $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $pl_name);
905 if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0) {
906 $types[$row['type_tag']] = $pl->getQuestionTypeTranslation();
907 }
908 }
909 }
910 }
911 ksort($types);
912 return $types;
913 }
914
921 public static function _getAvailableQuestionpools($use_object_id = false, $could_be_offline = false, $showPath = false, $permission = "read")
922 {
923 global $DIC;
924
925 $ilUser = $DIC->user();
926 global $DIC;
927
928 $ilDB = $DIC->database();
929
930 $result_array = array();
931 $qpls = ilUtil::_getObjectsByOperations("spl", $permission, $ilUser->getId(), -1);
932 $titles = ilObject::_prepareCloneSelection($qpls, "spl", $showPath);
933 $allqpls = array();
934 $result = $ilDB->query("SELECT obj_fi, isonline FROM svy_qpl");
935 while ($row = $ilDB->fetchAssoc($result)) {
936 $allqpls[$row['obj_fi']] = $row['isonline'];
937 }
938 foreach ($qpls as $ref_id) {
940 if ($could_be_offline || $allqpls[$obj_id] == 1) {
941 if ($use_object_id) {
942 $result_array[$obj_id] = $titles[$ref_id];
943 } else {
944 $result_array[$ref_id] = $titles[$ref_id];
945 }
946 }
947 }
948 return $result_array;
949 }
950
957 public function isPluginActive($a_pname)
958 {
959 $ilPluginAdmin = $this->plugin_admin;
960 if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $a_pname)) {
961 return true;
962 } else {
963 return false;
964 }
965 }
966
973 public function getQuestionInfos($question_ids)
974 {
976
977 $found = array();
978 $query_result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
979 "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
980 "AND svy_question.tstamp > 0 AND " . $ilDB->in('svy_question.question_id', $question_ids, false, 'integer') . " " .
981 "ORDER BY svy_question.title");
982 if ($query_result->numRows() > 0) {
983 while ($data = $ilDB->fetchAssoc($query_result)) {
984 if (in_array($data["question_id"], $question_ids)) {
985 array_push($found, array('id' => $data["question_id"],
986 'title' => $data["title"],
987 'description' => $data["description"],
988 'type_tag' => $data["type_tag"]));
989 }
990 }
991 }
992 return $found;
993 }
994
995 /*
996 * Remove all questions with tstamp = 0
997 */
998 public function purgeQuestions()
999 {
1000 $ilDB = $this->db;
1002
1003 $result = $ilDB->queryF(
1004 "SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
1005 array("integer", "integer"),
1006 array($ilUser->getId(), 0)
1007 );
1008 while ($data = $ilDB->fetchAssoc($result)) {
1009 $this->removeQuestion($data["question_id"]);
1010 }
1011 }
1012
1018 public function copyToClipboard($question_id)
1019 {
1020 if (!array_key_exists("spl_clipboard", $_SESSION)) {
1021 $_SESSION["spl_clipboard"] = array();
1022 }
1023 $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
1024 }
1025
1031 public function moveToClipboard($question_id)
1032 {
1033 if (!array_key_exists("spl_clipboard", $_SESSION)) {
1034 $_SESSION["spl_clipboard"] = array();
1035 }
1036 $_SESSION["spl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "move");
1037 }
1038
1042 public function pasteFromClipboard()
1043 {
1044 $ilDB = $this->db;
1045
1046 if (array_key_exists("spl_clipboard", $_SESSION)) {
1047 foreach ($_SESSION["spl_clipboard"] as $question_object) {
1048 if (strcmp($question_object["action"], "move") == 0) {
1049 $result = $ilDB->queryF(
1050 "SELECT obj_fi FROM svy_question WHERE question_id = %s",
1051 array('integer'),
1052 array($question_object["question_id"])
1053 );
1054 if ($result->numRows() == 1) {
1055 $row = $ilDB->fetchAssoc($result);
1056 $source_questionpool = $row["obj_fi"];
1057 if ($this->getId() != $source_questionpool) {
1058 // change the questionpool id in the qpl_questions table
1059 $affectedRows = $ilDB->manipulateF(
1060 "UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
1061 array('integer','integer'),
1062 array($this->getId(), $question_object["question_id"])
1063 );
1064
1065 // move question data to the new target directory
1066 $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
1067 if (@is_dir($source_path)) {
1068 $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/";
1069 if (!@is_dir($target_path)) {
1070 ilUtil::makeDirParents($target_path);
1071 }
1072 @rename($source_path, $target_path . $question_object["question_id"]);
1073 }
1074 } else {
1075 ilUtil::sendFailure($this->lng->txt("spl_move_same_pool"), true);
1076 return;
1077 }
1078 }
1079 } else {
1080 $this->copyQuestion($question_object["question_id"], $this->getId());
1081 }
1082 }
1083 }
1084 ilUtil::sendSuccess($this->lng->txt("spl_paste_success"), true);
1085 unset($_SESSION["spl_clipboard"]);
1086 }
1087
1094 public function setObligatoryStates($obligatory_questions)
1095 {
1096 $ilDB = $this->db;
1097
1098 foreach ($this->getQuestions() as $question_id) {
1099 $status = (int) (in_array($question_id, $obligatory_questions));
1100
1101 $ilDB->manipulate("UPDATE svy_question" .
1102 " SET obligatory = " . $ilDB->quote($status, "integer") .
1103 " WHERE question_id = " . $ilDB->quote($question_id, "integer"));
1104 }
1105 }
1106} // END class.ilSurveyObjQuestionPool
$result
user()
Definition: user.php:4
$metadata['__DYNAMIC:1__']
$source
Definition: linkback.php:22
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Survey Question Import Parser.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
const IL_COMP_MODULE
static _getInstance($a_copy_id)
Get instance of copy wizard options.
moveToClipboard($question_id)
Moves a question to the clipboard.
getQuestionsData($arrFilter)
Calculates the data for the output of the questionpool.
setOnline($a_online_status)
Sets the questionpool online status.
removeQuestion($question_id)
Removes a question from the question pool.
createImportDirectory()
creates data directory for import files (data_dir/spl_data/spl_<id>/import, depending on data directo...
loadFromDb()
Loads a ilObjQuestionpool object from a database.
getQuestionInfos($question_ids)
Returns title, description and type for an array of question id's.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Creates a 1:1 copy of the object and places the copy in a given repository.
paste($question_id)
Pastes a question in the question pool.
copyToClipboard($question_id)
Copies a question to the clipboard.
static _getAvailableQuestionpools($use_object_id=false, $could_be_offline=false, $showPath=false, $permission="read")
Returns the available question pools for the active user.
importObject($source, $spl_exists=false)
Imports survey questions into ILIAS.
createExportDirectory()
creates data directory for export files (data_dir/spl_data/spl_<id>/export, depending on data directo...
copyQuestion($question_id, $questionpool_to)
Copies a question into another question pool.
static _isWriteable($object_id, $user_id)
Returns true, if the question pool is writeable by a given user.
static _getQuestiontypes()
Creates a list of all available question types.
create($a_upload=false)
create question pool object
getExportDirectory()
get export directory of survey
isPluginActive($a_pname)
Checks whether or not a question plugin with a given name is active.
read()
read object data from db into object @access public
pasteFromClipboard()
Copies/Moves a question from the clipboard.
& createQuestion($question_type, $question_id=-1)
toXML($questions)
export questions to xml
saveToDb()
Saves a ilObjSurveyQuestionPool object to a database.
static _setOnline($a_obj_id, $a_online_status)
getImportDirectory()
get import directory of survey
& getQuestionsInfo($question_array)
Retrieves the datase entries for questions from a given array.
isInUse($question_id)
Checks if a question is in use by a survey.
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
getQuestiontype($question_id)
Returns the question type of a question with a given id.
duplicateQuestion($question_id, $obj_id="")
Duplicates a question for a questionpool.
setObligatoryStates($obligatory_questions)
Sets the obligatory states for questions in a survey from the questions form.
Class ilObject Basic functions for all objects.
getType()
get object type @access public
static _lookupObjectId($a_ref_id)
lookup object id
deleteMetaData()
delete meta data entry
updateMetaData()
update meta data entry
createMetaData()
create meta data entry
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id @access public
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _prepareCloneSelection($a_ref_ids, $new_type, $show_path=true)
Prepare copy wizard object selection.
getTitle()
get object title @access public
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Survey exception class.
static getDataDir()
get data directory (outside webspace)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _getObjectsByOperations($a_obj_type, $a_operation, $a_usr_id=0, $limit=0)
Get all objects of a specific type and check access This function is not recursive,...
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
XML writer class.
xmlHeader()
Writes xml header @access public.
$key
Definition: croninfo.php:18
$row
update($pash, $contents, Config $config)
$query
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6
$rows
Definition: xhr_table.php:10