00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00025
00036 class ilObjQuestionPool extends ilObject
00037 {
00043 var $online;
00044
00051 function ilObjQuestionPool($a_id = 0,$a_call_by_reference = true)
00052 {
00053 $this->type = "qpl";
00054 $this->ilObject($a_id,$a_call_by_reference);
00055 $this->setOnline(0);
00056 }
00057
00061 function create($a_upload = false)
00062 {
00063 parent::create();
00064
00065
00066
00067 if (!$a_upload)
00068 {
00069 $this->createMetaData();
00070 }
00071 }
00072
00081 function createReference()
00082 {
00083 $result = parent::createReference();
00084 $this->saveToDb();
00085 return $result;
00086 }
00087
00094 function update()
00095 {
00096 $this->updateMetaData();
00097 if (!parent::update())
00098 {
00099 return false;
00100 }
00101
00102
00103
00104 return true;
00105 }
00106
00107 function updateMetaData()
00108 {
00109 global $ilUser;
00110 include_once "./Services/MetaData/classes/class.ilMD.php";
00111 $md =& new ilMD($this->getId(), 0, $this->getType());
00112 $md_gen =& $md->getGeneral();
00113 if ($md_gen == false)
00114 {
00115 include_once "./Services/MetaData/classes/class.ilMDCreator.php";
00116 $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
00117 $md_creator->setTitle($this->getTitle());
00118 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00119 $md_creator->create();
00120 }
00121 parent::updateMetaData();
00122 }
00123
00129 function read($a_force_db = false)
00130 {
00131 parent::read($a_force_db);
00132 $this->loadFromDb();
00133 }
00134
00135
00142 function delete()
00143 {
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 if (!parent::delete())
00162 {
00163 return false;
00164 }
00165
00166
00167 $this->deleteMetaData();
00168
00169
00170 $this->deleteQuestionpool();
00171
00172 return true;
00173 }
00174
00175 function deleteQuestionpool()
00176 {
00177 $questions =& $this->getAllQuestions();
00178
00179 if (count($questions))
00180 {
00181 foreach ($questions as $question_id)
00182 {
00183 $this->deleteQuestion($question_id);
00184 }
00185 }
00186
00187
00188 include_once "./Services/Utilities/classes/class.ilUtil.php";
00189 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00190 $directory = $qpl_data_dir."/qpl_".$this->getId();
00191 if (is_dir($directory))
00192 {
00193 include_once "./Services/Utilities/classes/class.ilUtil.php";
00194 ilUtil::delDir($directory);
00195 }
00196 }
00197
00207 function initDefaultRoles()
00208 {
00209 global $rbacadmin;
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 return $roles ? $roles : array();
00222 }
00223
00237 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00238 {
00239 global $tree;
00240
00241 switch ($a_event)
00242 {
00243 case "link":
00244
00245
00246
00247
00248 break;
00249
00250 case "cut":
00251
00252
00253
00254 break;
00255
00256 case "copy":
00257
00258
00259
00260
00261 break;
00262
00263 case "paste":
00264
00265
00266
00267 break;
00268
00269 case "new":
00270
00271
00272
00273 break;
00274 }
00275
00276
00277 if ($a_node_id==$_GET["ref_id"])
00278 {
00279 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00280 $parent_type = $parent_obj->getType();
00281 if($parent_type == $this->getType())
00282 {
00283 $a_node_id = (int) $tree->getParentId($a_node_id);
00284 }
00285 }
00286
00287 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00288 }
00289
00298 function deleteQuestion($question_id)
00299 {
00300 include_once "./Modules/Test/classes/class.ilObjTest.php";
00301 $question =& ilObjTest::_instanciateQuestion($question_id);
00302 $question->delete($question_id);
00303 }
00304
00312 function loadFromDb()
00313 {
00314 global $ilDB;
00315
00316 $query = sprintf("SELECT * FROM qpl_questionpool WHERE obj_fi = %s",
00317 $ilDB->quote($this->getId() . "")
00318 );
00319 $result = $ilDB->query($query);
00320 if ($result->numRows() == 1)
00321 {
00322 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00323 $this->setOnline($row["online"]);
00324 }
00325 }
00326
00334 function saveToDb()
00335 {
00336 global $ilDB;
00337
00338 $query = sprintf("SELECT * FROM qpl_questionpool WHERE obj_fi = %s",
00339 $ilDB->quote($this->getId() . "")
00340 );
00341 $result = $ilDB->query($query);
00342 if ($result->numRows() == 1)
00343 {
00344 $query = sprintf("UPDATE qpl_questionpool SET online = %s WHERE obj_fi = %s",
00345 $ilDB->quote($this->getOnline() . ""),
00346 $ilDB->quote($this->getId() . "")
00347 );
00348 $result = $ilDB->query($query);
00349 if ($result != DB_OK)
00350 {
00351 }
00352 }
00353 else
00354 {
00355 $query = sprintf("INSERT INTO qpl_questionpool (online, obj_fi) VALUES (%s, %s)",
00356 $ilDB->quote($this->getOnline() . ""),
00357 $ilDB->quote($this->getId() . "")
00358 );
00359 $result = $ilDB->query($query);
00360 if ($result != DB_OK)
00361 {
00362 }
00363 }
00364 }
00365
00375 function getQuestiontype($question_id)
00376 {
00377 global $ilDB;
00378
00379 if ($question_id < 1)
00380 {
00381 return;
00382 }
00383
00384 $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",
00385 $ilDB->quote($question_id));
00386
00387 $result = $ilDB->query($query);
00388 if ($result->numRows() == 1)
00389 {
00390 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00391 return $data->type_tag;
00392 }
00393 else
00394 {
00395 return;
00396 }
00397 }
00398
00404 function getDescription()
00405 {
00406 return parent::getDescription();
00407 }
00408
00412 function setDescription($a_description)
00413 {
00414 parent::setDescription($a_description);
00415 }
00416
00422 function getTitle()
00423 {
00424 return parent::getTitle();
00425 }
00426
00430 function setTitle($a_title)
00431 {
00432 parent::setTitle($a_title);
00433 }
00434
00444 function isInUse($question_id)
00445 {
00446 global $ilDB;
00447
00448 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00449 $ilDB->quote("$question_id"));
00450
00451 $result = $ilDB->query($query);
00452 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00453
00454 return $row->solution_count;
00455 }
00456
00457 function &createQuestion($question_type, $question_id = -1)
00458 {
00459 if ((!$question_type) and ($question_id > 0))
00460 {
00461 $question_type = $this->getQuestiontype($question_id);
00462 }
00463
00464 include_once "./Modules/TestQuestionPool/classes/class.".$question_type."GUI.php";
00465 $question_type_gui = $question_type . "GUI";
00466 $question =& new $question_type_gui();
00467
00468 if ($question_id > 0)
00469 {
00470 $question->object->loadFromDb($question_id);
00471 }
00472
00473 return $question;
00474 }
00475
00484 function duplicateQuestion($question_id)
00485 {
00486 $question =& $this->createQuestion("", $question_id);
00487 $newtitle = $question->object->getTitle();
00488 if ($question->object->questionTitleExists($this->getId(), $question->object->getTitle()))
00489 {
00490 $counter = 2;
00491 while ($question->object->questionTitleExists($this->getId(), $question->object->getTitle() . " ($counter)"))
00492 {
00493 $counter++;
00494 }
00495 $newtitle = $question->object->getTitle() . " ($counter)";
00496 }
00497 $question->object->duplicate(false, $newtitle);
00498
00499 ilObjQuestionPool::_updateQuestionCount($this->getId());
00500 }
00501
00511 function copyQuestion($question_id, $questionpool_to)
00512 {
00513 $question_gui =& $this->createQuestion("", $question_id);
00514 if ($question_gui->object->getObjId() == $questionpool_to)
00515 {
00516
00517 $this->duplicateQuestion($question_id);
00518 }
00519 else
00520 {
00521
00522 $newtitle = $question_gui->object->getTitle();
00523 if ($question_gui->object->questionTitleExists($this->getId(), $question_gui->object->getTitle()))
00524 {
00525 $counter = 2;
00526 while ($question_gui->object->questionTitleExists($this->getId(), $question_gui->object->getTitle() . " ($counter)"))
00527 {
00528 $counter++;
00529 }
00530 $newtitle = $question_gui->object->getTitle() . " ($counter)";
00531 }
00532 $question_gui->object->copyObject($this->getId(), $newtitle);
00533 }
00534 }
00535
00543 function getQuestionsTable($sort, $sortorder, $filter_text, $sel_filter_type, $startrow = 0)
00544 {
00545 global $ilUser;
00546 global $ilDB;
00547
00548 $where = "";
00549 if (strlen($filter_text) > 0)
00550 {
00551 switch($sel_filter_type)
00552 {
00553 case "title":
00554 $where = " AND qpl_questions.title LIKE " . $ilDB->quote("%" . $filter_text . "%");
00555 break;
00556 case "comment":
00557 $where = " AND qpl_questions.comment LIKE " . $ilDB->quote("%" . $filter_text . "%");
00558 break;
00559 case "author":
00560 $where = " AND qpl_questions.author LIKE " . $ilDB->quote("%" . $filter_text . "%");
00561 break;
00562 }
00563 }
00564
00565
00566 $order = "";
00567 $images = array();
00568 include_once "./Services/Utilities/classes/class.ilUtil.php";
00569 switch($sort)
00570 {
00571 case "title":
00572 $order = " ORDER BY title $sortorder";
00573 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00574 break;
00575 case "comment":
00576 $order = " ORDER BY comment $sortorder";
00577 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00578 break;
00579 case "type":
00580 $order = " ORDER BY question_type_id $sortorder";
00581 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00582 break;
00583 case "author":
00584 $order = " ORDER BY author $sortorder";
00585 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00586 break;
00587 case "created":
00588 $order = " ORDER BY created $sortorder";
00589 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00590 break;
00591 case "updated":
00592 $order = " ORDER BY TIMESTAMP14 $sortorder";
00593 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00594 break;
00595 }
00596 $maxentries = $ilUser->prefs["hits_per_page"];
00597 if ($maxentries < 1)
00598 {
00599 $maxentries = 9999;
00600 }
00601 $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";
00602 $query_result = $ilDB->query($query);
00603 $max = $query_result->numRows();
00604 if ($startrow > $max -1)
00605 {
00606 $startrow = $max - ($max % $maxentries);
00607 }
00608 else if ($startrow < 0)
00609 {
00610 $startrow = 0;
00611 }
00612 $limit = " LIMIT $startrow, $maxentries";
00613 $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";
00614 $query_result = $ilDB->query($query);
00615 $rows = array();
00616 if ($query_result->numRows())
00617 {
00618 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00619 {
00620 array_push($rows, $row);
00621 }
00622 }
00623 $nextrow = $startrow + $maxentries;
00624 if ($nextrow > $max - 1)
00625 {
00626 $nextrow = $startrow;
00627 }
00628 $prevrow = $startrow - $maxentries;
00629 if ($prevrow < 0)
00630 {
00631 $prevrow = 0;
00632 }
00633 return array(
00634 "rows" => $rows,
00635 "images" => $images,
00636 "startrow" => $startrow,
00637 "nextrow" => $nextrow,
00638 "prevrow" => $prevrow,
00639 "step" => $maxentries,
00640 "rowcount" => $max
00641 );
00642 }
00643
00651 function &getPrintviewQuestions($sort)
00652 {
00653 global $ilDB;
00654
00655
00656 $order = "";
00657 switch($sort)
00658 {
00659 case "title":
00660 $order = " ORDER BY title";
00661 break;
00662 case "comment":
00663 $order = " ORDER BY comment,title";
00664 break;
00665 case "type":
00666 $order = " ORDER BY question_type_id,title";
00667 break;
00668 case "author":
00669 $order = " ORDER BY author,title";
00670 break;
00671 case "created":
00672 $order = " ORDER BY created,title";
00673 break;
00674 case "updated":
00675 $order = " ORDER BY TIMESTAMP14,title";
00676 break;
00677 }
00678 $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() . " $order";
00679 $query_result = $ilDB->query($query);
00680 $rows = array();
00681 if ($query_result->numRows())
00682 {
00683 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00684 {
00685 array_push($rows, $row);
00686 }
00687 }
00688 return $rows;
00689 }
00690
00697 function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00698 {
00699 global $ilBench;
00700
00701 $this->mob_ids = array();
00702 $this->file_ids = array();
00703
00704 $attrs = array();
00705 $attrs["Type"] = "Questionpool_Test";
00706 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00707
00708
00709 $this->exportXMLMetaData($a_xml_writer);
00710
00711
00712 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00713 $ilBench->start("ContentObjectExport", "exportPageObjects");
00714 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00715 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00716 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00717
00718
00719 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00720 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00721 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00722 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00723 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00724
00725
00726 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00727 $ilBench->start("ContentObjectExport", "exportFileItems");
00728 $this->exportFileItems($a_target_dir, $expLog);
00729 $ilBench->stop("ContentObjectExport", "exportFileItems");
00730 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00731
00732 $a_xml_writer->xmlEndTag("ContentObject");
00733 }
00734
00741 function exportXMLMetaData(&$a_xml_writer)
00742 {
00743 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00744 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
00745 $md2xml->setExportMode(true);
00746 $md2xml->startExport();
00747 $a_xml_writer->appendXML($md2xml->getXML());
00748 }
00749
00750 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00751 {
00752 if ($a_tag == "Identifier" && $a_param == "Entry")
00753 {
00754 include_once "./Services/Utilities/classes/class.ilUtil.php";
00755 $a_value = ilUtil::insertInstIntoID($a_value);
00756 }
00757
00758 return $a_value;
00759 }
00760
00761
00768 function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00769 {
00770 global $ilBench;
00771
00772 include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
00773
00774 foreach ($questions as $question_id)
00775 {
00776 $ilBench->start("ContentObjectExport", "exportPageObject");
00777 $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00778
00779 $attrs = array();
00780 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00781
00782
00783
00784 $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00785 $page_object = new ilPageObject("qpl", $question_id);
00786 $page_object->buildDom();
00787 $page_object->insertInstIntoIDs($a_inst);
00788 $mob_ids = $page_object->collectMediaObjects(false);
00789 $file_ids = $page_object->collectFileItems();
00790 $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00791 $xml = str_replace("&","&", $xml);
00792 $a_xml_writer->appendXML($xml);
00793 $page_object->freeDom();
00794 unset ($page_object);
00795
00796 $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00797
00798
00799 $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00800
00801 foreach($mob_ids as $mob_id)
00802 {
00803 $this->mob_ids[$mob_id] = $mob_id;
00804 }
00805 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00806
00807
00808 $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00809
00810 foreach($file_ids as $file_id)
00811 {
00812 $this->file_ids[$file_id] = $file_id;
00813 }
00814 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00815
00816 $a_xml_writer->xmlEndTag("PageObject");
00817
00818
00819 $ilBench->stop("ContentObjectExport", "exportPageObject");
00820
00821
00822 }
00823 }
00824
00831 function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00832 {
00833 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00834
00835 foreach ($this->mob_ids as $mob_id)
00836 {
00837 $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00838 $media_obj = new ilObjMediaObject($mob_id);
00839 $media_obj->exportXML($a_xml_writer, $a_inst);
00840 $media_obj->exportFiles($a_target_dir);
00841 unset($media_obj);
00842 }
00843 }
00844
00849 function exportFileItems($a_target_dir, &$expLog)
00850 {
00851 include_once("./Modules/File/classes/class.ilObjFile.php");
00852
00853 foreach ($this->file_ids as $file_id)
00854 {
00855 $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00856 $file_obj = new ilObjFile($file_id, false);
00857 $file_obj->export($a_target_dir);
00858 unset($file_obj);
00859 }
00860 }
00861
00867 function createExportDirectory()
00868 {
00869 include_once "./Services/Utilities/classes/class.ilUtil.php";
00870 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00871 ilUtil::makeDir($qpl_data_dir);
00872 if(!is_writable($qpl_data_dir))
00873 {
00874 $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00875 .") not writeable.",$this->ilias->error_obj->FATAL);
00876 }
00877
00878
00879 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00880 ilUtil::makeDir($qpl_dir);
00881 if(!@is_dir($qpl_dir))
00882 {
00883 $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00884 }
00885
00886 $export_dir = $qpl_dir."/export";
00887 ilUtil::makeDir($export_dir);
00888 if(!@is_dir($export_dir))
00889 {
00890 $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00891 }
00892 }
00893
00897 function getExportDirectory()
00898 {
00899 include_once "./Services/Utilities/classes/class.ilUtil.php";
00900 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00901 return $export_dir;
00902 }
00903
00907 function getExportFiles($dir)
00908 {
00909
00910 if (!@is_dir($dir) or
00911 !is_writeable($dir))
00912 {
00913 return array();
00914 }
00915
00916 $dir = dir($dir);
00917
00918
00919 $file = array();
00920
00921
00922 while ($entry = $dir->read())
00923 {
00924 if ($entry != "." and
00925 $entry != ".." and
00926 (substr($entry, -4) == ".zip" or substr($entry, -4) == ".xls") and
00927 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl__)*[0-9]+\.(zip|xls)\$", $entry))
00928 {
00929 $file[] = $entry;
00930 }
00931 }
00932
00933
00934 $dir->close();
00935
00936
00937 sort ($file);
00938 reset ($file);
00939 return $file;
00940 }
00941
00947 function _createImportDirectory()
00948 {
00949 global $ilias;
00950
00951 include_once "./Services/Utilities/classes/class.ilUtil.php";
00952 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00953 ilUtil::makeDir($qpl_data_dir);
00954
00955 if(!is_writable($qpl_data_dir))
00956 {
00957 $ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00958 .") not writeable.",$ilias->error_obj->FATAL);
00959 }
00960
00961
00962 $qpl_dir = $qpl_data_dir."/qpl_import";
00963 ilUtil::makeDir($qpl_dir);
00964 if(!@is_dir($qpl_dir))
00965 {
00966 $ilias->raiseError("Creation of Questionpool Directory failed.",$ilias->error_obj->FATAL);
00967 }
00968 }
00969
00973 function _getImportDirectory()
00974 {
00975 include_once "./Services/Utilities/classes/class.ilUtil.php";
00976 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
00977 if(@is_dir($import_dir))
00978 {
00979 return $import_dir;
00980 }
00981 else
00982 {
00983 return false;
00984 }
00985 }
00986
00990 function getImportDirectory()
00991 {
00992 include_once "./Services/Utilities/classes/class.ilUtil.php";
00993 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
00994 if(@is_dir($import_dir))
00995 {
00996 return $import_dir;
00997 }
00998 else
00999 {
01000 return false;
01001 }
01002 }
01003
01011 function &getAllQuestions()
01012 {
01013 global $ilDB;
01014
01015 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
01016 $ilDB->quote($this->getId())
01017 );
01018
01019 $result = $ilDB->query($query);
01020 $questions = array();
01021
01022 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01023 {
01024 array_push($questions, $row["question_id"]);
01025 }
01026 return $questions;
01027 }
01028
01029 function &getAllQuestionIds()
01030 {
01031 global $ilDB;
01032
01033 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s AND complete = %s",
01034 $ilDB->quote($this->getId()),
01035 $ilDB->quote("1")
01036 );
01037 $query_result = $ilDB->query($query);
01038 $questions = array();
01039 if ($query_result->numRows())
01040 {
01041 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01042 {
01043 array_push($questions, $row["question_id"]);
01044 }
01045 }
01046 return $questions;
01047 }
01048
01053 function getImportMapping()
01054 {
01055 if (!is_array($this->import_mapping))
01056 {
01057 return array();
01058 }
01059 else
01060 {
01061 return $this->import_mapping;
01062 }
01063 }
01064
01074 function toXML($questions)
01075 {
01076 $xml = "";
01077
01078 if (count($questions) > 0)
01079 {
01080 foreach ($questions as $key => $value)
01081 {
01082 $question =& $this->createQuestion("", $value);
01083 $xml .= $question->object->toXML();
01084 }
01085 if (count($questions) > 1)
01086 {
01087 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01088 }
01089 }
01090 $xml = preg_replace("/(<\?xml[^>]*?>)/", "\\1" . "<!DOCTYPE questestinterop SYSTEM \"ims_qtiasiv1p2p1.dtd\">", $xml);
01091 return $xml;
01092 }
01093
01104 function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01105 {
01106 global $ilDB;
01107 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01108 $ilDB->quote($questionpool_id . "")
01109 );
01110 if ($complete_questions_only)
01111 {
01112 $query .= " AND complete = '1'";
01113 }
01114 $result = $ilDB->query($query);
01115 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01116 return $row["question_count"];
01117 }
01118
01128 function setOnline($a_online_status)
01129 {
01130 switch ($a_online_status)
01131 {
01132 case 0:
01133 case 1:
01134 $this->online = $a_online_status;
01135 break;
01136 default:
01137 $this->online = 0;
01138 break;
01139 }
01140 }
01141
01142 function getOnline()
01143 {
01144 if (strcmp($this->online, "") == 0) $this->online = "0";
01145 return $this->online;
01146 }
01147
01148 function _lookupOnline($a_obj_id, $is_reference = FALSE)
01149 {
01150 global $ilDB;
01151
01152 if ($is_reference)
01153 {
01154 $query = sprintf("SELECT qpl_questionpool.online FROM qpl_questionpool,object_reference WHERE object_reference.ref_id = %s AND object_reference.obj_id = qpl_questionpool.obj_fi",
01155 $ilDB->quote($a_obj_id . "")
01156 );
01157 }
01158 else
01159 {
01160 $query = sprintf("SELECT online FROM qpl_questionpool WHERE obj_fi = %s",
01161 $ilDB->quote($a_obj_id . "")
01162 );
01163 }
01164 $result = $ilDB->query($query);
01165 if ($result->numRows() == 1)
01166 {
01167 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01168 return $row["online"];
01169 }
01170 return 0;
01171 }
01172
01181 function _hasEqualPoints($a_obj_id, $is_reference = FALSE)
01182 {
01183 global $ilDB;
01184
01185 if ($is_reference)
01186 {
01187 $query = sprintf("SELECT count(DISTINCT qpl_questions.points) AS equal_points FROM qpl_questions, object_reference WHERE object_reference.ref_id = %s AND object_reference.obj_id = qpl_questions.obj_fi AND qpl_questions.original_id IS NULL",
01188 $ilDB->quote($a_obj_id . "")
01189 );
01190 }
01191 else
01192 {
01193 $query = sprintf("SELECT count(DISTINCT points) AS equal_points FROM qpl_questions WHERE obj_fi = %s AND qpl_questions.original_id IS NULL",
01194 $ilDB->quote($a_obj_id . "")
01195 );
01196 }
01197 $result = $ilDB->query($query);
01198 if ($result->numRows() == 1)
01199 {
01200 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01201 if ($row["equal_points"] == 1)
01202 {
01203 return 1;
01204 }
01205 else
01206 {
01207 return 0;
01208 }
01209 }
01210 return 0;
01211 }
01212
01220 function pasteFromClipboard()
01221 {
01222 global $ilDB;
01223
01224 if (array_key_exists("qpl_clipboard", $_SESSION))
01225 {
01226 foreach ($_SESSION["qpl_clipboard"] as $question_object)
01227 {
01228 if (strcmp($question_object["action"], "move") == 0)
01229 {
01230 $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
01231 $ilDB->quote($question_object["question_id"])
01232 );
01233 $result = $ilDB->query($query);
01234 if ($result->numRows() == 1)
01235 {
01236 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01237 $source_questionpool = $row["obj_fi"];
01238
01239 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s WHERE question_id = %s",
01240 $ilDB->quote($this->getId() . ""),
01241 $ilDB->quote($question_object["question_id"])
01242 );
01243 $ilDB->query($query);
01244
01245
01246 $source_path = CLIENT_WEB_DIR . "/assessment/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
01247 if (@is_dir($source_path))
01248 {
01249 $target_path = CLIENT_WEB_DIR . "/assessment/" . $this->getId() . "/";
01250 if (!@is_dir($target_path))
01251 {
01252 include_once "./Services/Utilities/classes/class.ilUtil.php";
01253 ilUtil::makeDirParents($target_path);
01254 }
01255 @rename($source_path, $target_path . $question_object["question_id"]);
01256 }
01257
01258 ilObjQuestionPool::_updateQuestionCount($source_questionpool);
01259 }
01260 }
01261 else
01262 {
01263 $this->copyQuestion($question_object["question_id"], $this->getId());
01264 }
01265 }
01266 }
01267
01268 ilObjQuestionPool::_updateQuestionCount($this->getId());
01269 unset($_SESSION["qpl_clipboard"]);
01270 }
01271
01280 function copyToClipboard($question_id)
01281 {
01282 if (!array_key_exists("qpl_clipboard", $_SESSION))
01283 {
01284 $_SESSION["qpl_clipboard"] = array();
01285 }
01286 $_SESSION["qpl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
01287 }
01288
01297 function moveToClipboard($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" => "move");
01304 }
01305
01315 function _isWriteable($object_id, $user_id)
01316 {
01317 global $rbacsystem;
01318 global $ilDB;
01319
01320 $result_array = array();
01321 $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",
01322 $ilDB->quote($object_id . "")
01323 );
01324 $result = $ilDB->query($query);
01325 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01326 {
01327 include_once "./classes/class.ilObject.php";
01328 if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
01329 {
01330 return true;
01331 }
01332 }
01333 return false;
01334 }
01335
01345 function &getQuestionDetails($question_ids)
01346 {
01347 global $ilDB;
01348
01349 $result = array();
01350 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01351 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01352 $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";
01353 $query_result = $ilDB->query($query);
01354 if ($query_result->numRows())
01355 {
01356 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01357 {
01358 array_push($result, $row);
01359 }
01360 }
01361 return $result;
01362 }
01363
01375 function &getDeleteableQuestionDetails($question_ids)
01376 {
01377 global $ilDB;
01378
01379 $result = array();
01380 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01381 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01382 $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";
01383 $query_result = $ilDB->query($query);
01384 if ($query_result->numRows())
01385 {
01386 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
01387 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01388 {
01389 if (!assQuestion::_isUsedInRandomTest($row["question_id"]))
01390 {
01391 array_push($result, $row);
01392 }
01393 else
01394 {
01395
01396
01397
01398
01399
01400
01401 $question =& $this->createQuestion("", $row["question_id"]);
01402 $duplicate_id = $question->object->duplicate(true);
01403 if ($duplicate_id > 0)
01404 {
01405
01406 $query = sprintf("UPDATE tst_solutions SET question_fi = %s WHERE question_fi = %s",
01407 $ilDB->quote($duplicate_id),
01408 $ilDB->quote($row["question_id"])
01409 );
01410 $ilDB->query($query);
01411
01412
01413 $query = sprintf("UPDATE tst_test_random_question SET question_fi = %s WHERE question_fi = %s",
01414 $ilDB->quote($duplicate_id),
01415 $ilDB->quote($row["question_id"])
01416 );
01417 $ilDB->query($query);
01418
01419
01420 $query = sprintf("UPDATE tst_test_result SET question_fi = %s WHERE question_fi = %s",
01421 $ilDB->quote($duplicate_id),
01422 $ilDB->quote($row["question_id"])
01423 );
01424 $ilDB->query($query);
01425
01426
01427 $query = sprintf("UPDATE ass_log SET question_fi = %s WHERE question_fi = %s",
01428 $ilDB->quote($duplicate_id),
01429 $ilDB->quote($row["question_id"])
01430 );
01431 $ilDB->query($query);
01432
01433
01434 array_push($result, $row);
01435 }
01436 }
01437 }
01438 }
01439 return $result;
01440 }
01441
01453 function &getUsedQuestionDetails($question_ids)
01454 {
01455 global $ilDB;
01456
01457 $result = array();
01458 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01459 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01460 $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";
01461 $query_result = $ilDB->query($query);
01462 if ($query_result->numRows())
01463 {
01464 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
01465 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01466 {
01467 if (assQuestion::_isUsedInRandomTest($row["question_id"]))
01468 {
01469 array_push($result, $row);
01470 }
01471 }
01472 }
01473 return $result;
01474 }
01475
01476
01485 function _getFullPathToQpl($ref_id)
01486 {
01487 global $tree;
01488 $path = $tree->getPathFull($ref_id);
01489 $items = array();
01490 $counter = 0;
01491 foreach ($path as $item)
01492 {
01493 if (($counter > 0) && ($counter < count($path)-1))
01494 {
01495 array_push($items, $item["title"]);
01496 }
01497 $counter++;
01498 }
01499 $fullpath = join(" > ", $items);
01500 include_once "./Services/Utilities/classes/class.ilStr.php";
01501 if (strlen($fullpath) > 60)
01502 {
01503 $fullpath = ilStr::subStr($fullpath, 0, 30) . "..." . ilStr::subStr($fullpath, ilStr::strLen($fullpath)-30, 30);
01504 }
01505 return $fullpath;
01506 }
01507
01516 function &_getAvailableQuestionpools($use_object_id = FALSE, $equal_points = FALSE, $could_be_offline = FALSE, $showPath = FALSE, $with_questioncount = FALSE, $permission = "read")
01517 {
01518 global $ilUser;
01519 global $ilDB;
01520
01521 $result_array = array();
01522 $permission = (strlen($permission) == 0) ? "read" : $permission;
01523 $qpls = ilUtil::_getObjectsByOperations("qpl", $permission, $ilUser->getId(), -1);
01524 $titles = ilObject::_prepareCloneSelection($qpls, "qpl");
01525 if (count($qpls))
01526 {
01527 $query = "";
01528 if ($could_be_offline)
01529 {
01530 $query = sprintf("SELECT object_data.*, object_reference.ref_id, qpl_questionpool.questioncount FROM object_data, object_reference, qpl_questionpool WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') AND qpl_questionpool.obj_fi = object_data.obj_id ORDER BY object_data.title",
01531 implode("','", $qpls)
01532 );
01533 }
01534 else
01535 {
01536 $query = sprintf("SELECT object_data.*, object_reference.ref_id, qpl_questionpool.questioncount FROM object_data, object_reference, qpl_questionpool WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') AND qpl_questionpool.online = '1' AND qpl_questionpool.obj_fi = object_data.obj_id ORDER BY object_data.title",
01537 implode("','", $qpls)
01538 );
01539 }
01540 $result = $ilDB->query($query);
01541 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01542 {
01543 $add = TRUE;
01544 if ($equal_points)
01545 {
01546 if (!ilObjQuestionPool::_hasEqualPoints($row["obj_id"]))
01547 {
01548 $add = FALSE;
01549 }
01550 }
01551 if ($add)
01552 {
01553 $title = (($showPath) ? $titles[$row["ref_id"]] : $row["title"]);
01554 if ($with_questioncount)
01555 {
01556 $title .= " [" . $row["questioncount"] . " " . ($row["questioncount"] == 1 ? $this->lng->txt("ass_question") : $this->lng->txt("assQuestions")) . "]";
01557 }
01558
01559 if ($use_object_id)
01560 {
01561 $result_array[$row["obj_id"]] = array("title" => $title, "count" => $row["questioncount"]);
01562 }
01563 else
01564 {
01565 $result_array[$row["ref_id"]] = array("title" => $title, "count" => $row["questioncount"]);
01566 }
01567 }
01568 }
01569 }
01570 return $result_array;
01571 }
01572
01573 function &getQplQuestions()
01574 {
01575 global $ilDB;
01576
01577 $questions = array();
01578 $query = sprintf("SELECT qpl_questions.question_id FROM qpl_questions WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.obj_fi = %s",
01579 $ilDB->quote($this->getId() . "")
01580 );
01581 $result = $ilDB->query($query);
01582 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01583 {
01584 array_push($questions, $row["question_id"]);
01585 }
01586 return $questions;
01587 }
01595 function cloneObject($a_target_id,$a_copy_id = 0)
01596 {
01597 global $ilLog;
01598 $newObj = parent::cloneObject($a_target_id,$a_copy_id);
01599 $newObj->setOnline($this->getOnline());
01600 $newObj->saveToDb();
01601
01602 $questions =& $this->getQplQuestions();
01603 foreach ($questions as $question_id)
01604 {
01605 $newObj->copyQuestion($question_id, $newObj->getId());
01606 }
01607
01608
01609 include_once "./Services/MetaData/classes/class.ilMD.php";
01610 $md = new ilMD($this->getId(),0,$this->getType());
01611 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
01612
01613
01614 $newObj->updateMetaData();
01615 return $newObj;
01616 }
01617
01618 function &getQuestionTypes($all_tags = FALSE)
01619 {
01620 return $this->_getQuestionTypes($all_tags);
01621 }
01622
01623 function &_getQuestionTypes($all_tags = FALSE)
01624 {
01625 global $ilDB;
01626 global $lng;
01627
01628 include_once "./classes/class.ilObjAssessmentFolder.php";
01629 $forbidden_types = ilObjAssessmentFolder::_getForbiddenQuestionTypes();
01630 $lng->loadLanguageModule("assessment");
01631 $query = "SELECT * FROM qpl_question_type";
01632 $result = $ilDB->query($query);
01633 $types = array();
01634 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01635 {
01636 if ($all_tags || (!in_array($row["question_type_id"], $forbidden_types)))
01637 {
01638 if (!DEVMODE)
01639 {
01640 if (strcmp($row["type_tag"], "assFlashApp") != 0)
01641 {
01642 $types[$lng->txt($row["type_tag"])] = $row;
01643 }
01644 }
01645 else
01646 {
01647 $types[$lng->txt($row["type_tag"])] = $row;
01648 }
01649 }
01650 }
01651 ksort($types);
01652 return $types;
01653 }
01654
01655 function &getQuestionList()
01656 {
01657 global $ilDB;
01658
01659 $questions = array();
01660 $query = sprintf("SELECT qpl_questions.*, qpl_questions.TIMESTAMP+0 AS TIMESTAMP14, qpl_question_type.* FROM qpl_questions, qpl_question_type WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.obj_fi = %s AND qpl_questions.question_type_fi = qpl_question_type.question_type_id",
01661 $ilDB->quote($this->getId() . "")
01662 );
01663 $result = $ilDB->query($query);
01664 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01665 {
01666 array_push($questions, $row);
01667 }
01668 return $questions;
01669 }
01670
01679 public static function _updateQuestionCount($object_id)
01680 {
01681 global $ilDB;
01682 $query = sprintf("UPDATE qpl_questionpool SET questioncount = %s WHERE obj_fi = %s",
01683 $ilDB->quote(ilObjQuestionPool::_getQuestionCount($object_id, TRUE)),
01684 $ilDB->quote($object_id)
01685 );
01686 $result = $ilDB->query($query);
01687 }
01688
01689 }
01690 ?>