• 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 title, 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                 $insert = FALSE;
00996                 $returnvalue = "";
00997                 if ($result->numRows()) 
00998                 {
00999                         $insert = TRUE;
01000                         while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01001                         {
01002                                 if (strcmp($row->title, $categorytext) == 0)
01003                                 {
01004                                         $returnvalue = $row->category_id;
01005                                         $insert = FALSE;
01006                                 }
01007                         }
01008                 }
01009                 else
01010                 {
01011                         $insert = TRUE;
01012                 }
01013                 if ($insert)
01014                 {
01015                         $query = sprintf("INSERT INTO survey_category (category_id, title, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
01016                                 $this->ilias->db->quote($categorytext),
01017                                 $this->ilias->db->quote($ilUser->id)
01018                         );
01019                         $result = $this->ilias->db->query($query);
01020                         $returnvalue = $this->ilias->db->getLastInsertId();
01021                 }
01022                 return $returnvalue;
01023         }
01024 
01033   function delete($question_id) 
01034   {
01035     if ($question_id < 1)
01036       return;
01037       
01038                 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01039                         $this->ilias->db->quote($question_id)
01040                 );
01041     $result = $this->ilias->db->query($query);
01042                 if ($result->numRows() == 1)
01043                 {
01044                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01045                         $obj_id = $row["obj_fi"];
01046                 }
01047                 else
01048                 {
01049                         return;
01050                 }
01051                 
01052                 $query = sprintf("DELETE FROM survey_answer 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_id FROM survey_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_question_constraint WHERE constraint_fi = %s",
01064                                 $this->ilias->db->quote($row->constraint_id)
01065                         );
01066                         $delresult = $this->ilias->db->query($query);
01067                 }
01068                 
01069                 $query = sprintf("DELETE FROM survey_constraint WHERE question_fi = %s",
01070                         $this->ilias->db->quote($question_id)
01071                 );
01072                 $result = $this->ilias->db->query($query);
01073 
01074                 $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s",
01075                         $this->ilias->db->quote($question_id)
01076                 );
01077                 $result = $this->ilias->db->query($query);
01078                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01079                 {
01080                         $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
01081                                 $this->ilias->db->quote($row->constraint_fi)
01082                         );
01083                         $delresult = $this->ilias->db->query($query);
01084                 }
01085                 $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s",
01086                         $this->ilias->db->quote($question_id)
01087                 );
01088                 $result = $this->ilias->db->query($query);
01089 
01090                 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
01091                         $this->ilias->db->quote($question_id)
01092                 );
01093                 $result = $this->ilias->db->query($query);
01094 
01095                 $query = sprintf("DELETE FROM survey_questionblock_question WHERE question_fi = %s",
01096                         $this->ilias->db->quote($question_id)
01097                 );
01098                 $result = $this->ilias->db->query($query);
01099 
01100                 $query = sprintf("DELETE FROM survey_question_obligatory WHERE question_fi = %s",
01101                         $this->ilias->db->quote($question_id)
01102                 );
01103                 $result = $this->ilias->db->query($query);
01104 
01105                 $query = sprintf("DELETE FROM survey_survey_question WHERE question_fi = %s",
01106                         $this->ilias->db->quote($question_id)
01107                 );
01108                 $result = $this->ilias->db->query($query);
01109 
01110                 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01111                         $this->ilias->db->quote($question_id)
01112                 );
01113                 $result = $this->ilias->db->query($query);
01114 
01115                 $query = sprintf("DELETE FROM survey_question WHERE question_id = %s",
01116                         $this->ilias->db->quote($question_id)
01117                 );
01118                 $result = $this->ilias->db->query($query);
01119 
01120                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01121                         $this->ilias->db->quote($question_id)
01122                 );
01123                 $result = $this->ilias->db->query($query);
01124                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01125                 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01126 
01127                 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
01128                 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
01129                 {
01130                         $directory = escapeshellarg($directory);
01131                         exec("rm -rf $directory");
01132                 }
01133         }
01134 
01144   function _getQuestionType($question_id) {
01145                 global $ilDB;
01146 
01147     if ($question_id < 1)
01148       return "";
01149 
01150     $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",
01151       $ilDB->quote($question_id)
01152     );
01153     $result = $ilDB->query($query);
01154     if ($result->numRows() == 1) {
01155       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01156       return $data->type_tag;
01157     } else {
01158       return "";
01159     }
01160   }
01161 
01171         function _getOriginalId($question_id)
01172         {
01173                 global $ilDB;
01174                 $query = sprintf("SELECT * FROM survey_question WHERE question_id = %s",
01175                         $ilDB->quote($question_id . "")
01176                 );
01177                 $result = $ilDB->query($query);
01178                 if ($result->numRows() > 0)
01179                 {
01180                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01181                         if ($row["original_id"] > 0)
01182                         {
01183                                 return $row["original_id"];
01184                         }
01185                         else
01186                         {
01187                                 return $row["question_id"];
01188                         }
01189                 }
01190                 else
01191                 {
01192                         return "";
01193                 }
01194         }
01195         
01196         function _getRefIdFromObjId($obj_id)
01197         {
01198                 global $ilDB;
01199                 
01200                 $query = sprintf("SELECT ref_id FROM object_reference WHERE obj_id=%s",
01201                         $ilDB->quote($obj_id)
01202                         
01203                 );
01204                 $result = $ilDB->query($query);
01205                 if ($result->numRows())
01206                 {
01207                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01208                         return $row["ref_id"];
01209                 }
01210                 return 0;
01211         }
01212         
01213         function syncWithOriginal()
01214         {
01215                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01216                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01217                         $this->ilias->db->quote($this->original_id . "")
01218                 );
01219                 $result = $this->ilias->db->query($query);
01220                 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
01221                 $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01222                         $this->ilias->db->quote($this->original_id . ""),
01223                         $this->ilias->db->quote($this->material["internal_link"] . ""),
01224                         $this->ilias->db->quote($this->material["import_id"] . "")
01225                 );
01226                 $this->ilias->db->query($query);
01227                 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
01228                 {
01229                         ilInternalLink::_saveLink("sqst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01230                 }
01231         }
01232 
01241         function getPhrase($phrase_id)
01242         {
01243                 $query = sprintf("SELECT title FROM survey_phrase WHERE phrase_id = %s",
01244                         $this->ilias->db->quote($phrase_id)
01245                 );
01246     $result = $this->ilias->db->query($query);
01247                 if ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01248                 {
01249                         return $row["title"];
01250                 }
01251                 return "";
01252         }
01253 
01263         function phraseExists($title)
01264         {
01265                 global $ilUser;
01266                 
01267                 $query = sprintf("SELECT phrase_id FROM survey_phrase WHERE title = %s AND owner_fi = %s",
01268                         $this->ilias->db->quote($title),
01269                         $this->ilias->db->quote($ilUser->id)
01270                 );
01271     $result = $this->ilias->db->query($query);
01272                 if ($result->numRows() == 0)
01273                 {
01274                         return false;
01275                 }
01276                 else
01277                 {
01278                         return true;
01279                 }
01280         }
01281 
01291         function savePhrase($phrases, $title)
01292         {
01293                 global $ilUser;
01294                 
01295                 $query = sprintf("INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01296                         $this->ilias->db->quote($title),
01297                         $this->ilias->db->quote("1"),
01298                         $this->ilias->db->quote($ilUser->id)
01299                 );
01300     $result = $this->ilias->db->query($query);
01301                 $phrase_id = $this->ilias->db->getLastInsertId();
01302                                 
01303                 $counter = 1;
01304           foreach ($this->categories as $key => $value) 
01305                 {
01306                         if (in_array($key, $phrases))
01307                         {
01308                                 $query = sprintf("INSERT INTO survey_category (category_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
01309                                         $this->ilias->db->quote($value),
01310                                         $this->ilias->db->quote("1"),
01311                                         $this->ilias->db->quote($ilUser->id)
01312                                 );
01313                     $result = $this->ilias->db->query($query);
01314                                 $category_id = $this->ilias->db->getLastInsertId();
01315                                 $query = sprintf("INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
01316                                         $this->ilias->db->quote($phrase_id),
01317                                         $this->ilias->db->quote($category_id),
01318                                         $this->ilias->db->quote("$counter")
01319                                 );
01320                     $result = $this->ilias->db->query($query);
01321                                 $counter++;
01322                         }
01323                 }
01324         }
01325         
01335         function addStandardNumbers($lower_limit, $upper_limit)
01336         {
01337                 for ($i = $lower_limit; $i <= $upper_limit; $i++)
01338                 {
01339                         array_push($this->categories, $i);
01340                 }
01341         }
01342 
01352         function _questionExists($question_id)
01353         {
01354                 global $ilDB;
01355 
01356                 if ($question_id < 1)
01357                 {
01358                         return false;
01359                 }
01360                 
01361                 $query = sprintf("SELECT question_id FROM survey_question WHERE question_id = %s",
01362                         $ilDB->quote($question_id)
01363                 );
01364     $result = $ilDB->query($query);
01365                 if ($result->numRows() == 1)
01366                 {
01367                         return true;
01368                 }
01369                 else
01370                 {
01371                         return false;
01372                 }
01373         }
01374 
01384         function setMaterial($material_id = "", $is_import = false, $material_title = "")
01385         {
01386                 if (strcmp($material_id, "") != 0)
01387                 {
01388                         $import_id = "";
01389                         if ($is_import)
01390                         {
01391                                 $import_id = $material_id;
01392                                 $material_id = $this->_resolveInternalLink($import_id);
01393                         }
01394                         if (strcmp($material_title, "") == 0)
01395                         {
01396                                 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
01397                                 {
01398                                         $type = $matches[1];
01399                                         $target_id = $matches[2];
01400                                         $material_title = $this->lng->txt("obj_$type") . ": ";
01401                                         switch ($type)
01402                                         {
01403                                                 case "lm":
01404                                                         require_once("./content/classes/class.ilObjContentObject.php");
01405                                                         $cont_obj =& new ilObjContentObject($target_id, true);
01406                                                         $material_title .= $cont_obj->getTitle();
01407                                                         break;
01408                                                 case "pg":
01409                                                         require_once("./content/classes/class.ilLMPageObject.php");
01410                                                         require_once("./content/classes/class.ilLMObject.php");
01411                                                         require_once("./content/classes/class.ilObjContentObject.php");
01412                                                         $lm_id = ilLMObject::_lookupContObjID($target_id);
01413                                                         $cont_obj =& new ilObjContentObject($lm_id, false);
01414                                                         $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
01415                                                         $material_title .= $pg_obj->getTitle();
01416                                                         break;
01417                                                 case "st":
01418                                                         require_once("content/classes/class.ilStructureObject.php");
01419                                                         require_once("./content/classes/class.ilLMObject.php");
01420                                                         require_once("./content/classes/class.ilObjContentObject.php");
01421                                                         $lm_id = ilLMObject::_lookupContObjID($target_id);
01422                                                         $cont_obj =& new ilObjContentObject($lm_id, false);
01423                                                         $st_obj =& new ilStructureObject($cont_obj, $target_id);
01424                                                         $material_title .= $st_obj->getTitle();
01425                                                         break;
01426                                                 case "git":
01427                                                         require_once "./content/classes/class.ilGlossaryTerm.php";
01428                                                         $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
01429                                                         break;
01430                                                 case "mob":
01431                                                         break;
01432                                         }
01433                                 }
01434                         }
01435                         $this->material = array(
01436                                 "internal_link" => $material_id,
01437                                 "import_id" => $import_id,
01438                                 "title" => $material_title
01439                         );
01440                 }
01441         }
01442         
01443         function _resolveInternalLink($internal_link)
01444         {
01445                 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01446                 {
01447                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01448                         require_once "./content/classes/class.ilLMObject.php";
01449                         require_once "./content/classes/class.ilGlossaryTerm.php";
01450                         switch ($matches[2])
01451                         {
01452                                 case "lm":
01453                                         $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01454                                         break;
01455                                 case "pg":
01456                                         $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01457                                         break;
01458                                 case "st":
01459                                         $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01460                                         break;
01461                                 case "git":
01462                                         $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01463                                         break;
01464                                 case "mob":
01465                                         $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01466                                         break;
01467                         }
01468                         if (strcmp($resolved_link, "") == 0)
01469                         {
01470                                 $resolved_link = $internal_link;
01471                         }
01472                 }
01473                 else
01474                 {
01475                         $resolved_link = $internal_link;
01476                 }
01477                 return $resolved_link;
01478         }
01479         
01480         function _resolveIntLinks($question_id)
01481         {
01482                 global $ilDB;
01483                 $resolvedlinks = 0;
01484                 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01485                         $ilDB->quote($question_id . "")
01486                 );
01487                 $result = $ilDB->query($query);
01488                 if ($result->numRows())
01489                 {
01490                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01491                         {
01492                                 $internal_link = $row["internal_link"];
01493                                 $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
01494                                 if (strcmp($internal_link, $resolved_link) != 0)
01495                                 {
01496                                         // internal link was resolved successfully
01497                                         $queryupdate = sprintf("UPDATE survey_material SET internal_link = %s WHERE material_id = %s",
01498                                                 $ilDB->quote($resolved_link),
01499                                                 $ilDB->quote($row["material_id"] . "")
01500                                         );
01501                                         $updateresult = $ilDB->query($queryupdate);
01502                                         $resolvedlinks++;
01503                                 }
01504                         }
01505                 }
01506                 if ($resolvedlinks)
01507                 {
01508                         // there are resolved links -> reenter theses links to the database
01509 
01510                         // delete all internal links from the database
01511                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01512                         ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01513 
01514                         $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01515                                 $ilDB->quote($question_id . "")
01516                         );
01517                         $result = $ilDB->query($query);
01518                         if ($result->numRows())
01519                         {
01520                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01521                                 {
01522                                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01523                                         {
01524                                                 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
01525                                         }
01526                                 }
01527                         }
01528                 }
01529         }
01530         
01531         function _getInternalLinkHref($target = "")
01532         {
01533                 global $ilDB;
01534                 $linktypes = array(
01535                         "lm" => "LearningModule",
01536                         "pg" => "PageObject",
01537                         "st" => "StructureObject",
01538                         "git" => "GlossaryItem",
01539                         "mob" => "MediaObject"
01540                 );
01541                 $href = "";
01542                 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01543                 {
01544                         $type = $matches[1];
01545                         $target_id = $matches[2];
01546                         switch($linktypes[$matches[1]])
01547                         {
01548                                 case "LearningModule":
01549                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01550                                         break;
01551                                 case "PageObject":
01552                                 case "StructureObject":
01553                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01554                                         break;
01555                                 case "GlossaryItem":
01556                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01557                                         break;
01558                                 case "MediaObject":
01559                                         $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;
01560                                         break;
01561                         }
01562                 }
01563                 return $href;
01564         }
01565         
01566 }
01567 ?>

Generated on Fri Dec 13 2013 09:06:38 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1