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

survey/classes/class.ilObjSurveyQuestionPool.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 include_once "./classes/class.ilObject.php";
00036 include_once "./survey/classes/inc.SurveyConstants.php";
00037 
00038 class ilObjSurveyQuestionPool extends ilObject
00039 {
00045         var $online;
00046         
00053         function ilObjSurveyQuestionPool($a_id = 0,$a_call_by_reference = true)
00054         {
00055                 $this->type = "spl";
00056                 $this->ilObject($a_id,$a_call_by_reference);
00057         }
00058 
00062         function create($a_upload = false)
00063         {
00064                 parent::create();
00065                 if(!$a_upload)
00066                 {
00067                         $this->createMetaData();
00068                 }
00069         }
00070 
00077         function update()
00078         {
00079                 $this->updateMetaData();
00080                 if (!parent::update())
00081                 {
00082                         return false;
00083                 }
00084 
00085                 // put here object specific stuff
00086 
00087                 return true;
00088         }
00089 
00095         function read($a_force_db = false)
00096         {
00097                 parent::read($a_force_db);
00098                 $this->loadFromDb();
00099         }
00100 
00108         function loadFromDb()
00109         {
00110                 global $ilDB;
00111                 
00112                 $query = sprintf("SELECT * FROM survey_questionpool WHERE obj_fi = %s",
00113                         $ilDB->quote($this->getId() . "")
00114                 );
00115                 $result = $ilDB->query($query);
00116                 if ($result->numRows() == 1)
00117                 {
00118                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00119                         $this->setOnline($row["online"]);
00120                 }
00121         }
00122         
00130   function saveToDb()
00131   {
00132                 global $ilDB;
00133                 
00134                 $query = sprintf("SELECT * FROM survey_questionpool WHERE obj_fi = %s",
00135                         $ilDB->quote($this->getId() . "")
00136                 );
00137                 $result = $ilDB->query($query);
00138                 if ($result->numRows() == 1)
00139                 {
00140                         $query = sprintf("UPDATE survey_questionpool SET online = %s WHERE obj_fi = %s",
00141                                 $ilDB->quote($this->getOnline() . ""),
00142                                 $ilDB->quote($this->getId() . "")
00143                         );
00144       $result = $ilDB->query($query);
00145       if ($result != DB_OK) 
00146                         {
00147       }
00148                 }
00149                 else
00150                 {
00151                         $query = sprintf("INSERT INTO survey_questionpool (online, obj_fi) VALUES (%s, %s)",
00152                                 $ilDB->quote($this->getOnline() . ""),
00153                                 $ilDB->quote($this->getId() . "")
00154                         );
00155       $result = $ilDB->query($query);
00156       if ($result != DB_OK) 
00157                         {
00158       }
00159                 }
00160         }
00161         
00169         function ilClone($a_parent_ref)
00170         {               
00171                 global $rbacadmin;
00172 
00173                 // always call parent ilClone function first!!
00174                 $new_ref_id = parent::ilClone($a_parent_ref);
00175                 
00176                 // get object instance of ilCloned object
00177                 //$newObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00178 
00179                 // create a local role folder & default roles
00180                 //$roles = $newObj->initDefaultRoles();
00181 
00182                 // ...finally assign role to creator of object
00183                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "n");          
00184 
00185                 // always destroy objects in ilClone method because ilClone() is recursive and creates instances for each object in subtree!
00186                 //unset($newObj);
00187 
00188                 // ... and finally always return new reference ID!!
00189                 return $new_ref_id;
00190         }
00191 
00198         function delete()
00199         {
00200                 $remove = parent::delete();
00201                 // always call parent delete function first!!
00202                 if (!$remove)
00203                 {
00204                         return false;
00205                 }
00206 
00207                 // delete all related questions
00208                 $this->deleteAllData();
00209 
00210                 // delete meta data
00211                 $this->deleteMetaData();
00212                 
00213                 return true;
00214         }
00215 
00216         function deleteAllData()
00217         {
00218                 $query = sprintf("SELECT question_id FROM survey_question WHERE obj_fi = %s",
00219                         $this->ilias->db->quote($this->getId())
00220                 );
00221                 $result = $this->ilias->db->query($query);
00222                 $found_questions = array();
00223                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00224                 {
00225                         $this->removeQuestion($row["question_id"]);
00226                 }
00227 
00228                 // delete export files
00229                 include_once "./classes/class.ilUtil.php";
00230                 $spl_data_dir = ilUtil::getDataDir()."/spl_data";
00231                 $directory = $spl_data_dir."/spl_".$this->getId();
00232                 if (is_dir($directory))
00233                 {
00234                         include_once "./classes/class.ilUtil.php";
00235                         ilUtil::delDir($directory);
00236                 }
00237         }
00238 
00252         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00253         {
00254                 global $tree;
00255                 
00256                 switch ($a_event)
00257                 {
00258                         case "link":
00259                                 
00260                                 //var_dump("<pre>",$a_params,"</pre>");
00261                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00262                                 //exit;
00263                                 break;
00264                         
00265                         case "cut":
00266                                 
00267                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00268                                 //exit;
00269                                 break;
00270                                 
00271                         case "copy":
00272                         
00273                                 //var_dump("<pre>",$a_params,"</pre>");
00274                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00275                                 //exit;
00276                                 break;
00277 
00278                         case "paste":
00279                                 
00280                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00281                                 //exit;
00282                                 break;
00283                         
00284                         case "new":
00285                                 
00286                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00287                                 //exit;
00288                                 break;
00289                 }
00290                 
00291                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00292                 if ($a_node_id==$_GET["ref_id"])
00293                 {       
00294                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00295                         $parent_type = $parent_obj->getType();
00296                         if($parent_type == $this->getType())
00297                         {
00298                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00299                         }
00300                 }
00301                 
00302                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00303         }
00304 
00310         function getTitle()
00311         {
00312                 //return $this->title;
00313                 return parent::getTitle();
00314         }
00315 
00319         function setTitle($a_title)
00320         {
00321                 parent::setTitle($a_title);
00322         }
00323 
00332   function removeQuestion($question_id)
00333   {
00334     if ($question_id < 1)
00335       return;
00336 
00337                 include_once "./survey/classes/class.SurveyQuestion.php";
00338                 $question = new SurveyQuestion();
00339                 $question->delete($question_id);
00340         }
00341 
00351   function getQuestiontype($question_id) 
00352   {
00353     if ($question_id < 1)
00354       return;
00355       
00356     $query = sprintf("SELECT survey_questiontype.type_tag FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id = %s",
00357       $this->ilias->db->quote($question_id)
00358     );
00359     $result = $this->ilias->db->query($query);
00360     if ($result->numRows() == 1) {
00361       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00362                         return $data->type_tag;
00363     } else {
00364       return;
00365     }
00366   }
00367         
00377         function isInUse($question_id)
00378         {
00379                 // check out the already answered questions
00380                 $query = sprintf("SELECT answer_id FROM survey_answer WHERE question_fi = %s",
00381                         $this->ilias->db->quote($question_id)
00382                 );
00383     $result = $this->ilias->db->query($query);
00384                 $answered = $result->numRows();
00385                 
00386                 // check out the questions inserted in surveys
00387                 $query = sprintf("SELECT survey_survey.* FROM survey_survey, survey_survey_question WHERE survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = %s",
00388                         $this->ilias->db->quote($question_id)
00389                 );
00390     $result = $this->ilias->db->query($query);
00391                 $inserted = $result->numRows();
00392                 if (($inserted + $answered) == 0)
00393                 {
00394                         return false;
00395                 }
00396                 $result_array = array();
00397                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00398                 {
00399                         array_push($result_array, $row);
00400                 }
00401                 return $result_array;
00402         }
00403         
00412         function paste($question_id)
00413         {
00414                 $this->duplicateQuestion($question_id, $this->getId());
00415         }
00416         
00426         function &getQuestionsInfo($question_array)
00427         {
00428                 $result_array = array();
00429                 $query = sprintf("SELECT survey_question.*, survey_questiontype.type_tag FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id IN (%s)",
00430                         join($question_array, ",")
00431                 );
00432     $result = $this->ilias->db->query($query);
00433                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00434                 {
00435                         array_push($result_array, $row);
00436                 }
00437                 return $result_array;
00438         }
00439         
00448   function duplicateQuestion($question_id, $obj_id = "") 
00449         {
00450                 global $ilUser;
00451                 
00452                 include_once "./survey/classes/class.SurveyNominalQuestion.php";
00453                 include_once "./survey/classes/class.SurveyTextQuestion.php";
00454                 include_once "./survey/classes/class.SurveyMetricQuestion.php";
00455                 include_once "./survey/classes/class.SurveyOrdinalQuestion.php";
00456                 $questiontype = $this->getQuestiontype($question_id);
00457                 switch ($questiontype)
00458                 {
00459                         case "qt_nominal":
00460                                 include_once "./survey/classes/class.SurveyNominalQuestion.php";
00461                                 $question = new SurveyNominalQuestion();
00462                                 break;
00463                         case "qt_ordinal":
00464                                 include_once "./survey/classes/class.SurveyOrdinalQuestion.php";
00465                                 $question = new SurveyOrdinalQuestion();
00466                                 break;
00467                         case "qt_metric":
00468                                 include_once "./survey/classes/class.SurveyMetricQuestion.php";
00469                                 $question = new SurveyMetricQuestion();
00470                                 break;
00471                         case "qt_text":
00472                                 include_once "./survey/classes/class.SurveyTextQuestion.php";
00473                                 $question = new SurveyTextQuestion();
00474                                 break;
00475                 }
00476                 $question->loadFromDb($question_id);
00477                 $suffix = "";
00478     $counter = 1;
00479     while ($question->questionTitleExists($question->getTitle().$suffix, $obj_id)) 
00480                 {
00481       $counter++;
00482                         if ($counter > 1) $suffix = " ($counter)";
00483     }
00484                 if ($obj_id)
00485                 {
00486                         $question->setObjId($obj_id);
00487                 }
00488                 $question->duplicate(false, $question->getTitle() . $suffix, $ilUser->fullname, $ilUser->id);
00489   }
00490         
00499         function deletePhrases($phrase_array)
00500         {
00501                 $query = "DELETE FROM survey_phrase WHERE phrase_id IN (" . join($phrase_array, ",") . ")";
00502                 $result = $this->ilias->db->query($query);
00503                 $query = "DELETE FROM survey_phrase_category WHERE phrase_fi IN (" . join($phrase_array, ",") . ")";
00504                 $result = $this->ilias->db->query($query);
00505         }
00506 
00514         function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00515         {
00516                 global $ilUser;
00517                 $where = "";
00518                 if (strlen($filter_text) > 0) {
00519                         switch($sel_filter_type) {
00520                                 case "title":
00521                                         $where = " AND survey_question.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00522                                         break;
00523                                 case "description":
00524                                         $where = " AND survey_question.description LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00525                                         break;
00526                                 case "author":
00527                                         $where = " AND survey_question.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00528                                         break;
00529                         }
00530                 }
00531   
00532     // build sort order for sql query
00533                 $order = "";
00534                 $images = array();
00535                 include_once "./classes/class.ilUtil.php";
00536     if (count($sortoptions)) 
00537                 {
00538       foreach ($sortoptions as $key => $value) 
00539                         {
00540         switch($key) 
00541                                 {
00542           case "title":
00543             $order = " ORDER BY title $value";
00544             $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00545             break;
00546           case "description":
00547             $order = " ORDER BY description $value";
00548             $images["description"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00549             break;
00550           case "type":
00551             $order = " ORDER BY questiontype_id $value";
00552             $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00553             break;
00554           case "author":
00555             $order = " ORDER BY author $value";
00556             $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00557             break;
00558           case "created":
00559             $order = " ORDER BY created $value";
00560             $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00561             break;
00562           case "updated":
00563             $order = " ORDER BY TIMESTAMP14 $value";
00564             $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00565             break;
00566         }
00567       }
00568     }
00569                 $maxentries = $ilUser->prefs["hits_per_page"];
00570                 if ($maxentries < 1)
00571                 {
00572                         $maxentries = 9999;
00573                 }
00574     $query = "SELECT survey_question.question_id, survey_question.TIMESTAMP + 0 AS TIMESTAMP14 FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.obj_fi = " . $this->getId() . " AND ISNULL(survey_question.original_id) $where$order$limit";
00575     $query_result = $this->ilias->db->query($query);
00576                 $max = $query_result->numRows();
00577                 if ($startrow > $max -1)
00578                 {
00579                         $startrow = $max - ($max % $maxentries);
00580                 }
00581                 else if ($startrow < 0)
00582                 {
00583                         $startrow = 0;
00584                 }
00585                 $limit = " LIMIT $startrow, $maxentries";
00586     $query = "SELECT survey_question.*, survey_question.TIMESTAMP + 0 AS TIMESTAMP14, survey_questiontype.type_tag FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.obj_fi = " . $this->getId() . " AND ISNULL(survey_question.original_id) $where$order$limit";
00587     $query_result = $this->ilias->db->query($query);
00588                 $rows = array();
00589                 if ($query_result->numRows())
00590                 {
00591                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00592                         {
00593                                 array_push($rows, $row);
00594                         }
00595                 }
00596                 $nextrow = $startrow + $maxentries;
00597                 if ($nextrow > $max - 1)
00598                 {
00599                         $nextrow = $startrow;
00600                 }
00601                 $prevrow = $startrow - $maxentries;
00602                 if ($prevrow < 0)
00603                 {
00604                         $prevrow = 0;
00605                 }
00606                 return array(
00607                         "rows" => $rows,
00608                         "images" => $images,
00609                         "startrow" => $startrow,
00610                         "nextrow" => $nextrow,
00611                         "prevrow" => $prevrow,
00612                         "step" => $maxentries,
00613                         "rowcount" => $max
00614                 );
00615         }
00616         
00622         function createExportDirectory()
00623         {
00624                 include_once "./classes/class.ilUtil.php";
00625                 $spl_data_dir = ilUtil::getDataDir()."/spl_data";
00626                 ilUtil::makeDir($spl_data_dir);
00627                 if(!is_writable($spl_data_dir))
00628                 {
00629                         $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
00630                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00631                 }
00632                 
00633                 // create learning module directory (data_dir/lm_data/lm_<id>)
00634                 $spl_dir = $spl_data_dir."/spl_".$this->getId();
00635                 ilUtil::makeDir($spl_dir);
00636                 if(!@is_dir($spl_dir))
00637                 {
00638                         $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00639                 }
00640                 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00641                 $export_dir = $spl_dir."/export";
00642                 ilUtil::makeDir($export_dir);
00643                 if(!@is_dir($export_dir))
00644                 {
00645                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00646                 }
00647         }
00648 
00652         function getExportDirectory()
00653         {
00654                 include_once "./classes/class.ilUtil.php";
00655                 $export_dir = ilUtil::getDataDir()."/spl_data"."/spl_".$this->getId()."/export";
00656                 return $export_dir;
00657         }
00658         
00662         function getExportFiles($dir)
00663         {
00664                 // quit if import dir not available
00665                 if (!@is_dir($dir) or
00666                         !is_writeable($dir))
00667                 {
00668                         return array();
00669                 }
00670 
00671                         // open directory
00672                 $dir = dir($dir);
00673 
00674                 // initialize array
00675                 $file = array();
00676 
00677                 // get files and save the in the array
00678                 while ($entry = $dir->read())
00679                 {
00680                         if ($entry != "." and
00681                                 $entry != ".." and
00682                                 substr($entry, -4) == ".xml" and
00683                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(spl__)*[0-9]+\.xml\$", $entry))
00684                         {
00685                                 $file[] = $entry;
00686                         }
00687                 }
00688 
00689                 // close import directory
00690                 $dir->close();
00691                 // sort files
00692                 sort ($file);
00693                 reset ($file);
00694 
00695                 return $file;
00696         }
00697 
00703         function createImportDirectory()
00704         {
00705                 include_once "./classes/class.ilUtil.php";
00706                 $spl_data_dir = ilUtil::getDataDir()."/spl_data";
00707                 ilUtil::makeDir($spl_data_dir);
00708                 
00709                 if(!is_writable($spl_data_dir))
00710                 {
00711                         $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
00712                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00713                 }
00714 
00715                 // create test directory (data_dir/spl_data/spl_<id>)
00716                 $spl_dir = $spl_data_dir."/spl_".$this->getId();
00717                 ilUtil::makeDir($spl_dir);
00718                 if(!@is_dir($spl_dir))
00719                 {
00720                         $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00721                 }
00722 
00723                 // create import subdirectory (data_dir/spl_data/spl_<id>/import)
00724                 $import_dir = $spl_dir."/import";
00725                 ilUtil::makeDir($import_dir);
00726                 if(!@is_dir($import_dir))
00727                 {
00728                         $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
00729                 }
00730         }
00731 
00735         function getImportDirectory()
00736         {
00737                 include_once "./classes/class.ilUtil.php";
00738                 $import_dir = ilUtil::getDataDir()."/spl_data".
00739                         "/spl_".$this->getId()."/import";
00740                 if(@is_dir($import_dir))
00741                 {
00742                         return $import_dir;
00743                 }
00744                 else
00745                 {
00746                         return false;
00747                 }
00748         }
00749 
00753         function to_xml($questions)
00754         {
00755                 include_once "./survey/classes/class.SurveyNominalQuestion.php";
00756                 include_once "./survey/classes/class.SurveyTextQuestion.php";
00757                 include_once "./survey/classes/class.SurveyMetricQuestion.php";
00758                 include_once "./survey/classes/class.SurveyOrdinalQuestion.php";
00759                 if (!is_array($questions))
00760                 {
00761                         $questions =& $this->getQuestions();
00762                 }
00763                 if (count($questions) == 0)
00764                 {
00765                         $questions =& $this->getQuestions();
00766                 }
00767                 $xml = "";
00768 
00769                 foreach ($questions as $key => $value)
00770                 {
00771                         $questiontype = $this->getQuestiontype($value);
00772                         switch ($questiontype)
00773                         {
00774                                 case "qt_nominal":
00775                                         $question = new SurveyNominalQuestion();
00776                                         break;
00777                                 case "qt_ordinal":
00778                                         $question = new SurveyOrdinalQuestion();
00779                                         break;
00780                                 case "qt_metric":
00781                                         $question = new SurveyMetricQuestion();
00782                                         break;
00783                                 case "qt_text":
00784                                         $question = new SurveyTextQuestion();
00785                                         break;
00786                         }
00787                         $question->loadFromDb($value);
00788                         $xml .= $question->to_xml(false);
00789                 }
00790                 if (count($questions) > 1)
00791                 {
00792                         $xml = preg_replace("/<\/questestinterop>\s*<questestinterop>/", "", $xml);
00793                 }
00794                 $xml = str_replace("<questestinterop>", "", $xml);
00795                 $xml = str_replace("</questestinterop>", "", $xml);
00796                 
00797                 include_once("./classes/class.ilXmlWriter.php");
00798                 $a_xml_writer = new ilXmlWriter;
00799                 // set xml header
00800                 $a_xml_writer->xmlHeader();
00801                 $a_xml_writer->xmlStartTag("questestinterop");
00802                 $attrs = array(
00803                         "ident" => "qpl_" . $this->getId(),
00804                         "title" => $this->getTitle()
00805                 );
00806                 $a_xml_writer->xmlStartTag("section", $attrs);
00807                 // add ILIAS specific metadata
00808                 $a_xml_writer->xmlStartTag("qtimetadata");
00809                 $a_xml_writer->xmlStartTag("qtimetadatafield");
00810                 $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
00811 
00812                 include_once "./Services/MetaData/classes/class.ilMD.php";
00813                 $md = new ilMD($this->getId(),0, $this->getType());
00814                 $writer = new ilXmlWriter();
00815                 $md->toXml($writer);
00816                 $metadata = $writer->xmlDumpMem();
00817 
00818                 $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
00819                 $a_xml_writer->xmlEndTag("qtimetadatafield");
00820                 $a_xml_writer->xmlEndTag("qtimetadata");
00821                 $a_xml_writer->xmlEndTag("section");
00822                 $a_xml_writer->xmlEndTag("questestinterop");
00823 
00824                 $qtixml = $a_xml_writer->xmlDumpMem(FALSE);
00825                 $qtixml = str_replace("</section>", $xml . "\n</section>", $qtixml);
00826                 return $qtixml;
00827         }
00828 
00829         function &getQuestions()
00830         {
00831                 $questions = array();
00832                 $query = sprintf("SELECT question_id FROM survey_question WHERE obj_fi = %s AND ISNULL(original_id)",
00833                         $this->ilias->db->quote($this->getId() . "")
00834                 );
00835                 $result = $this->ilias->db->query($query);
00836                 if ($result->numRows())
00837                 {
00838                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00839                         {
00840                                 array_push($questions, $row["question_id"]);
00841                         }
00842                 }
00843                 return $questions;
00844         }
00845 
00846         function importObject($source)
00847         {
00848                 include_once "./survey/classes/class.SurveyNominalQuestion.php";
00849                 include_once "./survey/classes/class.SurveyTextQuestion.php";
00850                 include_once "./survey/classes/class.SurveyMetricQuestion.php";
00851                 include_once "./survey/classes/class.SurveyOrdinalQuestion.php";
00852                 $metadata = "";
00853                 if (is_file($source))
00854                 {
00855                         $fh = fopen($source, "r") or die("");
00856                         $xml = fread($fh, filesize($source));
00857                         fclose($fh) or die("");
00858 
00859                         // read questionpool metadata from xml file
00860                         $xml = preg_replace("/>\s*?</", "><", $xml);
00861                         $domxml = domxml_open_mem($xml);
00862                         if (!empty($domxml))
00863                         {
00864                                 $nodeList = $domxml->get_elements_by_tagname("fieldlabel");
00865                                 foreach ($nodeList as $node)
00866                                 {
00867                                         switch ($node->get_content())
00868                                         {
00869                                                 case "SCORM":
00870                                                         $metanode = $node->next_sibling();
00871                                                         if (strcmp($metanode->node_name(), "fieldentry") == 0)
00872                                                         {
00873                                                                 $metadata = $metanode->get_content();
00874                                                         }
00875                                         }
00876                                 }
00877                                 $domxml->free();
00878                         }
00879 
00880                         // import file into questionpool
00881                         if (preg_match_all("/(<item[^>]*>.*?<\/item>)/si", $xml, $matches))
00882                         {
00883                                 foreach ($matches[1] as $index => $item)
00884                                 {
00885                                         // get identifier
00886                                         if (preg_match("/(<item[^>]*>)/is", $item, $start_tag))
00887                                         {
00888                                                 if (preg_match("/(ident=\"([^\"]*)\")/is", $start_tag[1], $ident))
00889                                                 {
00890                                                         $ident = $ident[2];
00891                                                 }
00892                                         }
00893                                         $question = "";
00894                                         if (preg_match("/<qticomment>Questiontype\=(.*?)<\/qticomment>/is", $item, $questiontype))
00895                                         {
00896                                                 include_once "./survey/classes/class.SurveyNominalQuestion.php";
00897                                                 include_once "./survey/classes/class.SurveyOrdinalQuestion.php";
00898                                                 include_once "./survey/classes/class.SurveyMetricQuestion.php";
00899                                                 include_once "./survey/classes/class.SurveyTextQuestion.php";
00900                                                 switch ($questiontype[1])
00901                                                 {
00902                                                         case NOMINAL_QUESTION_IDENTIFIER:
00903                                                                 $question = new SurveyNominalQuestion();
00904                                                                 break;
00905                                                         case ORDINAL_QUESTION_IDENTIFIER:
00906                                                                 $question = new SurveyOrdinalQuestion();
00907                                                                 break;
00908                                                         case METRIC_QUESTION_IDENTIFIER:
00909                                                                 $question = new SurveyMetricQuestion();
00910                                                                 break;
00911                                                         case TEXT_QUESTION_IDENTIFIER:
00912                                                                 $question = new SurveyTextQuestion();
00913                                                                 break;
00914                                                 }
00915                                                 if ($question)
00916                                                 {
00917                                                         $question->setObjId($this->getId());
00918                                                         if ($question->from_xml("<questestinterop>$item</questestinterop>"))
00919                                                         {
00920                                                                 $question->saveToDb();
00921                                                         }
00922                                                         else
00923                                                         {
00924                                                                 $this->ilias->raiseError($this->lng->txt("error_importing_question"), $this->ilias->error_obj->MESSAGE);
00925                                                         }
00926                                                 }
00927                                         }
00928                                 }
00929                         }
00930                         
00931                         if ($metadata)
00932                         {
00933                                 include_once "./Services/MetaData/classes/class.ilMDSaxParser.php";
00934                                 include_once "./Services/MetaData/classes/class.ilMD.php";
00935                                 $md_sax_parser = new ilMDSaxParser();
00936                                 $md_sax_parser->setXMLContent($metadata);
00937                                 $md_sax_parser->setMDObject($tmp = new ilMD($this->getId(),0,'spl'));
00938                                 $md_sax_parser->enableMDParsing(true);
00939                                 $md_sax_parser->startParsing();
00940 
00941                                 // Finally update title description
00942                                 // Update title description
00943                                 $this->MDUpdateListener('General');
00944                         }
00945 
00946                 }
00947         }
00948 
00958         function setOnline($a_online_status)
00959         {
00960                 switch ($a_online_status)
00961                 {
00962                         case 0:
00963                         case 1:
00964                                 $this->online = $a_online_status;
00965                                 break;
00966                         default:
00967                                 $this->online = 0;
00968                                 break;
00969                 }
00970         }
00971         
00972         function getOnline()
00973         {
00974                 if (strcmp($this->online, "") == 0) $this->online = "0";
00975                 return $this->online;
00976         }
00977         
00978         function _lookupOnline($a_obj_id)
00979         {
00980                 global $ilDB;
00981                 
00982                 $query = sprintf("SELECT online FROM survey_questionpool WHERE obj_fi = %s",
00983                         $ilDB->quote($a_obj_id . "")
00984                 );
00985                 $result = $ilDB->query($query);
00986                 if ($result->numRows() == 1)
00987                 {
00988                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00989                         return $row["online"];
00990                 }
00991                 return 0;
00992         }
00993 
01003         function _isWriteable($object_id, $user_id)
01004         {
01005                 global $rbacsystem;
01006                 global $ilDB;
01007                 
01008                 $result_array = array();
01009                 $query = sprintf("SELECT object_data.*, object_data.obj_id, object_reference.ref_id FROM object_data, object_reference WHERE object_data.obj_id = object_reference.obj_id AND object_data.obj_id = %s",
01010                         $ilDB->quote($object_id . "")
01011                 );
01012                 $result = $ilDB->query($query);
01013                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01014                 {               
01015                         include_once "./classes/class.ilObject.php";
01016                         if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
01017                         {
01018                                 return true;
01019                         }
01020                 }
01021                 return false;
01022         }
01023 } // END class.ilSurveyObjQuestionPool
01024 ?>

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