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 "./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
00067
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
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
00148 $new_ref_id = parent::ilClone($a_parent_ref);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 return $new_ref_id;
00164 }
00165
00172 function delete()
00173 {
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 if (!parent::delete())
00192 {
00193 return false;
00194 }
00195
00196
00197 $this->deleteMetaData();
00198
00199
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
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
00242
00243
00244
00245
00246
00247
00248
00249
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
00276
00277
00278 break;
00279
00280 case "cut":
00281
00282
00283
00284 break;
00285
00286 case "copy":
00287
00288
00289
00290
00291 break;
00292
00293 case "paste":
00294
00295
00296
00297 break;
00298
00299 case "new":
00300
00301
00302
00303 break;
00304 }
00305
00306
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.ilObjTest.php";
00331 $question =& ilObjTest::_instanciateQuestion($question_id);
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 global $ilDB;
00408
00409 if ($question_id < 1)
00410 {
00411 return;
00412 }
00413
00414 $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",
00415 $ilDB->quote($question_id));
00416
00417 $result = $ilDB->query($query);
00418 if ($result->numRows() == 1)
00419 {
00420 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00421 return $data->type_tag;
00422 }
00423 else
00424 {
00425 return;
00426 }
00427 }
00428
00434 function getDescription()
00435 {
00436 return parent::getDescription();
00437 }
00438
00442 function setDescription($a_description)
00443 {
00444 parent::setDescription($a_description);
00445 }
00446
00452 function getTitle()
00453 {
00454 return parent::getTitle();
00455 }
00456
00460 function setTitle($a_title)
00461 {
00462 parent::setTitle($a_title);
00463 }
00464
00474 function isInUse($question_id)
00475 {
00476 global $ilDB;
00477
00478 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00479 $ilDB->quote("$question_id"));
00480
00481 $result = $ilDB->query($query);
00482 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00483
00484 return $row->solution_count;
00485 }
00486
00487 function &createQuestion($question_type, $question_id = -1)
00488 {
00489 if ((!$question_type) and ($question_id > 0))
00490 {
00491 $question_type = $this->getQuestiontype($question_id);
00492 }
00493
00494 include_once "./assessment/classes/class.".$question_type."GUI.php";
00495 $question_type_gui = $question_type . "GUI";
00496 $question =& new $question_type_gui();
00497
00498 if ($question_id > 0)
00499 {
00500 $question->object->loadFromDb($question_id);
00501 }
00502
00503 return $question;
00504 }
00505
00514 function duplicateQuestion($question_id)
00515 {
00516 $question =& $this->createQuestion("", $question_id);
00517 $newtitle = $question->object->getTitle();
00518 if ($question->object->questionTitleExists($this->getId(), $question->object->getTitle()))
00519 {
00520 $counter = 2;
00521 while ($question->object->questionTitleExists($this->getId(), $question->object->getTitle() . " ($counter)"))
00522 {
00523 $counter++;
00524 }
00525 $newtitle = $question->object->getTitle() . " ($counter)";
00526 }
00527 $question->object->duplicate(false, $newtitle);
00528
00529 ilObjQuestionPool::_updateQuestionCount($this->getId());
00530 }
00531
00541 function copyQuestion($question_id, $questionpool_to)
00542 {
00543 $question_gui =& $this->createQuestion("", $question_id);
00544 if ($question_gui->object->getObjId() == $questionpool_to)
00545 {
00546
00547 $this->duplicateQuestion($question_id);
00548 }
00549 else
00550 {
00551
00552 $newtitle = $question_gui->object->getTitle();
00553 if ($question_gui->object->questionTitleExists($this->getId(), $question_gui->object->getTitle()))
00554 {
00555 $counter = 2;
00556 while ($question_gui->object->questionTitleExists($this->getId(), $question_gui->object->getTitle() . " ($counter)"))
00557 {
00558 $counter++;
00559 }
00560 $newtitle = $question_gui->object->getTitle() . " ($counter)";
00561 }
00562 $question_gui->object->copyObject($this->getId(), $newtitle);
00563 }
00564 }
00565
00573 function getQuestionsTable($sort, $sortorder, $filter_text, $sel_filter_type, $startrow = 0)
00574 {
00575 global $ilUser;
00576 global $ilDB;
00577
00578 $where = "";
00579 if (strlen($filter_text) > 0)
00580 {
00581 switch($sel_filter_type)
00582 {
00583 case "title":
00584 $where = " AND qpl_questions.title LIKE " . $ilDB->quote("%" . $filter_text . "%");
00585 break;
00586
00587 case "comment":
00588 $where = " AND qpl_questions.comment LIKE " . $ilDB->quote("%" . $filter_text . "%");
00589 break;
00590
00591 case "author":
00592 $where = " AND qpl_questions.author LIKE " . $ilDB->quote("%" . $filter_text . "%");
00593 break;
00594 }
00595 }
00596
00597
00598 $order = "";
00599 $images = array();
00600 include_once "./classes/class.ilUtil.php";
00601 switch($sort)
00602 {
00603 case "title":
00604 $order = " ORDER BY title $sortorder";
00605 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00606 break;
00607 case "comment":
00608 $order = " ORDER BY comment $sortorder";
00609 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00610 break;
00611 case "type":
00612 $order = " ORDER BY question_type_id $sortorder";
00613 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00614 break;
00615 case "author":
00616 $order = " ORDER BY author $sortorder";
00617 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00618 break;
00619 case "created":
00620 $order = " ORDER BY created $sortorder";
00621 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00622 break;
00623 case "updated":
00624 $order = " ORDER BY TIMESTAMP14 $sortorder";
00625 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . $this->lng->txt(strtolower($sortorder) . "ending_order")."\" />";
00626 break;
00627 }
00628 $maxentries = $ilUser->prefs["hits_per_page"];
00629 if ($maxentries < 1)
00630 {
00631 $maxentries = 9999;
00632 }
00633 $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";
00634 $query_result = $ilDB->query($query);
00635 $max = $query_result->numRows();
00636 if ($startrow > $max -1)
00637 {
00638 $startrow = $max - ($max % $maxentries);
00639 }
00640 else if ($startrow < 0)
00641 {
00642 $startrow = 0;
00643 }
00644 $limit = " LIMIT $startrow, $maxentries";
00645 $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";
00646 $query_result = $ilDB->query($query);
00647 $rows = array();
00648 if ($query_result->numRows())
00649 {
00650 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00651 {
00652 array_push($rows, $row);
00653 }
00654 }
00655 $nextrow = $startrow + $maxentries;
00656 if ($nextrow > $max - 1)
00657 {
00658 $nextrow = $startrow;
00659 }
00660 $prevrow = $startrow - $maxentries;
00661 if ($prevrow < 0)
00662 {
00663 $prevrow = 0;
00664 }
00665 return array(
00666 "rows" => $rows,
00667 "images" => $images,
00668 "startrow" => $startrow,
00669 "nextrow" => $nextrow,
00670 "prevrow" => $prevrow,
00671 "step" => $maxentries,
00672 "rowcount" => $max
00673 );
00674 }
00675
00683 function &getPrintviewQuestions($sort)
00684 {
00685 global $ilDB;
00686
00687
00688 $order = "";
00689 switch($sort)
00690 {
00691 case "title":
00692 $order = " ORDER BY title";
00693 break;
00694 case "comment":
00695 $order = " ORDER BY comment,title";
00696 break;
00697 case "type":
00698 $order = " ORDER BY question_type_id,title";
00699 break;
00700 case "author":
00701 $order = " ORDER BY author,title";
00702 break;
00703 case "created":
00704 $order = " ORDER BY created,title";
00705 break;
00706 case "updated":
00707 $order = " ORDER BY TIMESTAMP14,title";
00708 break;
00709 }
00710 $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";
00711 $query_result = $ilDB->query($query);
00712 $rows = array();
00713 if ($query_result->numRows())
00714 {
00715 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00716 {
00717 array_push($rows, $row);
00718 }
00719 }
00720 return $rows;
00721 }
00722
00729 function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00730 {
00731 global $ilBench;
00732
00733 $this->mob_ids = array();
00734 $this->file_ids = array();
00735
00736 $attrs = array();
00737 $attrs["Type"] = "Questionpool_Test";
00738 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00739
00740
00741 $this->exportXMLMetaData($a_xml_writer);
00742
00743
00744 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00745 $ilBench->start("ContentObjectExport", "exportPageObjects");
00746 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00747 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00748 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00749
00750
00751 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00752 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00753 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00754 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00755 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00756
00757
00758 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00759 $ilBench->start("ContentObjectExport", "exportFileItems");
00760 $this->exportFileItems($a_target_dir, $expLog);
00761 $ilBench->stop("ContentObjectExport", "exportFileItems");
00762 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00763
00764 $a_xml_writer->xmlEndTag("ContentObject");
00765 }
00766
00773 function exportXMLMetaData(&$a_xml_writer)
00774 {
00775 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00776 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
00777 $md2xml->setExportMode(true);
00778 $md2xml->startExport();
00779 $a_xml_writer->appendXML($md2xml->getXML());
00780 }
00781
00782 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00783 {
00784 if ($a_tag == "Identifier" && $a_param == "Entry")
00785 {
00786 include_once "./classes/class.ilUtil.php";
00787 $a_value = ilUtil::insertInstIntoID($a_value);
00788 }
00789
00790 return $a_value;
00791 }
00792
00793
00800 function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00801 {
00802 global $ilBench;
00803
00804 include_once "./content/classes/class.ilLMPageObject.php";
00805
00806 foreach ($questions as $question_id)
00807 {
00808 $ilBench->start("ContentObjectExport", "exportPageObject");
00809 $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00810
00811 $attrs = array();
00812 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00813
00814
00815
00816 $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00817 $page_object = new ilPageObject("qpl", $question_id);
00818 $page_object->buildDom();
00819 $page_object->insertInstIntoIDs($a_inst);
00820 $mob_ids = $page_object->collectMediaObjects(false);
00821 $file_ids = $page_object->collectFileItems();
00822 $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00823 $xml = str_replace("&","&", $xml);
00824 $a_xml_writer->appendXML($xml);
00825 $page_object->freeDom();
00826 unset ($page_object);
00827
00828 $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00829
00830
00831 $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00832
00833 foreach($mob_ids as $mob_id)
00834 {
00835 $this->mob_ids[$mob_id] = $mob_id;
00836 }
00837 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00838
00839
00840 $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00841
00842 foreach($file_ids as $file_id)
00843 {
00844 $this->file_ids[$file_id] = $file_id;
00845 }
00846 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00847
00848 $a_xml_writer->xmlEndTag("PageObject");
00849
00850
00851 $ilBench->stop("ContentObjectExport", "exportPageObject");
00852
00853
00854 }
00855 }
00856
00863 function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00864 {
00865 include_once("content/classes/Media/class.ilObjMediaObject.php");
00866
00867 foreach ($this->mob_ids as $mob_id)
00868 {
00869 $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00870 $media_obj = new ilObjMediaObject($mob_id);
00871 $media_obj->exportXML($a_xml_writer, $a_inst);
00872 $media_obj->exportFiles($a_target_dir);
00873 unset($media_obj);
00874 }
00875 }
00876
00881 function exportFileItems($a_target_dir, &$expLog)
00882 {
00883 include_once("classes/class.ilObjFile.php");
00884
00885 foreach ($this->file_ids as $file_id)
00886 {
00887 $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00888 $file_obj = new ilObjFile($file_id, false);
00889 $file_obj->export($a_target_dir);
00890 unset($file_obj);
00891 }
00892 }
00893
00899 function createExportDirectory()
00900 {
00901 include_once "./classes/class.ilUtil.php";
00902 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00903 ilUtil::makeDir($qpl_data_dir);
00904 if(!is_writable($qpl_data_dir))
00905 {
00906 $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00907 .") not writeable.",$this->ilias->error_obj->FATAL);
00908 }
00909
00910
00911 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00912 ilUtil::makeDir($qpl_dir);
00913 if(!@is_dir($qpl_dir))
00914 {
00915 $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00916 }
00917
00918 $export_dir = $qpl_dir."/export";
00919 ilUtil::makeDir($export_dir);
00920 if(!@is_dir($export_dir))
00921 {
00922 $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00923 }
00924 }
00925
00929 function getExportDirectory()
00930 {
00931 include_once "./classes/class.ilUtil.php";
00932 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00933 return $export_dir;
00934 }
00935
00939 function getExportFiles($dir)
00940 {
00941
00942 if (!@is_dir($dir) or
00943 !is_writeable($dir))
00944 {
00945 return array();
00946 }
00947
00948 $dir = dir($dir);
00949
00950
00951 $file = array();
00952
00953
00954 while ($entry = $dir->read())
00955 {
00956 if ($entry != "." and
00957 $entry != ".." and
00958 (substr($entry, -4) == ".zip" or substr($entry, -4) == ".xls") and
00959 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl__)*[0-9]+\.(zip|xls)\$", $entry))
00960 {
00961 $file[] = $entry;
00962 }
00963 }
00964
00965
00966 $dir->close();
00967
00968
00969 sort ($file);
00970 reset ($file);
00971 return $file;
00972 }
00973
00979 function _createImportDirectory()
00980 {
00981 global $ilias;
00982
00983 include_once "./classes/class.ilUtil.php";
00984 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00985 ilUtil::makeDir($qpl_data_dir);
00986
00987 if(!is_writable($qpl_data_dir))
00988 {
00989 $ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00990 .") not writeable.",$ilias->error_obj->FATAL);
00991 }
00992
00993
00994 $qpl_dir = $qpl_data_dir."/qpl_import";
00995 ilUtil::makeDir($qpl_dir);
00996 if(!@is_dir($qpl_dir))
00997 {
00998 $ilias->raiseError("Creation of Questionpool Directory failed.",$ilias->error_obj->FATAL);
00999 }
01000 }
01001
01005 function _getImportDirectory()
01006 {
01007 include_once "./classes/class.ilUtil.php";
01008 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
01009 if(@is_dir($import_dir))
01010 {
01011 return $import_dir;
01012 }
01013 else
01014 {
01015 return false;
01016 }
01017 }
01018
01022 function getImportDirectory()
01023 {
01024 include_once "./classes/class.ilUtil.php";
01025 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
01026 if(@is_dir($import_dir))
01027 {
01028 return $import_dir;
01029 }
01030 else
01031 {
01032 return false;
01033 }
01034 }
01035
01043 function &getAllQuestions()
01044 {
01045 global $ilDB;
01046
01047 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
01048 $ilDB->quote($this->getId())
01049 );
01050
01051 $result = $ilDB->query($query);
01052 $questions = array();
01053
01054 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01055 {
01056 array_push($questions, $row["question_id"]);
01057 }
01058 return $questions;
01059 }
01060
01061 function &getAllQuestionIds()
01062 {
01063 global $ilDB;
01064
01065 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s AND complete = %s",
01066 $ilDB->quote($this->getId()),
01067 $ilDB->quote("1")
01068 );
01069 $query_result = $ilDB->query($query);
01070 $questions = array();
01071 if ($query_result->numRows())
01072 {
01073 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01074 {
01075 array_push($questions, $row["question_id"]);
01076 }
01077 }
01078 return $questions;
01079 }
01080
01085 function getImportMapping()
01086 {
01087 if (!is_array($this->import_mapping))
01088 {
01089 return array();
01090 }
01091 else
01092 {
01093 return $this->import_mapping;
01094 }
01095 }
01096
01106 function to_xml($questions)
01107 {
01108 $xml = "";
01109
01110 if (count($questions) > 0)
01111 {
01112 foreach ($questions as $key => $value)
01113 {
01114 $question =& $this->createQuestion("", $value);
01115 $xml .= $question->object->to_xml();
01116 }
01117 if (count($questions) > 1)
01118 {
01119 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01120 }
01121 }
01122 $xml = preg_replace("/(<\?xml[^>]*?>)/", "\\1" . "<!DOCTYPE questestinterop SYSTEM \"ims_qtiasiv1p2p1.dtd\">", $xml);
01123 return $xml;
01124 }
01125
01136 function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01137 {
01138 global $ilDB;
01139 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01140 $ilDB->quote($questionpool_id . "")
01141 );
01142 if ($complete_questions_only)
01143 {
01144 $query .= " AND complete = '1'";
01145 }
01146 $result = $ilDB->query($query);
01147 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01148 return $row["question_count"];
01149 }
01150
01160 function setOnline($a_online_status)
01161 {
01162 switch ($a_online_status)
01163 {
01164 case 0:
01165 case 1:
01166 $this->online = $a_online_status;
01167 break;
01168 default:
01169 $this->online = 0;
01170 break;
01171 }
01172 }
01173
01174 function getOnline()
01175 {
01176 if (strcmp($this->online, "") == 0) $this->online = "0";
01177 return $this->online;
01178 }
01179
01180 function _lookupOnline($a_obj_id)
01181 {
01182 global $ilDB;
01183
01184 $query = sprintf("SELECT online FROM qpl_questionpool WHERE obj_fi = %s",
01185 $ilDB->quote($a_obj_id . "")
01186 );
01187 $result = $ilDB->query($query);
01188 if ($result->numRows() == 1)
01189 {
01190 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01191 return $row["online"];
01192 }
01193 return 0;
01194 }
01195
01204 function _hasEqualPoints($a_obj_id)
01205 {
01206 global $ilDB;
01207 $query = sprintf("SELECT count(DISTINCT points) AS equal_points FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
01208 $ilDB->quote($a_obj_id . "")
01209 );
01210 $result = $ilDB->query($query);
01211 if ($result->numRows() == 1)
01212 {
01213 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01214 if ($row["equal_points"] == 1)
01215 {
01216 return 1;
01217 }
01218 else
01219 {
01220 return 0;
01221 }
01222 }
01223 return 0;
01224 }
01225
01234 function pasteFromClipboard()
01235 {
01236 global $ilDB;
01237
01238 if (array_key_exists("qpl_clipboard", $_SESSION))
01239 {
01240 foreach ($_SESSION["qpl_clipboard"] as $question_object)
01241 {
01242 if (strcmp($question_object["action"], "move") == 0)
01243 {
01244 $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
01245 $ilDB->quote($question_object["question_id"])
01246 );
01247 $result = $ilDB->query($query);
01248 if ($result->numRows() == 1)
01249 {
01250 include_once "./content/classes/Pages/class.ilPageObject.php";
01251 $page = new ilPageObject("qpl", $question_object["question_id"]);
01252 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01253 $source_questionpool = $row["obj_fi"];
01254
01255 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s WHERE question_id = %s",
01256 $ilDB->quote($this->getId() . ""),
01257 $ilDB->quote($question_object["question_id"])
01258 );
01259 $ilDB->query($query);
01260
01261
01262 $query = sprintf("UPDATE page_object SET parent_id = %s WHERE page_id = %s",
01263 $ilDB->quote($this->getId() . ""),
01264 $ilDB->quote($question_object["question_id"])
01265 );
01266 $ilDB->query($query);
01267
01268
01269 $source_path = CLIENT_WEB_DIR . "/assessment/" . $source_questionpool . "/" . $question_object["question_id"] . "/";
01270 if (@is_dir($source_path))
01271 {
01272 $target_path = CLIENT_WEB_DIR . "/assessment/" . $this->getId() . "/";
01273 if (!@is_dir($target_path))
01274 {
01275 include_once "./classes/class.ilUtil.php";
01276 ilUtil::makeDirParents($target_path);
01277 }
01278 @rename($source_path, $target_path . $question_object["question_id"]);
01279 }
01280
01281 ilObjQuestionPool::_updateQuestionCount($source_questionpool);
01282 }
01283 }
01284 else
01285 {
01286 $this->copyQuestion($question_object["question_id"], $this->getId());
01287 }
01288 }
01289 }
01290
01291 ilObjQuestionPool::_updateQuestionCount($this->getId());
01292 unset($_SESSION["qpl_clipboard"]);
01293 }
01294
01303 function copyToClipboard($question_id)
01304 {
01305 if (!array_key_exists("qpl_clipboard", $_SESSION))
01306 {
01307 $_SESSION["qpl_clipboard"] = array();
01308 }
01309 $_SESSION["qpl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "copy");
01310 }
01311
01320 function moveToClipboard($question_id)
01321 {
01322 if (!array_key_exists("qpl_clipboard", $_SESSION))
01323 {
01324 $_SESSION["qpl_clipboard"] = array();
01325 }
01326 $_SESSION["qpl_clipboard"][$question_id] = array("question_id" => $question_id, "action" => "move");
01327 }
01328
01338 function _isWriteable($object_id, $user_id)
01339 {
01340 global $rbacsystem;
01341 global $ilDB;
01342
01343 $result_array = array();
01344 $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",
01345 $ilDB->quote($object_id . "")
01346 );
01347 $result = $ilDB->query($query);
01348 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01349 {
01350 include_once "./classes/class.ilObject.php";
01351 if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
01352 {
01353 return true;
01354 }
01355 }
01356 return false;
01357 }
01358
01368 function &getQuestionDetails($question_ids)
01369 {
01370 global $ilDB;
01371
01372 $result = array();
01373 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01374 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01375 $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";
01376 $query_result = $ilDB->query($query);
01377 if ($query_result->numRows())
01378 {
01379 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01380 {
01381 array_push($result, $row);
01382 }
01383 }
01384 return $result;
01385 }
01386
01398 function &getDeleteableQuestionDetails($question_ids)
01399 {
01400 global $ilDB;
01401
01402 $result = array();
01403 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01404 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01405 $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";
01406 $query_result = $ilDB->query($query);
01407 if ($query_result->numRows())
01408 {
01409 include_once "./assessment/classes/class.assQuestion.php";
01410 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01411 {
01412 if (!assQuestion::_isUsedInRandomTest($row["question_id"]))
01413 {
01414 array_push($result, $row);
01415 }
01416 else
01417 {
01418
01419
01420
01421
01422
01423
01424 $question =& $this->createQuestion("", $row["question_id"]);
01425 $duplicate_id = $question->object->duplicate(true);
01426 if ($duplicate_id > 0)
01427 {
01428
01429 $query = sprintf("UPDATE tst_solutions SET question_fi = %s WHERE question_fi = %s",
01430 $ilDB->quote($duplicate_id),
01431 $ilDB->quote($row["question_id"])
01432 );
01433 $ilDB->query($query);
01434
01435
01436 $query = sprintf("UPDATE tst_test_random_question SET question_fi = %s WHERE question_fi = %s",
01437 $ilDB->quote($duplicate_id),
01438 $ilDB->quote($row["question_id"])
01439 );
01440 $ilDB->query($query);
01441
01442
01443 $query = sprintf("UPDATE tst_test_result SET question_fi = %s WHERE question_fi = %s",
01444 $ilDB->quote($duplicate_id),
01445 $ilDB->quote($row["question_id"])
01446 );
01447 $ilDB->query($query);
01448
01449
01450 $query = sprintf("UPDATE ass_log SET question_fi = %s WHERE question_fi = %s",
01451 $ilDB->quote($duplicate_id),
01452 $ilDB->quote($row["question_id"])
01453 );
01454 $ilDB->query($query);
01455
01456
01457 array_push($result, $row);
01458 }
01459 }
01460 }
01461 }
01462 return $result;
01463 }
01464
01476 function &getUsedQuestionDetails($question_ids)
01477 {
01478 global $ilDB;
01479
01480 $result = array();
01481 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01482 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01483 $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";
01484 $query_result = $ilDB->query($query);
01485 if ($query_result->numRows())
01486 {
01487 include_once "./assessment/classes/class.assQuestion.php";
01488 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01489 {
01490 if (assQuestion::_isUsedInRandomTest($row["question_id"]))
01491 {
01492 array_push($result, $row);
01493 }
01494 }
01495 }
01496 return $result;
01497 }
01498
01507 function &_getAvailableQuestionpools($use_object_id = false)
01508 {
01509 global $rbacsystem;
01510 global $ilDB;
01511
01512 $result_array = array();
01513 $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";
01514 $result = $ilDB->query($query);
01515 include_once "./classes/class.ilObject.php";
01516 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01517 {
01518 if ($rbacsystem->checkAccess("write", $row->ref_id) && (ilObject::_hasUntrashedReference($row->obj_id)))
01519 {
01520 if ($use_object_id)
01521 {
01522 $result_array[$row->obj_id] = $row->title;
01523 }
01524 else
01525 {
01526 $result_array[$row->ref_id] = $row->title;
01527 }
01528 }
01529 }
01530 return $result_array;
01531 }
01532
01533 function &getQplQuestions()
01534 {
01535 global $ilDB;
01536
01537 $questions = array();
01538 $query = sprintf("SELECT qpl_questions.question_id FROM qpl_questions WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.obj_fi = %s",
01539 $ilDB->quote($this->getId() . "")
01540 );
01541 $result = $ilDB->query($query);
01542 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01543 {
01544 array_push($questions, $row["question_id"]);
01545 }
01546 return $questions;
01547 }
01555 function _clone($obj_id)
01556 {
01557 $original = new ilObjQuestionPool($obj_id, false);
01558 $original->loadFromDb();
01559
01560 $newObj = new ilObjQuestionPool();
01561 $newObj->setType("qpl");
01562 $newObj->setTitle($original->getTitle() . " (".ilFormat::formatDate(ilFormat::unixtimestamp2datetime()).")");
01563 $newObj->setDescription($original->getDescription());
01564 $newObj->create(true);
01565 $newObj->createReference();
01566 $newObj->putInTree($_GET["ref_id"]);
01567 $newObj->setPermissions($_GET["ref_id"]);
01568 $newObj->setOnline($original->getOnline());
01569 $newObj->saveToDb();
01570
01571 $questions =& $original->getQplQuestions();
01572 foreach ($questions as $question_id)
01573 {
01574 $newObj->copyQuestion($question_id, $newObj->getId());
01575 }
01576
01577
01578 include_once "./Services/MetaData/classes/class.ilMD.php";
01579 $md = new ilMD($original->getId(),0,$original->getType());
01580 $new_md =& $md->cloneMD($newObj->getId(),0,$newObj->getType());
01581
01582
01583 $newObj->updateMetaData();
01584
01585 return $newObj->getRefId();
01586 }
01587
01588 function &getQuestionTypes()
01589 {
01590 global $ilDB;
01591
01592 $query = "SELECT * FROM qpl_question_type ORDER BY question_type_id";
01593 $result = $ilDB->query($query);
01594 $types = array();
01595 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01596 {
01597 $types[$this->lng->txt($row["type_tag"])] = $row;
01598 }
01599 ksort($types);
01600 return $types;
01601 }
01602
01603 function &getQuestionList()
01604 {
01605 global $ilDB;
01606
01607 $questions = array();
01608 $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",
01609 $ilDB->quote($this->getId() . "")
01610 );
01611 $result = $ilDB->query($query);
01612 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01613 {
01614 array_push($questions, $row);
01615 }
01616 return $questions;
01617 }
01618
01627 function _updateQuestionCount($object_id)
01628 {
01629 global $ilDB;
01630 if ($ilDB->tableColumnExists("qpl_questionpool", "questioncount"))
01631 {
01632 $query = sprintf("UPDATE qpl_questionpool SET questioncount = %s WHERE obj_fi = %s",
01633 $ilDB->quote(ilObjQuestionPool::_getQuestionCount($object_id, TRUE)),
01634 $ilDB->quote($object_id)
01635 );
01636 $result = $ilDB->query($query);
01637 }
01638 }
01639 }
01640 ?>