• 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 require_once "./classes/class.ilObjectGUI.php";
00036 require_once "./classes/class.ilMetaData.php";
00037 require_once "./survey/classes/class.SurveyNominalQuestion.php";
00038 require_once "./survey/classes/class.SurveyTextQuestion.php";
00039 require_once "./survey/classes/class.SurveyMetricQuestion.php";
00040 require_once "./survey/classes/class.SurveyOrdinalQuestion.php";
00041 require_once "./survey/classes/class.SurveyQuestion.php";
00042 
00043 class ilObjSurveyQuestionPool extends ilObject
00044 {
00051         function ilObjSurveyQuestionPool($a_id = 0,$a_call_by_reference = true)
00052         {
00053                 $this->type = "spl";
00054                 $this->ilObject($a_id,$a_call_by_reference);
00055                 if ($a_id == 0)
00056                 {
00057                         $new_meta =& new ilMetaData();
00058                         $this->assignMetaData($new_meta);
00059                 }
00060         }
00061 
00065         function create($a_upload = false)
00066         {
00067                 parent::create();
00068                 if (!$a_upload)
00069                 {
00070                         $this->meta_data->setId($this->getId());
00071                         $this->meta_data->setType($this->getType());
00072                         $this->meta_data->setTitle($this->getTitle());
00073                         $this->meta_data->setDescription($this->getDescription());
00074                         $this->meta_data->setObject($this);
00075                         $this->meta_data->create();
00076                 }
00077         }
00078 
00085         function update()
00086         {
00087                 if (!parent::update())
00088                 {                       
00089                         return false;
00090                 }
00091 
00092                 // put here object specific stuff
00093                 
00094                 return true;
00095         }
00096         
00102         function read($a_force_db = false)
00103         {
00104                 parent::read($a_force_db);
00105                 $this->meta_data =& new ilMetaData($this->getType(), $this->getId());
00106         }
00107         
00115         function ilClone($a_parent_ref)
00116         {               
00117                 global $rbacadmin;
00118 
00119                 // always call parent ilClone function first!!
00120                 $new_ref_id = parent::ilClone($a_parent_ref);
00121                 
00122                 // get object instance of ilCloned object
00123                 //$newObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00124 
00125                 // create a local role folder & default roles
00126                 //$roles = $newObj->initDefaultRoles();
00127 
00128                 // ...finally assign role to creator of object
00129                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "n");          
00130 
00131                 // always destroy objects in ilClone method because ilClone() is recursive and creates instances for each object in subtree!
00132                 //unset($newObj);
00133 
00134                 // ... and finally always return new reference ID!!
00135                 return $new_ref_id;
00136         }
00137 
00144         function delete()
00145         {               
00146                 $remove = parent::delete();
00147                 // always call parent delete function first!!
00148                 if (!$remove)
00149                 {
00150                         return false;
00151                 }
00152                 
00153                 // delete all related questions
00154                 $this->deleteAllData();
00155                 
00156                 return true;
00157         }
00158 
00159         function deleteAllData()
00160         {
00161                 $query = sprintf("SELECT question_id FROM survey_question WHERE obj_fi = %s",
00162                         $this->ilias->db->quote($this->getId())
00163                 );
00164                 $result = $this->ilias->db->query($query);
00165                 $found_questions = array();
00166                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00167                 {
00168                         $this->removeQuestion($row["question_id"]);
00169                 }
00170 
00171                 // delete export files
00172                 $spl_data_dir = ilUtil::getDataDir()."/spl_data";
00173                 $directory = $spl_data_dir."/spl_".$this->getId();
00174                 if (is_dir($directory))
00175                 {
00176                         $directory = escapeshellarg($directory);
00177                         exec("rm -rf $directory");
00178                 }
00179         }
00180 
00190         function initDefaultRoles()
00191         {
00192                 global $rbacadmin;
00193                 
00194                 // create a local role folder
00195                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00196 
00197                 // create moderator role and assign role to rolefolder...
00198                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00199                 //$roles[] = $roleObj->getId();
00200 
00201                 //unset($rfoldObj);
00202                 //unset($roleObj);
00203 
00204                 return $roles ? $roles : array();
00205         }
00206 
00220         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00221         {
00222                 global $tree;
00223                 
00224                 switch ($a_event)
00225                 {
00226                         case "link":
00227                                 
00228                                 //var_dump("<pre>",$a_params,"</pre>");
00229                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00230                                 //exit;
00231                                 break;
00232                         
00233                         case "cut":
00234                                 
00235                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00236                                 //exit;
00237                                 break;
00238                                 
00239                         case "copy":
00240                         
00241                                 //var_dump("<pre>",$a_params,"</pre>");
00242                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00243                                 //exit;
00244                                 break;
00245 
00246                         case "paste":
00247                                 
00248                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00249                                 //exit;
00250                                 break;
00251                         
00252                         case "new":
00253                                 
00254                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00255                                 //exit;
00256                                 break;
00257                 }
00258                 
00259                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00260                 if ($a_node_id==$_GET["ref_id"])
00261                 {       
00262                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00263                         $parent_type = $parent_obj->getType();
00264                         if($parent_type == $this->getType())
00265                         {
00266                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00267                         }
00268                 }
00269                 
00270                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00271         }
00272 
00278         function getTitle()
00279         {
00280                 //return $this->title;
00281                 return parent::getTitle();
00282                 //return $this->meta_data->getTitle();
00283         }
00284 
00288         function setTitle($a_title)
00289         {
00290                 parent::setTitle($a_title);
00291                 $this->meta_data->setTitle($a_title);
00292         }
00293 
00299         function assignMetaData(&$a_meta_data)
00300         {
00301                 $this->meta_data =& $a_meta_data;
00302         }
00303 
00309         function &getMetaData()
00310         {
00311                 return $this->meta_data;
00312         }
00313 
00317         function initMeta()
00318         {
00319                 if (!is_object($this->meta_data))
00320                 {
00321                         if ($this->getId())
00322                         {
00323                                 $new_meta =& new ilMetaData($this->getType(), $this->getId());
00324                         }       
00325                         else
00326                         {
00327                                 $new_meta =& new ilMetaData();
00328                         }
00329                         $this->assignMetaData($new_meta);
00330                 }
00331         }
00332 
00336         function updateMetaData()
00337         {
00338                 $this->initMeta();
00339                 $this->meta_data->update();
00340                 if ($this->meta_data->section != "General")
00341                 {
00342                         $meta = $this->meta_data->getElement("Title", "General");
00343                         $this->meta_data->setTitle($meta[0]["value"]);
00344                         $meta = $this->meta_data->getElement("Description", "General");
00345                         $this->meta_data->setDescription($meta[0]["value"]);
00346                 }
00347                 else
00348                 {
00349                         $this->setTitle($this->meta_data->getTitle());
00350                         $this->setDescription($this->meta_data->getDescription());
00351                 }
00352                 parent::update();
00353         }
00354 
00363   function removeQuestion($question_id) 
00364   {
00365     if ($question_id < 1)
00366       return;
00367                 
00368                 $question = new SurveyQuestion();
00369                 $question->delete($question_id);
00370         }
00371 
00381   function getQuestiontype($question_id) 
00382   {
00383     if ($question_id < 1)
00384       return;
00385       
00386     $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",
00387       $this->ilias->db->quote($question_id)
00388     );
00389     $result = $this->ilias->db->query($query);
00390     if ($result->numRows() == 1) {
00391       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00392                         return $data->type_tag;
00393     } else {
00394       return;
00395     }
00396   }
00397         
00407         function isInUse($question_id)
00408         {
00409                 // check out the already answered questions
00410                 $query = sprintf("SELECT answer_id FROM survey_answer WHERE question_fi = %s",
00411                         $this->ilias->db->quote($question_id)
00412                 );
00413     $result = $this->ilias->db->query($query);
00414                 $answered = $result->numRows();
00415                 
00416                 // check out the questions inserted in surveys
00417                 $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",
00418                         $this->ilias->db->quote($question_id)
00419                 );
00420     $result = $this->ilias->db->query($query);
00421                 $inserted = $result->numRows();
00422                 if (($inserted + $answered) == 0)
00423                 {
00424                         return false;
00425                 }
00426                 $result_array = array();
00427                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00428                 {
00429                         array_push($result_array, $row);
00430                 }
00431                 return $result_array;
00432         }
00433         
00442         function paste($question_id)
00443         {
00444                 $this->duplicateQuestion($question_id, $this->getId());
00445         }
00446         
00456         function &getQuestionsInfo($question_array)
00457         {
00458                 $result_array = array();
00459                 $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)",
00460                         join($question_array, ",")
00461                 );
00462     $result = $this->ilias->db->query($query);
00463                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00464                 {
00465                         array_push($result_array, $row);
00466                 }
00467                 return $result_array;
00468         }
00469         
00478   function duplicateQuestion($question_id, $obj_id = "") {
00479                 global $ilUser;
00480                 
00481                 $questiontype = $this->getQuestiontype($question_id);
00482                 switch ($questiontype)
00483                 {
00484                         case "qt_nominal":
00485                                 $question = new SurveyNominalQuestion();
00486                                 break;
00487                         case "qt_ordinal":
00488                                 $question = new SurveyOrdinalQuestion();
00489                                 break;
00490                         case "qt_metric":
00491                                 $question = new SurveyMetricQuestion();
00492                                 break;
00493                         case "qt_text":
00494                                 $question = new SurveyTextQuestion();
00495                                 break;
00496                 }
00497                 $question->loadFromDb($question_id);
00498     $counter = 2;
00499     while ($question->questionTitleExists($question->getTitle() . " ($counter)")) {
00500       $counter++;
00501     }
00502                 if ($obj_id)
00503                 {
00504                         $question->setObjId($obj_id);
00505                 }
00506                 $question->duplicate(false, $question->getTitle() . " ($counter)", $ilUser->fullname, $ilUser->id);
00507   }
00508         
00517         function deletePhrases($phrase_array)
00518         {
00519                 $query = "DELETE FROM survey_phrase WHERE phrase_id IN (" . join($phrase_array, ",") . ")";
00520                 $result = $this->ilias->db->query($query);
00521                 $query = "DELETE FROM survey_phrase_category WHERE phrase_fi IN (" . join($phrase_array, ",") . ")";
00522                 $result = $this->ilias->db->query($query);
00523         }
00524 
00532         function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00533         {
00534                 global $ilUser;
00535                 $where = "";
00536                 if (strlen($filter_text) > 0) {
00537                         switch($sel_filter_type) {
00538                                 case "title":
00539                                         $where = " AND survey_question.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00540                                         break;
00541                                 case "description":
00542                                         $where = " AND survey_question.description LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00543                                         break;
00544                                 case "author":
00545                                         $where = " AND survey_question.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00546                                         break;
00547                         }
00548                 }
00549   
00550     // build sort order for sql query
00551                 $order = "";
00552                 $images = array();
00553     if (count($sortoptions)) {
00554       foreach ($sortoptions as $key => $value) {
00555         switch($key) {
00556           case "title":
00557             $order = " ORDER BY title $value";
00558             $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00559             break;
00560           case "description":
00561             $order = " ORDER BY description $value";
00562             $images["description"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00563             break;
00564           case "type":
00565             $order = " ORDER BY questiontype_id $value";
00566             $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00567             break;
00568           case "author":
00569             $order = " ORDER BY author $value";
00570             $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00571             break;
00572           case "created":
00573             $order = " ORDER BY created $value";
00574             $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00575             break;
00576           case "updated":
00577             $order = " ORDER BY TIMESTAMP14 $value";
00578             $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00579             break;
00580         }
00581       }
00582     }
00583                 $maxentries = $ilUser->prefs["hits_per_page"];
00584                 if ($maxentries < 1)
00585                 {
00586                         $maxentries = 9999;
00587                 }
00588     $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";
00589     $query_result = $this->ilias->db->query($query);
00590                 $max = $query_result->numRows();
00591                 if ($startrow > $max -1)
00592                 {
00593                         $startrow = $max - ($max % $maxentries);
00594                 }
00595                 else if ($startrow < 0)
00596                 {
00597                         $startrow = 0;
00598                 }
00599                 $limit = " LIMIT $startrow, $maxentries";
00600     $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";
00601     $query_result = $this->ilias->db->query($query);
00602                 $rows = array();
00603                 if ($query_result->numRows())
00604                 {
00605                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00606                         {
00607                                 array_push($rows, $row);
00608                         }
00609                 }
00610                 $nextrow = $startrow + $maxentries;
00611                 if ($nextrow > $max - 1)
00612                 {
00613                         $nextrow = $startrow;
00614                 }
00615                 $prevrow = $startrow - $maxentries;
00616                 if ($prevrow < 0)
00617                 {
00618                         $prevrow = 0;
00619                 }
00620                 return array(
00621                         "rows" => $rows,
00622                         "images" => $images,
00623                         "startrow" => $startrow,
00624                         "nextrow" => $nextrow,
00625                         "prevrow" => $prevrow,
00626                         "step" => $maxentries,
00627                         "rowcount" => $max
00628                 );
00629         }
00630         
00636         function createExportDirectory()
00637         {
00638                 $spl_data_dir = ilUtil::getDataDir()."/spl_data";
00639                 ilUtil::makeDir($spl_data_dir);
00640                 if(!is_writable($spl_data_dir))
00641                 {
00642                         $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
00643                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00644                 }
00645                 
00646                 // create learning module directory (data_dir/lm_data/lm_<id>)
00647                 $spl_dir = $spl_data_dir."/spl_".$this->getId();
00648                 ilUtil::makeDir($spl_dir);
00649                 if(!@is_dir($spl_dir))
00650                 {
00651                         $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00652                 }
00653                 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00654                 $export_dir = $spl_dir."/export";
00655                 ilUtil::makeDir($export_dir);
00656                 if(!@is_dir($export_dir))
00657                 {
00658                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00659                 }
00660         }
00661 
00665         function getExportDirectory()
00666         {
00667                 $export_dir = ilUtil::getDataDir()."/spl_data"."/spl_".$this->getId()."/export";
00668 
00669                 return $export_dir;
00670         }
00671         
00675         function getExportFiles($dir)
00676         {
00677                 // quit if import dir not available
00678                 if (!@is_dir($dir) or
00679                         !is_writeable($dir))
00680                 {
00681                         return array();
00682                 }
00683 
00684                         // open directory
00685                 $dir = dir($dir);
00686 
00687                 // initialize array
00688                 $file = array();
00689 
00690                 // get files and save the in the array
00691                 while ($entry = $dir->read())
00692                 {
00693                         if ($entry != "." and
00694                                 $entry != ".." and
00695                                 substr($entry, -4) == ".xml" and
00696                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(spl__)*[0-9]+\.xml\$", $entry))
00697                         {
00698                                 $file[] = $entry;
00699                         }
00700                 }
00701 
00702                 // close import directory
00703                 $dir->close();
00704                 // sort files
00705                 sort ($file);
00706                 reset ($file);
00707 
00708                 return $file;
00709         }
00710 
00716         function createImportDirectory()
00717         {
00718                 $spl_data_dir = ilUtil::getDataDir()."/spl_data";
00719                 ilUtil::makeDir($spl_data_dir);
00720                 
00721                 if(!is_writable($spl_data_dir))
00722                 {
00723                         $this->ilias->raiseError("Survey Questionpool Data Directory (".$spl_data_dir
00724                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00725                 }
00726 
00727                 // create test directory (data_dir/spl_data/spl_<id>)
00728                 $spl_dir = $spl_data_dir."/spl_".$this->getId();
00729                 ilUtil::makeDir($spl_dir);
00730                 if(!@is_dir($spl_dir))
00731                 {
00732                         $this->ilias->raiseError("Creation of Survey Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00733                 }
00734 
00735                 // create import subdirectory (data_dir/spl_data/spl_<id>/import)
00736                 $import_dir = $spl_dir."/import";
00737                 ilUtil::makeDir($import_dir);
00738                 if(!@is_dir($import_dir))
00739                 {
00740                         $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
00741                 }
00742         }
00743 
00747         function getImportDirectory()
00748         {
00749                 $import_dir = ilUtil::getDataDir()."/spl_data".
00750                         "/spl_".$this->getId()."/import";
00751                 if(@is_dir($import_dir))
00752                 {
00753                         return $import_dir;
00754                 }
00755                 else
00756                 {
00757                         return false;
00758                 }
00759         }
00760 
00764         function to_xml($questions)
00765         {
00766                 if (!is_array($questions))
00767                 {
00768                         $questions =& $this->getQuestions();
00769                 }
00770                 if (count($questions) == 0)
00771                 {
00772                         $questions =& $this->getQuestions();
00773                 }
00774                 $xml = "";
00775 
00776                 foreach ($questions as $key => $value)
00777                 {
00778                         $questiontype = $this->getQuestiontype($value);
00779                         switch ($questiontype)
00780                         {
00781                                 case "qt_nominal":
00782                                         $question = new SurveyNominalQuestion();
00783                                         break;
00784                                 case "qt_ordinal":
00785                                         $question = new SurveyOrdinalQuestion();
00786                                         break;
00787                                 case "qt_metric":
00788                                         $question = new SurveyMetricQuestion();
00789                                         break;
00790                                 case "qt_text":
00791                                         $question = new SurveyTextQuestion();
00792                                         break;
00793                         }
00794                         $question->loadFromDb($value);
00795                         $xml .= $question->to_xml(false);
00796                 }
00797                 if (count($questions) > 1)
00798                 {
00799                         $xml = preg_replace("/<\/questestinterop>\s*<questestinterop>/", "", $xml);
00800                 }
00801                 $xml = str_replace("<questestinterop>", "", $xml);
00802                 $xml = str_replace("</questestinterop>", "", $xml);
00803                 
00804                 // export questionpool metadata
00805                 $xml_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00806                 $xml_header .= "<questestinterop></questestinterop>\n";
00807                 $domxml = domxml_open_mem($xml_header);
00808                 $root = $domxml->document_element();
00809 
00810                 // qti section
00811                 $qtiSection = $domxml->create_element("section");
00812                 $qtiSection->set_attribute("ident", "qpl_" . $this->getId());
00813                 $qtiSection->set_attribute("title", $this->getTitle());
00814 
00815                 // qti metadata
00816                 $qtiMetadata = $domxml->create_element("qtimetadata");
00817                 $qtiMetadatafield = $domxml->create_element("qtimetadatafield");
00818                 $qtiFieldlabel = $domxml->create_element("fieldlabel");
00819                 $qtiFieldlabelText = $domxml->create_text_node("SCORM");
00820                 $qtiFieldlabel->append_child($qtiFieldlabelText);
00821                 $qtiFieldentry = $domxml->create_element("fieldentry");
00822                 $this->initMeta();
00823 
00824                 $metadata = $this->meta_data->nested_obj->dom->dump_mem(0);
00825                 $qtiFieldentryText = $domxml->create_CDATA_Section($metadata);
00826                 $qtiFieldentry->append_child($qtiFieldentryText);
00827                 $qtiMetadatafield->append_child($qtiFieldlabel);
00828                 $qtiMetadatafield->append_child($qtiFieldentry);
00829                 $qtiMetadata->append_child($qtiMetadatafield);
00830                 $qtiSection->append_child($qtiMetadata);
00831                 $root->append_child($qtiSection);
00832                 $qtixml = $domxml->dump_mem(true);
00833                 $qtixml = str_replace("</section>", $xml . "\n</section>", $qtixml);
00834                 $domxml->free();
00835                 return $qtixml;
00836         }
00837         
00838         function &getQuestions()
00839         {
00840                 $questions = array();
00841                 $query = sprintf("SELECT question_id FROM survey_question WHERE obj_fi = %s AND ISNULL(original_id)",
00842                         $this->ilias->db->quote($this->getId() . "")
00843                 );
00844                 $result = $this->ilias->db->query($query);
00845                 if ($result->numRows())
00846                 {
00847                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00848                         {
00849                                 array_push($questions, $row["question_id"]);
00850                         }
00851                 }
00852                 return $questions;
00853         }
00854 
00855         function importObject($source)
00856         {       
00857                 $metadata = "";
00858                 if (is_file($source))
00859                 {
00860                         $fh = fopen($source, "r") or die("");
00861                         $xml = fread($fh, filesize($source));
00862                         fclose($fh) or die("");
00863 
00864                         // read questionpool metadata from xml file
00865                         $xml = preg_replace("/>\s*?</", "><", $xml);
00866                         $domxml = domxml_open_mem($xml);
00867                         if (!empty($domxml))
00868                         {
00869                                 $nodeList = $domxml->get_elements_by_tagname("fieldlabel");
00870                                 foreach ($nodeList as $node)
00871                                 {
00872                                         switch ($node->get_content())
00873                                         {
00874                                                 case "SCORM":
00875                                                         $metanode = $node->next_sibling();
00876                                                         if (strcmp($metanode->node_name(), "fieldentry") == 0)
00877                                                         {
00878                                                                 $metadata = $metanode->get_content();
00879                                                         }
00880                                         }
00881                                 }
00882                                 $domxml->free();
00883                         }
00884 
00885                         // import file into questionpool
00886                         if (preg_match_all("/(<item[^>]*>.*?<\/item>)/si", $xml, $matches))
00887                         {
00888                                 foreach ($matches[1] as $index => $item)
00889                                 {
00890                                         // get identifier
00891                                         if (preg_match("/(<item[^>]*>)/is", $item, $start_tag))
00892                                         {
00893                                                 if (preg_match("/(ident=\"([^\"]*)\")/is", $start_tag[1], $ident))
00894                                                 {
00895                                                         $ident = $ident[2];
00896                                                 }
00897                                         }
00898                                         $question = "";
00899                                         if (preg_match("/<qticomment>Questiontype\=(.*?)<\/qticomment>/is", $item, $questiontype))
00900                                         {
00901                                                 switch ($questiontype[1])
00902                                                 {
00903                                                         case NOMINAL_QUESTION_IDENTIFIER:
00904                                                                 $question = new SurveyNominalQuestion();
00905                                                                 break;
00906                                                         case ORDINAL_QUESTION_IDENTIFIER:
00907                                                                 $question = new SurveyOrdinalQuestion();
00908                                                                 break;
00909                                                         case METRIC_QUESTION_IDENTIFIER:
00910                                                                 $question = new SurveyMetricQuestion();
00911                                                                 break;
00912                                                         case TEXT_QUESTION_IDENTIFIER:
00913                                                                 $question = new SurveyTextQuestion();
00914                                                                 break;
00915                                                 }
00916                                                 if ($question)
00917                                                 {
00918                                                         $question->setObjId($this->getId());
00919                                                         if ($question->from_xml("<questestinterop>$item</questestinterop>"))
00920                                                         {
00921                                                                 $question->saveToDb();
00922                                                         }
00923                                                         else
00924                                                         {
00925                                                                 $this->ilias->raiseError($this->lng->txt("error_importing_question"), $this->ilias->error_obj->MESSAGE);
00926                                                         }
00927                                                 }
00928                                         }
00929                                 }
00930                         }
00931                         
00932                         if ($metadata)
00933                         {
00934                                 include_once("./classes/class.ilNestedSetXML.php");
00935                                 $nested = new ilNestedSetXML();
00936                                 $nested->dom = domxml_open_mem($metadata);
00937                                 $nodes = $nested->getDomContent("//MetaData/General", "Identifier");
00938                                 if (is_array($nodes))
00939                                 {
00940                                         $nodes[0]["Entry"] = "il__" . $this->getType() . "_" . $this->getId();
00941                                         $nested->updateDomContent("//MetaData/General", "Identifier", 0, $nodes[0]);
00942                                 }
00943                                 $nodes = $nested->getDomContent("//MetaData/General", "Title");
00944                                 if (is_array($nodes))
00945                                 {
00946                                         $this->setTitle($nodes[0]["value"]);
00947                                 }
00948                                 $nodes = $nested->getDomContent("//MetaData/General", "Description");
00949                                 if (is_array($nodes))
00950                                 {
00951                                         $this->setDescription($nodes[0]["value"]);
00952                                 }
00953                                 $xml = $nested->dom->dump_mem(0);
00954                                 $nested->import($xml, $this->getId(), $this->getType());
00955                         }
00956                 }
00957         }
00958         
00959 } // END class.ilSurveyObjQuestionPool
00960 ?>

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