34include_once 
"./Services/Object/classes/class.ilObject.php";
 
   61    public function __construct($a_id = 0, $a_call_by_reference = 
true)
 
   65        $this->log = 
$DIC[
"ilLog"];
 
   66        $this->db = 
$DIC->database();
 
   67        $this->
user = $DIC->user();
 
   68        $this->plugin_admin = 
$DIC[
"ilPluginAdmin"];
 
   70        parent::__construct($a_id, $a_call_by_reference);
 
   76    public function create($a_upload = 
false)
 
  117    public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = 
false)
 
  120        $newObj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
 
  125        if (!$cp_options->isRootNode($this->getRefId())) {
 
  132        foreach ($questions as $question_id) {
 
  133            $newObj->copyQuestion($question_id, $newObj->getId());
 
  137        include_once 
"./Services/MetaData/classes/class.ilMD.php";
 
  139        $new_md =&$md->cloneMD($newObj->getId(), 0, $newObj->getType());
 
  142        $newObj->updateMetaData();
 
  148        if ((!$question_type) and ($question_id > 0)) {
 
  152        include_once 
"./Modules/SurveyQuestionPool/classes/class." . $question_type . 
"GUI.php";
 
  153        $question_type_gui = $question_type . 
"GUI";
 
  154        $question = 
new $question_type_gui();
 
  156        if ($question_id > 0) {
 
  157            $question->object->loadFromDb($question_id);
 
  173        if ($question_gui->object->getObjId() == $questionpool_to) {
 
  178            $newtitle = $question_gui->object->getTitle();
 
  179            if ($question_gui->object->questionTitleExists($question_gui->object->getTitle(), $questionpool_to)) {
 
  181                while ($question_gui->object->questionTitleExists($question_gui->object->getTitle() . 
" ($counter)", $questionpool_to)) {
 
  184                $newtitle = $question_gui->object->getTitle() . 
" ($counter)";
 
  186            $question_gui->object->copyObject($this->
getId(), $newtitle);
 
  200            "SELECT * FROM svy_qpl WHERE obj_fi = %s",
 
  202            array($this->
getId())
 
  222            "SELECT * FROM svy_qpl WHERE obj_fi = %s",
 
  224            array($this->
getId())
 
  227            $affectedRows = 
$ilDB->manipulateF(
 
  228                "UPDATE svy_qpl SET isonline = %s, tstamp = %s WHERE obj_fi = %s",
 
  229                array(
'text',
'integer',
'integer'),
 
  233            $next_id = 
$ilDB->nextId(
'svy_qpl');
 
  235                "INSERT INTO svy_qpl (id_questionpool, isonline, obj_fi, tstamp) VALUES (%s, %s, %s, %s)",
 
  236                array(
'integer', 
'text', 
'integer', 
'integer'),
 
  248    public function delete()
 
  250        $remove = parent::delete();
 
  269            "SELECT question_id FROM svy_question WHERE obj_fi = %s AND original_id IS NULL",
 
  271            array($this->
getId())
 
  273        $found_questions = array();
 
  280        $directory = $spl_data_dir . 
"/spl_" . $this->
getId();
 
  281        if (is_dir($directory)) {
 
  294        if ($question_id < 1) {
 
  297        include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
  299        $question->delete($question_id);
 
  312        if ($question_id < 1) {
 
  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",
 
  322            return $data[
"type_tag"];
 
  340            "SELECT answer_id FROM svy_answer WHERE question_fi = %s",
 
  344        $answered = 
$result->numRows();
 
  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",
 
  352        $inserted = 
$result->numRows();
 
  353        if (($inserted + $answered) == 0) {
 
  356        $result_array = array();
 
  358            array_push($result_array, 
$row);
 
  360        return $result_array;
 
  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'));
 
  387            if (
$row[
"plugin"]) {
 
  389                    array_push($result_array, 
$row);
 
  392                array_push($result_array, 
$row);
 
  395        return $result_array;
 
  407        include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
  411        while ($question->questionTitleExists($question->getTitle() . $suffix, $obj_id)) {
 
  414                $suffix = 
" ($counter)";
 
  418            $question->setObjId($obj_id);
 
  420        $question->duplicate(
false, $question->getTitle() . $suffix, 
$ilUser->fullname, 
$ilUser->id);
 
  433        if (is_array($arrFilter)) {
 
  434            foreach ($arrFilter as 
$key => $value) {
 
  435                $arrFilter[
$key] = str_replace(
'%', 
'', $arrFilter[
$key]);
 
  437            if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title'])) {
 
  438                $where .= 
" AND " . 
$ilDB->like(
'svy_question.title', 
'text', 
"%%" . $arrFilter[
'title'] . 
"%%");
 
  440            if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description'])) {
 
  441                $where .= 
" AND " . 
$ilDB->like(
'svy_question.description', 
'text', 
"%%" . $arrFilter[
'description'] . 
"%%");
 
  443            if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author'])) {
 
  444                $where .= 
" AND " . 
$ilDB->like(
'svy_question.author', 
'text', 
"%%" . $arrFilter[
'author'] . 
"%%");
 
  446            if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type'])) {
 
  447                $where .= 
" AND svy_qtype.type_tag = " . 
$ilDB->quote($arrFilter[
'type'], 
'text');
 
  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,
 
  453            array($this->
getId())
 
  456        if ($query_result->numRows()) {
 
  457            while (
$row = 
$ilDB->fetchAssoc($query_result)) {
 
  458                if (
$row[
"plugin"]) {
 
  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.");
 
  487        $spl_dir = $spl_data_dir . 
"/spl_" . $this->
getId();
 
  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.");
 
  494        $export_dir = $spl_dir . 
"/export";
 
  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.");
 
  517        if (!@is_dir($dir) or
 
  518            !is_writeable($dir)) {
 
  529        while ($entry = $dir->read()) {
 
  532                preg_match(
"/^[0-9]{10}__[0-9]+__(spl_)*[0-9]+\.[A-Za-z]{3}$/", $entry)) {
 
  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.");
 
  564        $spl_dir = $spl_data_dir . 
"/spl_" . $this->
getId();
 
  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.");
 
  572        $import_dir = $spl_dir . 
"/import";
 
  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.");
 
  586            "/spl_" . $this->
getId() . 
"/import";
 
  587        if (@is_dir($import_dir)) {
 
  599        if (!is_array($questions)) {
 
  602        if (count($questions) == 0) {
 
  607        include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
 
  612            "xmlns:xsi" => 
"http://www.w3.org/2001/XMLSchema-instance",
 
  613            "xsi:noNamespaceSchemaLocation" => 
"http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd" 
  615        $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
 
  617            "id" => 
"qpl_" . $this->
getId(),
 
  621        $a_xml_writer->xmlStartTag(
"surveyquestions", $attrs);
 
  622        $a_xml_writer->xmlElement(
"dummy", 
null, 
"dummy");
 
  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";
 
  632        $a_xml_writer->xmlElement(
"fieldentry", 
null, 
$metadata);
 
  633        $a_xml_writer->xmlEndTag(
"metadatafield");
 
  634        $a_xml_writer->xmlEndTag(
"metadata");
 
  636        $a_xml_writer->xmlEndTag(
"surveyquestions");
 
  637        $a_xml_writer->xmlEndTag(
"surveyobject");
 
  639        $xml = $a_xml_writer->xmlDumpMem(
false);
 
  642        foreach ($questions as 
$key => $value) {
 
  644            include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
  646            $question = 
new $questiontype();
 
  647            $question->loadFromDb($value);
 
  648            $questionxml .= $question->toXML(
false);
 
  651        $xml = str_replace(
"<dummy>dummy</dummy>", $questionxml, 
$xml);
 
  658        $questions = array();
 
  660            "SELECT question_id FROM svy_question WHERE obj_fi = %s AND svy_question.tstamp > 0 AND original_id IS NULL",
 
  662            array($this->
getId())
 
  666                array_push($questions, 
$row[
"question_id"]);
 
  681            $isZip = (strcmp(strtolower(substr(
$source, -3)), 
'zip') == 0);
 
  687                $subdir = basename(
$source, 
".zip");
 
  688                $source = dirname(
$source) . 
"/" . $subdir . 
"/" . $subdir . 
".xml";
 
  693            fclose(
$fh) or die(
"");
 
  695                $subdir = basename(
$source, 
".zip");
 
  696                if (@is_dir(dirname(
$source) . 
"/" . $subdir)) {
 
  700            if (strpos(
$xml, 
"questestinterop") > 0) {
 
  701                include_once(
"./Modules/Survey/exceptions/class.ilInvalidSurveyImportFileException.php");
 
  712                include_once 
"./Services/Survey/classes/class.SurveyImportParser.php";
 
  714                $import->setXMLContent(
$xml);
 
  715                $import->startParsing();
 
  720    public static function _setOnline($a_obj_id, $a_online_status)
 
  727        switch ($a_online_status) {
 
  730                $status = 
"$a_online_status";
 
  733        $affectedRows = 
$ilDB->manipulateF(
 
  734            "UPDATE svy_qpl SET isonline = %s  WHERE obj_fi = %s",
 
  735            array(
'text',
'integer'),
 
  736            array($status, $a_obj_id)
 
  749        switch ($a_online_status) {
 
  752                $this->online = $a_online_status;
 
  762        if (strcmp($this->online, 
"") == 0) {
 
  775            "SELECT isonline FROM svy_qpl WHERE obj_fi = %s",
 
  781            return $row[
"isonline"];
 
  797        $rbacsystem = 
$DIC->rbac()->system();
 
  804        foreach ($refs as $ref) {
 
  827        $lng->loadLanguageModule(
"survey");
 
  829        $query_result = 
$ilDB->query(
"SELECT * FROM svy_qtype ORDER BY type_tag");
 
  830        while (
$row = 
$ilDB->fetchAssoc($query_result)) {
 
  832            if (
$row[
"plugin"] == 0) {
 
  837                $ilPluginAdmin = 
$DIC[
"ilPluginAdmin"];
 
  838                $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE, 
"SurveyQuestionPool", 
"svyq");
 
  839                foreach ($pl_names as $pl_name) {
 
  841                    if (strcmp($pl->getQuestionType(), 
$row[
"type_tag"]) == 0) {
 
  842                        $types[$pl->getQuestionTypeTranslation()] = 
$row;
 
  852        $default_sorting = array_flip(array(
 
  853            "SurveySingleChoiceQuestion",
 
  854            "SurveyMultipleChoiceQuestion",
 
  855            "SurveyMatrixQuestion",
 
  856            "SurveyMetricQuestion",
 
  861        $idx = 
sizeof($default_sorting);
 
  862        foreach ($types as $caption => $item) {
 
  863            $type = $item[
"type_tag"];
 
  864            $item[
"caption"] = $caption;
 
  867            if (array_key_exists(
$type, $default_sorting)) {
 
  868                $sorted[$default_sorting[
$type]] = $item;
 
  872                $sorted[$idx] = $item;
 
  880        foreach ($sorted as $item) {
 
  881            $types[$item[
"caption"]] = $item;
 
  900        $ilPluginAdmin = 
$DIC[
"ilPluginAdmin"];
 
  902        $lng->loadLanguageModule(
"survey");
 
  906            if (
$row[
"plugin"] == 0) {
 
  909                $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE, 
"SurveyQuestionPool", 
"svyq");
 
  910                foreach ($pl_names as $pl_name) {
 
  912                    if (strcmp($pl->getQuestionType(), 
$row[
"type_tag"]) == 0) {
 
  913                        $types[
$row[
'type_tag']] = $pl->getQuestionTypeTranslation();
 
  928    public static function _getAvailableQuestionpools($use_object_id = 
false, $could_be_offline = 
false, $showPath = 
false, $permission = 
"read")
 
  937        $result_array = array();
 
  941        $result = 
$ilDB->query(
"SELECT obj_fi, isonline FROM svy_qpl");
 
  943            $allqpls[
$row[
'obj_fi']] = 
$row[
'isonline'];
 
  947            if ($could_be_offline || $allqpls[$obj_id] == 1) {
 
  948                if ($use_object_id) {
 
  949                    $result_array[$obj_id] = $titles[
$ref_id];
 
  955        return $result_array;
 
  967        if ($ilPluginAdmin->isActive(
IL_COMP_MODULE, 
"SurveyQuestionPool", 
"svyq", $a_pname)) {
 
  985        $query_result = 
$ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype " .
 
  986            "WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
 
  987            "AND svy_question.tstamp > 0 AND " . 
$ilDB->in(
'svy_question.question_id', $question_ids, 
false, 
'integer') . 
" " .
 
  988            "ORDER BY svy_question.title");
 
  989        if ($query_result->numRows() > 0) {
 
  990            while (
$data = 
$ilDB->fetchAssoc($query_result)) {
 
  991                if (in_array(
$data[
"question_id"], $question_ids)) {
 
  992                    array_push($found, array(
'id' => 
$data[
"question_id"],
 
  993                        'title' => 
$data[
"title"],
 
  994                        'description' => 
$data[
"description"],
 
  995                        'type_tag' => 
$data[
"type_tag"]));
 
 1011            "SELECT question_id FROM svy_question WHERE owner_fi = %s AND tstamp = %s",
 
 1012            array(
"integer", 
"integer"),
 
 1027        if (!array_key_exists(
"spl_clipboard", 
$_SESSION)) {
 
 1030        $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id, 
"action" => 
"copy");
 
 1040        if (!array_key_exists(
"spl_clipboard", 
$_SESSION)) {
 
 1043        $_SESSION[
"spl_clipboard"][$question_id] = array(
"question_id" => $question_id, 
"action" => 
"move");
 
 1053        if (array_key_exists(
"spl_clipboard", 
$_SESSION)) {
 
 1054            foreach (
$_SESSION[
"spl_clipboard"] as $question_object) {
 
 1055                if (strcmp($question_object[
"action"], 
"move") == 0) {
 
 1057                        "SELECT obj_fi FROM svy_question WHERE question_id = %s",
 
 1059                        array($question_object[
"question_id"])
 
 1061                    if (
$result->numRows() == 1) {
 
 1063                        $source_questionpool = 
$row[
"obj_fi"];
 
 1064                        if ($this->
getId() != $source_questionpool) {
 
 1066                            $affectedRows = 
$ilDB->manipulateF(
 
 1067                                "UPDATE svy_question SET obj_fi = %s WHERE question_id = %s",
 
 1068                                array(
'integer',
'integer'),
 
 1069                                array($this->
getId(), $question_object[
"question_id"])
 
 1073                            $source_path = CLIENT_WEB_DIR . 
"/survey/" . $source_questionpool . 
"/" . $question_object[
"question_id"] . 
"/";
 
 1074                            if (@is_dir($source_path)) {
 
 1075                                $target_path = CLIENT_WEB_DIR . 
"/survey/" . $this->
getId() . 
"/";
 
 1076                                if (!@is_dir($target_path)) {
 
 1079                                @rename($source_path, $target_path . $question_object[
"question_id"]);
 
 1106            $status = (int) (in_array($question_id, $obligatory_questions));
 
 1108            $ilDB->manipulate(
"UPDATE svy_question" .
 
 1109                " SET obligatory = " . 
$ilDB->quote($status, 
"integer") .
 
 1110                " WHERE question_id = " . 
$ilDB->quote($question_id, 
"integer"));
 
$metadata['__DYNAMIC:1__']
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.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Class ilInvalidSurveyImportFileException.
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.
static _getQuestionTypeTranslations()
read()
read object data from db into object @access public
pasteFromClipboard()
Copies/Moves a question from the clipboard.
& createQuestion($question_type, $question_id=-1)
static _lookupOnline($a_obj_id)
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
update()
update object data
& 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.
getExportFiles($dir)
get export files
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($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get plugin object.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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 ...
xmlHeader()
Writes xml header @access public.
update($pash, $contents, Config $config)
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file