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 "./survey/classes/inc.SurveyConstants.php";
00025
00037 class SurveyQuestion
00038 {
00046 var $id;
00047
00055 var $title;
00063 var $description;
00072 var $owner;
00073
00082 var $author;
00083
00091 var $materials;
00092
00100 var $survey_id;
00101
00109 var $obj_id;
00110
00118 var $questiontext;
00119
00127 var $obligatory;
00128
00136 var $ilias;
00137
00145 var $tpl;
00146
00154 var $lng;
00155
00163 var $domxml;
00164
00172 var $orientation;
00173
00174 var $material;
00175
00187 function SurveyQuestion(
00188 $title = "",
00189 $description = "",
00190 $author = "",
00191 $questiontext = "",
00192 $owner = -1
00193 )
00194
00195 {
00196 global $ilias;
00197 global $lng;
00198 global $tpl;
00199
00200 $this->ilias =& $ilias;
00201 $this->lng =& $lng;
00202 $this->tpl =& $tpl;
00203
00204 $this->title = $title;
00205 $this->description = $description;
00206 $this->questiontext = $questiontext;
00207 $this->author = $author;
00208 if (!$this->author) {
00209 $this->author = $this->ilias->account->fullname;
00210 }
00211 $this->owner = $owner;
00212 if ($this->owner == -1) {
00213 $this->owner = $this->ilias->account->id;
00214 }
00215 $this->id = -1;
00216 $this->survey_id = -1;
00217 $this->obligatory = 1;
00218 $this->orientation = 0;
00219 $this->materials = array();
00220 $this->material = array();
00221 register_shutdown_function(array(&$this, '_SurveyQuestion'));
00222 }
00223
00224 function _SurveyQuestion()
00225 {
00226 if (!empty($this->domxml))
00227 {
00228 $this->domxml->free();
00229 }
00230 }
00231
00232
00241 function isComplete()
00242 {
00243 return false;
00244 }
00245
00256 function questionTitleExists($title, $questionpool_object = "")
00257 {
00258 $refwhere = "";
00259 if (strcmp($questionpool_reference, "") != 0)
00260 {
00261 $refwhere = sprintf(" AND obj_fi = %s",
00262 $this->ilias->db->quote($questionpool_object)
00263 );
00264 }
00265 $query = sprintf("SELECT question_id FROM survey_question WHERE title = %s$refwhere",
00266 $this->ilias->db->quote($title)
00267 );
00268 $result = $this->ilias->db->query($query);
00269 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00270 {
00271 if ($result->numRows() == 1)
00272 {
00273 return TRUE;
00274 }
00275 }
00276 return FALSE;
00277 }
00278
00288 function setTitle($title = "")
00289 {
00290 $this->title = $title;
00291 }
00292
00302 function setObligatory($obligatory = 1)
00303 {
00304 if ($obligatory)
00305 {
00306 $this->obligatory = 1;
00307 }
00308 else
00309 {
00310 $this->obligatory = 0;
00311 }
00312 }
00313
00323 function setOrientation($orientation = 0)
00324 {
00325 $this->orientation = $orientation;
00326 }
00327
00337 function setId($id = -1)
00338 {
00339 $this->id = $id;
00340 }
00341
00351 function setSurveyId($id = -1)
00352 {
00353 $this->survey_id = $id;
00354 }
00355
00365 function setDescription($description = "")
00366 {
00367 $this->description = $description;
00368 }
00369
00370
00381 function addMaterials($materials_file, $materials_name="")
00382 {
00383 if(empty($materials_name))
00384 {
00385 $materials_name = $materials_file;
00386 }
00387 if ((!empty($materials_name))&&(!$this->keyInArray($materials_name, $this->materials)))
00388 {
00389 $this->materials[$materials_name] = $materials_file;
00390 }
00391
00392 }
00393
00404 function keyInArray($searchkey, $array)
00405 {
00406 if ($searchKey)
00407 {
00408 foreach ($array as $key => $value)
00409 {
00410 if (strcmp($key, $searchkey)==0)
00411 {
00412 return true;
00413 }
00414 }
00415 }
00416 return false;
00417 }
00418
00428 function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
00429 {
00430 if (!empty($materials_filename))
00431 {
00432 include_once "./classes/class.ilUtil.php";
00433 $materialspath = $this->getMaterialsPath();
00434 if (!file_exists($materialspath))
00435 {
00436 ilUtil::makeDirParents($materialspath);
00437 }
00438
00439 if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
00440 $materialspath.$materials_filename))
00441 {
00442 print "image not uploaded!!!! ";
00443 }
00444 else
00445 {
00446 $this->addMaterials($materials_filename, $materials_name);
00447 }
00448 }
00449 }
00450
00460 function deleteMaterial($materials_name = "")
00461 {
00462 foreach ($this->materials as $key => $value)
00463 {
00464 if (strcmp($key, $materials_name)==0)
00465 {
00466 if (file_exists($this->getMaterialsPath().$value))
00467 {
00468 unlink($this->getMaterialsPath().$value);
00469 }
00470 unset($this->materials[$key]);
00471 }
00472 }
00473 }
00474
00483 function flushMaterials()
00484 {
00485 $this->materials = array();
00486 }
00487
00497 function setAuthor($author = "")
00498 {
00499 if (!$author)
00500 {
00501 $author = $this->ilias->account->fullname;
00502 }
00503 $this->author = $author;
00504 }
00505
00515 function setQuestiontext($questiontext = "")
00516 {
00517 $this->questiontext = $questiontext;
00518 }
00519
00529 function setOwner($owner = "")
00530 {
00531 $this->owner = $owner;
00532 }
00533
00543 function getTitle()
00544 {
00545 return $this->title;
00546 }
00547
00557 function getId()
00558 {
00559 return $this->id;
00560 }
00561
00572 function getObligatory()
00573 {
00574 return $this->obligatory;
00575 }
00576
00586 function getSurveyId()
00587 {
00588 return $this->survey_id;
00589 }
00590
00600 function getOrientation()
00601 {
00602 switch ($this->orientation)
00603 {
00604 case 0:
00605 case 1:
00606 case 2:
00607 break;
00608 default:
00609 $this->orientation = 0;
00610 break;
00611 }
00612 return $this->orientation;
00613 }
00614
00615
00625 function getDescription()
00626 {
00627 return $this->description;
00628 }
00629
00639 function getAuthor()
00640 {
00641 return $this->author;
00642 }
00643
00653 function getOwner()
00654 {
00655 return $this->owner;
00656 }
00657
00667 function getQuestiontext() {
00668 return $this->questiontext;
00669 }
00670
00680 function getObjId() {
00681 return $this->obj_id;
00682 }
00683
00693 function setObjId($obj_id = 0) {
00694 $this->obj_id = $obj_id;
00695 }
00696
00704 function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
00705 {
00706 if ($this->getId() <= 0)
00707 {
00708
00709 return;
00710 }
00711
00712 $clone = $this;
00713 $original_id = $this->getId();
00714 $clone->setId(-1);
00715 if ($title)
00716 {
00717 $clone->setTitle($title);
00718 }
00719 if ($author)
00720 {
00721 $clone->setAuthor($author);
00722 }
00723 if ($owner)
00724 {
00725 $clone->setOwner($owner);
00726 }
00727 if ($for_survey)
00728 {
00729 $clone->saveToDb($original_id);
00730 }
00731 else
00732 {
00733 $clone->saveToDb();
00734 }
00735
00736 $clone->duplicateMaterials($original_id);
00737
00738 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00739 return $clone->getId();
00740 }
00741
00750 function copyXHTMLMediaObjectsOfQuestion($a_q_id)
00751 {
00752 include_once("./content/classes/Media/class.ilObjMediaObject.php");
00753 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id);
00754 foreach ($mobs as $mob)
00755 {
00756 ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId());
00757 }
00758 }
00759
00768 function duplicateMaterials($question_id)
00769 {
00770 foreach ($this->materials as $filename)
00771 {
00772 $materialspath = $this->getMaterialsPath();
00773 $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
00774 if (!file_exists($materialspath))
00775 {
00776 include_once "./classes/class.ilUtil.php";
00777 ilUtil::makeDirParents($materialspath);
00778 }
00779 if (!copy($materialspath_original . $filename, $materialspath . $filename))
00780 {
00781 print "material could not be duplicated!!!! ";
00782 }
00783 }
00784 }
00785
00786
00795 function loadFromDb($question_id)
00796 {
00797 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
00798 $this->ilias->db->quote($this->getId() . "")
00799 );
00800 $result = $this->ilias->db->query($query);
00801 $this->material = array();
00802 if ($result->numRows())
00803 {
00804 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00805 {
00806 $this->material = array(
00807 "internal_link" => $row["internal_link"],
00808 "import_id" => $row["import_id"],
00809 "title" => $row["material_title"]
00810 );
00811 }
00812 }
00813 }
00814
00823 function _isComplete($question_id)
00824 {
00825 global $ilDB;
00826
00827 $query = sprintf("SELECT complete FROM survey_question WHERE question_id = %s",
00828 $ilDB->quote($question_id . "")
00829 );
00830 $result = $ilDB->query($query);
00831 if ($result->numRows())
00832 {
00833 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00834 if ($row["complete"] == 1)
00835 {
00836 return TRUE;
00837 }
00838 }
00839 return FALSE;
00840 }
00841
00849 function saveCompletionStatus()
00850 {
00851 $complete = 0;
00852 if ($this->isComplete())
00853 {
00854 $complete = 1;
00855 }
00856 if ($this->id > 0)
00857 {
00858
00859 $query = sprintf("UPDATE survey_question SET complete = %s WHERE question_id = %s",
00860 $this->ilias->db->quote("$complete"),
00861 $this->ilias->db->quote($this->id)
00862 );
00863 $result = $this->ilias->db->query($query);
00864 }
00865 }
00866
00875 function saveToDb($original_id = "")
00876 {
00877 include_once "./content/classes/Pages/class.ilInternalLink.php";
00878 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
00879 $this->ilias->db->quote($this->getId() . "")
00880 );
00881 $result = $this->ilias->db->query($query);
00882 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->getId());
00883 if (count($this->material))
00884 {
00885 $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00886 $this->ilias->db->quote($this->getId() . ""),
00887 $this->ilias->db->quote($this->material["internal_link"] . ""),
00888 $this->ilias->db->quote($this->material["import_id"] . ""),
00889 $this->ilias->db->quote($this->material["title"] . "")
00890 );
00891 $this->ilias->db->query($query);
00892 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00893 {
00894 ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
00895 }
00896 }
00897 }
00898
00899
00908 function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
00909 {
00910 }
00911
00920 function getImagePath()
00921 {
00922 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
00923 }
00924
00933 function getMaterialsPath()
00934 {
00935 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
00936 }
00937
00946 function getImagePathWeb()
00947 {
00948 include_once "./classes/class.ilUtil.php";
00949 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
00950 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00951 }
00952
00961 function getMaterialsPathWeb()
00962 {
00963 include_once "./classes/class.ilUtil.php";
00964 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
00965 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00966 }
00967
00976 function saveMaterialsToDb()
00977 {
00978 if ($this->id > 0)
00979 {
00980 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
00981 $this->ilias->db->quote($this->id)
00982 );
00983 $result = $this->ilias->db->query($query);
00984 if (!empty($this->materials)) {
00985 foreach ($this->materials as $key => $value)
00986 {
00987 $query = sprintf("INSERT INTO survey_question_material (question_fi, materials, materials_file) VALUES (%s, %s, %s)",
00988 $this->ilias->db->quote($this->id),
00989 $this->ilias->db->quote($key),
00990 $this->ilias->db->quote($value)
00991 );
00992 $result = $this->ilias->db->query($query);
00993 }
00994 }
00995 }
00996 }
00997
01006 function loadMaterialFromDb($question_id)
01007 {
01008 $query = sprintf("SELECT * FROM survey_question_material WHERE question_fi = %s",
01009 $this->ilias->db->quote($question_id)
01010 );
01011 $result = $this->ilias->db->query($query);
01012 if (strcmp(strtolower(get_class($result)), db_result) == 0)
01013 {
01014 $this->materials = array();
01015 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01016 {
01017 $this->addMaterials($data->materials_file, $data->materials);
01018 }
01019 }
01020 }
01021
01032 function saveCategoryToDb($categorytext)
01033 {
01034 global $ilUser;
01035
01036 $query = sprintf("SELECT title, category_id FROM survey_category WHERE title = %s AND owner_fi = %s",
01037 $this->ilias->db->quote($categorytext),
01038 $this->ilias->db->quote($ilUser->id)
01039 );
01040 $result = $this->ilias->db->query($query);
01041 $insert = FALSE;
01042 $returnvalue = "";
01043 if ($result->numRows())
01044 {
01045 $insert = TRUE;
01046 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01047 {
01048 if (strcmp($row->title, $categorytext) == 0)
01049 {
01050 $returnvalue = $row->category_id;
01051 $insert = FALSE;
01052 }
01053 }
01054 }
01055 else
01056 {
01057 $insert = TRUE;
01058 }
01059 if ($insert)
01060 {
01061 $query = sprintf("INSERT INTO survey_category (category_id, title, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
01062 $this->ilias->db->quote($categorytext),
01063 $this->ilias->db->quote($ilUser->id)
01064 );
01065 $result = $this->ilias->db->query($query);
01066 $returnvalue = $this->ilias->db->getLastInsertId();
01067 }
01068 return $returnvalue;
01069 }
01070
01079 function deleteAdditionalTableData($question_id)
01080 {
01081 global $ilDB;
01082 $additional_table_name = $this->getAdditionalTableName();
01083 $query = sprintf("DELETE FROM $additional_table_name WHERE question_fi = %s",
01084 $ilDB->quote($question_id . "")
01085 );
01086 $result = $ilDB->query($query);
01087 }
01088
01097 function delete($question_id)
01098 {
01099 if ($question_id < 1)
01100 return;
01101
01102 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01103 $this->ilias->db->quote($question_id)
01104 );
01105 $result = $this->ilias->db->query($query);
01106 if ($result->numRows() == 1)
01107 {
01108 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01109 $obj_id = $row["obj_fi"];
01110 }
01111 else
01112 {
01113 return;
01114 }
01115
01116 $query = sprintf("DELETE FROM survey_answer WHERE question_fi = %s",
01117 $this->ilias->db->quote($question_id)
01118 );
01119 $result = $this->ilias->db->query($query);
01120
01121 $query = sprintf("SELECT constraint_id FROM survey_constraint WHERE question_fi = %s",
01122 $this->ilias->db->quote($question_id)
01123 );
01124 $result = $this->ilias->db->query($query);
01125 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01126 {
01127 $query = sprintf("DELETE FROM survey_question_constraint WHERE constraint_fi = %s",
01128 $this->ilias->db->quote($row->constraint_id)
01129 );
01130 $delresult = $this->ilias->db->query($query);
01131 }
01132
01133 $query = sprintf("DELETE FROM survey_constraint WHERE question_fi = %s",
01134 $this->ilias->db->quote($question_id)
01135 );
01136 $result = $this->ilias->db->query($query);
01137
01138 $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s",
01139 $this->ilias->db->quote($question_id)
01140 );
01141 $result = $this->ilias->db->query($query);
01142 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01143 {
01144 $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
01145 $this->ilias->db->quote($row->constraint_fi)
01146 );
01147 $delresult = $this->ilias->db->query($query);
01148 }
01149 $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s",
01150 $this->ilias->db->quote($question_id)
01151 );
01152 $result = $this->ilias->db->query($query);
01153
01154 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
01155 $this->ilias->db->quote($question_id)
01156 );
01157 $result = $this->ilias->db->query($query);
01158
01159 $query = sprintf("DELETE FROM survey_questionblock_question WHERE question_fi = %s",
01160 $this->ilias->db->quote($question_id)
01161 );
01162 $result = $this->ilias->db->query($query);
01163
01164 $query = sprintf("DELETE FROM survey_question_obligatory WHERE question_fi = %s",
01165 $this->ilias->db->quote($question_id)
01166 );
01167 $result = $this->ilias->db->query($query);
01168
01169 $query = sprintf("DELETE FROM survey_survey_question WHERE question_fi = %s",
01170 $this->ilias->db->quote($question_id)
01171 );
01172 $result = $this->ilias->db->query($query);
01173
01174 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01175 $this->ilias->db->quote($question_id)
01176 );
01177 $result = $this->ilias->db->query($query);
01178
01179 $query = sprintf("DELETE FROM survey_question WHERE question_id = %s",
01180 $this->ilias->db->quote($question_id)
01181 );
01182 $result = $this->ilias->db->query($query);
01183
01184 $this->deleteAdditionalTableData($question_id);
01185
01186 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01187 $this->ilias->db->quote($question_id)
01188 );
01189 $result = $this->ilias->db->query($query);
01190 include_once "./content/classes/Pages/class.ilInternalLink.php";
01191 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01192
01193 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
01194 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
01195 {
01196 include_once "./classes/class.ilUtil.php";
01197 ilUtil::delDir($directory);
01198 }
01199
01200 include_once("./content/classes/Media/class.ilObjMediaObject.php");
01201 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
01202
01203
01204
01205
01206 foreach($mobs as $mob)
01207 {
01208 ilObjMediaObject::_removeUsage($mob, "spl:html", $question_id);
01209 $mob_obj =& new ilObjMediaObject($mob);
01210 $mob_obj->delete();
01211 }
01212 }
01213
01223 function _getQuestionType($question_id)
01224 {
01225 global $ilDB;
01226
01227 if ($question_id < 1)
01228 return "";
01229
01230 $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",
01231 $ilDB->quote($question_id)
01232 );
01233 $result = $ilDB->query($query);
01234 if ($result->numRows() == 1)
01235 {
01236 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01237 return $data->type_tag;
01238 }
01239 else
01240 {
01241 return "";
01242 }
01243 }
01244
01254 function _getOriginalId($question_id)
01255 {
01256 global $ilDB;
01257 $query = sprintf("SELECT * FROM survey_question WHERE question_id = %s",
01258 $ilDB->quote($question_id . "")
01259 );
01260 $result = $ilDB->query($query);
01261 if ($result->numRows() > 0)
01262 {
01263 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01264 if ($row["original_id"] > 0)
01265 {
01266 return $row["original_id"];
01267 }
01268 else
01269 {
01270 return $row["question_id"];
01271 }
01272 }
01273 else
01274 {
01275 return "";
01276 }
01277 }
01278
01279 function _getRefIdFromObjId($obj_id)
01280 {
01281 global $ilDB;
01282
01283 $query = sprintf("SELECT ref_id FROM object_reference WHERE obj_id=%s",
01284 $ilDB->quote($obj_id)
01285
01286 );
01287 $result = $ilDB->query($query);
01288 if ($result->numRows())
01289 {
01290 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01291 return $row["ref_id"];
01292 }
01293 return 0;
01294 }
01295
01296 function syncWithOriginal()
01297 {
01298 include_once "./content/classes/Pages/class.ilInternalLink.php";
01299 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01300 $this->ilias->db->quote($this->original_id . "")
01301 );
01302 $result = $this->ilias->db->query($query);
01303 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
01304 if (strlen($this->material["internal_link"]))
01305 {
01306 $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01307 $this->ilias->db->quote($this->original_id . ""),
01308 $this->ilias->db->quote($this->material["internal_link"] . ""),
01309 $this->ilias->db->quote($this->material["import_id"] . ""),
01310 $this->ilias->db->quote($this->material["title"] . "")
01311 );
01312 $this->ilias->db->query($query);
01313 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
01314 {
01315 ilInternalLink::_saveLink("sqst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01316 }
01317 }
01318 }
01319
01328 function getPhrase($phrase_id)
01329 {
01330 $query = sprintf("SELECT title FROM survey_phrase WHERE phrase_id = %s",
01331 $this->ilias->db->quote($phrase_id)
01332 );
01333 $result = $this->ilias->db->query($query);
01334 if ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01335 {
01336 return $row["title"];
01337 }
01338 return "";
01339 }
01340
01350 function phraseExists($title)
01351 {
01352 global $ilUser;
01353
01354 $query = sprintf("SELECT phrase_id FROM survey_phrase WHERE title = %s AND owner_fi = %s",
01355 $this->ilias->db->quote($title),
01356 $this->ilias->db->quote($ilUser->id)
01357 );
01358 $result = $this->ilias->db->query($query);
01359 if ($result->numRows() == 0)
01360 {
01361 return false;
01362 }
01363 else
01364 {
01365 return true;
01366 }
01367 }
01368
01378 function _questionExists($question_id)
01379 {
01380 global $ilDB;
01381
01382 if ($question_id < 1)
01383 {
01384 return false;
01385 }
01386
01387 $query = sprintf("SELECT question_id FROM survey_question WHERE question_id = %s",
01388 $ilDB->quote($question_id)
01389 );
01390 $result = $ilDB->query($query);
01391 if ($result->numRows() == 1)
01392 {
01393 return true;
01394 }
01395 else
01396 {
01397 return false;
01398 }
01399 }
01400
01410 function setMaterial($material_id = "", $is_import = false, $material_title = "")
01411 {
01412 if (strcmp($material_id, "") != 0)
01413 {
01414 $import_id = "";
01415 if ($is_import)
01416 {
01417 $import_id = $material_id;
01418 $material_id = $this->_resolveInternalLink($import_id);
01419 }
01420 if (strcmp($material_title, "") == 0)
01421 {
01422 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
01423 {
01424 $type = $matches[1];
01425 $target_id = $matches[2];
01426 $material_title = $this->lng->txt("obj_$type") . ": ";
01427 switch ($type)
01428 {
01429 case "lm":
01430 include_once("./content/classes/class.ilObjContentObject.php");
01431 $cont_obj =& new ilObjContentObject($target_id, true);
01432 $material_title .= $cont_obj->getTitle();
01433 break;
01434 case "pg":
01435 include_once("./content/classes/class.ilLMPageObject.php");
01436 include_once("./content/classes/class.ilLMObject.php");
01437 include_once("./content/classes/class.ilObjContentObject.php");
01438 $lm_id = ilLMObject::_lookupContObjID($target_id);
01439 $cont_obj =& new ilObjContentObject($lm_id, false);
01440 $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
01441 $material_title .= $pg_obj->getTitle();
01442 break;
01443 case "st":
01444 include_once("content/classes/class.ilStructureObject.php");
01445 include_once("./content/classes/class.ilLMObject.php");
01446 include_once("./content/classes/class.ilObjContentObject.php");
01447 $lm_id = ilLMObject::_lookupContObjID($target_id);
01448 $cont_obj =& new ilObjContentObject($lm_id, false);
01449 $st_obj =& new ilStructureObject($cont_obj, $target_id);
01450 $material_title .= $st_obj->getTitle();
01451 break;
01452 case "git":
01453 include_once "./content/classes/class.ilGlossaryTerm.php";
01454 $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
01455 break;
01456 case "mob":
01457 break;
01458 }
01459 }
01460 }
01461 $this->material = array(
01462 "internal_link" => $material_id,
01463 "import_id" => $import_id,
01464 "title" => $material_title
01465 );
01466 }
01467 }
01468
01469 function _resolveInternalLink($internal_link)
01470 {
01471 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01472 {
01473 include_once "./content/classes/Pages/class.ilInternalLink.php";
01474 include_once "./content/classes/class.ilLMObject.php";
01475 include_once "./content/classes/class.ilGlossaryTerm.php";
01476 switch ($matches[2])
01477 {
01478 case "lm":
01479 $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01480 break;
01481 case "pg":
01482 $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01483 break;
01484 case "st":
01485 $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01486 break;
01487 case "git":
01488 $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01489 break;
01490 case "mob":
01491 $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01492 break;
01493 }
01494 if (strcmp($resolved_link, "") == 0)
01495 {
01496 $resolved_link = $internal_link;
01497 }
01498 }
01499 else
01500 {
01501 $resolved_link = $internal_link;
01502 }
01503 return $resolved_link;
01504 }
01505
01506 function _resolveIntLinks($question_id)
01507 {
01508 global $ilDB;
01509 $resolvedlinks = 0;
01510 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01511 $ilDB->quote($question_id . "")
01512 );
01513 $result = $ilDB->query($query);
01514 if ($result->numRows())
01515 {
01516 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01517 {
01518 $internal_link = $row["internal_link"];
01519 include_once "./survey/classes/class.SurveyQuestion.php";
01520 $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
01521 if (strcmp($internal_link, $resolved_link) != 0)
01522 {
01523
01524 $queryupdate = sprintf("UPDATE survey_material SET internal_link = %s WHERE material_id = %s",
01525 $ilDB->quote($resolved_link),
01526 $ilDB->quote($row["material_id"] . "")
01527 );
01528 $updateresult = $ilDB->query($queryupdate);
01529 $resolvedlinks++;
01530 }
01531 }
01532 }
01533 if ($resolvedlinks)
01534 {
01535
01536
01537
01538 include_once "./content/classes/Pages/class.ilInternalLink.php";
01539 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01540
01541 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01542 $ilDB->quote($question_id . "")
01543 );
01544 $result = $ilDB->query($query);
01545 if ($result->numRows())
01546 {
01547 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01548 {
01549 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01550 {
01551 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
01552 }
01553 }
01554 }
01555 }
01556 }
01557
01558 function _getInternalLinkHref($target = "")
01559 {
01560 global $ilDB;
01561 $linktypes = array(
01562 "lm" => "LearningModule",
01563 "pg" => "PageObject",
01564 "st" => "StructureObject",
01565 "git" => "GlossaryItem",
01566 "mob" => "MediaObject"
01567 );
01568 $href = "";
01569 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01570 {
01571 $type = $matches[1];
01572 $target_id = $matches[2];
01573 include_once "./classes/class.ilUtil.php";
01574 switch($linktypes[$matches[1]])
01575 {
01576 case "LearningModule":
01577 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01578 break;
01579 case "PageObject":
01580 case "StructureObject":
01581 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01582 break;
01583 case "GlossaryItem":
01584 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01585 break;
01586 case "MediaObject":
01587 $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/content/lm_presentation.php?obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=".$_GET["ref_id"]."&mob_id=".$target_id;
01588 break;
01589 }
01590 }
01591 return $href;
01592 }
01593
01594 function saveCategoriesToDb()
01595 {
01596
01597
01598
01599 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01600 $this->ilias->db->quote($this->id)
01601 );
01602 $result = $this->ilias->db->query($query);
01603
01604 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
01605 {
01606 $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
01607 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01608 $this->ilias->db->quote($category_id . ""),
01609 $this->ilias->db->quote($this->id . ""),
01610 $this->ilias->db->quote(($i + 1) . ""),
01611 $this->ilias->db->quote($i . "")
01612 );
01613 $answer_result = $this->ilias->db->query($query);
01614 }
01615 $this->saveCompletionStatus();
01616 }
01617
01628 function _isWriteable($question_id, $user_id)
01629 {
01630 global $ilDB;
01631
01632 if (($question_id < 1) || ($user_id < 1))
01633 {
01634 return false;
01635 }
01636
01637 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01638 $ilDB->quote($question_id . "")
01639 );
01640 $result = $ilDB->query($query);
01641 if ($result->numRows() == 1)
01642 {
01643 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01644 $qpl_object_id = $row["obj_fi"];
01645 include_once "./survey/classes/class.ilObjSurveyQuestionPool.php";
01646 return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
01647 }
01648 else
01649 {
01650 return false;
01651 }
01652 }
01653
01662 function getQuestionType()
01663 {
01664 return 0;
01665 }
01666
01676 function &_instanciateQuestion($question_id)
01677 {
01678 $question_type = SurveyQuestion::_getQuestionType($question_id);
01679 include_once "./survey/classes/class.$question_type.php";
01680 $question = new $question_type();
01681 $question->loadFromDb($question_id);
01682 return $question;
01683 }
01684
01685 function &outEvaluationCumulatedResults(&$cumulated_results)
01686 {
01687 $result_array = array();
01688 $result_array["QUESTION_TITLE"] = $this->getTitle();
01689 $result_array["QUESTION_TEXT"] = $this->getQuestiontext();
01690 $result_array["USERS_ANSWERED"] = $cumulated_results["USERS_ANSWERED"];
01691 $result_array["USERS_SKIPPED"] = $cumulated_results["USERS_SKIPPED"];
01692 $result_array["QUESTION_TYPE"] = $this->lng->txt($cumulated_results["QUESTION_TYPE"]);
01693 $result_array["MODE"] = $cumulated_results["MODE"];
01694 $result_array["MODE_VALUE"] = $cumulated_results["MODE_VALUE"];
01695 $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated_results["MODE_NR_OF_SELECTIONS"];
01696 $result_array["MEDIAN"] = $cumulated_results["MEDIAN"];
01697 $result_array["ARITHMETIC_MEAN"] = $cumulated_results["ARITHMETIC_MEAN"];
01698 return $result_array;
01699 }
01700
01709 function isHTML($a_text)
01710 {
01711 if (preg_match("/<[^>]*?>/", $a_text))
01712 {
01713 return TRUE;
01714 }
01715 else
01716 {
01717 return FALSE;
01718 }
01719 }
01720
01728 function QTIMaterialToString($a_material)
01729 {
01730 $result = "";
01731 for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
01732 {
01733 $material = $a_material->getMaterial($i);
01734 if (strcmp($material["type"], "mattext") == 0)
01735 {
01736 $result .= $material["material"]->getContent();
01737 }
01738 if (strcmp($material["type"], "matimage") == 0)
01739 {
01740 $matimage = $material["material"];
01741 if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
01742 {
01743
01744 if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
01745 array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
01746 }
01747 }
01748 }
01749 return $result;
01750 }
01751
01760 function addQTIMaterial(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE)
01761 {
01762 include_once "./Services/RTE/classes/class.ilRTE.php";
01763 include_once("./content/classes/Media/class.ilObjMediaObject.php");
01764
01765 $a_xml_writer->xmlStartTag("material");
01766 $attrs = array(
01767 "texttype" => "text/plain"
01768 );
01769 if ($this->isHTML($a_material))
01770 {
01771 $attrs["texttype"] = "text/xhtml";
01772 }
01773 $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
01774
01775 if ($add_mobs)
01776 {
01777 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $this->getId());
01778 foreach ($mobs as $mob)
01779 {
01780 $mob_obj =& new ilObjMediaObject($mob);
01781 $imgattrs = array(
01782 "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
01783 "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
01784 );
01785 $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
01786 }
01787 }
01788 if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
01789 }
01790
01797 function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
01798 {
01799 include_once "./classes/class.ilObjAdvancedEditing.php";
01800 $result = $txt_output;
01801 $is_html = $this->isHTML($result);
01802 if ($prepare_for_latex_output)
01803 {
01804 $result = ilUtil::insertLatexImages($result, "<span class\=\"latex\">", "<\/span>", URL_TO_LATEX);
01805 $result = ilUtil::insertLatexImages($result, "\[tex\]", "\[\/tex\]", URL_TO_LATEX);
01806 }
01807
01808
01809
01810 if (!$is_html)
01811 {
01812
01813 $result = preg_replace("/[\n]/", "<br />", $result);
01814 }
01815 else
01816 {
01817
01818 if (preg_match_all("/(<pre>.*?<\/pre>)/ims", $result, $matches))
01819 {
01820 foreach ($matches[0] as $found)
01821 {
01822 $replacement = "";
01823 if (strpos("\n", $found) === FALSE)
01824 {
01825 $replacement = "\n";
01826 }
01827 $removed = preg_replace("/<br\s*?\/>/ims", $replacement, $found);
01828 $result = str_replace($found, $removed, $result);
01829 }
01830 }
01831 }
01832 $result = str_replace("{", "{", $result);
01833 $result = str_replace("}", "}", $result);
01834 $result = str_replace("\\", "\", $result);
01835 return $result;
01836 }
01837
01847 function _getQuestionDataArray($id)
01848 {
01849 return array();
01850 }
01851 }
01852 ?>