38         bool $a_call_by_reference = 
true    41         $this->main_tpl = $DIC->ui()->mainTemplate();
    43         $this->log = $DIC[
"ilLog"];
    44         $this->db = $DIC->database();
    45         $this->
user = $DIC->user();
    46         $this->component_repository = $DIC[
"component.repository"];
    49         $this->edit_manager = $DIC->surveyQuestionPool()
    53         $this->domain = $DIC->surveyQuestionPool()->internal()->domain();
    58         $id = parent::create();
    68         if (!parent::update()) {
    74     public function read(): void
    82         $newObj = parent::cloneObject($target_id, $copy_id, $omit_tree);
    90         foreach ($questions as $question_id) {
    91             $newObj->copyQuestion($question_id, $newObj->getId());
    98         $newObj->updateMetaData();
   106         string $question_type,
   107         int $question_id = -1
   109         if ((!$question_type) and ($question_id > 0)) {
   113         $question_type_gui = $question_type . 
"GUI";
   114         $question = 
new $question_type_gui();
   116         if ($question_id > 0) {
   117             $question->object->loadFromDb($question_id);
   132         if ($question_gui->object->getObjId() === $questionpool_to) {
   137             $newtitle = $question_gui->object->getTitle();
   138             if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to)) {
   140                 while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() . 
" ($counter)", $questionpool_to)) {
   143                 $newtitle = $question_gui->object->getTitle() . 
" ($counter)";
   145             $question_gui->object->copyObject($this->
getId(), $newtitle);
   159         $result = 
$ilDB->queryF(
   160             "SELECT * FROM svy_qpl WHERE obj_fi = %s",
   162             array($this->
getId())
   164         if ($result->numRows() !== 1) {
   165             $next_id = 
$ilDB->nextId(
'svy_qpl');
   166             $query = 
$ilDB->manipulateF(
   167                 "INSERT INTO svy_qpl (id_questionpool, obj_fi, tstamp) VALUES (%s, %s, %s)",
   168                 array(
'integer', 
'integer', 
'integer'),
   169                 array($next_id, $this->
getId(), time())
   174     public function delete(): 
bool   176         $remove = parent::delete();
   194         $result = 
$ilDB->queryF(
   195             "SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
   197             array($this->
getId())
   199         $found_questions = array();
   200         while ($row = 
$ilDB->fetchAssoc($result)) {
   206         $directory = $spl_data_dir . 
"/spl_" . $this->
getId();
   207         if (is_dir($directory)) {
   217         if ($question_id < 1) {
   221         $question->delete($question_id);
   231         if ($question_id < 1) {
   234         $result = 
$ilDB->queryF(
   235             "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",
   239         if ($result->numRows() === 1) {
   241             return $data[
"type_tag"];
   252     public function isInUse(
int $question_id): ?array
   256         $result = 
$ilDB->queryF(
   257             "SELECT answer_id FROM svy_answer WHERE question_fi = %s",
   261         $answered = $result->numRows();
   264         $result = 
$ilDB->queryF(
   265             "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",
   269         $inserted = $result->numRows();
   270         if (($inserted + $answered) === 0) {
   273         $result_array = array();
   274         while ($row = 
$ilDB->fetchObject($result)) {
   275             $result_array[] = $row;
   277         return $result_array;
   283     public function paste(
int $question_id): void
   293         array $question_array
   296         $result_array = array();
   297         $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'));
   298         while ($row = 
$ilDB->fetchAssoc($result)) {
   299             if ($row[
"plugin"]) {
   302                 $result_array[] = $row;
   305         return $result_array;
   319         while ($question->questionTitleExists($question->getTitle() . $suffix, $obj_id)) {
   322                 $suffix = 
" ($counter)";
   326             $question->setObjId($obj_id);
   329         if (strlen($question->getTitle() . $suffix) > $max_len) {
   330             $title = substr($question->getTitle(), 0, $max_len - strlen($suffix)) . $suffix;
   332             $title = $question->getTitle() . $suffix;
   334         $question->duplicate(
false, 
$title, $ilUser->fullname, $ilUser->id);
   346         if (count($arrFilter) > 0) {
   347             foreach ($arrFilter as $key => $value) {
   348                 $arrFilter[$key] = str_replace(
'%', 
'', $value);
   350             if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title'] ?? 
"")) {
   351                 $where .= 
" AND " . 
$ilDB->like(
'svy_question.title', 
'text', 
"%%" . $arrFilter[
'title'] . 
"%%");
   353             if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description'] ?? 
"")) {
   354                 $where .= 
" AND " . 
$ilDB->like(
'svy_question.description', 
'text', 
"%%" . $arrFilter[
'description'] . 
"%%");
   356             if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author'] ?? 
"")) {
   357                 $where .= 
" AND " . 
$ilDB->like(
'svy_question.author', 
'text', 
"%%" . $arrFilter[
'author'] . 
"%%");
   359             if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type'] ?? 
"")) {
   360                 $where .= 
" AND svy_qtype.type_tag = " . 
$ilDB->quote($arrFilter[
'type'], 
'text');
   363         $query_result = 
$ilDB->queryF(
   364             "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,
   366             array($this->
getId())
   369         if ($query_result->numRows()) {
   370             while ($row = 
$ilDB->fetchAssoc($query_result)) {
   371                 if ($row[
"plugin"]) {
   390         if (!is_writable($spl_data_dir)) {
   391             throw new ilSurveyException(
"Survey Questionpool Data Directory (" . $spl_data_dir . 
") not writeable.");
   395         $spl_dir = $spl_data_dir . 
"/spl_" . $this->
getId();
   397         if (!is_dir($spl_dir)) {
   398             throw new ilSurveyException(
"Creation of Survey Questionpool Directory failed.");
   401         $export_dir = $spl_dir . 
"/export";
   403         if (!is_dir($export_dir)) {
   404             throw new ilSurveyException(
"Creation of Survey Questionpool Export Directory failed.");
   424             !is_writable($dir)) {
   435         while ($entry = $dir->read()) {
   436             if ($entry !== 
"." &&
   438                 preg_match(
"/^[0-9]{10}__[0-9]+__(spl_)*[0-9]+\.[A-Za-z]{3}$/", $entry)) {
   461         if (!is_writable($spl_data_dir)) {
   462             throw new ilSurveyException(
"Survey Questionpool Data Directory (" . $spl_data_dir . 
") not writeable.");
   466         $spl_dir = $spl_data_dir . 
"/spl_" . $this->
getId();
   468         if (!is_dir($spl_dir)) {
   469             throw new ilSurveyException(
"Creation of Survey Questionpool Directory failed.");
   473         $import_dir = $spl_dir . 
"/import";
   475         if (!is_dir($import_dir)) {
   476             throw new ilSurveyException(
"Creation of Survey Questionpool Import Directory failed.");
   483             "/spl_" . $this->
getId() . 
"/import";
   490     public function toXML(?array $questions): string
   492         if (is_null($questions) || count($questions) === 0) {
   497         $a_xml_writer->xmlHeader();
   499             "xmlns:xsi" => 
"http://www.w3.org/2001/XMLSchema-instance",
   500             "xsi:noNamespaceSchemaLocation" => 
"https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"   502         $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
   504             "id" => 
"qpl_" . $this->
getId(),
   507         $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
   508         $a_xml_writer->xmlElement(
"dummy", null, 
"dummy");
   510         $a_xml_writer->xmlStartTag(
"metadata");
   511         $a_xml_writer->xmlStartTag(
"metadatafield");
   512         $a_xml_writer->xmlElement(
"fieldlabel", null, 
"SCORM");
   516         $metadata = $writer->xmlDumpMem();
   517         $a_xml_writer->xmlElement(
"fieldentry", null, $metadata);
   518         $a_xml_writer->xmlEndTag(
"metadatafield");
   519         $a_xml_writer->xmlEndTag(
"metadata");
   521         $a_xml_writer->xmlEndTag(
"surveyquestions");
   522         $a_xml_writer->xmlEndTag(
"surveyobject");
   524         $xml = $a_xml_writer->xmlDumpMem(
false);
   527         foreach ($questions as $key => $value) {
   530             $question = 
new $questiontype();
   531             $question->loadFromDb($value);
   532             $questionxml .= $question->toXML(
false);
   535         $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, $xml);
   544             "xmlns:xsi" => 
"http://www.w3.org/2001/XMLSchema-instance",
   545             "xsi:noNamespaceSchemaLocation" => 
"https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"   547         $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
   549             "id" => 
"qpl_" . $this->
getId(),
   552         $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
   553         $a_xml_writer->xmlElement(
"dummy", null, 
"dummy");
   554         $a_xml_writer->xmlEndTag(
"surveyquestions");
   555         $a_xml_writer->xmlEndTag(
"surveyobject");
   556         $xml = $a_xml_writer->xmlDumpMem(
false);
   558         foreach ($questions as $key => $value) {
   561             $question = 
new $questiontype();
   562             $question->loadFromDb($value);
   563             $questionxml .= $question->toXML(
false);
   565         $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, $xml);
   572         $questions = array();
   573         $result = 
$ilDB->queryF(
   574             "SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
   576             array($this->
getId())
   578         if ($result->numRows()) {
   579             while ($row = 
$ilDB->fetchAssoc($result)) {
   580                 $questions[] = $row[
"question_id"];
   593         bool $spl_exists = 
false   595         if (is_file($source)) {
   596             $isZip = (strcmp(strtolower(substr($source, -3)), 
'zip') === 0);
   599                 $this->domain->resources()->zip()->unzipFile($source);
   602                 $subdir = basename($source, 
".zip");
   603                 $source = dirname($source) . 
"/" . $subdir . 
"/" . $subdir . 
".xml";
   606             $fh = fopen($source, 
'rb') or die(
"");
   607             $xml = fread($fh, filesize($source));
   608             fclose($fh) or die(
"");
   610                 $subdir = basename($source, 
".zip");
   611                 if (is_dir(dirname($source) . 
"/" . $subdir)) {
   615             if (strpos($xml, 
"questestinterop") > 0) {
   621             $import->setXMLContent($xml);
   622             $import->startParsing();
   628         return !self::getOfflineStatus($a_obj_id);
   640         $rbacsystem = $DIC->rbac()->system();
   643         foreach ($refs as $ref) {
   659         $ilDB = $DIC->database();
   660         $lng = $DIC->language();
   664         $query_result = 
$ilDB->query(
"SELECT * FROM svy_qtype ORDER BY type_tag");
   665         while ($row = 
$ilDB->fetchAssoc($query_result)) {
   667             if ((
int) $row[
"plugin"] === 0) {
   668                 $types[
$lng->
txt($row[
"type_tag"])] = $row;
   676         $default_sorting = array_flip(array(
   677             "SurveySingleChoiceQuestion",
   678             "SurveyMultipleChoiceQuestion",
   679             "SurveyMatrixQuestion",
   680             "SurveyMetricQuestion",
   685         $idx = count($default_sorting);
   686         foreach ($types as $caption => $item) {
   687             $type = $item[
"type_tag"];
   688             $item[
"caption"] = $caption;
   691             if (array_key_exists(
$type, $default_sorting)) {
   692                 $sorted[$default_sorting[
$type]] = $item;
   696                 $sorted[$idx] = $item;
   704         foreach ($sorted as $item) {
   705             $types[$item[
"caption"]] = $item;
   714             static function (array 
$c): 
string {
   715                 return $c[
"type_tag"];
   717             self::_getQuestiontypes()
   729         $ilDB = $DIC->database();
   730         $lng = $DIC->language();
   732         $component_factory = $DIC[
"component.factory"];
   735         $result = 
$ilDB->query(
"SELECT * FROM svy_qtype");
   737         while ($row = 
$ilDB->fetchAssoc($result)) {
   738             if ((
int) $row[
"plugin"] === 0) {
   739                 $types[$row[
'type_tag']] = 
$lng->
txt($row[
"type_tag"]);
   751         bool $use_object_id = 
false,
   752         bool $could_be_offline = 
false,
   753         bool $showPath = 
false,
   754         string $permission = 
"read"   758         $ilUser = $DIC->user();
   761         $ilDB = $DIC->database();
   763         $result_array = array();
   767         $result = 
$ilDB->query(
"SELECT sq.obj_fi, od.offline as offline FROM svy_qpl sq JOIN object_data od ON (sq.obj_fi = od.obj_id) WHERE sq.obj_fi > 0 AND sq.tstamp > 0 AND NOT(od.offline = 1)");
   768         while ($row = 
$ilDB->fetchAssoc($result)) {
   769             $allqpls[$row[
'obj_fi']] = !($row[
'offline']);
   773             if ($could_be_offline || ($allqpls[$obj_id] ?? 0) == 1) {
   774                 if ($use_object_id) {
   775                     $result_array[$obj_id] = $titles[
$ref_id];
   777                     $result_array[(
int) $ref_id] = $titles[$ref_id];
   781         return $result_array;
   795         $query_result = 
$ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
   796             "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
   797             "AND svy_question.tstamp > 0 AND " . 
$ilDB->in(
'svy_question.question_id', $question_ids, 
false, 
'integer') . 
" " .
   798             "ORDER BY svy_question.title");
   799         if ($query_result->numRows() > 0) {
   800             while (
$data = 
$ilDB->fetchAssoc($query_result)) {
   801                 if (in_array(
$data[
"question_id"], $question_ids)) {
   802                     $found[] = array(
'id' => 
$data[
"question_id"],
   803                                      'title' => 
$data[
"title"],
   804                                      'description' => 
$data[
"description"],
   805                                      'type_tag' => 
$data[
"type_tag"]
   821         $result = 
$ilDB->queryF(
   822             "SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
   823             array(
"integer", 
"integer"),
   824             array($ilUser->getId(), 0)
   838         $this->edit_manager->addQuestionToClipboard($question_id, 
"copy");
   847         $this->edit_manager->addQuestionToClipboard($question_id, 
"move");
   857         $qentries = $this->edit_manager->getQuestionsFromClipboard();
   858         if (count($qentries) > 0) {
   859             foreach ($qentries as $question_object) {
   860                 if (strcmp($question_object[
"action"], 
"move") === 0) {
   861                     $result = 
$ilDB->queryF(
   862                         "SELECT obj_fi FROM svy_question WHERE question_id = %s",
   864                         array($question_object[
"question_id"])
   866                     if ($result->numRows() === 1) {
   867                         $row = 
$ilDB->fetchAssoc($result);
   868                         $source_questionpool = $row[
"obj_fi"];
   869                         if ($this->
getId() != $source_questionpool) {
   871                             $affectedRows = 
$ilDB->manipulateF(
   872                                 "UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
   873                                 array(
'integer',
'integer'),
   874                                 array($this->
getId(), $question_object[
"question_id"])
   878                             $source_path = 
CLIENT_WEB_DIR . 
"/survey/" . $source_questionpool . 
"/" . $question_object[
"question_id"] . 
"/";
   879                             if (is_dir($source_path)) {
   881                                 if (!is_dir($target_path)) {
   887                             $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"spl_move_same_pool"), 
true);
   896         $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"spl_paste_success"), 
true);
   897         $this->edit_manager->clearClipboardQuestions();
   904         array $obligatory_questions
   908             $status = (
int) (isset($obligatory_questions[
"$question_id"]));
   910             $ilDB->manipulate(
"UPDATE svy_question" .
   911                 " SET obligatory = " . 
$ilDB->quote($status, 
"integer") .
   912                 " WHERE question_id = " . 
$ilDB->quote($question_id, 
"integer"));
 removeQuestion(int $question_id)
Removes a question from the question pool. 
 
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
 
Readable part of repository interface to ilComponentDataDB. 
 
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
 
Class ilObjSurveyQuestionPool. 
 
getQuestionInfos(array $question_ids)
Returns title, description and type for an array of question id's. 
 
InternalDomainService $domain
 
__construct(int $a_id=0, bool $a_call_by_reference=true)
 
static _getAllReferences(int $id)
get all reference ids for object ID 
 
createImportDirectory()
creates data directory for import files (data_dir/spl_data/spl_<id>/import 
 
getExportDirectory()
get export directory of survey 
 
duplicateQuestion(int $question_id, int $obj_id=0)
Duplicates a question for a question pool. 
 
copyQuestion(int $question_id, int $questionpool_to)
 
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash 
 
static _getAvailableQuestionpools(bool $use_object_id=false, bool $could_be_offline=false, bool $showPath=false, string $permission="read")
Returns the available question pools for the active user. 
 
getQuestiontype(int $question_id)
 
isInUse(int $question_id)
Checks if a question is in use by a survey. 
 
loadLanguageModule(string $a_module)
Load language module. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static _getQuestionTypeTranslations()
 
purgeQuestions()
Remove all questions with tstamp = 0. 
 
ilGlobalTemplateInterface $main_tpl
 
static makeDirParents(string $a_dir)
Create a new directory and all parent directories. 
 
createQuestion(string $question_type, int $question_id=-1)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
sort()
 description: > Example for rendering a Sort Glyph. 
 
static _isWriteable(int $object_id)
Returns true, if the question pool is writeable for the current user. 
 
EditManager $edit_manager
 
moveToClipboard(int $question_id)
Moves a question to the clipboard. 
 
cloneMetaData(ilObject $target_obj)
Copy meta data. 
 
static _prepareCloneSelection(array $ref_ids, string $new_type, bool $show_path=true)
Prepare copy wizard object selection. 
 
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively 
 
static _lookupObjectId(int $ref_id)
 
getQuestionsInfo(array $question_array)
 
static _includeClass(string $question_type, int $gui=0)
Include the php class file for a given question type. 
 
static _lookupOnline(int $a_obj_id)
 
static _getObjectsByOperations( $a_obj_type, string $a_operation, int $a_usr_id=0, int $limit=0)
Get all objects of a specific type and check access This function is not recursive, instead it parses the serialized rbac_pa entries. 
 
static getDataDir()
get data directory (outside webspace) 
 
importObject(string $source, bool $spl_exists=false)
Imports survey questions into ILIAS. 
 
pasteFromClipboard()
Copies/Moves a question from the clipboard. 
 
paste(int $question_id)
Pastes a duplicate of a question in the question pool. 
 
getQuestionsData(array $arrFilter)
Retrieve the data for the output of the question pool. 
 
Manages editing processes/repos. 
 
getExportFiles(string $dir)
get export files 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
__construct(Container $dic, ilPlugin $plugin)
 
static _getQuestiontypes()
Get all available question types. 
 
setObligatoryStates(array $obligatory_questions)
 
copyToClipboard(int $question_id)
Copies a question to the clipboard. 
 
static _getQuestionClasses()
 
static rename(string $a_source, string $a_target)
 
static _getInstance(int $a_copy_id)
 
toXML(?array $questions)
export questions to xml 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static _instanciateQuestion(int $question_id)
Get question object. 
 
Basic class for all survey question types The SurveyQuestionGUI class defines and encapsulates basic ...
 
createExportDirectory()
creates data directory for export files data_dir/spl_data/spl_<id>/export 
 
ilComponentRepository $component_repository
 
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...