• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

survey/classes/class.SurveyQuestion.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00035 class SurveyQuestion {
00043   var $id;
00044 
00052   var $title;
00060   var $description;
00069   var $owner;
00070 
00079   var $author;
00080 
00088   var $materials;
00089 
00097   var $survey_id;
00098 
00106   var $obj_id;
00107 
00115   var $questiontext;
00116 
00124   var $obligatory;
00125         
00133   var $ilias;
00134 
00142   var $tpl;
00143 
00151   var $lng;
00152 
00160         var $domxml;
00161 
00169         var $orientation;
00170         
00171         var $material;
00172 
00184   function SurveyQuestion(
00185     $title = "",
00186     $description = "",
00187     $author = "",
00188                 $questiontext = "",
00189     $owner = -1
00190   )
00191 
00192   {
00193                 global $ilias;
00194     global $lng;
00195     global $tpl;
00196 
00197                 $this->ilias =& $ilias;
00198     $this->lng =& $lng;
00199     $this->tpl =& $tpl;
00200 
00201     $this->title = $title;
00202     $this->description = $description;
00203                 $this->questiontext = $questiontext;
00204     $this->author = $author;
00205     if (!$this->author) {
00206       $this->author = $this->ilias->account->fullname;
00207     }
00208     $this->owner = $owner;
00209     if ($this->owner == -1) {
00210       $this->owner = $this->ilias->account->id;
00211     }
00212     $this->id = -1;
00213     $this->survey_id = -1;
00214                 $this->obligatory = 1;
00215                 $this->orientation = 0;
00216                 $this->materials = array();
00217                 $this->material = array();
00218                 register_shutdown_function(array(&$this, '_SurveyQuestion'));
00219         }
00220 
00221         function _SurveyQuestion()
00222         {
00223                 if (!empty($this->domxml))
00224                 {
00225                         $this->domxml->free();
00226                 }
00227         }
00228 
00229         
00238         function isComplete()
00239         {
00240                 return false;
00241         }
00242 
00248         function getCallingScript()
00249         {
00250                 return "questionpool.php";
00251         }
00252         
00263   function questionTitleExists($title, $questionpool_object = "") {
00264                 $refwhere = "";
00265                 if (strcmp($questionpool_reference, "") != 0)
00266                 {
00267                         $refwhere = sprintf(" AND obj_fi = %s",
00268                                 $this->ilias->db->quote($questionpool_object)
00269                         );
00270                 }
00271     $query = sprintf("SELECT question_id FROM survey_question WHERE title = %s$refwhere",
00272       $this->ilias->db->quote($title)
00273     );
00274     $result = $this->ilias->db->query($query);
00275     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00276       if ($result->numRows() == 1) {
00277         return TRUE;
00278       }
00279     }
00280     return FALSE;
00281   }
00282 
00292   function setTitle($title = "") {
00293     $this->title = $title;
00294   }
00295 
00305   function setObligatory($obligatory = 1) {
00306                 if ($obligatory)
00307                 {
00308             $this->obligatory = 1;
00309                 }
00310                 else
00311                 {
00312             $this->obligatory = 0;
00313                 }
00314   }
00315 
00325   function setOrientation($orientation = 0) {
00326     $this->orientation = $orientation;
00327   }
00328 
00338   function setId($id = -1) {
00339     $this->id = $id;
00340   }
00341 
00351   function setSurveyId($id = -1) {
00352     $this->survey_id = $id;
00353   }
00354 
00364   function setDescription($description = "") {
00365     $this->description = $description;
00366   }
00367 
00368 
00379   function addMaterials($materials_file, $materials_name="") {
00380         if(empty($materials_name)) {
00381         $materials_name = $materials_file;
00382     }
00383     if ((!empty($materials_name))&&(!$this->keyInArray($materials_name, $this->materials))) {
00384       $this->materials[$materials_name] = $materials_file;
00385     }
00386 
00387   }
00388 
00399   function keyInArray($searchkey, $array) {
00400           if ($searchKey) {
00401                    foreach ($array as $key => $value) {
00402                            if (strcmp($key, $searchkey)==0) {
00403                                    return true;
00404                            }
00405                    }
00406            }
00407            return false;
00408   }
00409 
00419         function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
00420         {
00421                 if (!empty($materials_filename))
00422                 {
00423                         $materialspath = $this->getMaterialsPath();
00424                         if (!file_exists($materialspath))
00425                         {
00426                                 ilUtil::makeDirParents($materialspath);
00427                         }
00428                         //if (!move_uploaded_file($materials_tempfilename, $materialspath . $materials_filename))
00429                         if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
00430                                 $materialspath.$materials_filename))
00431                         {
00432                                 print "image not uploaded!!!! ";
00433                         }
00434                         else
00435                         {
00436                                 $this->addMaterials($materials_filename, $materials_name);
00437                         }
00438                 }
00439         }
00440 
00450   function deleteMaterial($materials_name = "") {
00451         foreach ($this->materials as $key => $value) {
00452                 if (strcmp($key, $materials_name)==0) {
00453                         if (file_exists($this->getMaterialsPath().$value)) {
00454                                 unlink($this->getMaterialsPath().$value);
00455                         }
00456                         unset($this->materials[$key]);
00457                 }
00458         }
00459   }
00460 
00469   function flushMaterials() {
00470     $this->materials = array();
00471   }
00472 
00482   function setAuthor($author = "") {
00483     if (!$author) {
00484       $author = $this->ilias->account->fullname;
00485     }
00486     $this->author = $author;
00487   }
00488 
00498   function setQuestiontext($questiontext = "") {
00499     $this->questiontext = $questiontext;
00500   }
00501 
00511   function setOwner($owner = "") {
00512     $this->owner = $owner;
00513   }
00514 
00524   function getTitle() {
00525     return $this->title;
00526   }
00527 
00537   function getId() {
00538     return $this->id;
00539   }
00540 
00550   function getObligatory() {
00551     return $this->obligatory;
00552   }
00553 
00563   function getSurveyId() {
00564     return $this->survey_id;
00565   }
00566 
00576   function getOrientation() {
00577     return $this->orientation;
00578   }
00579 
00580 
00590   function getDescription() {
00591     return $this->description;
00592   }
00593 
00603   function getAuthor() {
00604     return $this->author;
00605   }
00606 
00616   function getOwner() {
00617     return $this->owner;
00618   }
00619 
00629   function getQuestiontext() {
00630     return $this->questiontext;
00631   }
00632 
00642   function getObjId() {
00643     return $this->obj_id;
00644   }
00645 
00655   function setObjId($obj_id = 0) {
00656     $this->obj_id = $obj_id;
00657   }
00658 
00667   function insertIntoSurvey($survey_id) {
00668     // get maximum sequence index in survey
00669 /*    $query = sprintf("SELECT MAX(sequence) AS seq FROM dum_survey_question WHERE survey_fi=%s",
00670       $this->ilias->db->quote($survey_id)
00671     );
00672     $result = $this->ilias->db->db->query($query);
00673     $sequence = 1;
00674     if ($result->numRows() == 1) {
00675       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00676       $sequence = $data->seq + 1;
00677     }
00678     $query = sprintf("INSERT INTO dum_survey_question (survey_question_id, survey_fi, question_fi, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00679       $this->ilias->db->quote($survey_id),
00680       $this->ilias->db->quote($this->get_id()),
00681       $this->ilias->db->quote($sequence)
00682     );
00683     $result = $this->ilias->db->db->query($query);
00684     if ($result != DB_OK) {
00685       // Fehlermeldung
00686     }
00687 */  }
00688 
00696         function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
00697         {
00698                 if ($this->getId() <= 0)
00699                 {
00700                         // The question has not been saved. It cannot be duplicated
00701                         return;
00702                 }
00703                 // duplicate the question in database
00704                 $clone = $this;
00705                 $original_id = $this->getId();
00706                 $clone->setId(-1);
00707                 if ($title)
00708                 {
00709                         $clone->setTitle($title);
00710                 }
00711                 if ($author)
00712                 {
00713                         $clone->setAuthor($author);
00714                 }
00715                 if ($owner)
00716                 {
00717                         $clone->setOwner($owner);
00718                 }
00719                 if ($for_survey)
00720                 {
00721                         $clone->saveToDb($original_id);
00722                 }
00723                 else
00724                 {
00725                         $clone->saveToDb();
00726                 }
00727                 // duplicate the materials
00728                 $clone->duplicateMaterials($original_id);
00729                 return $clone->getId();
00730         }
00731 
00740         function duplicateMaterials($question_id)
00741         {
00742                 foreach ($this->materials as $filename)
00743                 {
00744                         $materialspath = $this->getMaterialsPath();
00745                         $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
00746                         if (!file_exists($materialspath)) {
00747                                 ilUtil::makeDirParents($materialspath);
00748                         }
00749                         if (!copy($materialspath_original . $filename, $materialspath . $filename)) {
00750                                 print "material could not be duplicated!!!! ";
00751                         }
00752                 }
00753         }
00754 
00755 
00764         function loadFromDb($question_id)
00765         {
00766                 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
00767                         $this->ilias->db->quote($this->getId() . "")
00768                 );
00769                 $result = $this->ilias->db->query($query);
00770                 $this->material = array();
00771                 if ($result->numRows())
00772                 {
00773                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00774                         {
00775                                 $this->material = array(
00776                                         "internal_link" => $row["internal_link"],
00777                                         "import_id" => $row["import_id"],
00778                                         "title" => $row["material_title"]
00779                                 );
00780                         }
00781                 }
00782         }
00783 
00792         function saveToDb($original_id = "")
00793         {
00794                 require_once "./content/classes/Pages/class.ilInternalLink.php";
00795                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
00796                         $this->ilias->db->quote($this->getId() . "")
00797                 );
00798                 $result = $this->ilias->db->query($query);
00799                 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->getId());
00800                 if (count($this->material))
00801                 {
00802                         $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00803                                 $this->ilias->db->quote($this->getId() . ""),
00804                                 $this->ilias->db->quote($this->material["internal_link"] . ""),
00805                                 $this->ilias->db->quote($this->material["import_id"] . ""),
00806                                 $this->ilias->db->quote($this->material["title"] . "")
00807                         );
00808                         $this->ilias->db->query($query);
00809                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00810                         {
00811                                 ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
00812                         }
00813                 }
00814         }
00815         
00816 
00825   function saveWorkingData($limit_to = LIMIT_NO_LIMIT) 
00826         {
00827   }
00828 
00837         function getImagePath() {
00838                 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
00839         }
00840 
00849         function getMaterialsPath() {
00850                 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
00851         }
00852 
00861         function getImagePathWeb() {
00862                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
00863                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00864         }
00865 
00874         function getMaterialsPathWeb() {
00875                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
00876                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00877         }
00878 
00887   function saveMaterialsToDb()
00888   {
00889                 if ($this->id > 0) 
00890                 {
00891                         $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
00892                                 $this->ilias->db->quote($this->id)
00893                         );
00894                         $result = $this->ilias->db->query($query);
00895                         if (!empty($this->materials)) {
00896                                 foreach ($this->materials as $key => $value) {
00897                                         $query = sprintf("INSERT INTO survey_question_material (question_fi, materials, materials_file) VALUES (%s, %s, %s)",
00898                                                 $this->ilias->db->quote($this->id),
00899                                                 $this->ilias->db->quote($key),
00900                                                 $this->ilias->db->quote($value)
00901                                         );
00902                                         $result = $this->ilias->db->query($query);
00903                                 }
00904                         }
00905                 }
00906         }
00907 
00916   function loadMaterialFromDb($question_id)
00917   {
00918     $query = sprintf("SELECT * FROM survey_question_material WHERE question_fi = %s",
00919       $this->ilias->db->quote($question_id)
00920     );
00921     $result = $this->ilias->db->query($query);
00922     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00923         $this->materials = array();
00924         while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
00925                                 $this->addMaterials($data->materials_file, $data->materials);
00926                         }
00927                 }
00928         }
00929 
00930 
00939         function isInUse() {
00940 /*              $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00941                         $this->ilias->db->quote("$this->id")
00942                 );
00943                 $result = $this->ilias->db->query($query);
00944                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00945                 return $row->solution_count;
00946 */      }
00947         
00959         function removeAllQuestionReferences() {
00960 /*              $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi = %s", $this->ilias->db->quote("$this->id"));
00961                 $result = $this->ilias->db->query($query);
00962                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
00963                         // Mark all surveys containing this question as "not started"
00964                         $querychange = sprintf("DELETE FROM tst_active WHERE user_fi = %s AND survey_fi = %s",
00965                                 $this->ilias->db->quote("$result->user_fi"),
00966                                 $this->ilias->db->quote("$result->survey_fi")
00967                         );
00968                         $changeresult = $this->ilias->db->query($querychange);
00969                 }
00970                 // delete all resultsets for this question
00971                 $querydelete = sprintf("DELETE FROM tst_solutions WHERE question_fi = %s", $this->ilias->db->quote("$this->id"));
00972                 $deleteresult = $this->ilias->db->query($querydelete);
00973         }
00974 */}
00975 
00986         function saveCategoryToDb($categorytext)
00987         {
00988                 global $ilUser;
00989                 
00990                 $query = sprintf("SELECT category_id FROM survey_category WHERE title = %s AND owner_fi = %s",
00991                         $this->ilias->db->quote($categorytext),
00992                         $this->ilias->db->quote($ilUser->id)
00993                 );
00994     $result = $this->ilias->db->query($query);
00995                 if ($result->numRows()) {
00996                         $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00997                         return $row->category_id;
00998                 } else {
00999                         $query = sprintf("INSERT INTO survey_category (category_id, title, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
01000                                 $this->ilias->db->quote($categorytext),
01001                                 $this->ilias->db->quote($ilUser->id)
01002                         );
01003                         $result = $this->ilias->db->query($query);
01004                         return $this->ilias->db->getLastInsertId();
01005                 }
01006         }
01007 
01016   function delete($question_id) 
01017   {
01018     if ($question_id < 1)
01019       return;
01020       
01021                 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01022                         $this->ilias->db->quote($question_id)
01023                 );
01024     $result = $this->ilias->db->query($query);
01025                 if ($result->numRows() == 1)
01026                 {
01027                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01028                         $obj_id = $row["obj_fi"];
01029                 }
01030                 else
01031                 {
01032                         return;
01033                 }
01034                 
01035                 $query = sprintf("DELETE FROM survey_answer WHERE question_fi = %s",
01036                         $this->ilias->db->quote($question_id)
01037                 );
01038                 $result = $this->ilias->db->query($query);
01039 
01040                 $query = sprintf("SELECT constraint_id FROM survey_constraint WHERE question_fi = %s",
01041                         $this->ilias->db->quote($question_id)
01042                 );
01043                 $result = $this->ilias->db->query($query);
01044                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01045                 {
01046                         $query = sprintf("DELETE FROM survey_question_constraint WHERE constraint_fi = %s",
01047                                 $this->ilias->db->quote($row->constraint_id)
01048                         );
01049                         $delresult = $this->ilias->db->query($query);
01050                 }
01051                 
01052                 $query = sprintf("DELETE FROM survey_constraint WHERE question_fi = %s",
01053                         $this->ilias->db->quote($question_id)
01054                 );
01055                 $result = $this->ilias->db->query($query);
01056 
01057                 $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s",
01058                         $this->ilias->db->quote($question_id)
01059                 );
01060                 $result = $this->ilias->db->query($query);
01061                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01062                 {
01063                         $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
01064                                 $this->ilias->db->quote($row->constraint_fi)
01065                         );
01066                         $delresult = $this->ilias->db->query($query);
01067                 }
01068                 $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s",
01069                         $this->ilias->db->quote($question_id)
01070                 );
01071                 $result = $this->ilias->db->query($query);
01072 
01073                 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
01074                         $this->ilias->db->quote($question_id)
01075                 );
01076                 $result = $this->ilias->db->query($query);
01077 
01078                 $query = sprintf("DELETE FROM survey_questionblock_question WHERE question_fi = %s",
01079                         $this->ilias->db->quote($question_id)
01080                 );
01081                 $result = $this->ilias->db->query($query);
01082 
01083                 $query = sprintf("DELETE FROM survey_question_obligatory WHERE question_fi = %s",
01084                         $this->ilias->db->quote($question_id)
01085                 );
01086                 $result = $this->ilias->db->query($query);
01087 
01088                 $query = sprintf("DELETE FROM survey_survey_question WHERE question_fi = %s",
01089                         $this->ilias->db->quote($question_id)
01090                 );
01091                 $result = $this->ilias->db->query($query);
01092 
01093                 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01094                         $this->ilias->db->quote($question_id)
01095                 );
01096                 $result = $this->ilias->db->query($query);
01097 
01098                 $query = sprintf("DELETE FROM survey_question WHERE question_id = %s",
01099                         $this->ilias->db->quote($question_id)
01100                 );
01101                 $result = $this->ilias->db->query($query);
01102 
01103                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01104                         $this->ilias->db->quote($question_id)
01105                 );
01106                 $result = $this->ilias->db->query($query);
01107                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01108                 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01109 
01110                 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
01111                 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
01112                 {
01113                         $directory = escapeshellarg($directory);
01114                         exec("rm -rf $directory");
01115                 }
01116         }
01117 
01127   function _getQuestionType($question_id) {
01128                 global $ilDB;
01129 
01130     if ($question_id < 1)
01131       return "";
01132 
01133     $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",
01134       $ilDB->quote($question_id)
01135     );
01136     $result = $ilDB->query($query);
01137     if ($result->numRows() == 1) {
01138       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01139       return $data->type_tag;
01140     } else {
01141       return "";
01142     }
01143   }
01144 
01154         function _getOriginalId($question_id)
01155         {
01156                 global $ilDB;
01157                 $query = sprintf("SELECT * FROM survey_question WHERE question_id = %s",
01158                         $ilDB->quote($question_id . "")
01159                 );
01160                 $result = $ilDB->query($query);
01161                 if ($result->numRows() > 0)
01162                 {
01163                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01164                         if ($row["original_id"] > 0)
01165                         {
01166                                 return $row["original_id"];
01167                         }
01168                         else
01169                         {
01170                                 return $row["question_id"];
01171                         }
01172                 }
01173                 else
01174                 {
01175                         return "";
01176                 }
01177         }
01178         
01179         function _getRefIdFromObjId($obj_id)
01180         {
01181                 global $ilDB;
01182                 
01183                 $query = sprintf("SELECT ref_id FROM object_reference WHERE obj_id=%s",
01184                         $ilDB->quote($obj_id)
01185                         
01186                 );
01187                 $result = $ilDB->query($query);
01188                 if ($result->numRows())
01189                 {
01190                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01191                         return $row["ref_id"];
01192                 }
01193                 return 0;
01194         }
01195         
01196         function syncWithOriginal()
01197         {
01198                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01199                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01200                         $this->ilias->db->quote($this->original_id . "")
01201                 );
01202                 $result = $this->ilias->db->query($query);
01203                 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
01204                 $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01205                         $this->ilias->db->quote($this->original_id . ""),
01206                         $this->ilias->db->quote($this->material["internal_link"] . ""),
01207                         $this->ilias->db->quote($this->material["import_id"] . "")
01208                 );
01209                 $this->ilias->db->query($query);
01210                 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
01211                 {
01212                         ilInternalLink::_saveLink("sqst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01213                 }
01214         }
01215 
01224         function getPhrase($phrase_id)
01225         {
01226                 $query = sprintf("SELECT title FROM survey_phrase WHERE phrase_id = %s",
01227                         $this->ilias->db->quote($phrase_id)
01228                 );
01229     $result = $this->ilias->db->query($query);
01230                 if ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01231                 {
01232                         return $row["title"];
01233                 }
01234                 return "";
01235         }
01236 
01246         function phraseExists($title)
01247         {
01248                 global $ilUser;
01249                 
01250                 $query = sprintf("SELECT phrase_id FROM survey_phrase WHERE title = %s AND owner_fi = %s",
01251                         $this->ilias->db->quote($title),
01252                         $this->ilias->db->quote($ilUser->id)
01253                 );
01254     $result = $this->ilias->db->query($query);
01255                 if ($result->numRows() == 0)
01256                 {
01257                         return false;
01258                 }
01259                 else
01260                 {
01261                         return true;
01262                 }
01263         }
01264 
01274         function savePhrase($phrases, $title)
01275         {
01276                 global $ilUser;
01277                 
01278                 $query = sprintf("INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01279                         $this->ilias->db->quote($title),
01280                         $this->ilias->db->quote("1"),
01281                         $this->ilias->db->quote($ilUser->id)
01282                 );
01283     $result = $this->ilias->db->query($query);
01284                 $phrase_id = $this->ilias->db->getLastInsertId();
01285                                 
01286                 $counter = 1;
01287           foreach ($this->categories as $key => $value) 
01288                 {
01289                         if (in_array($key, $phrases))
01290                         {
01291                                 $query = sprintf("INSERT INTO survey_category (category_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01292                                         $this->ilias->db->quote($value),
01293                                         $this->ilias->db->quote("1"),
01294                                         $this->ilias->db->quote($ilUser->id)
01295                                 );
01296                     $result = $this->ilias->db->query($query);
01297                                 $category_id = $this->ilias->db->getLastInsertId();
01298                                 $query = sprintf("INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
01299                                         $this->ilias->db->quote($phrase_id),
01300                                         $this->ilias->db->quote($category_id),
01301                                         $this->ilias->db->quote("$counter")
01302                                 );
01303                     $result = $this->ilias->db->query($query);
01304                                 $counter++;
01305                         }
01306                 }
01307         }
01308         
01318         function addStandardNumbers($lower_limit, $upper_limit)
01319         {
01320                 for ($i = $lower_limit; $i <= $upper_limit; $i++)
01321                 {
01322                         array_push($this->categories, $i);
01323                 }
01324         }
01325 
01335         function _questionExists($question_id)
01336         {
01337                 global $ilDB;
01338 
01339                 if ($question_id < 1)
01340                 {
01341                         return false;
01342                 }
01343                 
01344                 $query = sprintf("SELECT question_id FROM survey_question WHERE question_id = %s",
01345                         $ilDB->quote($question_id)
01346                 );
01347     $result = $ilDB->query($query);
01348                 if ($result->numRows() == 1)
01349                 {
01350                         return true;
01351                 }
01352                 else
01353                 {
01354                         return false;
01355                 }
01356         }
01357 
01367         function setMaterial($material_id = "", $is_import = false, $material_title = "")
01368         {
01369                 if (strcmp($material_id, "") != 0)
01370                 {
01371                         $import_id = "";
01372                         if ($is_import)
01373                         {
01374                                 $import_id = $material_id;
01375                                 $material_id = $this->_resolveInternalLink($import_id);
01376                         }
01377                         if (strcmp($material_title, "") == 0)
01378                         {
01379                                 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
01380                                 {
01381                                         $type = $matches[1];
01382                                         $target_id = $matches[2];
01383                                         $material_title = $this->lng->txt("obj_$type") . ": ";
01384                                         switch ($type)
01385                                         {
01386                                                 case "lm":
01387                                                         require_once("./content/classes/class.ilObjContentObject.php");
01388                                                         $cont_obj =& new ilObjContentObject($target_id, true);
01389                                                         $material_title .= $cont_obj->getTitle();
01390                                                         break;
01391                                                 case "pg":
01392                                                         require_once("./content/classes/class.ilLMPageObject.php");
01393                                                         require_once("./content/classes/class.ilLMObject.php");
01394                                                         require_once("./content/classes/class.ilObjContentObject.php");
01395                                                         $lm_id = ilLMObject::_lookupContObjID($target_id);
01396                                                         $cont_obj =& new ilObjContentObject($lm_id, false);
01397                                                         $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
01398                                                         $material_title .= $pg_obj->getTitle();
01399                                                         break;
01400                                                 case "st":
01401                                                         require_once("content/classes/class.ilStructureObject.php");
01402                                                         require_once("./content/classes/class.ilLMObject.php");
01403                                                         require_once("./content/classes/class.ilObjContentObject.php");
01404                                                         $lm_id = ilLMObject::_lookupContObjID($target_id);
01405                                                         $cont_obj =& new ilObjContentObject($lm_id, false);
01406                                                         $st_obj =& new ilStructureObject($cont_obj, $target_id);
01407                                                         $material_title .= $st_obj->getTitle();
01408                                                         break;
01409                                                 case "git":
01410                                                         require_once "./content/classes/class.ilGlossaryTerm.php";
01411                                                         $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
01412                                                         break;
01413                                                 case "mob":
01414                                                         break;
01415                                         }
01416                                 }
01417                         }
01418                         $this->material = array(
01419                                 "internal_link" => $material_id,
01420                                 "import_id" => $import_id,
01421                                 "title" => $material_title
01422                         );
01423                 }
01424         }
01425         
01426         function _resolveInternalLink($internal_link)
01427         {
01428                 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01429                 {
01430                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01431                         require_once "./content/classes/class.ilLMObject.php";
01432                         require_once "./content/classes/class.ilGlossaryTerm.php";
01433                         switch ($matches[2])
01434                         {
01435                                 case "lm":
01436                                         $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01437                                         break;
01438                                 case "pg":
01439                                         $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01440                                         break;
01441                                 case "st":
01442                                         $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01443                                         break;
01444                                 case "git":
01445                                         $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01446                                         break;
01447                                 case "mob":
01448                                         $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01449                                         break;
01450                         }
01451                         if (strcmp($resolved_link, "") == 0)
01452                         {
01453                                 $resolved_link = $internal_link;
01454                         }
01455                 }
01456                 else
01457                 {
01458                         $resolved_link = $internal_link;
01459                 }
01460                 return $resolved_link;
01461         }
01462         
01463         function _resolveIntLinks($question_id)
01464         {
01465                 global $ilDB;
01466                 $resolvedlinks = 0;
01467                 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01468                         $ilDB->quote($question_id . "")
01469                 );
01470                 $result = $ilDB->query($query);
01471                 if ($result->numRows())
01472                 {
01473                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01474                         {
01475                                 $internal_link = $row["internal_link"];
01476                                 $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
01477                                 if (strcmp($internal_link, $resolved_link) != 0)
01478                                 {
01479                                         // internal link was resolved successfully
01480                                         $queryupdate = sprintf("UPDATE survey_material SET internal_link = %s WHERE material_id = %s",
01481                                                 $ilDB->quote($resolved_link),
01482                                                 $ilDB->quote($row["material_id"] . "")
01483                                         );
01484                                         $updateresult = $ilDB->query($queryupdate);
01485                                         $resolvedlinks++;
01486                                 }
01487                         }
01488                 }
01489                 if ($resolvedlinks)
01490                 {
01491                         // there are resolved links -> reenter theses links to the database
01492 
01493                         // delete all internal links from the database
01494                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01495                         ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01496 
01497                         $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01498                                 $ilDB->quote($question_id . "")
01499                         );
01500                         $result = $ilDB->query($query);
01501                         if ($result->numRows())
01502                         {
01503                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01504                                 {
01505                                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01506                                         {
01507                                                 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
01508                                         }
01509                                 }
01510                         }
01511                 }
01512         }
01513         
01514         function _getInternalLinkHref($target = "")
01515         {
01516                 global $ilDB;
01517                 $linktypes = array(
01518                         "lm" => "LearningModule",
01519                         "pg" => "PageObject",
01520                         "st" => "StructureObject",
01521                         "git" => "GlossaryItem",
01522                         "mob" => "MediaObject"
01523                 );
01524                 $href = "";
01525                 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01526                 {
01527                         $type = $matches[1];
01528                         $target_id = $matches[2];
01529                         switch($linktypes[$matches[1]])
01530                         {
01531                                 case "LearningModule":
01532                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01533                                         break;
01534                                 case "PageObject":
01535                                 case "StructureObject":
01536                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01537                                         break;
01538                                 case "GlossaryItem":
01539                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01540                                         break;
01541                                 case "MediaObject":
01542                                         $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;
01543                                         break;
01544                         }
01545                 }
01546                 return $href;
01547         }
01548         
01549 }
01550 ?>

Generated on Fri Dec 13 2013 08:00:19 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1