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

assessment/classes/class.ilObjQuestionPool.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 "./assessment/classes/inc.AssessmentConstants.php";
00025 
00037 class ilObjQuestionPool extends ilObject
00038 {
00044         var $online;
00045         
00052         function ilObjQuestionPool($a_id = 0,$a_call_by_reference = true)
00053         {
00054                 $this->type = "qpl";
00055                 $this->ilObject($a_id,$a_call_by_reference);
00056                 $this->setOnline(0);
00057         }
00058 
00062         function create($a_upload = false)
00063         {
00064                 parent::create();
00065                 
00066                 // meta data will be created by
00067                 // import parser
00068                 if (!$a_upload)
00069                 {
00070                         $this->createMetaData();
00071                 }
00072         }
00073 
00082         function createReference() 
00083         {
00084                 $result = parent::createReference();
00085                 $this->saveToDb();
00086                 return $result;
00087         }
00088         
00095         function update()
00096         {
00097                 $this->updateMetaData();
00098                 if (!parent::update())
00099                 {
00100                         return false;
00101                 }
00102 
00103                 // put here object specific stuff
00104 
00105                 return true;
00106         }
00107 
00108         function updateMetaData()
00109         {
00110                 global $ilUser;
00111                 include_once "./Services/MetaData/classes/class.ilMD.php";
00112                 $md =& new ilMD($this->getId(), 0, $this->getType());
00113                 $md_gen =& $md->getGeneral();
00114                 if ($md_gen == false)
00115                 {
00116                         include_once "./Services/MetaData/classes/class.ilMDCreator.php";
00117                         $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
00118                         $md_creator->setTitle($this->getTitle());
00119                         $md_creator->setTitleLanguage($ilUser->getPref('language'));
00120                         $md_creator->create();
00121                 }
00122                 parent::updateMetaData();
00123         }
00124 
00130         function read($a_force_db = false)
00131         {
00132                 parent::read($a_force_db);
00133                 $this->loadFromDb();
00134         }
00135 
00143         function ilClone($a_parent_ref)
00144         {
00145                 global $rbacadmin;
00146 
00147                 // always call parent ilClone function first!!
00148                 $new_ref_id = parent::ilClone($a_parent_ref);
00149 
00150                 // get object instance of ilCloned object
00151                 //$newObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00152 
00153                 // create a local role folder & default roles
00154                 //$roles = $newObj->initDefaultRoles();
00155 
00156                 // ...finally assign role to creator of object
00157                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "n");
00158 
00159                 // always destroy objects in ilClone method because ilClone() is recursive and creates instances for each object in subtree!
00160                 //unset($newObj);
00161 
00162                 // ... and finally always return new reference ID!!
00163                 return $new_ref_id;
00164         }
00165 
00172         function delete()
00173         {
00174 /*              $questions =& $this->getAllQuestions();
00175                 $used_questions = 0;
00176                 include_once "./assessment/classes/class.assQuestion.php";
00177                 foreach ($questions as $question_id)
00178                 {
00179                         if (ASS_Question::_isUsedInRandomTest($question_id))
00180                         {
00181                                 $used_questions++;
00182                         }
00183                 }
00184                 
00185                 if ($used_questions)
00186                 {
00187                         return false;
00188                 }
00189 */              
00190                 // always call parent delete function first!!
00191                 if (!parent::delete())
00192                 {
00193                         return false;
00194                 }
00195 
00196                 // delete meta data
00197                 $this->deleteMetaData();
00198 
00199                 //put here your module specific stuff
00200                 $this->deleteQuestionpool();
00201 
00202                 return true;
00203         }
00204 
00205         function deleteQuestionpool()
00206         {
00207                 $questions =& $this->getAllQuestions();
00208 
00209                 if (count($questions))
00210                 {
00211                         foreach ($questions as $question_id)
00212                         {
00213                                 $this->deleteQuestion($question_id);
00214                         }
00215                 }
00216 
00217                 // delete export files
00218                 include_once "./classes/class.ilUtil.php";
00219                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00220                 $directory = $qpl_data_dir."/qpl_".$this->getId();
00221                 if (is_dir($directory))
00222                 {
00223                         include_once "./classes/class.ilUtil.php";
00224                         ilUtil::delDir($directory);
00225                 }
00226         }
00227 
00237         function initDefaultRoles()
00238         {
00239                 global $rbacadmin;
00240 
00241                 // create a local role folder
00242                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00243 
00244                 // create moderator role and assign role to rolefolder...
00245                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00246                 //$roles[] = $roleObj->getId();
00247 
00248                 //unset($rfoldObj);
00249                 //unset($roleObj);
00250 
00251                 return $roles ? $roles : array();
00252         }
00253 
00267         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00268         {
00269                 global $tree;
00270 
00271                 switch ($a_event)
00272                 {
00273                         case "link":
00274 
00275                                 //var_dump("<pre>",$a_params,"</pre>");
00276                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00277                                 //exit;
00278                                 break;
00279 
00280                         case "cut":
00281 
00282                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00283                                 //exit;
00284                                 break;
00285 
00286                         case "copy":
00287 
00288                                 //var_dump("<pre>",$a_params,"</pre>");
00289                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00290                                 //exit;
00291                                 break;
00292 
00293                         case "paste":
00294 
00295                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00296                                 //exit;
00297                                 break;
00298 
00299                         case "new":
00300 
00301                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00302                                 //exit;
00303                                 break;
00304                 }
00305 
00306                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00307                 if ($a_node_id==$_GET["ref_id"])
00308                 {
00309                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00310                         $parent_type = $parent_obj->getType();
00311                         if($parent_type == $this->getType())
00312                         {
00313                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00314                         }
00315                 }
00316 
00317                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00318         }
00319 
00328         function deleteQuestion($question_id)
00329         {
00330                 include_once "./assessment/classes/class.assQuestion.php";
00331                 $question = new ASS_Question();
00332                 $question->delete($question_id);
00333         }
00334 
00342         function loadFromDb()
00343         {
00344                 global $ilDB;
00345                 
00346                 $query = sprintf("SELECT * FROM qpl_questionpool WHERE obj_fi = %s",
00347                         $ilDB->quote($this->getId() . "")
00348                 );
00349                 $result = $ilDB->query($query);
00350                 if ($result->numRows() == 1)
00351                 {
00352                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00353                         $this->setOnline($row["online"]);
00354                 }
00355         }
00356         
00364   function saveToDb()
00365   {
00366                 global $ilDB;
00367                 
00368                 $query = sprintf("SELECT * FROM qpl_questionpool WHERE obj_fi = %s",
00369                         $ilDB->quote($this->getId() . "")
00370                 );
00371                 $result = $ilDB->query($query);
00372                 if ($result->numRows() == 1)
00373                 {
00374                         $query = sprintf("UPDATE qpl_questionpool SET online = %s WHERE obj_fi = %s",
00375                                 $ilDB->quote($this->getOnline() . ""),
00376                                 $ilDB->quote($this->getId() . "")
00377                         );
00378       $result = $ilDB->query($query);
00379       if ($result != DB_OK) 
00380                         {
00381       }
00382                 }
00383                 else
00384                 {
00385                         $query = sprintf("INSERT INTO qpl_questionpool (online, obj_fi) VALUES (%s, %s)",
00386                                 $ilDB->quote($this->getOnline() . ""),
00387                                 $ilDB->quote($this->getId() . "")
00388                         );
00389       $result = $ilDB->query($query);
00390       if ($result != DB_OK) 
00391                         {
00392       }
00393                 }
00394         }
00395         
00405         function getQuestiontype($question_id)
00406         {
00407                 if ($question_id < 1)
00408                 {
00409                         return;
00410                 }
00411 
00412                 $query = sprintf("SELECT qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.question_id = %s",
00413                         $this->ilias->db->quote($question_id));
00414 
00415                 $result = $this->ilias->db->query($query);
00416                 if ($result->numRows() == 1)
00417                 {
00418                         $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00419                         return $data->type_tag;
00420                 }
00421                 else
00422                 {
00423                         return;
00424                 }
00425         }
00426 
00432         function getDescription()
00433         {
00434                 return parent::getDescription();
00435         }
00436 
00440         function setDescription($a_description)
00441         {
00442                 parent::setDescription($a_description);
00443         }
00444 
00450         function getTitle()
00451         {
00452                 return parent::getTitle();
00453         }
00454 
00458         function setTitle($a_title)
00459         {
00460                 parent::setTitle($a_title);
00461         }
00462 
00472         function isInUse($question_id)
00473         {
00474                 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00475                         $this->ilias->db->quote("$question_id"));
00476 
00477                 $result = $this->ilias->db->query($query);
00478                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00479 
00480                 return $row->solution_count;
00481         }
00482 
00483         function &createQuestion($question_type, $question_id = -1)
00484         {
00485                 if ((!$question_type) and ($question_id > 0))
00486                 {
00487                         $question_type = $this->getQuestiontype($question_id);
00488                 }
00489 
00490                 switch ($question_type)
00491                 {
00492                         case "qt_multiple_choice_sr":
00493                                 include_once "./assessment/classes/class.assMultipleChoiceGUI.php";
00494                                 $question =& new ASS_MultipleChoiceGUI();
00495                                 $question->object->set_response(RESPONSE_SINGLE);
00496                                 break;
00497 
00498                         case "qt_multiple_choice_mr":
00499                                 include_once "./assessment/classes/class.assMultipleChoiceGUI.php";
00500                                 $question =& new ASS_MultipleChoiceGUI();
00501                                 $question->object->set_response(RESPONSE_MULTIPLE);
00502                                 break;
00503 
00504                         case "qt_cloze":
00505                                 include_once "./assessment/classes/class.assClozeTestGUI.php";
00506                                 $question =& new ASS_ClozeTestGUI();
00507                                 break;
00508 
00509                         case "qt_matching":
00510                                 include_once "./assessment/classes/class.assMatchingQuestionGUI.php";
00511                                 $question =& new ASS_MatchingQuestionGUI();
00512                                 break;
00513 
00514                         case "qt_ordering":
00515                                 include_once "./assessment/classes/class.assOrderingQuestionGUI.php";
00516                                 $question =& new ASS_OrderingQuestionGUI();
00517                                 break;
00518 
00519                         case "qt_imagemap":
00520                                 include_once "./assessment/classes/class.assImagemapQuestionGUI.php";
00521                                 $question =& new ASS_ImagemapQuestionGUI();
00522                                 break;
00523 
00524                         case "qt_javaapplet":
00525                                 include_once "./assessment/classes/class.assJavaAppletGUI.php";
00526                                 $question =& new ASS_JavaAppletGUI();
00527                                 break;
00528 
00529                         case "qt_text":
00530                                 include_once "./assessment/classes/class.assTextQuestionGUI.php";
00531                                 $question =& new ASS_TextQuestionGUI();
00532                                 break;
00533                 }
00534 
00535                 if ($question_id > 0)
00536                 {
00537                         $question->object->loadFromDb($question_id);
00538                 }
00539 
00540                 return $question;
00541         }
00542 
00551         function duplicateQuestion($question_id)
00552         {
00553                 $question =& $this->createQuestion("", $question_id);
00554                 $newtitle = $question->object->getTitle(); 
00555                 if ($question->object->questionTitleExists($this->getId(), $question->object->getTitle()))
00556                 {
00557                         $counter = 2;
00558                         while ($question->object->questionTitleExists($this->getId(), $question->object->getTitle() . " ($counter)"))
00559                         {
00560                                 $counter++;
00561                         }
00562                         $newtitle = $question->object->getTitle() . " ($counter)";
00563                 }
00564                 $question->object->duplicate(false, $newtitle);
00565         }
00566         
00576         function copyQuestion($question_id, $questionpool_to)
00577         {
00578                 $question_gui =& $this->createQuestion("", $question_id);
00579                 if ($question_gui->object->getObjId() == $questionpool_to)
00580                 {
00581                         // the question is copied into the same question pool
00582                         $this->duplicateQuestion($question_id);
00583                 }
00584                 else
00585                 {
00586                         // the question is copied into another question pool
00587                         $newtitle = $question_gui->object->getTitle(); 
00588                         if ($question_gui->object->questionTitleExists($this->getId(), $question_gui->object->getTitle()))
00589                         {
00590                                 $counter = 2;
00591                                 while ($question_gui->object->questionTitleExists($this->getId(), $question_gui->object->getTitle() . " ($counter)"))
00592                                 {
00593                                         $counter++;
00594                                 }
00595                                 $newtitle = $question_gui->object->getTitle() . " ($counter)";
00596                         }
00597                         $question_gui->object->copyObject($this->getId(), $newtitle);
00598                 }
00599         }
00600 
00608         function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00609         {
00610                 global $ilUser;
00611                 $where = "";
00612                 if (strlen($filter_text) > 0)
00613                 {
00614                         switch($sel_filter_type)
00615                         {
00616                                 case "title":
00617                                         $where = " AND qpl_questions.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00618                                         break;
00619 
00620                                 case "comment":
00621                                         $where = " AND qpl_questions.comment LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00622                                         break;
00623 
00624                                 case "author":
00625                                         $where = " AND qpl_questions.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00626                                         break;
00627                         }
00628                 }
00629 
00630             // build sort order for sql query
00631                 $order = "";
00632                 $images = array();
00633                 include_once "./classes/class.ilUtil.php";
00634                 if (count($sortoptions))
00635                 {
00636                         foreach ($sortoptions as $key => $value)
00637                         {
00638                                 switch($key)
00639                                 {
00640                                         case "title":
00641                                                 $order = " ORDER BY title $value";
00642                                                 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . $this->lng->txt(strtolower($value) . "ending_order")."\" />";
00643                                                 break;
00644                                         case "comment":
00645                                                 $order = " ORDER BY comment $value";
00646                                                 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . $this->lng->txt(strtolower($value) . "ending_order")."\" />";
00647                                                 break;
00648                                         case "type":
00649                                                 $order = " ORDER BY question_type_id $value";
00650                                                 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . $this->lng->txt(strtolower($value) . "ending_order")."\" />";
00651                                                 break;
00652                                         case "author":
00653                                                 $order = " ORDER BY author $value";
00654                                                 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . $this->lng->txt(strtolower($value) . "ending_order")."\" />";
00655                                                 break;
00656                                         case "created":
00657                                                 $order = " ORDER BY created $value";
00658                                                 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . $this->lng->txt(strtolower($value) . "ending_order")."\" />";
00659                                                 break;
00660                                         case "updated":
00661                                                 $order = " ORDER BY TIMESTAMP14 $value";
00662                                                 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . $this->lng->txt(strtolower($value) . "ending_order")."\" />";
00663                                                 break;
00664                                 }
00665                         }
00666                 }
00667                 $maxentries = $ilUser->prefs["hits_per_page"];
00668                 if ($maxentries < 1)
00669                 {
00670                         $maxentries = 9999;
00671                 }
00672                 $query = "SELECT qpl_questions.question_id, qpl_questions.TIMESTAMP + 0 AS TIMESTAMP14 FROM qpl_questions, qpl_question_type WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.obj_fi = " . $this->getId() . " $where$order$limit";
00673                 $query_result = $this->ilias->db->query($query);
00674                 $max = $query_result->numRows();
00675                 if ($startrow > $max -1)
00676                 {
00677                         $startrow = $max - ($max % $maxentries);
00678                 }
00679                 else if ($startrow < 0)
00680                 {
00681                         $startrow = 0;
00682                 }
00683                 $limit = " LIMIT $startrow, $maxentries";
00684                 $query = "SELECT qpl_questions.*, qpl_questions.TIMESTAMP + 0 AS TIMESTAMP14, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.obj_fi = " . $this->getId() . " $where$order$limit";
00685                 $query_result = $this->ilias->db->query($query);
00686                 $rows = array();
00687                 if ($query_result->numRows())
00688                 {
00689                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00690                         {
00691                                 array_push($rows, $row);
00692                         }
00693                 }
00694                 $nextrow = $startrow + $maxentries;
00695                 if ($nextrow > $max - 1)
00696                 {
00697                         $nextrow = $startrow;
00698                 }
00699                 $prevrow = $startrow - $maxentries;
00700                 if ($prevrow < 0)
00701                 {
00702                         $prevrow = 0;
00703                 }
00704                 return array(
00705                         "rows" => $rows,
00706                         "images" => $images,
00707                         "startrow" => $startrow,
00708                         "nextrow" => $nextrow,
00709                         "prevrow" => $prevrow,
00710                         "step" => $maxentries,
00711                         "rowcount" => $max
00712                 );
00713         }
00714 
00721         function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00722         {
00723                 global $ilBench;
00724                 
00725                 $this->mob_ids = array();
00726                 $this->file_ids = array();
00727 
00728                 $attrs = array();
00729                 $attrs["Type"] = "Questionpool_Test";
00730                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00731 
00732                 // MetaData
00733                 $this->exportXMLMetaData($a_xml_writer);
00734 
00735                 // PageObjects
00736                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00737                 $ilBench->start("ContentObjectExport", "exportPageObjects");
00738                 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00739                 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00740                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00741 
00742                 // MediaObjects
00743                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00744                 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00745                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00746                 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00747                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00748 
00749                 // FileItems
00750                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00751                 $ilBench->start("ContentObjectExport", "exportFileItems");
00752                 $this->exportFileItems($a_target_dir, $expLog);
00753                 $ilBench->stop("ContentObjectExport", "exportFileItems");
00754                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00755 
00756                 $a_xml_writer->xmlEndTag("ContentObject");
00757         }
00758 
00765         function exportXMLMetaData(&$a_xml_writer)
00766         {
00767                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00768                 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
00769                 $md2xml->setExportMode(true);
00770                 $md2xml->startExport();
00771                 $a_xml_writer->appendXML($md2xml->getXML());
00772         }
00773 
00774         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00775         {
00776                 if ($a_tag == "Identifier" && $a_param == "Entry")
00777                 {
00778                         include_once "./classes/class.ilUtil.php";
00779                         $a_value = ilUtil::insertInstIntoID($a_value);
00780                 }
00781 
00782                 return $a_value;
00783         }
00784 
00785 
00792         function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00793         {
00794                 global $ilBench;
00795 
00796                 include_once "./content/classes/class.ilLMPageObject.php";
00797 
00798                 foreach ($questions as $question_id)
00799                 {
00800                         $ilBench->start("ContentObjectExport", "exportPageObject");
00801                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00802 
00803                         $attrs = array();
00804                         $a_xml_writer->xmlStartTag("PageObject", $attrs);
00805 
00806                         
00807                         // export xml to writer object
00808                         $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00809                         $page_object = new ilPageObject("qpl", $question_id);
00810                         $page_object->buildDom();
00811                         $page_object->insertInstIntoIDs($a_inst);
00812                         $mob_ids = $page_object->collectMediaObjects(false);
00813                         $file_ids = $page_object->collectFileItems();
00814                         $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00815                         $xml = str_replace("&","&amp;", $xml);
00816                         $a_xml_writer->appendXML($xml);
00817                         $page_object->freeDom();
00818                         unset ($page_object);
00819                         
00820                         $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00821 
00822                         // collect media objects
00823                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00824                         //$mob_ids = $page_obj->getMediaObjectIDs();
00825                         foreach($mob_ids as $mob_id)
00826                         {
00827                                 $this->mob_ids[$mob_id] = $mob_id;
00828                         }
00829                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00830 
00831                         // collect all file items
00832                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00833                         //$file_ids = $page_obj->getFileItemIds();
00834                         foreach($file_ids as $file_id)
00835                         {
00836                                 $this->file_ids[$file_id] = $file_id;
00837                         }
00838                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00839                         
00840                         $a_xml_writer->xmlEndTag("PageObject");
00841                         //unset($page_obj);
00842 
00843                         $ilBench->stop("ContentObjectExport", "exportPageObject");
00844                         
00845 
00846                 }
00847         }
00848 
00855         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00856         {
00857                 include_once("content/classes/Media/class.ilObjMediaObject.php");
00858 
00859                 foreach ($this->mob_ids as $mob_id)
00860                 {
00861                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00862                         $media_obj = new ilObjMediaObject($mob_id);
00863                         $media_obj->exportXML($a_xml_writer, $a_inst);
00864                         $media_obj->exportFiles($a_target_dir);
00865                         unset($media_obj);
00866                 }
00867         }
00868 
00873         function exportFileItems($a_target_dir, &$expLog)
00874         {
00875                 include_once("classes/class.ilObjFile.php");
00876 
00877                 foreach ($this->file_ids as $file_id)
00878                 {
00879                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00880                         $file_obj = new ilObjFile($file_id, false);
00881                         $file_obj->export($a_target_dir);
00882                         unset($file_obj);
00883                 }
00884         }       
00885 
00891         function createExportDirectory()
00892         {
00893                 include_once "./classes/class.ilUtil.php";
00894                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00895                 ilUtil::makeDir($qpl_data_dir);
00896                 if(!is_writable($qpl_data_dir))
00897                 {
00898                         $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00899                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00900                 }
00901                 
00902                 // create learning module directory (data_dir/lm_data/lm_<id>)
00903                 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00904                 ilUtil::makeDir($qpl_dir);
00905                 if(!@is_dir($qpl_dir))
00906                 {
00907                         $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00908                 }
00909                 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00910                 $export_dir = $qpl_dir."/export";
00911                 ilUtil::makeDir($export_dir);
00912                 if(!@is_dir($export_dir))
00913                 {
00914                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00915                 }
00916         }
00917 
00921         function getExportDirectory()
00922         {
00923                 include_once "./classes/class.ilUtil.php";
00924                 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00925                 return $export_dir;
00926         }
00927         
00931         function getExportFiles($dir)
00932         {
00933                 // quit if import dir not available
00934                 if (!@is_dir($dir) or
00935                         !is_writeable($dir))
00936                 {
00937                         return array();
00938                 }
00939                 // open directory
00940                 $dir = dir($dir);
00941 
00942                 // initialize array
00943                 $file = array();
00944 
00945                 // get files and save the in the array
00946                 while ($entry = $dir->read())
00947                 {
00948                         if ($entry != "." and
00949                                 $entry != ".." and
00950                                 substr($entry, -4) == ".zip" and
00951                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl__)*[0-9]+\.zip\$", $entry))
00952                         {
00953                                 $file[] = $entry;
00954                         }
00955                 }
00956 
00957                 // close import directory
00958                 $dir->close();
00959 
00960                 // sort files
00961                 sort ($file);
00962                 reset ($file);
00963                 return $file;
00964         }
00965 
00971         function _createImportDirectory()
00972         {
00973                 global $ilias;
00974                 
00975                 include_once "./classes/class.ilUtil.php";
00976                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00977                 ilUtil::makeDir($qpl_data_dir);
00978                 
00979                 if(!is_writable($qpl_data_dir))
00980                 {
00981                         $ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00982                                 .") not writeable.",$ilias->error_obj->FATAL);
00983                 }
00984 
00985                 // create questionpool directory (data_dir/qpl_data/qpl_import)
00986                 $qpl_dir = $qpl_data_dir."/qpl_import";
00987                 ilUtil::makeDir($qpl_dir);
00988                 if(!@is_dir($qpl_dir))
00989                 {
00990                         $ilias->raiseError("Creation of Questionpool Directory failed.",$ilias->error_obj->FATAL);
00991                 }
00992         }
00993 
00997         function _getImportDirectory()
00998         {
00999                 include_once "./classes/class.ilUtil.php";
01000                 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
01001                 if(@is_dir($import_dir))
01002                 {
01003                         return $import_dir;
01004                 }
01005                 else
01006                 {
01007                         return false;
01008                 }
01009         }
01010 
01014         function getImportDirectory()
01015         {
01016                 include_once "./classes/class.ilUtil.php";
01017                 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
01018                 if(@is_dir($import_dir))
01019                 {
01020                         return $import_dir;
01021                 }
01022                 else
01023                 {
01024                         return false;
01025                 }
01026         }
01027         
01035         function &getAllQuestions()
01036         {
01037                 global $ilDB;
01038                 
01039                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
01040                         $ilDB->quote($this->getId())
01041                 );
01042 
01043                 $result = $ilDB->query($query);
01044                 $questions = array();
01045 
01046                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01047                 {
01048                         array_push($questions, $row["question_id"]);
01049                 }
01050                 return $questions;
01051         }
01052         
01053         function &getAllQuestionIds()
01054         {
01055                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s AND complete = %s",
01056                         $this->ilias->db->quote($this->getId()),
01057                         $this->ilias->db->quote("1")
01058                 );
01059                 $query_result = $this->ilias->db->query($query);
01060                 $questions = array();
01061                 if ($query_result->numRows())
01062                 {
01063                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01064                         {
01065                                 array_push($questions, $row["question_id"]);
01066                         }
01067                 }
01068                 return $questions;
01069         }
01070         
01075         function getImportMapping()
01076         {
01077                 if (!is_array($this->import_mapping))
01078                 {
01079                         return array();
01080                 }
01081                 else
01082                 {
01083                         return $this->import_mapping;
01084                 }
01085         }
01086         
01096         function to_xml($questions)
01097         {
01098                 $xml = "";
01099                 // export button was pressed
01100                 if (count($questions) > 0)
01101                 {
01102                         foreach ($questions as $key => $value)
01103                         {
01104                                 $question =& $this->createQuestion("", $value);
01105                                 $xml .= $question->object->to_xml();
01106                         }
01107                         if (count($questions) > 1)
01108                         {
01109                                 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01110                         }
01111                 }
01112                 return $xml;
01113         }
01114         
01125         function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01126         {
01127                 global $ilDB;
01128                 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01129                         $ilDB->quote($questionpool_id . "")
01130                 );
01131                 if ($complete_questions_only)
01132                 {
01133                         $query .= " AND complete = '1'";
01134                 }
01135                 $result = $ilDB->query($query);
01136                 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01137                 return $row["question_count"];
01138         }
01139         
01149         function setOnline($a_online_status)
01150         {
01151                 switch ($a_online_status)
01152                 {
01153                         case 0:
01154                         case 1:
01155                                 $this->online = $a_online_status;
01156                                 break;
01157                         default:
01158                                 $this->online = 0;
01159                                 break;
01160                 }
01161         }
01162         
01163         function getOnline()
01164         {
01165                 if (strcmp($this->online, "") == 0) $this->online = "0";
01166                 return $this->online;
01167         }
01168         
01177         function _lookupOnline($a_obj_id)
01178         {
01179                 global $ilDB;
01180                 
01181                 $query = sprintf("SELECT online FROM qpl_questionpool WHERE obj_fi = %s",
01182                         $ilDB->quote($a_obj_id . "")
01183                 );
01184                 $result = $ilDB->query($query);
01185                 if ($result->numRows() == 1)
01186                 {
01187                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01188                         return $row["online"];
01189                 }
01190                 return 0;
01191         }
01192         
01201         function _hasEqualPoints($a_obj_id)
01202         {
01203                 global $ilDB;
01204                 
01205                 $query = sprintf("SELECT count(DISTINCT points) AS equal_points FROM qpl_questions WHERE obj_fi = %s",
01206                         $ilDB->quote($a_obj_id . "")
01207                 );
01208                 $result = $ilDB->query($query);
01209                 if ($result->numRows() == 1)
01210                 {
01211                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01212                         if ($row["equal_points"] == 1)
01213                         {
01214                                 return 1;
01215                         }
01216                         else
01217                         {
01218                                 return 0;
01219                         }
01220                 }
01221                 return 0;
01222         }
01223         
01232         function pasteFromClipboard()
01233         {
01234                 global $ilDB;
01235 
01236                 if (array_key_exists("qpl_clipboard", $_SESSION))
01237                 {
01238                         foreach ($_SESSION["qpl_clipboard"] as $question_object)
01239                         {
01240                                 if (strcmp($question_object["action"], "move") == 0)
01241                                 {
01242                                         $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
01243                                                 $ilDB->quote($question_object["question_id"])
01244                                         );
01245                                         $result = $ilDB->query($query);
01246                                         if ($result->numRows() == 1)
01247                                         {
01248                                                 include_once "./content/classes/Pages/class.ilPageObject.php";
01249                                                 $page = new ilPageObject("qpl", $question_object["question_id"]);
01250                                                 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01251                                                 $source_questionpool = $row["obj_fi"];
01252                                                 // change the questionpool id in the qpl_questions table
01253                                                 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s WHERE question_id = %s",
01254                                                         $ilDB->quote($this->getId() . ""),
01255                                                         $ilDB->quote($question_object["question_id"])
01256                                                 );
01257                                                 $ilDB->query($query);
01258                                                 
01259                                                 // change page object of question and set the correct parent id
01260                                                 $query = sprintf("UPDATE page_object SET parent_id = %s WHERE page_id = %s",
01261                                                         $ilDB->quote($this->getId() . ""),
01262                                                         $ilDB->quote($question_object["question_id"])
01263                                                 );
01264                                                 $ilDB->query($query);
01265                                                 
01266                                                 // move question data to the new target directory
01267                                                 $source_path = CLIENT_WEB_DIR . "/assessment/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
01268                                                 if (@is_dir($source_path))
01269                                                 {
01270                                                         $target_path = CLIENT_WEB_DIR . "/assessment/" . $this->getId() . "/";
01271                                                         if (!@is_dir($target_path))
01272                                                         {
01273                                                                 include_once "./classes/class.ilUtil.php";
01274                                                                 ilUtil::makeDirParents($target_path);
01275                                                         }
01276                                                         @rename($source_path, $target_path . $question_object["question_id"]);
01277                                                 }
01278                                         }
01279                                 }
01280                                 else
01281                                 {
01282                                         $this->copyQuestion($question_object["question_id"], $this->getId());
01283                                 }
01284                         }
01285                 }
01286                 unset($_SESSION["qpl_clipboard"]);
01287         }
01288         
01297         function copyToClipboard($question_id)
01298         {
01299                 if (!array_key_exists("qpl_clipboard", $_SESSION))
01300                 {
01301                         $_SESSION["qpl_clipboard"] = array();
01302                 }
01303                 $_SESSION["qpl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
01304         }
01305         
01314         function moveToClipboard($question_id)
01315         {
01316                 if (!array_key_exists("qpl_clipboard", $_SESSION))
01317                 {
01318                         $_SESSION["qpl_clipboard"] = array();
01319                 }
01320                 $_SESSION["qpl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "move");
01321         }
01322         
01332         function _isWriteable($object_id, $user_id)
01333         {
01334                 global $rbacsystem;
01335                 global $ilDB;
01336                 
01337                 $result_array = array();
01338                 $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",
01339                         $ilDB->quote($object_id . "")
01340                 );
01341                 $result = $ilDB->query($query);
01342                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01343                 {               
01344                         include_once "./classes/class.ilObject.php";
01345                         if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
01346                         {
01347                                 return true;
01348                         }
01349                 }
01350                 return false;
01351         }
01352         
01362         function &getQuestionDetails($question_ids)
01363         {
01364                 global $ilDB;
01365                 
01366                 $result = array();
01367                 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01368                 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01369                 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id$whereclause ORDER BY qpl_questions.title";
01370                 $query_result = $ilDB->query($query);
01371                 if ($query_result->numRows())
01372                 {
01373                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01374                         {
01375                                 array_push($result, $row);
01376                         }
01377                 }
01378                 return $result;
01379         }
01380 
01392         function &getDeleteableQuestionDetails($question_ids)
01393         {
01394                 global $ilDB;
01395                 
01396                 $result = array();
01397                 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01398                 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01399                 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id$whereclause ORDER BY qpl_questions.title";
01400                 $query_result = $ilDB->query($query);
01401                 if ($query_result->numRows())
01402                 {
01403                         include_once "./assessment/classes/class.assQuestion.php";
01404                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01405                         {
01406                                 if (!ASS_Question::_isUsedInRandomTest($row["question_id"]))
01407                                 {
01408                                         array_push($result, $row);
01409                                 }
01410                         }
01411                 }
01412                 return $result;
01413         }
01414 
01426         function &getUsedQuestionDetails($question_ids)
01427         {
01428                 global $ilDB;
01429                 
01430                 $result = array();
01431                 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01432                 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01433                 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id$whereclause ORDER BY qpl_questions.title";
01434                 $query_result = $ilDB->query($query);
01435                 if ($query_result->numRows())
01436                 {
01437                         include_once "./assessment/classes/class.assQuestion.php";
01438                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01439                         {
01440                                 if (ASS_Question::_isUsedInRandomTest($row["question_id"]))
01441                                 {
01442                                         array_push($result, $row);
01443                                 }
01444                         }
01445                 }
01446                 return $result;
01447         }
01448 
01457         function &_getAvailableQuestionpools($use_object_id = false)
01458         {
01459                 global $rbacsystem;
01460                 global $ilDB;
01461                 
01462                 $result_array = array();
01463                 $query = "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.type = 'qpl' ORDER BY object_data.title";
01464                 $result = $ilDB->query($query);
01465                 include_once "./classes/class.ilObject.php";
01466                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01467                 {               
01468                         if ($rbacsystem->checkAccess("write", $row->ref_id) && (ilObject::_hasUntrashedReference($row->obj_id)))
01469                         {
01470                                 if ($use_object_id)
01471                                 {
01472                                         $result_array[$row->obj_id] = $row->title;
01473                                 }
01474                                 else
01475                                 {
01476                                         $result_array[$row->ref_id] = $row->title;
01477                                 }
01478                         }
01479                 }
01480                 return $result_array;
01481         }
01482 
01483         function &getQplQuestions()
01484         {
01485                 global $ilDB;
01486                 
01487                 $questions = array();
01488                 $query = sprintf("SELECT qpl_questions.question_id FROM qpl_questions WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.obj_fi = %s",
01489                         $ilDB->quote($this->getId() . "")
01490                 );
01491                 $result = $ilDB->query($query);
01492                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01493                 {
01494                         array_push($questions, $row["question_id"]);
01495                 }
01496                 return $questions;
01497         }
01505         function _clone($obj_id)
01506         {
01507                 $original = new ilObjQuestionPool($obj_id, false);
01508                 $original->loadFromDb();
01509                 
01510                 $newObj = new ilObjQuestionPool();
01511                 $newObj->setType("qpl");
01512                 $newObj->setTitle($original->getTitle() . " (".ilFormat::formatDate(ilFormat::unixtimestamp2datetime()).")");
01513                 $newObj->setDescription($original->getDescription());
01514                 $newObj->create(true);
01515                 $newObj->createReference();
01516                 $newObj->putInTree($_GET["ref_id"]);
01517                 $newObj->setPermissions($_GET["ref_id"]);
01518                 $newObj->setOnline($original->getOnline());
01519                 $newObj->saveToDb();
01520                 // clone the questions in the question pool
01521                 $questions =& $original->getQplQuestions();
01522                 foreach ($questions as $question_id)
01523                 {
01524                         $newObj->copyQuestion($question_id, $newObj->getId());
01525                 }
01526                 
01527                 // clone meta data
01528                 include_once "./Services/MetaData/classes/class.ilMD.php";
01529                 $md = new ilMD($original->getId(),0,$original->getType());
01530                 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
01531 
01532                 // update the metadata with the new title of the question pool
01533                 $newObj->updateMetaData();
01534 
01535                 return $newObj->getRefId();
01536         }
01537 } // END class.ilObjQuestionPool
01538 ?>

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