00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00025
00036 class SurveyQuestion
00037 {
00045 var $id;
00046
00054 var $title;
00062 var $description;
00071 var $owner;
00072
00081 var $author;
00082
00090 var $materials;
00091
00099 var $survey_id;
00100
00108 var $obj_id;
00109
00117 var $questiontext;
00118
00126 var $obligatory;
00127
00135 var $ilias;
00136
00144 var $tpl;
00145
00153 var $lng;
00154
00162 var $orientation;
00163
00164 var $material;
00165
00177 function SurveyQuestion(
00178 $title = "",
00179 $description = "",
00180 $author = "",
00181 $questiontext = "",
00182 $owner = -1
00183 )
00184
00185 {
00186 global $ilias;
00187 global $lng;
00188 global $tpl;
00189
00190 $this->ilias =& $ilias;
00191 $this->lng =& $lng;
00192 $this->tpl =& $tpl;
00193
00194 $this->title = $title;
00195 $this->description = $description;
00196 $this->questiontext = $questiontext;
00197 $this->author = $author;
00198 if (!$this->author) {
00199 $this->author = $this->ilias->account->fullname;
00200 }
00201 $this->owner = $owner;
00202 if ($this->owner == -1) {
00203 $this->owner = $this->ilias->account->id;
00204 }
00205 $this->id = -1;
00206 $this->survey_id = -1;
00207 $this->obligatory = 1;
00208 $this->orientation = 0;
00209 $this->materials = array();
00210 $this->material = array();
00211 register_shutdown_function(array(&$this, '_SurveyQuestion'));
00212 }
00213
00214 function _SurveyQuestion()
00215 {
00216 }
00217
00218
00227 function isComplete()
00228 {
00229 return false;
00230 }
00231
00242 function questionTitleExists($title, $questionpool_object = "")
00243 {
00244 global $ilDB;
00245
00246 $refwhere = "";
00247 if (strcmp($questionpool_object, "") != 0)
00248 {
00249 $refwhere = sprintf(" AND obj_fi = %s",
00250 $ilDB->quote($questionpool_object)
00251 );
00252 }
00253 $query = sprintf("SELECT question_id FROM survey_question WHERE title = %s$refwhere",
00254 $ilDB->quote($title)
00255 );
00256 $result = $ilDB->query($query);
00257 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00258 {
00259 if ($result->numRows() == 1)
00260 {
00261 return TRUE;
00262 }
00263 }
00264 return FALSE;
00265 }
00266
00276 function setTitle($title = "")
00277 {
00278 $this->title = $title;
00279 }
00280
00290 function setObligatory($obligatory = 1)
00291 {
00292 if ($obligatory)
00293 {
00294 $this->obligatory = 1;
00295 }
00296 else
00297 {
00298 $this->obligatory = 0;
00299 }
00300 }
00301
00311 function setOrientation($orientation = 0)
00312 {
00313 if (strlen($orientation) == 0)
00314 {
00315 $this->orientation = 0;
00316 }
00317 else
00318 {
00319 $this->orientation = $orientation;
00320 }
00321 }
00322
00332 function setId($id = -1)
00333 {
00334 $this->id = $id;
00335 }
00336
00346 function setSurveyId($id = -1)
00347 {
00348 $this->survey_id = $id;
00349 }
00350
00360 function setDescription($description = "")
00361 {
00362 $this->description = $description;
00363 }
00364
00365
00376 function addMaterials($materials_file, $materials_name="")
00377 {
00378 if(empty($materials_name))
00379 {
00380 $materials_name = $materials_file;
00381 }
00382 if ((!empty($materials_name))&&(!$this->keyInArray($materials_name, $this->materials)))
00383 {
00384 $this->materials[$materials_name] = $materials_file;
00385 }
00386
00387 }
00388
00399 function keyInArray($searchkey, $array)
00400 {
00401 if ($searchKey)
00402 {
00403 foreach ($array as $key => $value)
00404 {
00405 if (strcmp($key, $searchkey)==0)
00406 {
00407 return true;
00408 }
00409 }
00410 }
00411 return false;
00412 }
00413
00423 function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
00424 {
00425 if (!empty($materials_filename))
00426 {
00427 include_once "./Services/Utilities/classes/class.ilUtil.php";
00428 $materialspath = $this->getMaterialsPath();
00429 if (!file_exists($materialspath))
00430 {
00431 ilUtil::makeDirParents($materialspath);
00432 }
00433
00434 if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
00435 $materialspath.$materials_filename))
00436 {
00437 print "image not uploaded!!!! ";
00438 }
00439 else
00440 {
00441 $this->addMaterials($materials_filename, $materials_name);
00442 }
00443 }
00444 }
00445
00455 function deleteMaterial($materials_name = "")
00456 {
00457 foreach ($this->materials as $key => $value)
00458 {
00459 if (strcmp($key, $materials_name)==0)
00460 {
00461 if (file_exists($this->getMaterialsPath().$value))
00462 {
00463 unlink($this->getMaterialsPath().$value);
00464 }
00465 unset($this->materials[$key]);
00466 }
00467 }
00468 }
00469
00478 function flushMaterials()
00479 {
00480 $this->materials = array();
00481 }
00482
00492 function setAuthor($author = "")
00493 {
00494 if (!$author)
00495 {
00496 $author = $this->ilias->account->fullname;
00497 }
00498 $this->author = $author;
00499 }
00500
00510 function setQuestiontext($questiontext = "")
00511 {
00512 $this->questiontext = $questiontext;
00513 }
00514
00524 function setOwner($owner = "")
00525 {
00526 $this->owner = $owner;
00527 }
00528
00538 function getTitle()
00539 {
00540 return $this->title;
00541 }
00542
00552 function getId()
00553 {
00554 return $this->id;
00555 }
00556
00567 function getObligatory($survey_id = "")
00568 {
00569 if ($survey_id > 0)
00570 {
00571 global $ilDB;
00572
00573 $query = sprintf("SELECT * FROM survey_question_obligatory WHERE survey_fi = %s AND question_fi = %s",
00574 $ilDB->quote($survey_id . ""),
00575 $ilDB->quote($this->getId() . "")
00576 );
00577 $result = $ilDB->query($query);
00578 if ($result->numRows())
00579 {
00580 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00581 return $row["obligatory"];
00582 }
00583 else
00584 {
00585 return $this->obligatory;
00586 }
00587 }
00588 else
00589 {
00590 return $this->obligatory;
00591 }
00592 }
00593
00603 function getSurveyId()
00604 {
00605 return $this->survey_id;
00606 }
00607
00617 function getOrientation()
00618 {
00619 switch ($this->orientation)
00620 {
00621 case 0:
00622 case 1:
00623 case 2:
00624 break;
00625 default:
00626 $this->orientation = 0;
00627 break;
00628 }
00629 return $this->orientation;
00630 }
00631
00632
00642 function getDescription()
00643 {
00644 return $this->description;
00645 }
00646
00656 function getAuthor()
00657 {
00658 return $this->author;
00659 }
00660
00670 function getOwner()
00671 {
00672 return $this->owner;
00673 }
00674
00684 function getQuestiontext()
00685 {
00686 return $this->questiontext;
00687 }
00688
00698 function getObjId() {
00699 return $this->obj_id;
00700 }
00701
00711 function setObjId($obj_id = 0) {
00712 $this->obj_id = $obj_id;
00713 }
00714
00722 function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
00723 {
00724 if ($this->getId() <= 0)
00725 {
00726
00727 return;
00728 }
00729
00730 $clone = $this;
00731 $original_id = $this->getId();
00732 $clone->setId(-1);
00733 if ($title)
00734 {
00735 $clone->setTitle($title);
00736 }
00737 if ($author)
00738 {
00739 $clone->setAuthor($author);
00740 }
00741 if ($owner)
00742 {
00743 $clone->setOwner($owner);
00744 }
00745 if ($for_survey)
00746 {
00747 $clone->saveToDb($original_id);
00748 }
00749 else
00750 {
00751 $clone->saveToDb();
00752 }
00753
00754 $clone->duplicateMaterials($original_id);
00755
00756 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00757 return $clone->getId();
00758 }
00759
00767 function copyObject($target_questionpool, $title = "")
00768 {
00769 if ($this->getId() <= 0)
00770 {
00771
00772 return;
00773 }
00774 $clone = $this;
00775 $original_id = SurveyQuestion::_getOriginalId($this->getId());
00776 $clone->setId(-1);
00777 $source_questionpool = $this->getObjId();
00778 $clone->setObjId($target_questionpool);
00779 if ($title)
00780 {
00781 $clone->setTitle($title);
00782 }
00783
00784 $clone->saveToDb();
00785
00786
00787 $clone->duplicateMaterials($original_id);
00788
00789 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00790 return $clone->getId();
00791 }
00792
00801 function copyXHTMLMediaObjectsOfQuestion($a_q_id)
00802 {
00803 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00804 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
00805 foreach ($mobs as $mob)
00806 {
00807 ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
00808 }
00809 }
00810
00819 function duplicateMaterials($question_id)
00820 {
00821 foreach ($this->materials as $filename)
00822 {
00823 $materialspath = $this->getMaterialsPath();
00824 $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
00825 if (!file_exists($materialspath))
00826 {
00827 include_once "./Services/Utilities/classes/class.ilUtil.php";
00828 ilUtil::makeDirParents($materialspath);
00829 }
00830 if (!copy($materialspath_original . $filename, $materialspath . $filename))
00831 {
00832 print "material could not be duplicated!!!! ";
00833 }
00834 }
00835 }
00836
00837
00846 function loadFromDb($question_id)
00847 {
00848 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
00849 $this->ilias->db->quote($this->getId() . "")
00850 );
00851 $result = $this->ilias->db->query($query);
00852 $this->material = array();
00853 if ($result->numRows())
00854 {
00855 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00856 {
00857 $this->material = array(
00858 "internal_link" => $row["internal_link"],
00859 "import_id" => $row["import_id"],
00860 "title" => $row["material_title"]
00861 );
00862 }
00863 }
00864 }
00865
00874 function _isComplete($question_id)
00875 {
00876 global $ilDB;
00877
00878 $query = sprintf("SELECT complete FROM survey_question WHERE question_id = %s",
00879 $ilDB->quote($question_id . "")
00880 );
00881 $result = $ilDB->query($query);
00882 if ($result->numRows())
00883 {
00884 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00885 if ($row["complete"] == 1)
00886 {
00887 return TRUE;
00888 }
00889 }
00890 return FALSE;
00891 }
00892
00900 function saveCompletionStatus($original_id = "")
00901 {
00902 $question_id = $this->getId();
00903 if (strlen($original_id))
00904 {
00905 $question_id = $original_id;
00906 }
00907
00908 $complete = 0;
00909 if ($this->isComplete())
00910 {
00911 $complete = 1;
00912 }
00913 if ($this->id > 0)
00914 {
00915
00916 $query = sprintf("UPDATE survey_question SET complete = %s WHERE question_id = %s",
00917 $this->ilias->db->quote("$complete"),
00918 $this->ilias->db->quote($question_id . "")
00919 );
00920 $result = $this->ilias->db->query($query);
00921 }
00922 }
00923
00932 function saveToDb($original_id = "")
00933 {
00934 include_once "./Services/COPage/classes/class.ilInternalLink.php";
00935 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
00936 $this->ilias->db->quote($this->getId() . "")
00937 );
00938 $result = $this->ilias->db->query($query);
00939 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->getId());
00940 if (count($this->material))
00941 {
00942 $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00943 $this->ilias->db->quote($this->getId() . ""),
00944 $this->ilias->db->quote($this->material["internal_link"] . ""),
00945 $this->ilias->db->quote($this->material["import_id"] . ""),
00946 $this->ilias->db->quote($this->material["title"] . "")
00947 );
00948 $this->ilias->db->query($query);
00949 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00950 {
00951 ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
00952 }
00953 }
00954 }
00955
00956
00965 function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
00966 {
00967 }
00968
00977 function getImagePath()
00978 {
00979 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
00980 }
00981
00990 function getMaterialsPath()
00991 {
00992 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
00993 }
00994
01003 function getImagePathWeb()
01004 {
01005 include_once "./Services/Utilities/classes/class.ilUtil.php";
01006 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
01007 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
01008 }
01009
01018 function getMaterialsPathWeb()
01019 {
01020 include_once "./Services/Utilities/classes/class.ilUtil.php";
01021 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
01022 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
01023 }
01024
01033 function saveMaterialsToDb()
01034 {
01035 if ($this->id > 0)
01036 {
01037 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
01038 $this->ilias->db->quote($this->id)
01039 );
01040 $result = $this->ilias->db->query($query);
01041 if (!empty($this->materials)) {
01042 foreach ($this->materials as $key => $value)
01043 {
01044 $query = sprintf("INSERT INTO survey_question_material (question_fi, materials, materials_file) VALUES (%s, %s, %s)",
01045 $this->ilias->db->quote($this->id),
01046 $this->ilias->db->quote($key),
01047 $this->ilias->db->quote($value)
01048 );
01049 $result = $this->ilias->db->query($query);
01050 }
01051 }
01052 }
01053 }
01054
01063 function loadMaterialFromDb($question_id)
01064 {
01065 $query = sprintf("SELECT * FROM survey_question_material WHERE question_fi = %s",
01066 $this->ilias->db->quote($question_id)
01067 );
01068 $result = $this->ilias->db->query($query);
01069 if (strcmp(strtolower(get_class($result)), db_result) == 0)
01070 {
01071 $this->materials = array();
01072 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01073 {
01074 $this->addMaterials($data->materials_file, $data->materials);
01075 }
01076 }
01077 }
01078
01089 function saveCategoryToDb($categorytext, $neutral = 0)
01090 {
01091 global $ilUser;
01092
01093 $query = sprintf("SELECT title, category_id FROM survey_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
01094 $this->ilias->db->quote($categorytext . ""),
01095 $this->ilias->db->quote($neutral . ""),
01096 $this->ilias->db->quote($ilUser->getId() . "")
01097 );
01098 $result = $this->ilias->db->query($query);
01099 $insert = FALSE;
01100 $returnvalue = "";
01101 if ($result->numRows())
01102 {
01103 $insert = TRUE;
01104 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01105 {
01106 if (strcmp($row->title, $categorytext) == 0)
01107 {
01108 $returnvalue = $row->category_id;
01109 $insert = FALSE;
01110 }
01111 }
01112 }
01113 else
01114 {
01115 $insert = TRUE;
01116 }
01117 if ($insert)
01118 {
01119 $query = sprintf("INSERT INTO survey_category (category_id, title, neutral, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01120 $this->ilias->db->quote($categorytext . ""),
01121 $this->ilias->db->quote($neutral . ""),
01122 $this->ilias->db->quote($ilUser->getId() . "")
01123 );
01124 $result = $this->ilias->db->query($query);
01125 $returnvalue = $this->ilias->db->getLastInsertId();
01126 }
01127 return $returnvalue;
01128 }
01129
01138 function deleteAdditionalTableData($question_id)
01139 {
01140 global $ilDB;
01141 $additional_table_name = $this->getAdditionalTableName();
01142 $query = sprintf("DELETE FROM $additional_table_name WHERE question_fi = %s",
01143 $ilDB->quote($question_id . "")
01144 );
01145 $result = $ilDB->query($query);
01146 }
01147
01156 function delete($question_id)
01157 {
01158 if ($question_id < 1)
01159 return;
01160
01161 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01162 $this->ilias->db->quote($question_id)
01163 );
01164 $result = $this->ilias->db->query($query);
01165 if ($result->numRows() == 1)
01166 {
01167 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01168 $obj_id = $row["obj_fi"];
01169 }
01170 else
01171 {
01172 return;
01173 }
01174
01175 $query = sprintf("DELETE FROM survey_answer WHERE question_fi = %s",
01176 $this->ilias->db->quote($question_id)
01177 );
01178 $result = $this->ilias->db->query($query);
01179
01180 $query = sprintf("SELECT constraint_id FROM survey_constraint WHERE question_fi = %s",
01181 $this->ilias->db->quote($question_id)
01182 );
01183 $result = $this->ilias->db->query($query);
01184 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01185 {
01186 $query = sprintf("DELETE FROM survey_question_constraint WHERE constraint_fi = %s",
01187 $this->ilias->db->quote($row->constraint_id)
01188 );
01189 $delresult = $this->ilias->db->query($query);
01190 }
01191
01192 $query = sprintf("DELETE FROM survey_constraint WHERE question_fi = %s",
01193 $this->ilias->db->quote($question_id)
01194 );
01195 $result = $this->ilias->db->query($query);
01196
01197 $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s",
01198 $this->ilias->db->quote($question_id)
01199 );
01200 $result = $this->ilias->db->query($query);
01201 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01202 {
01203 $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
01204 $this->ilias->db->quote($row->constraint_fi)
01205 );
01206 $delresult = $this->ilias->db->query($query);
01207 }
01208 $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s",
01209 $this->ilias->db->quote($question_id)
01210 );
01211 $result = $this->ilias->db->query($query);
01212
01213 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
01214 $this->ilias->db->quote($question_id)
01215 );
01216 $result = $this->ilias->db->query($query);
01217
01218 $query = sprintf("DELETE FROM survey_questionblock_question WHERE question_fi = %s",
01219 $this->ilias->db->quote($question_id)
01220 );
01221 $result = $this->ilias->db->query($query);
01222
01223 $query = sprintf("DELETE FROM survey_question_obligatory WHERE question_fi = %s",
01224 $this->ilias->db->quote($question_id)
01225 );
01226 $result = $this->ilias->db->query($query);
01227
01228 $query = sprintf("DELETE FROM survey_survey_question WHERE question_fi = %s",
01229 $this->ilias->db->quote($question_id)
01230 );
01231 $result = $this->ilias->db->query($query);
01232
01233 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01234 $this->ilias->db->quote($question_id)
01235 );
01236 $result = $this->ilias->db->query($query);
01237
01238 $query = sprintf("DELETE FROM survey_question WHERE question_id = %s",
01239 $this->ilias->db->quote($question_id)
01240 );
01241 $result = $this->ilias->db->query($query);
01242
01243 $this->deleteAdditionalTableData($question_id);
01244
01245 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01246 $this->ilias->db->quote($question_id)
01247 );
01248 $result = $this->ilias->db->query($query);
01249 include_once "./Services/COPage/classes/class.ilInternalLink.php";
01250 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01251
01252 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
01253 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
01254 {
01255 include_once "./Services/Utilities/classes/class.ilUtil.php";
01256 ilUtil::delDir($directory);
01257 }
01258
01259 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
01260 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
01261
01262
01263
01264
01265 foreach($mobs as $mob)
01266 {
01267 ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
01268 $mob_obj =& new ilObjMediaObject($mob);
01269 $mob_obj->delete();
01270 }
01271 }
01272
01282 function _getQuestionType($question_id)
01283 {
01284 global $ilDB;
01285
01286 if ($question_id < 1)
01287 return "";
01288
01289 $query = sprintf("SELECT type_tag FROM survey_question, survey_questiontype WHERE survey_question.question_id = %s AND survey_question.questiontype_fi = survey_questiontype.questiontype_id",
01290 $ilDB->quote($question_id)
01291 );
01292 $result = $ilDB->query($query);
01293 if ($result->numRows() == 1)
01294 {
01295 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01296 return $data->type_tag;
01297 }
01298 else
01299 {
01300 return "";
01301 }
01302 }
01303
01313 function _getTitle($question_id)
01314 {
01315 global $ilDB;
01316
01317 if ($question_id < 1) return "";
01318
01319 $query = sprintf("SELECT title FROM survey_question WHERE survey_question.question_id = %s",
01320 $ilDB->quote($question_id)
01321 );
01322 $result = $ilDB->query($query);
01323 if ($result->numRows() == 1)
01324 {
01325 $data = $result->fetchRow(DB_FETCHMODE_ASSOC);
01326 return $data["title"];
01327 }
01328 else
01329 {
01330 return "";
01331 }
01332 }
01333
01343 function _getOriginalId($question_id)
01344 {
01345 global $ilDB;
01346 $query = sprintf("SELECT * FROM survey_question WHERE question_id = %s",
01347 $ilDB->quote($question_id . "")
01348 );
01349 $result = $ilDB->query($query);
01350 if ($result->numRows() > 0)
01351 {
01352 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01353 if ($row["original_id"] > 0)
01354 {
01355 return $row["original_id"];
01356 }
01357 else
01358 {
01359 return $row["question_id"];
01360 }
01361 }
01362 else
01363 {
01364 return "";
01365 }
01366 }
01367
01368 function _getRefIdFromObjId($obj_id)
01369 {
01370 global $ilDB;
01371
01372 $query = sprintf("SELECT ref_id FROM object_reference WHERE obj_id=%s",
01373 $ilDB->quote($obj_id)
01374
01375 );
01376 $result = $ilDB->query($query);
01377 if ($result->numRows())
01378 {
01379 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01380 return $row["ref_id"];
01381 }
01382 return 0;
01383 }
01384
01385 function syncWithOriginal()
01386 {
01387 include_once "./Services/COPage/classes/class.ilInternalLink.php";
01388 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01389 $this->ilias->db->quote($this->original_id . "")
01390 );
01391 $result = $this->ilias->db->query($query);
01392 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
01393 if (strlen($this->material["internal_link"]))
01394 {
01395 $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01396 $this->ilias->db->quote($this->original_id . ""),
01397 $this->ilias->db->quote($this->material["internal_link"] . ""),
01398 $this->ilias->db->quote($this->material["import_id"] . ""),
01399 $this->ilias->db->quote($this->material["title"] . "")
01400 );
01401 $this->ilias->db->query($query);
01402 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
01403 {
01404 ilInternalLink::_saveLink("sqst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01405 }
01406 }
01407 }
01408
01417 function getPhrase($phrase_id)
01418 {
01419 $query = sprintf("SELECT title FROM survey_phrase WHERE phrase_id = %s",
01420 $this->ilias->db->quote($phrase_id)
01421 );
01422 $result = $this->ilias->db->query($query);
01423 if ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01424 {
01425 return $row["title"];
01426 }
01427 return "";
01428 }
01429
01439 function phraseExists($title)
01440 {
01441 global $ilUser;
01442
01443 $query = sprintf("SELECT phrase_id FROM survey_phrase WHERE title = %s AND owner_fi = %s",
01444 $this->ilias->db->quote($title),
01445 $this->ilias->db->quote($ilUser->id)
01446 );
01447 $result = $this->ilias->db->query($query);
01448 if ($result->numRows() == 0)
01449 {
01450 return false;
01451 }
01452 else
01453 {
01454 return true;
01455 }
01456 }
01457
01467 function _questionExists($question_id)
01468 {
01469 global $ilDB;
01470
01471 if ($question_id < 1)
01472 {
01473 return false;
01474 }
01475
01476 $query = sprintf("SELECT question_id FROM survey_question WHERE question_id = %s",
01477 $ilDB->quote($question_id)
01478 );
01479 $result = $ilDB->query($query);
01480 if ($result->numRows() == 1)
01481 {
01482 return true;
01483 }
01484 else
01485 {
01486 return false;
01487 }
01488 }
01489
01499 function setMaterial($material_id = "", $is_import = false, $material_title = "")
01500 {
01501 if (strcmp($material_id, "") != 0)
01502 {
01503 $import_id = "";
01504 if ($is_import)
01505 {
01506 $import_id = $material_id;
01507 $material_id = $this->_resolveInternalLink($import_id);
01508 }
01509 if (strcmp($material_title, "") == 0)
01510 {
01511 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
01512 {
01513 $type = $matches[1];
01514 $target_id = $matches[2];
01515 $material_title = $this->lng->txt("obj_$type") . ": ";
01516 switch ($type)
01517 {
01518 case "lm":
01519 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
01520 $cont_obj_gui =& new ilObjContentObjectGUI("", $target_id, true);
01521 $cont_obj = $cont_obj_gui->object;
01522 $material_title .= $cont_obj->getTitle();
01523 break;
01524 case "pg":
01525 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
01526 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
01527 $lm_id = ilLMObject::_lookupContObjID($target_id);
01528 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
01529 $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
01530 $cont_obj = $cont_obj_gui->object;
01531 $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
01532 $material_title .= $pg_obj->getTitle();
01533 break;
01534 case "st":
01535 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
01536 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
01537 $lm_id = ilLMObject::_lookupContObjID($target_id);
01538 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
01539 $cont_obj_gui =& new ilObjContentObjectGUI("", $lm_id, FALSE);
01540 $cont_obj = $cont_obj_gui->object;
01541 $st_obj =& new ilStructureObject($cont_obj, $target_id);
01542 $material_title .= $st_obj->getTitle();
01543 break;
01544 case "git":
01545 include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
01546 $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
01547 break;
01548 case "mob":
01549 break;
01550 }
01551 }
01552 }
01553 $this->material = array(
01554 "internal_link" => $material_id,
01555 "import_id" => $import_id,
01556 "title" => $material_title
01557 );
01558 }
01559 }
01560
01561 function _resolveInternalLink($internal_link)
01562 {
01563 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01564 {
01565 include_once "./Services/COPage/classes/class.ilInternalLink.php";
01566 include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
01567 include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
01568 switch ($matches[2])
01569 {
01570 case "lm":
01571 $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01572 break;
01573 case "pg":
01574 $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01575 break;
01576 case "st":
01577 $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01578 break;
01579 case "git":
01580 $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01581 break;
01582 case "mob":
01583 $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01584 break;
01585 }
01586 if (strcmp($resolved_link, "") == 0)
01587 {
01588 $resolved_link = $internal_link;
01589 }
01590 }
01591 else
01592 {
01593 $resolved_link = $internal_link;
01594 }
01595 return $resolved_link;
01596 }
01597
01598 function _resolveIntLinks($question_id)
01599 {
01600 global $ilDB;
01601 $resolvedlinks = 0;
01602 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01603 $ilDB->quote($question_id . "")
01604 );
01605 $result = $ilDB->query($query);
01606 if ($result->numRows())
01607 {
01608 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01609 {
01610 $internal_link = $row["internal_link"];
01611 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
01612 $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
01613 if (strcmp($internal_link, $resolved_link) != 0)
01614 {
01615
01616 $queryupdate = sprintf("UPDATE survey_material SET internal_link = %s WHERE material_id = %s",
01617 $ilDB->quote($resolved_link),
01618 $ilDB->quote($row["material_id"] . "")
01619 );
01620 $updateresult = $ilDB->query($queryupdate);
01621 $resolvedlinks++;
01622 }
01623 }
01624 }
01625 if ($resolvedlinks)
01626 {
01627
01628
01629
01630 include_once "./Services/COPage/classes/class.ilInternalLink.php";
01631 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01632
01633 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01634 $ilDB->quote($question_id . "")
01635 );
01636 $result = $ilDB->query($query);
01637 if ($result->numRows())
01638 {
01639 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01640 {
01641 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01642 {
01643 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
01644 }
01645 }
01646 }
01647 }
01648 }
01649
01650 function _getInternalLinkHref($target = "")
01651 {
01652 global $ilDB;
01653 $linktypes = array(
01654 "lm" => "LearningModule",
01655 "pg" => "PageObject",
01656 "st" => "StructureObject",
01657 "git" => "GlossaryItem",
01658 "mob" => "MediaObject"
01659 );
01660 $href = "";
01661 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01662 {
01663 $type = $matches[1];
01664 $target_id = $matches[2];
01665 include_once "./Services/Utilities/classes/class.ilUtil.php";
01666 switch($linktypes[$matches[1]])
01667 {
01668 case "LearningModule":
01669 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01670 break;
01671 case "PageObject":
01672 case "StructureObject":
01673 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01674 break;
01675 case "GlossaryItem":
01676 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01677 break;
01678 case "MediaObject":
01679 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/ilias.php?baseClass=ilLMPresentationGUI&obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=".$_GET["ref_id"]."&mob_id=".$target_id;
01680 break;
01681 }
01682 }
01683 return $href;
01684 }
01685
01696 function _isWriteable($question_id, $user_id)
01697 {
01698 global $ilDB;
01699
01700 if (($question_id < 1) || ($user_id < 1))
01701 {
01702 return false;
01703 }
01704
01705 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01706 $ilDB->quote($question_id . "")
01707 );
01708 $result = $ilDB->query($query);
01709 if ($result->numRows() == 1)
01710 {
01711 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01712 $qpl_object_id = $row["obj_fi"];
01713 include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
01714 return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
01715 }
01716 else
01717 {
01718 return false;
01719 }
01720 }
01721
01730 function getQuestionTypeID()
01731 {
01732 global $ilDB;
01733 $query = sprintf("SELECT questiontype_id FROM survey_questiontype WHERE type_tag = %s",
01734 $ilDB->quote($this->getQuestionType())
01735 );
01736 $result = $ilDB->query($query);
01737 if ($result->numRows() == 1)
01738 {
01739 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01740 return $row["questiontype_id"];
01741 }
01742 else
01743 {
01744 return 0;
01745 }
01746 }
01747
01756 function getQuestionType()
01757 {
01758 return "";
01759 }
01760
01770 function &_instanciateQuestion($question_id)
01771 {
01772 $question_type = SurveyQuestion::_getQuestionType($question_id);
01773 include_once "./Modules/SurveyQuestionPool/classes/class.$question_type.php";
01774 $question = new $question_type();
01775 $question->loadFromDb($question_id);
01776 return $question;
01777 }
01778
01787 function isHTML($a_text)
01788 {
01789 if (preg_match("/<[^>]*?>/", $a_text))
01790 {
01791 return TRUE;
01792 }
01793 else
01794 {
01795 return FALSE;
01796 }
01797 }
01798
01806 function QTIMaterialToString($a_material)
01807 {
01808 $result = "";
01809 for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
01810 {
01811 $material = $a_material->getMaterial($i);
01812 if (strcmp($material["type"], "mattext") == 0)
01813 {
01814 $result .= $material["material"]->getContent();
01815 }
01816 if (strcmp($material["type"], "matimage") == 0)
01817 {
01818 $matimage = $material["material"];
01819 if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
01820 {
01821
01822 if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
01823 array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
01824 }
01825 }
01826 }
01827 return $result;
01828 }
01829
01838 function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE)
01839 {
01840 include_once "./Services/RTE/classes/class.ilRTE.php";
01841 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
01842
01843 $a_xml_writer->xmlStartTag("material");
01844 $attrs = array(
01845 "type" => "text/plain"
01846 );
01847 if ($this->isHTML($a_material))
01848 {
01849 $attrs["type"] = "text/xhtml";
01850 }
01851 $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
01852
01853 if ($add_mobs)
01854 {
01855 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
01856 foreach ($mobs as $mob)
01857 {
01858 $mob_obj =& new ilObjMediaObject($mob);
01859 $imgattrs = array(
01860 "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
01861 "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
01862 );
01863 $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
01864 }
01865 }
01866 if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
01867 }
01868
01875 function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
01876 {
01877 include_once "./Services/Utilities/classes/class.ilUtil.php";
01878 return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
01879 }
01880
01890 function _getQuestionDataArray($id)
01891 {
01892 return array();
01893 }
01894
01895
01904 function addUserSpecificResultsExportTitles(&$a_array)
01905 {
01906 array_push($a_array, $this->getTitle());
01907 }
01908
01918 function addUserSpecificResultsData(&$a_array, &$resultset)
01919 {
01920
01921 }
01922
01932 function &getUserAnswers($survey_id)
01933 {
01934
01935 return array();
01936 }
01937
01946 function &getWorkingDataFromUserInput($post_data)
01947 {
01948
01949 $data = array();
01950 return $data;
01951 }
01952
01963 function importAdditionalMetadata($a_meta)
01964 {
01965
01966 }
01967
01976 function importResponses($a_data)
01977 {
01978
01979 }
01980
01989 function importAdjectives($a_data)
01990 {
01991
01992 }
01993
02002 function importMatrix($a_data)
02003 {
02004
02005 }
02006
02020 function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row)
02021 {
02022 include_once ("./classes/class.ilExcelUtils.php");
02023 $worksheet->writeString($row, 0, ilExcelUtils::_convert_text($this->getTitle()));
02024 $worksheet->writeString($row, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
02025 $worksheet->writeString($row, 2, ilExcelUtils::_convert_text($this->lng->txt($eval_data["QUESTION_TYPE"])));
02026 $worksheet->write($row, 3, $eval_data["USERS_ANSWERED"]);
02027 $worksheet->write($row, 4, $eval_data["USERS_SKIPPED"]);
02028 $worksheet->write($row, 5, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
02029 $worksheet->write($row, 6, ilExcelUtils::_convert_text($eval_data["MODE"]));
02030 $worksheet->write($row, 7, $eval_data["MODE_NR_OF_SELECTIONS"]);
02031 $worksheet->write($row, 8, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
02032 $worksheet->write($row, 9, $eval_data["ARITHMETIC_MEAN"]);
02033 return $row + 1;
02034 }
02035
02049 function &setExportCumulatedCVS(&$eval_data)
02050 {
02051 $csvrow = array();
02052 array_push($csvrow, $this->getTitle());
02053 array_push($csvrow, $this->getQuestiontext());
02054 array_push($csvrow, $this->lng->txt($eval_data["QUESTION_TYPE"]));
02055 array_push($csvrow, $eval_data["USERS_ANSWERED"]);
02056 array_push($csvrow, $eval_data["USERS_SKIPPED"]);
02057 array_push($csvrow, $eval_data["MODE"]);
02058 array_push($csvrow, $eval_data["MODE_NR_OF_SELECTIONS"]);
02059 array_push($csvrow, $eval_data["MEDIAN"]);
02060 array_push($csvrow, $eval_data["ARITHMETIC_MEAN"]);
02061 $result = array();
02062 array_push($result, $csvrow);
02063 return $result;
02064 }
02065
02077 function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
02078 {
02079
02080 }
02081
02090 function usableForPrecondition()
02091 {
02092
02093 return FALSE;
02094 }
02095
02104 function getAvailableRelations()
02105 {
02106
02107 return array();
02108 }
02109
02118 function getPreconditionSelectValue($default = "")
02119 {
02120
02121 }
02122
02132 function getPreconditionValueOutput($value)
02133 {
02134
02135 return $value;
02136 }
02137
02148 function outChart($survey_id, $type = "")
02149 {
02150
02151 }
02152
02153 }
02154 ?>