• 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 
00024 include_once "./survey/classes/inc.SurveyConstants.php";
00025 
00037 class SurveyQuestion 
00038 {
00046   var $id;
00047 
00055   var $title;
00063   var $description;
00072   var $owner;
00073 
00082   var $author;
00083 
00091   var $materials;
00092 
00100   var $survey_id;
00101 
00109   var $obj_id;
00110 
00118   var $questiontext;
00119 
00127   var $obligatory;
00128         
00136   var $ilias;
00137 
00145   var $tpl;
00146 
00154   var $lng;
00155 
00163         var $domxml;
00164 
00172         var $orientation;
00173         
00174         var $material;
00175 
00187   function SurveyQuestion(
00188     $title = "",
00189     $description = "",
00190     $author = "",
00191                 $questiontext = "",
00192     $owner = -1
00193   )
00194 
00195   {
00196                 global $ilias;
00197     global $lng;
00198     global $tpl;
00199 
00200                 $this->ilias =& $ilias;
00201     $this->lng =& $lng;
00202     $this->tpl =& $tpl;
00203 
00204     $this->title = $title;
00205     $this->description = $description;
00206                 $this->questiontext = $questiontext;
00207     $this->author = $author;
00208     if (!$this->author) {
00209       $this->author = $this->ilias->account->fullname;
00210     }
00211     $this->owner = $owner;
00212     if ($this->owner == -1) {
00213       $this->owner = $this->ilias->account->id;
00214     }
00215     $this->id = -1;
00216     $this->survey_id = -1;
00217                 $this->obligatory = 1;
00218                 $this->orientation = 0;
00219                 $this->materials = array();
00220                 $this->material = array();
00221                 register_shutdown_function(array(&$this, '_SurveyQuestion'));
00222         }
00223 
00224         function _SurveyQuestion()
00225         {
00226                 if (!empty($this->domxml))
00227                 {
00228                         $this->domxml->free();
00229                 }
00230         }
00231 
00232         
00241         function isComplete()
00242         {
00243                 return false;
00244         }
00245 
00256   function questionTitleExists($title, $questionpool_object = "") 
00257         {
00258                 $refwhere = "";
00259                 if (strcmp($questionpool_reference, "") != 0)
00260                 {
00261                         $refwhere = sprintf(" AND obj_fi = %s",
00262                                 $this->ilias->db->quote($questionpool_object)
00263                         );
00264                 }
00265     $query = sprintf("SELECT question_id FROM survey_question WHERE title = %s$refwhere",
00266       $this->ilias->db->quote($title)
00267     );
00268     $result = $this->ilias->db->query($query);
00269     if (strcmp(strtolower(get_class($result)), db_result) == 0) 
00270                 {
00271       if ($result->numRows() == 1) 
00272                         {
00273         return TRUE;
00274       }
00275     }
00276     return FALSE;
00277   }
00278 
00288   function setTitle($title = "") 
00289         {
00290     $this->title = $title;
00291   }
00292 
00302   function setObligatory($obligatory = 1) 
00303         {
00304                 if ($obligatory)
00305                 {
00306             $this->obligatory = 1;
00307                 }
00308                 else
00309                 {
00310             $this->obligatory = 0;
00311                 }
00312   }
00313 
00323   function setOrientation($orientation = 0) 
00324         {
00325     $this->orientation = $orientation;
00326   }
00327 
00337   function setId($id = -1) 
00338         {
00339     $this->id = $id;
00340   }
00341 
00351   function setSurveyId($id = -1) 
00352         {
00353     $this->survey_id = $id;
00354   }
00355 
00365   function setDescription($description = "") 
00366         {
00367     $this->description = $description;
00368   }
00369 
00370 
00381   function addMaterials($materials_file, $materials_name="") 
00382         {
00383         if(empty($materials_name)) 
00384                 {
00385         $materials_name = $materials_file;
00386     }
00387     if ((!empty($materials_name))&&(!$this->keyInArray($materials_name, $this->materials))) 
00388                 {
00389       $this->materials[$materials_name] = $materials_file;
00390     }
00391 
00392   }
00393 
00404   function keyInArray($searchkey, $array) 
00405         {
00406           if ($searchKey) 
00407                 {
00408                    foreach ($array as $key => $value) 
00409                          {
00410                            if (strcmp($key, $searchkey)==0) 
00411                                  {
00412                                    return true;
00413                            }
00414                    }
00415            }
00416            return false;
00417   }
00418 
00428         function setMaterialsfile($materials_filename, $materials_tempfilename="", $materials_name="")
00429         {
00430                 if (!empty($materials_filename))
00431                 {
00432                         include_once "./classes/class.ilUtil.php";
00433                         $materialspath = $this->getMaterialsPath();
00434                         if (!file_exists($materialspath))
00435                         {
00436                                 ilUtil::makeDirParents($materialspath);
00437                         }
00438                         //if (!move_uploaded_file($materials_tempfilename, $materialspath . $materials_filename))
00439                         if (ilUtil::moveUploadedFile($materials_tempfilename, $materials_filename,
00440                                 $materialspath.$materials_filename))
00441                         {
00442                                 print "image not uploaded!!!! ";
00443                         }
00444                         else
00445                         {
00446                                 $this->addMaterials($materials_filename, $materials_name);
00447                         }
00448                 }
00449         }
00450 
00460   function deleteMaterial($materials_name = "") 
00461         {
00462                 foreach ($this->materials as $key => $value) 
00463                 {
00464                         if (strcmp($key, $materials_name)==0) 
00465                         {
00466                                 if (file_exists($this->getMaterialsPath().$value)) 
00467                                 {
00468                                         unlink($this->getMaterialsPath().$value);
00469                                 }
00470                                 unset($this->materials[$key]);
00471                         }
00472                 }
00473   }
00474 
00483   function flushMaterials() 
00484         {
00485     $this->materials = array();
00486   }
00487 
00497   function setAuthor($author = "") 
00498         {
00499     if (!$author) 
00500                 {
00501       $author = $this->ilias->account->fullname;
00502     }
00503     $this->author = $author;
00504   }
00505 
00515   function setQuestiontext($questiontext = "") 
00516         {
00517     $this->questiontext = $questiontext;
00518   }
00519 
00529   function setOwner($owner = "") 
00530         {
00531     $this->owner = $owner;
00532   }
00533 
00543   function getTitle() 
00544         {
00545     return $this->title;
00546   }
00547 
00557   function getId() 
00558         {
00559     return $this->id;
00560   }
00561 
00572         function getObligatory() 
00573         {
00574     return $this->obligatory;
00575   }
00576 
00586   function getSurveyId() 
00587         {
00588     return $this->survey_id;
00589   }
00590 
00600   function getOrientation() 
00601         {
00602                 switch ($this->orientation)
00603                 {
00604                         case 0:
00605                         case 1:
00606                         case 2:
00607                                 break;
00608                         default:
00609                                 $this->orientation = 0;
00610                                 break;
00611                 }
00612     return $this->orientation;
00613   }
00614 
00615 
00625   function getDescription() 
00626         {
00627     return $this->description;
00628   }
00629 
00639   function getAuthor() 
00640         {
00641     return $this->author;
00642   }
00643 
00653   function getOwner() 
00654         {
00655     return $this->owner;
00656   }
00657 
00667   function getQuestiontext() {
00668     return $this->questiontext;
00669   }
00670 
00680   function getObjId() {
00681     return $this->obj_id;
00682   }
00683 
00693   function setObjId($obj_id = 0) {
00694     $this->obj_id = $obj_id;
00695   }
00696 
00704         function duplicate($for_survey = true, $title = "", $author = "", $owner = "")
00705         {
00706                 if ($this->getId() <= 0)
00707                 {
00708                         // The question has not been saved. It cannot be duplicated
00709                         return;
00710                 }
00711                 // duplicate the question in database
00712                 $clone = $this;
00713                 $original_id = $this->getId();
00714                 $clone->setId(-1);
00715                 if ($title)
00716                 {
00717                         $clone->setTitle($title);
00718                 }
00719                 if ($author)
00720                 {
00721                         $clone->setAuthor($author);
00722                 }
00723                 if ($owner)
00724                 {
00725                         $clone->setOwner($owner);
00726                 }
00727                 if ($for_survey)
00728                 {
00729                         $clone->saveToDb($original_id);
00730                 }
00731                 else
00732                 {
00733                         $clone->saveToDb();
00734                 }
00735                 // duplicate the materials
00736                 $clone->duplicateMaterials($original_id);
00737                 return $clone->getId();
00738         }
00739 
00748         function duplicateMaterials($question_id)
00749         {
00750                 foreach ($this->materials as $filename)
00751                 {
00752                         $materialspath = $this->getMaterialsPath();
00753                         $materialspath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $materialspath);
00754                         if (!file_exists($materialspath)) 
00755                         {
00756                                 include_once "./classes/class.ilUtil.php";
00757                                 ilUtil::makeDirParents($materialspath);
00758                         }
00759                         if (!copy($materialspath_original . $filename, $materialspath . $filename)) 
00760                         {
00761                                 print "material could not be duplicated!!!! ";
00762                         }
00763                 }
00764         }
00765 
00766 
00775         function loadFromDb($question_id)
00776         {
00777                 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
00778                         $this->ilias->db->quote($this->getId() . "")
00779                 );
00780                 $result = $this->ilias->db->query($query);
00781                 $this->material = array();
00782                 if ($result->numRows())
00783                 {
00784                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00785                         {
00786                                 $this->material = array(
00787                                         "internal_link" => $row["internal_link"],
00788                                         "import_id" => $row["import_id"],
00789                                         "title" => $row["material_title"]
00790                                 );
00791                         }
00792                 }
00793         }
00794 
00803         function _isComplete($question_id)
00804         {
00805                 global $ilDB;
00806 
00807                 $query = sprintf("SELECT complete FROM survey_question WHERE question_id = %s",
00808                         $ilDB->quote($question_id . "")
00809                 );
00810                 $result = $ilDB->query($query);
00811                 if ($result->numRows())
00812                 {
00813                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00814                         if ($row["complete"] == 1)
00815                         {
00816                                 return TRUE;
00817                         }
00818                 }
00819                 return FALSE;
00820         }
00821         
00829         function saveCompletionStatus()
00830         {
00831                 $complete = 0;
00832                 if ($this->isComplete()) 
00833                 {
00834                         $complete = 1;
00835                 }
00836     if ($this->id > 0) 
00837                 {
00838       // update existing dataset
00839       $query = sprintf("UPDATE survey_question SET complete = %s WHERE question_id = %s",
00840                                 $this->ilias->db->quote("$complete"),
00841                                 $this->ilias->db->quote($this->id)
00842       );
00843       $result = $this->ilias->db->query($query);
00844     }
00845         }
00846 
00855         function saveToDb($original_id = "")
00856         {
00857                 include_once "./content/classes/Pages/class.ilInternalLink.php";
00858                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
00859                         $this->ilias->db->quote($this->getId() . "")
00860                 );
00861                 $result = $this->ilias->db->query($query);
00862                 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->getId());
00863                 if (count($this->material))
00864                 {
00865                         $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00866                                 $this->ilias->db->quote($this->getId() . ""),
00867                                 $this->ilias->db->quote($this->material["internal_link"] . ""),
00868                                 $this->ilias->db->quote($this->material["import_id"] . ""),
00869                                 $this->ilias->db->quote($this->material["title"] . "")
00870                         );
00871                         $this->ilias->db->query($query);
00872                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00873                         {
00874                                 ilInternalLink::_saveLink("sqst", $this->getId(), $matches[2], $matches[3], $matches[1]);
00875                         }
00876                 }
00877         }
00878         
00879 
00888   function saveWorkingData($limit_to = LIMIT_NO_LIMIT) 
00889         {
00890   }
00891 
00900         function getImagePath() 
00901         {
00902                 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/images/";
00903         }
00904 
00913         function getMaterialsPath() 
00914         {
00915                 return CLIENT_WEB_DIR . "/survey/$this->obj_id/$this->id/materials/";
00916         }
00917 
00926         function getImagePathWeb() 
00927         {
00928                 include_once "./classes/class.ilUtil.php";
00929                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/images/";
00930                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00931         }
00932 
00941         function getMaterialsPathWeb() 
00942         {
00943                 include_once "./classes/class.ilUtil.php";
00944                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/survey/$this->obj_id/$this->id/materials/";
00945                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00946         }
00947 
00956   function saveMaterialsToDb()
00957   {
00958                 if ($this->id > 0) 
00959                 {
00960                         $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
00961                                 $this->ilias->db->quote($this->id)
00962                         );
00963                         $result = $this->ilias->db->query($query);
00964                         if (!empty($this->materials)) {
00965                                 foreach ($this->materials as $key => $value) 
00966                                 {
00967                                         $query = sprintf("INSERT INTO survey_question_material (question_fi, materials, materials_file) VALUES (%s, %s, %s)",
00968                                                 $this->ilias->db->quote($this->id),
00969                                                 $this->ilias->db->quote($key),
00970                                                 $this->ilias->db->quote($value)
00971                                         );
00972                                         $result = $this->ilias->db->query($query);
00973                                 }
00974                         }
00975                 }
00976         }
00977 
00986   function loadMaterialFromDb($question_id)
00987   {
00988     $query = sprintf("SELECT * FROM survey_question_material WHERE question_fi = %s",
00989       $this->ilias->db->quote($question_id)
00990     );
00991     $result = $this->ilias->db->query($query);
00992     if (strcmp(strtolower(get_class($result)), db_result) == 0) 
00993                 {
00994         $this->materials = array();
00995         while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) 
00996                         {
00997                                 $this->addMaterials($data->materials_file, $data->materials);
00998                         }
00999                 }
01000         }
01001 
01012         function saveCategoryToDb($categorytext)
01013         {
01014                 global $ilUser;
01015                 
01016                 $query = sprintf("SELECT title, category_id FROM survey_category WHERE title = %s AND owner_fi = %s",
01017                         $this->ilias->db->quote($categorytext),
01018                         $this->ilias->db->quote($ilUser->id)
01019                 );
01020     $result = $this->ilias->db->query($query);
01021                 $insert = FALSE;
01022                 $returnvalue = "";
01023                 if ($result->numRows()) 
01024                 {
01025                         $insert = TRUE;
01026                         while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01027                         {
01028                                 if (strcmp($row->title, $categorytext) == 0)
01029                                 {
01030                                         $returnvalue = $row->category_id;
01031                                         $insert = FALSE;
01032                                 }
01033                         }
01034                 }
01035                 else
01036                 {
01037                         $insert = TRUE;
01038                 }
01039                 if ($insert)
01040                 {
01041                         $query = sprintf("INSERT INTO survey_category (category_id, title, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
01042                                 $this->ilias->db->quote($categorytext),
01043                                 $this->ilias->db->quote($ilUser->id)
01044                         );
01045                         $result = $this->ilias->db->query($query);
01046                         $returnvalue = $this->ilias->db->getLastInsertId();
01047                 }
01048                 return $returnvalue;
01049         }
01050 
01059   function delete($question_id) 
01060   {
01061     if ($question_id < 1)
01062       return;
01063       
01064                 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01065                         $this->ilias->db->quote($question_id)
01066                 );
01067     $result = $this->ilias->db->query($query);
01068                 if ($result->numRows() == 1)
01069                 {
01070                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01071                         $obj_id = $row["obj_fi"];
01072                 }
01073                 else
01074                 {
01075                         return;
01076                 }
01077                 
01078                 $query = sprintf("DELETE FROM survey_answer WHERE question_fi = %s",
01079                         $this->ilias->db->quote($question_id)
01080                 );
01081                 $result = $this->ilias->db->query($query);
01082 
01083                 $query = sprintf("SELECT constraint_id FROM survey_constraint WHERE question_fi = %s",
01084                         $this->ilias->db->quote($question_id)
01085                 );
01086                 $result = $this->ilias->db->query($query);
01087                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01088                 {
01089                         $query = sprintf("DELETE FROM survey_question_constraint WHERE constraint_fi = %s",
01090                                 $this->ilias->db->quote($row->constraint_id)
01091                         );
01092                         $delresult = $this->ilias->db->query($query);
01093                 }
01094                 
01095                 $query = sprintf("DELETE FROM survey_constraint WHERE question_fi = %s",
01096                         $this->ilias->db->quote($question_id)
01097                 );
01098                 $result = $this->ilias->db->query($query);
01099 
01100                 $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s",
01101                         $this->ilias->db->quote($question_id)
01102                 );
01103                 $result = $this->ilias->db->query($query);
01104                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01105                 {
01106                         $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
01107                                 $this->ilias->db->quote($row->constraint_fi)
01108                         );
01109                         $delresult = $this->ilias->db->query($query);
01110                 }
01111                 $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s",
01112                         $this->ilias->db->quote($question_id)
01113                 );
01114                 $result = $this->ilias->db->query($query);
01115 
01116                 $query = sprintf("DELETE FROM survey_question_material WHERE question_fi = %s",
01117                         $this->ilias->db->quote($question_id)
01118                 );
01119                 $result = $this->ilias->db->query($query);
01120 
01121                 $query = sprintf("DELETE FROM survey_questionblock_question WHERE question_fi = %s",
01122                         $this->ilias->db->quote($question_id)
01123                 );
01124                 $result = $this->ilias->db->query($query);
01125 
01126                 $query = sprintf("DELETE FROM survey_question_obligatory WHERE question_fi = %s",
01127                         $this->ilias->db->quote($question_id)
01128                 );
01129                 $result = $this->ilias->db->query($query);
01130 
01131                 $query = sprintf("DELETE FROM survey_survey_question WHERE question_fi = %s",
01132                         $this->ilias->db->quote($question_id)
01133                 );
01134                 $result = $this->ilias->db->query($query);
01135 
01136                 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01137                         $this->ilias->db->quote($question_id)
01138                 );
01139                 $result = $this->ilias->db->query($query);
01140 
01141                 $query = sprintf("DELETE FROM survey_question WHERE question_id = %s",
01142                         $this->ilias->db->quote($question_id)
01143                 );
01144                 $result = $this->ilias->db->query($query);
01145 
01146                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01147                         $this->ilias->db->quote($question_id)
01148                 );
01149                 $result = $this->ilias->db->query($query);
01150                 include_once "./content/classes/Pages/class.ilInternalLink.php";
01151                 ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01152 
01153                 $directory = CLIENT_WEB_DIR . "/survey/" . $obj_id . "/$question_id";
01154                 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
01155                 {
01156                         include_once "./classes/class.ilUtil.php";
01157                         ilUtil::delDir($directory);
01158                 }
01159         }
01160 
01170   function _getQuestionType($question_id) 
01171         {
01172                 global $ilDB;
01173 
01174     if ($question_id < 1)
01175       return "";
01176 
01177     $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",
01178       $ilDB->quote($question_id)
01179     );
01180     $result = $ilDB->query($query);
01181     if ($result->numRows() == 1) 
01182                 {
01183       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01184       return $data->type_tag;
01185     } 
01186                 else 
01187                 {
01188       return "";
01189     }
01190   }
01191 
01201         function _getOriginalId($question_id)
01202         {
01203                 global $ilDB;
01204                 $query = sprintf("SELECT * FROM survey_question WHERE question_id = %s",
01205                         $ilDB->quote($question_id . "")
01206                 );
01207                 $result = $ilDB->query($query);
01208                 if ($result->numRows() > 0)
01209                 {
01210                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01211                         if ($row["original_id"] > 0)
01212                         {
01213                                 return $row["original_id"];
01214                         }
01215                         else
01216                         {
01217                                 return $row["question_id"];
01218                         }
01219                 }
01220                 else
01221                 {
01222                         return "";
01223                 }
01224         }
01225         
01226         function _getRefIdFromObjId($obj_id)
01227         {
01228                 global $ilDB;
01229                 
01230                 $query = sprintf("SELECT ref_id FROM object_reference WHERE obj_id=%s",
01231                         $ilDB->quote($obj_id)
01232                         
01233                 );
01234                 $result = $ilDB->query($query);
01235                 if ($result->numRows())
01236                 {
01237                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01238                         return $row["ref_id"];
01239                 }
01240                 return 0;
01241         }
01242         
01243         function syncWithOriginal()
01244         {
01245                 include_once "./content/classes/Pages/class.ilInternalLink.php";
01246                 $query = sprintf("DELETE FROM survey_material WHERE question_fi = %s",
01247                         $this->ilias->db->quote($this->original_id . "")
01248                 );
01249                 $result = $this->ilias->db->query($query);
01250                 ilInternalLink::_deleteAllLinksOfSource("sqst", $this->original_id);
01251                 if (strlen($this->material["internal_link"]))
01252                 {
01253                         $query = sprintf("INSERT INTO survey_material (material_id, question_fi, internal_link, import_id, material_title, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01254                                 $this->ilias->db->quote($this->original_id . ""),
01255                                 $this->ilias->db->quote($this->material["internal_link"] . ""),
01256                                 $this->ilias->db->quote($this->material["import_id"] . ""),
01257                                 $this->ilias->db->quote($this->material["title"] . "")
01258                         );
01259                         $this->ilias->db->query($query);
01260                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
01261                         {
01262                                 ilInternalLink::_saveLink("sqst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01263                         }
01264                 }
01265         }
01266 
01275         function getPhrase($phrase_id)
01276         {
01277                 $query = sprintf("SELECT title FROM survey_phrase WHERE phrase_id = %s",
01278                         $this->ilias->db->quote($phrase_id)
01279                 );
01280     $result = $this->ilias->db->query($query);
01281                 if ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01282                 {
01283                         return $row["title"];
01284                 }
01285                 return "";
01286         }
01287 
01297         function phraseExists($title)
01298         {
01299                 global $ilUser;
01300                 
01301                 $query = sprintf("SELECT phrase_id FROM survey_phrase WHERE title = %s AND owner_fi = %s",
01302                         $this->ilias->db->quote($title),
01303                         $this->ilias->db->quote($ilUser->id)
01304                 );
01305     $result = $this->ilias->db->query($query);
01306                 if ($result->numRows() == 0)
01307                 {
01308                         return false;
01309                 }
01310                 else
01311                 {
01312                         return true;
01313                 }
01314         }
01315 
01325         function _questionExists($question_id)
01326         {
01327                 global $ilDB;
01328 
01329                 if ($question_id < 1)
01330                 {
01331                         return false;
01332                 }
01333                 
01334                 $query = sprintf("SELECT question_id FROM survey_question WHERE question_id = %s",
01335                         $ilDB->quote($question_id)
01336                 );
01337     $result = $ilDB->query($query);
01338                 if ($result->numRows() == 1)
01339                 {
01340                         return true;
01341                 }
01342                 else
01343                 {
01344                         return false;
01345                 }
01346         }
01347 
01357         function setMaterial($material_id = "", $is_import = false, $material_title = "")
01358         {
01359                 if (strcmp($material_id, "") != 0)
01360                 {
01361                         $import_id = "";
01362                         if ($is_import)
01363                         {
01364                                 $import_id = $material_id;
01365                                 $material_id = $this->_resolveInternalLink($import_id);
01366                         }
01367                         if (strcmp($material_title, "") == 0)
01368                         {
01369                                 if (preg_match("/il__(\w+)_(\d+)/", $material_id, $matches))
01370                                 {
01371                                         $type = $matches[1];
01372                                         $target_id = $matches[2];
01373                                         $material_title = $this->lng->txt("obj_$type") . ": ";
01374                                         switch ($type)
01375                                         {
01376                                                 case "lm":
01377                                                         include_once("./content/classes/class.ilObjContentObject.php");
01378                                                         $cont_obj =& new ilObjContentObject($target_id, true);
01379                                                         $material_title .= $cont_obj->getTitle();
01380                                                         break;
01381                                                 case "pg":
01382                                                         include_once("./content/classes/class.ilLMPageObject.php");
01383                                                         include_once("./content/classes/class.ilLMObject.php");
01384                                                         include_once("./content/classes/class.ilObjContentObject.php");
01385                                                         $lm_id = ilLMObject::_lookupContObjID($target_id);
01386                                                         $cont_obj =& new ilObjContentObject($lm_id, false);
01387                                                         $pg_obj =& new ilLMPageObject($cont_obj, $target_id);
01388                                                         $material_title .= $pg_obj->getTitle();
01389                                                         break;
01390                                                 case "st":
01391                                                         include_once("content/classes/class.ilStructureObject.php");
01392                                                         include_once("./content/classes/class.ilLMObject.php");
01393                                                         include_once("./content/classes/class.ilObjContentObject.php");
01394                                                         $lm_id = ilLMObject::_lookupContObjID($target_id);
01395                                                         $cont_obj =& new ilObjContentObject($lm_id, false);
01396                                                         $st_obj =& new ilStructureObject($cont_obj, $target_id);
01397                                                         $material_title .= $st_obj->getTitle();
01398                                                         break;
01399                                                 case "git":
01400                                                         include_once "./content/classes/class.ilGlossaryTerm.php";
01401                                                         $material_title = $this->lng->txt("glossary_term") . ": " . ilGlossaryTerm::_lookGlossaryTerm($target_id);
01402                                                         break;
01403                                                 case "mob":
01404                                                         break;
01405                                         }
01406                                 }
01407                         }
01408                         $this->material = array(
01409                                 "internal_link" => $material_id,
01410                                 "import_id" => $import_id,
01411                                 "title" => $material_title
01412                         );
01413                 }
01414         }
01415         
01416         function _resolveInternalLink($internal_link)
01417         {
01418                 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01419                 {
01420                         include_once "./content/classes/Pages/class.ilInternalLink.php";
01421                         include_once "./content/classes/class.ilLMObject.php";
01422                         include_once "./content/classes/class.ilGlossaryTerm.php";
01423                         switch ($matches[2])
01424                         {
01425                                 case "lm":
01426                                         $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01427                                         break;
01428                                 case "pg":
01429                                         $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01430                                         break;
01431                                 case "st":
01432                                         $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01433                                         break;
01434                                 case "git":
01435                                         $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01436                                         break;
01437                                 case "mob":
01438                                         $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01439                                         break;
01440                         }
01441                         if (strcmp($resolved_link, "") == 0)
01442                         {
01443                                 $resolved_link = $internal_link;
01444                         }
01445                 }
01446                 else
01447                 {
01448                         $resolved_link = $internal_link;
01449                 }
01450                 return $resolved_link;
01451         }
01452         
01453         function _resolveIntLinks($question_id)
01454         {
01455                 global $ilDB;
01456                 $resolvedlinks = 0;
01457                 $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01458                         $ilDB->quote($question_id . "")
01459                 );
01460                 $result = $ilDB->query($query);
01461                 if ($result->numRows())
01462                 {
01463                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01464                         {
01465                                 $internal_link = $row["internal_link"];
01466                                 include_once "./survey/classes/class.SurveyQuestion.php";
01467                                 $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
01468                                 if (strcmp($internal_link, $resolved_link) != 0)
01469                                 {
01470                                         // internal link was resolved successfully
01471                                         $queryupdate = sprintf("UPDATE survey_material SET internal_link = %s WHERE material_id = %s",
01472                                                 $ilDB->quote($resolved_link),
01473                                                 $ilDB->quote($row["material_id"] . "")
01474                                         );
01475                                         $updateresult = $ilDB->query($queryupdate);
01476                                         $resolvedlinks++;
01477                                 }
01478                         }
01479                 }
01480                 if ($resolvedlinks)
01481                 {
01482                         // there are resolved links -> reenter theses links to the database
01483 
01484                         // delete all internal links from the database
01485                         include_once "./content/classes/Pages/class.ilInternalLink.php";
01486                         ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
01487 
01488                         $query = sprintf("SELECT * FROM survey_material WHERE question_fi = %s",
01489                                 $ilDB->quote($question_id . "")
01490                         );
01491                         $result = $ilDB->query($query);
01492                         if ($result->numRows())
01493                         {
01494                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01495                                 {
01496                                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01497                                         {
01498                                                 ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
01499                                         }
01500                                 }
01501                         }
01502                 }
01503         }
01504         
01505         function _getInternalLinkHref($target = "")
01506         {
01507                 global $ilDB;
01508                 $linktypes = array(
01509                         "lm" => "LearningModule",
01510                         "pg" => "PageObject",
01511                         "st" => "StructureObject",
01512                         "git" => "GlossaryItem",
01513                         "mob" => "MediaObject"
01514                 );
01515                 $href = "";
01516                 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01517                 {
01518                         $type = $matches[1];
01519                         $target_id = $matches[2];
01520                         include_once "./classes/class.ilUtil.php";
01521                         switch($linktypes[$matches[1]])
01522                         {
01523                                 case "LearningModule":
01524                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01525                                         break;
01526                                 case "PageObject":
01527                                 case "StructureObject":
01528                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01529                                         break;
01530                                 case "GlossaryItem":
01531                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01532                                         break;
01533                                 case "MediaObject":
01534                                         $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;
01535                                         break;
01536                         }
01537                 }
01538                 return $href;
01539         }
01540         
01541         function saveCategoriesToDb()
01542         {
01543                 // save categories
01544                 
01545                 // delete existing category relations
01546                 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
01547                         $this->ilias->db->quote($this->id)
01548                 );
01549                 $result = $this->ilias->db->query($query);
01550                 // create new category relations
01551                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
01552                 {
01553                         $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
01554                         $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01555                                 $this->ilias->db->quote($category_id . ""),
01556                                 $this->ilias->db->quote($this->id . ""),
01557                                 $this->ilias->db->quote(($i + 1) . ""),
01558                                 $this->ilias->db->quote($i . "")
01559                         );
01560                         $answer_result = $this->ilias->db->query($query);
01561                 }
01562                 $this->saveCompletionStatus();
01563         }
01564         
01575         function _isWriteable($question_id, $user_id)
01576         {
01577                 global $ilDB;
01578 
01579                 if (($question_id < 1) || ($user_id < 1))
01580                 {
01581                         return false;
01582                 }
01583                 
01584                 $query = sprintf("SELECT obj_fi FROM survey_question WHERE question_id = %s",
01585                         $ilDB->quote($question_id . "")
01586                 );
01587     $result = $ilDB->query($query);
01588                 if ($result->numRows() == 1)
01589                 {
01590                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01591                         $qpl_object_id = $row["obj_fi"];
01592                         include_once "./survey/classes/class.ilObjSurveyQuestionPool.php";
01593                         return ilObjSurveyQuestionPool::_isWriteable($qpl_object_id, $user_id);
01594                 }
01595                 else
01596                 {
01597                         return false;
01598                 }
01599         }
01600 
01609         function getQuestionType()
01610         {
01611                 return 0;
01612         }
01613 }
01614 ?>

Generated on Fri Dec 13 2013 11:58:02 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1