00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 require_once "./classes/class.ilObjectGUI.php";
00036
00037 require_once "./assessment/classes/class.assQuestion.php";
00038 require_once "./assessment/classes/class.assClozeTestGUI.php";
00039 require_once "./assessment/classes/class.assImagemapQuestionGUI.php";
00040 require_once "./assessment/classes/class.assJavaAppletGUI.php";
00041 require_once "./assessment/classes/class.assMatchingQuestionGUI.php";
00042 require_once "./assessment/classes/class.assMultipleChoiceGUI.php";
00043 require_once "./assessment/classes/class.assOrderingQuestionGUI.php";
00044
00045 class ilObjQuestionPool extends ilObject
00046 {
00053 function ilObjQuestionPool($a_id = 0,$a_call_by_reference = true)
00054 {
00055 $this->type = "qpl";
00056 $this->ilObject($a_id,$a_call_by_reference);
00057
00058
00059
00060
00061
00062
00063
00064 }
00065
00069 function create($a_upload = false)
00070 {
00071 parent::create();
00072
00073
00074
00075 if (!$a_upload)
00076 {
00077 $this->createMetaData();
00078 }
00079 }
00080
00087 function update()
00088 {
00089 $this->updateMetaData();
00090 if (!parent::update())
00091 {
00092 return false;
00093 }
00094
00095
00096
00097 return true;
00098 }
00099
00105 function read($a_force_db = false)
00106 {
00107 parent::read($a_force_db);
00108
00109 }
00110
00118 function ilClone($a_parent_ref)
00119 {
00120 global $rbacadmin;
00121
00122
00123 $new_ref_id = parent::ilClone($a_parent_ref);
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 return $new_ref_id;
00139 }
00140
00147 function delete()
00148 {
00149
00150 if (!parent::delete())
00151 {
00152 return false;
00153 }
00154
00155
00156 $this->deleteMetaData();
00157
00158
00159 $this->deleteQuestionpool();
00160
00161 return true;
00162 }
00163
00164 function deleteQuestionpool()
00165 {
00166 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
00167 $this->ilias->db->quote($this->getId()));
00168
00169 $result = $this->ilias->db->query($query);
00170 $questions = array();
00171
00172 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00173 {
00174 array_push($questions, $row["question_id"]);
00175 }
00176
00177 if (count($questions))
00178 {
00179 foreach ($questions as $question_id)
00180 {
00181 $this->deleteQuestion($question_id);
00182 }
00183 }
00184
00185
00186 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00187 $directory = $qpl_data_dir."/qpl_".$this->getId();
00188 if (is_dir($directory))
00189 {
00190 $directory = escapeshellarg($directory);
00191 exec("rm -rf $directory");
00192 }
00193 }
00194
00204 function initDefaultRoles()
00205 {
00206 global $rbacadmin;
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 return $roles ? $roles : array();
00219 }
00220
00234 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00235 {
00236 global $tree;
00237
00238 switch ($a_event)
00239 {
00240 case "link":
00241
00242
00243
00244
00245 break;
00246
00247 case "cut":
00248
00249
00250
00251 break;
00252
00253 case "copy":
00254
00255
00256
00257
00258 break;
00259
00260 case "paste":
00261
00262
00263
00264 break;
00265
00266 case "new":
00267
00268
00269
00270 break;
00271 }
00272
00273
00274 if ($a_node_id==$_GET["ref_id"])
00275 {
00276 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00277 $parent_type = $parent_obj->getType();
00278 if($parent_type == $this->getType())
00279 {
00280 $a_node_id = (int) $tree->getParentId($a_node_id);
00281 }
00282 }
00283
00284 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00285 }
00286
00295 function deleteQuestion($question_id)
00296 {
00297 $question = new ASS_Question();
00298 $question->delete($question_id);
00299 }
00300
00310 function getQuestiontype($question_id)
00311 {
00312 if ($question_id < 1)
00313 {
00314 return;
00315 }
00316
00317 $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",
00318 $this->ilias->db->quote($question_id));
00319
00320 $result = $this->ilias->db->query($query);
00321 if ($result->numRows() == 1)
00322 {
00323 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00324 return $data->type_tag;
00325 }
00326 else
00327 {
00328 return;
00329 }
00330 }
00331
00337 function getDescription()
00338 {
00339 return parent::getDescription();
00340
00341 }
00342
00346 function setDescription($a_description)
00347 {
00348 parent::setDescription($a_description);
00349
00350 }
00351
00357 function getTitle()
00358 {
00359 return parent::getTitle();
00360 }
00361
00365 function setTitle($a_title)
00366 {
00367 parent::setTitle($a_title);
00368
00369 }
00370
00376
00377
00378
00379
00380
00381
00382
00388
00389
00390
00391
00392
00393
00394
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00449 function isInUse($question_id)
00450 {
00451 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00452 $this->ilias->db->quote("$question_id"));
00453
00454 $result = $this->ilias->db->query($query);
00455 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00456
00457 return $row->solution_count;
00458 }
00459
00460 function &createQuestion($question_type, $question_id = -1)
00461 {
00462 if ((!$question_type) and ($question_id > 0))
00463 {
00464 $question_type = $this->getQuestiontype($question_id);
00465 }
00466
00467 switch ($question_type)
00468 {
00469 case "qt_multiple_choice_sr":
00470 $question =& new ASS_MultipleChoiceGUI();
00471 $question->object->set_response(RESPONSE_SINGLE);
00472 break;
00473
00474 case "qt_multiple_choice_mr":
00475 $question =& new ASS_MultipleChoiceGUI();
00476 $question->object->set_response(RESPONSE_MULTIPLE);
00477 break;
00478
00479 case "qt_cloze":
00480 $question =& new ASS_ClozeTestGUI();
00481 break;
00482
00483 case "qt_matching":
00484 $question =& new ASS_MatchingQuestionGUI();
00485 break;
00486
00487 case "qt_ordering":
00488 $question =& new ASS_OrderingQuestionGUI();
00489 break;
00490
00491 case "qt_imagemap":
00492 $question =& new ASS_ImagemapQuestionGUI();
00493 break;
00494
00495 case "qt_javaapplet":
00496 $question =& new ASS_JavaAppletGUI();
00497 break;
00498
00499 case "qt_text":
00500 $question =& new ASS_TextQuestionGUI();
00501 break;
00502 }
00503
00504 if ($question_id > 0)
00505 {
00506 $question->object->loadFromDb($question_id);
00507 }
00508
00509 return $question;
00510 }
00511
00520 function duplicateQuestion($question_id)
00521 {
00522 global $ilUser;
00523
00524 $question =& $this->createQuestion("", $question_id);
00525 $counter = 2;
00526 while ($question->object->questionTitleExists($question->object->getTitle() . " ($counter)"))
00527 {
00528 $counter++;
00529 }
00530
00531 $question->object->duplicate(false, $question->object->getTitle() . " ($counter)", $ilUser->fullname, $ilUser->id);
00532 }
00533
00541 function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00542 {
00543 global $ilUser;
00544 $where = "";
00545 if (strlen($filter_text) > 0)
00546 {
00547 switch($sel_filter_type)
00548 {
00549 case "title":
00550 $where = " AND qpl_questions.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00551 break;
00552
00553 case "comment":
00554 $where = " AND qpl_questions.comment LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00555 break;
00556
00557 case "author":
00558 $where = " AND qpl_questions.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00559 break;
00560 }
00561 }
00562
00563
00564 $order = "";
00565 $images = array();
00566 if (count($sortoptions))
00567 {
00568 foreach ($sortoptions as $key => $value)
00569 {
00570 switch($key)
00571 {
00572 case "title":
00573 $order = " ORDER BY title $value";
00574 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00575 break;
00576 case "comment":
00577 $order = " ORDER BY comment $value";
00578 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00579 break;
00580 case "type":
00581 $order = " ORDER BY question_type_id $value";
00582 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00583 break;
00584 case "author":
00585 $order = " ORDER BY author $value";
00586 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00587 break;
00588 case "created":
00589 $order = " ORDER BY created $value";
00590 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00591 break;
00592 case "updated":
00593 $order = " ORDER BY TIMESTAMP14 $value";
00594 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00595 break;
00596 }
00597 }
00598 }
00599 $maxentries = $ilUser->prefs["hits_per_page"];
00600 if ($maxentries < 1)
00601 {
00602 $maxentries = 9999;
00603 }
00604 $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";
00605 $query_result = $this->ilias->db->query($query);
00606 $max = $query_result->numRows();
00607 if ($startrow > $max -1)
00608 {
00609 $startrow = $max - ($max % $maxentries);
00610 }
00611 else if ($startrow < 0)
00612 {
00613 $startrow = 0;
00614 }
00615 $limit = " LIMIT $startrow, $maxentries";
00616 $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";
00617 $query_result = $this->ilias->db->query($query);
00618 $rows = array();
00619 if ($query_result->numRows())
00620 {
00621 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00622 {
00623 array_push($rows, $row);
00624 }
00625 }
00626 $nextrow = $startrow + $maxentries;
00627 if ($nextrow > $max - 1)
00628 {
00629 $nextrow = $startrow;
00630 }
00631 $prevrow = $startrow - $maxentries;
00632 if ($prevrow < 0)
00633 {
00634 $prevrow = 0;
00635 }
00636 return array(
00637 "rows" => $rows,
00638 "images" => $images,
00639 "startrow" => $startrow,
00640 "nextrow" => $nextrow,
00641 "prevrow" => $prevrow,
00642 "step" => $maxentries,
00643 "rowcount" => $max
00644 );
00645 }
00646
00653 function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00654 {
00655 global $ilBench;
00656
00657 $this->mob_ids = array();
00658 $this->file_ids = array();
00659
00660 $attrs = array();
00661 $attrs["Type"] = "Questionpool_Test";
00662 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00663
00664
00665 $this->exportXMLMetaData($a_xml_writer);
00666
00667
00668 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00669 $ilBench->start("ContentObjectExport", "exportPageObjects");
00670 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00671 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00672 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00673
00674
00675 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00676 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00677 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00678 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00679 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00680
00681
00682 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00683 $ilBench->start("ContentObjectExport", "exportFileItems");
00684 $this->exportFileItems($a_target_dir, $expLog);
00685 $ilBench->stop("ContentObjectExport", "exportFileItems");
00686 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00687
00688 $a_xml_writer->xmlEndTag("ContentObject");
00689 }
00690
00697 function exportXMLMetaData(&$a_xml_writer)
00698 {
00699 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00700 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
00701 $md2xml->setExportMode(true);
00702 $md2xml->startExport();
00703 $a_xml_writer->appendXML($md2xml->getXML());
00704 }
00705
00706 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00707 {
00708 if ($a_tag == "Identifier" && $a_param == "Entry")
00709 {
00710 $a_value = ilUtil::insertInstIntoID($a_value);
00711 }
00712
00713 return $a_value;
00714 }
00715
00716
00723 function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00724 {
00725 global $ilBench;
00726
00727 include_once "./content/classes/class.ilLMPageObject.php";
00728
00729 foreach ($questions as $question_id)
00730 {
00731 $ilBench->start("ContentObjectExport", "exportPageObject");
00732 $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00733
00734 $attrs = array();
00735 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00736
00737
00738
00739 $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00740 $page_object = new ilPageObject("qpl", $question_id);
00741 $page_object->buildDom();
00742 $page_object->insertInstIntoIDs($a_inst);
00743 $mob_ids = $page_object->collectMediaObjects(false);
00744 $file_ids = $page_object->collectFileItems();
00745 $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00746 $xml = str_replace("&","&", $xml);
00747 $a_xml_writer->appendXML($xml);
00748 $page_object->freeDom();
00749 unset ($page_object);
00750
00751 $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00752
00753
00754 $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00755
00756 foreach($mob_ids as $mob_id)
00757 {
00758 $this->mob_ids[$mob_id] = $mob_id;
00759 }
00760 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00761
00762
00763 $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00764
00765 foreach($file_ids as $file_id)
00766 {
00767 $this->file_ids[$file_id] = $file_id;
00768 }
00769 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00770
00771 $a_xml_writer->xmlEndTag("PageObject");
00772
00773
00774 $ilBench->stop("ContentObjectExport", "exportPageObject");
00775
00776
00777 }
00778 }
00779
00786 function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00787 {
00788 include_once("content/classes/Media/class.ilObjMediaObject.php");
00789
00790 foreach ($this->mob_ids as $mob_id)
00791 {
00792 $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00793 $media_obj = new ilObjMediaObject($mob_id);
00794 $media_obj->exportXML($a_xml_writer, $a_inst);
00795 $media_obj->exportFiles($a_target_dir);
00796 unset($media_obj);
00797 }
00798 }
00799
00804 function exportFileItems($a_target_dir, &$expLog)
00805 {
00806 include_once("classes/class.ilObjFile.php");
00807
00808 foreach ($this->file_ids as $file_id)
00809 {
00810 $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00811 $file_obj = new ilObjFile($file_id, false);
00812 $file_obj->export($a_target_dir);
00813 unset($file_obj);
00814 }
00815 }
00816
00822 function createExportDirectory()
00823 {
00824 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00825 ilUtil::makeDir($qpl_data_dir);
00826 if(!is_writable($qpl_data_dir))
00827 {
00828 $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00829 .") not writeable.",$this->ilias->error_obj->FATAL);
00830 }
00831
00832
00833 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00834 ilUtil::makeDir($qpl_dir);
00835 if(!@is_dir($qpl_dir))
00836 {
00837 $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00838 }
00839
00840 $export_dir = $qpl_dir."/export";
00841 ilUtil::makeDir($export_dir);
00842 if(!@is_dir($export_dir))
00843 {
00844 $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00845 }
00846 }
00847
00851 function getExportDirectory()
00852 {
00853 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00854
00855 return $export_dir;
00856 }
00857
00861 function getExportFiles($dir)
00862 {
00863
00864 if (!@is_dir($dir) or
00865 !is_writeable($dir))
00866 {
00867 return array();
00868 }
00869
00870 $dir = dir($dir);
00871
00872
00873 $file = array();
00874
00875
00876 while ($entry = $dir->read())
00877 {
00878 if ($entry != "." and
00879 $entry != ".." and
00880 substr($entry, -4) == ".zip" and
00881 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl__)*[0-9]+\.zip\$", $entry))
00882 {
00883 $file[] = $entry;
00884 }
00885 }
00886
00887
00888 $dir->close();
00889
00890
00891 sort ($file);
00892 reset ($file);
00893 return $file;
00894 }
00895
00901 function _createImportDirectory()
00902 {
00903 global $ilias;
00904
00905 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00906 ilUtil::makeDir($qpl_data_dir);
00907
00908 if(!is_writable($qpl_data_dir))
00909 {
00910 $ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00911 .") not writeable.",$ilias->error_obj->FATAL);
00912 }
00913
00914
00915 $qpl_dir = $qpl_data_dir."/qpl_import";
00916 ilUtil::makeDir($qpl_dir);
00917 if(!@is_dir($qpl_dir))
00918 {
00919 $ilias->raiseError("Creation of Questionpool Directory failed.",$ilias->error_obj->FATAL);
00920 }
00921 }
00922
00926 function _getImportDirectory()
00927 {
00928 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
00929 if(@is_dir($import_dir))
00930 {
00931 return $import_dir;
00932 }
00933 else
00934 {
00935 return false;
00936 }
00937 }
00938
00942 function getImportDirectory()
00943 {
00944 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
00945 if(@is_dir($import_dir))
00946 {
00947 return $import_dir;
00948 }
00949 else
00950 {
00951 return false;
00952 }
00953 }
00954
00955 function &getAllQuestionIds()
00956 {
00957 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s AND complete = %s",
00958 $this->ilias->db->quote($this->getId()),
00959 $this->ilias->db->quote("1")
00960 );
00961 $query_result = $this->ilias->db->query($query);
00962 $questions = array();
00963 if ($query_result->numRows())
00964 {
00965 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00966 {
00967 array_push($questions, $row["question_id"]);
00968 }
00969 }
00970 return $questions;
00971 }
00972
00977 function getImportMapping()
00978 {
00979 if (!is_array($this->import_mapping))
00980 {
00981 return array();
00982 }
00983 else
00984 {
00985 return $this->import_mapping;
00986 }
00987 }
00988
00998 function to_xml($questions)
00999 {
01000 $xml = "";
01001
01002 if (count($questions) > 0)
01003 {
01004 foreach ($questions as $key => $value)
01005 {
01006 $question =& $this->createQuestion("", $value);
01007 $xml .= $question->object->to_xml();
01008 }
01009 if (count($questions) > 1)
01010 {
01011 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01012 }
01013 }
01014 return $xml;
01015 }
01016
01017 function importObject($source)
01018 {
01019 $this->import_mapping = array();
01020 if (is_file($source))
01021 {
01022
01023 $fh = fopen($source, "r") or die("");
01024 $xml = fread($fh, filesize($source));
01025 fclose($fh) or die("");
01026
01027 if (preg_match_all("/(<item[^>]*>.*?<\/item>)/si", $xml, $matches))
01028 {
01029 foreach ($matches[1] as $index => $item)
01030 {
01031
01032 if (preg_match("/(<item[^>]*>)/is", $item, $start_tag))
01033 {
01034 if (preg_match("/(ident=\"([^\"]*)\")/is", $start_tag[1], $ident))
01035 {
01036 $ident = $ident[2];
01037 }
01038 }
01039 $question = "";
01040 $qt = "";
01041 if (preg_match("/<fieldlabel>QUESTIONTYPE<\/fieldlabel>\s*<fieldentry>(.*?)<\/fieldentry>/is", $item, $questiontype))
01042 {
01043 $qt = $questiontype[1];
01044 }
01045 if (preg_match("/<qticomment>Questiontype\=(.*?)<\/qticomment>/is", $item, $questiontype))
01046 {
01047 $qt = $questiontype[1];
01048 }
01049 if (strlen($qt))
01050 {
01051 switch ($qt)
01052 {
01053 case CLOZE_TEST_IDENTIFIER:
01054 $question = new ASS_ClozeTest();
01055 break;
01056 case IMAGEMAP_QUESTION_IDENTIFIER:
01057 $question = new ASS_ImagemapQuestion();
01058 break;
01059 case MATCHING_QUESTION_IDENTIFIER:
01060 $question = new ASS_MatchingQuestion();
01061 break;
01062 case MULTIPLE_CHOICE_QUESTION_IDENTIFIER:
01063 $question = new ASS_MultipleChoice();
01064 break;
01065 case ORDERING_QUESTION_IDENTIFIER:
01066 $question = new ASS_OrderingQuestion();
01067 break;
01068 case JAVAAPPLET_QUESTION_IDENTIFIER:
01069 $question = new ASS_JavaApplet();
01070 break;
01071 case TEXT_QUESTION_IDENTIFIER:
01072 $question = new ASS_TextQuestion();
01073 break;
01074 }
01075 if ($question)
01076 {
01077 $question->setObjId($this->getId());
01078 if ($question->from_xml("<questestinterop>$item</questestinterop>"))
01079 {
01080 $question->saveToDb();
01081 $this->import_mapping[$ident] = array(
01082 "pool" => $question->getId(), "test" => 0);
01083 }
01084 else
01085 {
01086 $this->ilias->raiseError($this->lng->txt("error_importing_question"), $this->ilias->error_obj->MESSAGE);
01087 }
01088 }
01089 }
01090 }
01091 }
01092 }
01093 else
01094 {
01095 return FALSE;
01096 }
01097 return TRUE;
01098 }
01099
01110 function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01111 {
01112 global $ilDB;
01113 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01114 $ilDB->quote($questionpool_id . "")
01115 );
01116 if ($complete_questions_only)
01117 {
01118 $query .= " AND complete = '1'";
01119 }
01120 $result = $ilDB->query($query);
01121 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01122 return $row["question_count"];
01123 }
01124
01134 function _isWriteable($object_id, $user_id)
01135 {
01136 global $rbacsystem;
01137 global $ilDB;
01138
01139 $result_array = array();
01140 $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",
01141 $ilDB->quote($object_id . "")
01142 );
01143 $result = $ilDB->query($query);
01144 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01145 {
01146 include_once "./classes/class.ilObject.php";
01147 if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
01148 {
01149 return true;
01150 }
01151 }
01152 return false;
01153 }
01154
01164 function &getQuestionDetails($question_ids)
01165 {
01166 global $ilDB;
01167
01168 $result = array();
01169 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01170 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01171 $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";
01172 $query_result = $ilDB->query($query);
01173 if ($query_result->numRows())
01174 {
01175 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01176 {
01177 array_push($result, $row);
01178 }
01179 }
01180 return $result;
01181 }
01182
01194 function &getDeleteableQuestionDetails($question_ids)
01195 {
01196 global $ilDB;
01197
01198 $result = array();
01199 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01200 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01201 $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";
01202 $query_result = $ilDB->query($query);
01203 if ($query_result->numRows())
01204 {
01205 include_once "./assessment/classes/class.assQuestion.php";
01206 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01207 {
01208 if (!ASS_Question::_isUsedInRandomTest($row["question_id"]))
01209 {
01210 array_push($result, $row);
01211 }
01212 }
01213 }
01214 return $result;
01215 }
01216
01228 function &getUsedQuestionDetails($question_ids)
01229 {
01230 global $ilDB;
01231
01232 $result = array();
01233 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01234 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01235 $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";
01236 $query_result = $ilDB->query($query);
01237 if ($query_result->numRows())
01238 {
01239 include_once "./assessment/classes/class.assQuestion.php";
01240 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01241 {
01242 if (ASS_Question::_isUsedInRandomTest($row["question_id"]))
01243 {
01244 array_push($result, $row);
01245 }
01246 }
01247 }
01248 return $result;
01249 }
01250
01251 }
01252 ?>