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 require_once "./classes/class.ilMetaData.php";
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 if ($a_id == 0)
00058 {
00059 $new_meta =& new ilMetaData();
00060 $this->assignMetaData($new_meta);
00061 }
00062 }
00063
00067 function create($a_upload = false)
00068 {
00069 parent::create();
00070 if (!$a_upload)
00071 {
00072 $this->meta_data->setId($this->getId());
00073 $this->meta_data->setType($this->getType());
00074 $this->meta_data->setTitle($this->getTitle());
00075 $this->meta_data->setDescription($this->getDescription());
00076 $this->meta_data->setObject($this);
00077 $this->meta_data->create();
00078 }
00079 }
00080
00087 function update()
00088 {
00089 if (!parent::update())
00090 {
00091 return false;
00092 }
00093
00094
00095
00096 return true;
00097 }
00098
00104 function read($a_force_db = false)
00105 {
00106 parent::read($a_force_db);
00107 $this->meta_data =& new ilMetaData($this->getType(), $this->getId());
00108 }
00109
00117 function ilClone($a_parent_ref)
00118 {
00119 global $rbacadmin;
00120
00121
00122 $new_ref_id = parent::ilClone($a_parent_ref);
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 return $new_ref_id;
00138 }
00139
00146 function delete()
00147 {
00148
00149 if (!parent::delete())
00150 {
00151 return false;
00152 }
00153
00154
00155 $this->deleteQuestionpool();
00156
00157 return true;
00158 }
00159
00160 function deleteQuestionpool()
00161 {
00162 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s",
00163 $this->ilias->db->quote($this->getId()));
00164
00165 $result = $this->ilias->db->query($query);
00166 $questions = array();
00167
00168 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00169 {
00170 array_push($questions, $row["question_id"]);
00171 }
00172
00173 if (count($questions))
00174 {
00175 foreach ($questions as $question_id)
00176 {
00177 $this->deleteQuestion($question_id);
00178 }
00179 }
00180
00181
00182 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00183 $directory = $qpl_data_dir."/qpl_".$this->getId();
00184 if (is_dir($directory))
00185 {
00186 $directory = escapeshellarg($directory);
00187 exec("rm -rf $directory");
00188 }
00189 }
00190
00200 function initDefaultRoles()
00201 {
00202 global $rbacadmin;
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 return $roles ? $roles : array();
00215 }
00216
00230 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00231 {
00232 global $tree;
00233
00234 switch ($a_event)
00235 {
00236 case "link":
00237
00238
00239
00240
00241 break;
00242
00243 case "cut":
00244
00245
00246
00247 break;
00248
00249 case "copy":
00250
00251
00252
00253
00254 break;
00255
00256 case "paste":
00257
00258
00259
00260 break;
00261
00262 case "new":
00263
00264
00265
00266 break;
00267 }
00268
00269
00270 if ($a_node_id==$_GET["ref_id"])
00271 {
00272 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00273 $parent_type = $parent_obj->getType();
00274 if($parent_type == $this->getType())
00275 {
00276 $a_node_id = (int) $tree->getParentId($a_node_id);
00277 }
00278 }
00279
00280 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00281 }
00282
00291 function deleteQuestion($question_id)
00292 {
00293 $question = new ASS_Question();
00294 $question->delete($question_id);
00295 }
00296
00306 function getQuestiontype($question_id)
00307 {
00308 if ($question_id < 1)
00309 {
00310 return;
00311 }
00312
00313 $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",
00314 $this->ilias->db->quote($question_id));
00315
00316 $result = $this->ilias->db->query($query);
00317 if ($result->numRows() == 1)
00318 {
00319 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00320 return $data->type_tag;
00321 }
00322 else
00323 {
00324 return;
00325 }
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00396 function getDescription()
00397 {
00398 return parent::getDescription();
00399
00400 }
00401
00405 function setDescription($a_description)
00406 {
00407 parent::setDescription($a_description);
00408 $this->meta_data->setDescription($a_description);
00409 }
00410
00416 function getTitle()
00417 {
00418 return parent::getTitle();
00419 }
00420
00424 function setTitle($a_title)
00425 {
00426 parent::setTitle($a_title);
00427 $this->meta_data->setTitle($a_title);
00428 }
00429
00435 function assignMetaData(&$a_meta_data)
00436 {
00437 $this->meta_data =& $a_meta_data;
00438 }
00439
00445 function &getMetaData()
00446 {
00447 return $this->meta_data;
00448 }
00449
00453 function initMeta()
00454 {
00455 if (!is_object($this->meta_data))
00456 {
00457 if ($this->getId())
00458 {
00459 $new_meta =& new ilMetaData($this->getType(), $this->getId());
00460 }
00461 else
00462 {
00463 $new_meta =& new ilMetaData();
00464 }
00465 $this->assignMetaData($new_meta);
00466 }
00467 }
00468
00472 function updateMetaData()
00473 {
00474 $this->initMeta();
00475 $this->meta_data->update();
00476 if ($this->meta_data->section != "General")
00477 {
00478 $meta = $this->meta_data->getElement("Title", "General");
00479 $this->meta_data->setTitle($meta[0]["value"]);
00480 $meta = $this->meta_data->getElement("Description", "General");
00481 $this->meta_data->setDescription($meta[0]["value"]);
00482 }
00483 else
00484 {
00485 $this->setTitle($this->meta_data->getTitle());
00486 $this->setDescription($this->meta_data->getDescription());
00487 }
00488 parent::update();
00489 }
00490
00491
00501 function isInUse($question_id)
00502 {
00503 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00504 $this->ilias->db->quote("$question_id"));
00505
00506 $result = $this->ilias->db->query($query);
00507 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00508
00509 return $row->solution_count;
00510 }
00511
00512 function &createQuestion($question_type, $question_id = -1)
00513 {
00514 if ((!$question_type) and ($question_id > 0))
00515 {
00516 $question_type = $this->getQuestiontype($question_id);
00517 }
00518
00519 switch ($question_type)
00520 {
00521 case "qt_multiple_choice_sr":
00522 $question =& new ASS_MultipleChoiceGUI();
00523 $question->object->set_response(RESPONSE_SINGLE);
00524 break;
00525
00526 case "qt_multiple_choice_mr":
00527 $question =& new ASS_MultipleChoiceGUI();
00528 $question->object->set_response(RESPONSE_MULTIPLE);
00529 break;
00530
00531 case "qt_cloze":
00532 $question =& new ASS_ClozeTestGUI();
00533 break;
00534
00535 case "qt_matching":
00536 $question =& new ASS_MatchingQuestionGUI();
00537 break;
00538
00539 case "qt_ordering":
00540 $question =& new ASS_OrderingQuestionGUI();
00541 break;
00542
00543 case "qt_imagemap":
00544 $question =& new ASS_ImagemapQuestionGUI();
00545 break;
00546
00547 case "qt_javaapplet":
00548 $question =& new ASS_JavaAppletGUI();
00549 break;
00550
00551 case "qt_text":
00552 $question =& new ASS_TextQuestionGUI();
00553 break;
00554 }
00555
00556 if ($question_id > 0)
00557 {
00558 $question->object->loadFromDb($question_id);
00559 }
00560
00561 return $question;
00562 }
00563
00572 function duplicateQuestion($question_id)
00573 {
00574 global $ilUser;
00575
00576 $question =& $this->createQuestion("", $question_id);
00577 $counter = 2;
00578 while ($question->object->questionTitleExists($question->object->getTitle() . " ($counter)"))
00579 {
00580 $counter++;
00581 }
00582
00583 $question->object->duplicate(false, $question->object->getTitle() . " ($counter)", $ilUser->fullname, $ilUser->id);
00584 }
00585
00593 function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00594 {
00595 global $ilUser;
00596 $where = "";
00597 if (strlen($filter_text) > 0)
00598 {
00599 switch($sel_filter_type)
00600 {
00601 case "title":
00602 $where = " AND qpl_questions.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00603 break;
00604
00605 case "comment":
00606 $where = " AND qpl_questions.comment LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00607 break;
00608
00609 case "author":
00610 $where = " AND qpl_questions.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00611 break;
00612 }
00613 }
00614
00615
00616 $order = "";
00617 $images = array();
00618 if (count($sortoptions))
00619 {
00620 foreach ($sortoptions as $key => $value)
00621 {
00622 switch($key)
00623 {
00624 case "title":
00625 $order = " ORDER BY title $value";
00626 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00627 break;
00628 case "comment":
00629 $order = " ORDER BY comment $value";
00630 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00631 break;
00632 case "type":
00633 $order = " ORDER BY question_type_id $value";
00634 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00635 break;
00636 case "author":
00637 $order = " ORDER BY author $value";
00638 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00639 break;
00640 case "created":
00641 $order = " ORDER BY created $value";
00642 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00643 break;
00644 case "updated":
00645 $order = " ORDER BY TIMESTAMP $value";
00646 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00647 break;
00648 }
00649 }
00650 }
00651 $maxentries = $ilUser->prefs["hits_per_page"];
00652 if ($maxentries < 1)
00653 {
00654 $maxentries = 9999;
00655 }
00656 $query = "SELECT qpl_questions.question_id 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";
00657 $query_result = $this->ilias->db->query($query);
00658 $max = $query_result->numRows();
00659 if ($startrow > $max -1)
00660 {
00661 $startrow = $max - ($max % $maxentries);
00662 }
00663 else if ($startrow < 0)
00664 {
00665 $startrow = 0;
00666 }
00667 $limit = " LIMIT $startrow, $maxentries";
00668 $query = "SELECT qpl_questions.*, 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";
00669 $query_result = $this->ilias->db->query($query);
00670 $rows = array();
00671 if ($query_result->numRows())
00672 {
00673 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00674 {
00675 array_push($rows, $row);
00676 }
00677 }
00678 $nextrow = $startrow + $maxentries;
00679 if ($nextrow > $max - 1)
00680 {
00681 $nextrow = $startrow;
00682 }
00683 $prevrow = $startrow - $maxentries;
00684 if ($prevrow < 0)
00685 {
00686 $prevrow = 0;
00687 }
00688 return array(
00689 "rows" => $rows,
00690 "images" => $images,
00691 "startrow" => $startrow,
00692 "nextrow" => $nextrow,
00693 "prevrow" => $prevrow,
00694 "step" => $maxentries,
00695 "rowcount" => $max
00696 );
00697 }
00698
00705 function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00706 {
00707 global $ilBench;
00708
00709 $this->mob_ids = array();
00710 $this->file_ids = array();
00711
00712 $attrs = array();
00713 $attrs["Type"] = "Questionpool_Test";
00714 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00715
00716
00717 $this->exportXMLMetaData($a_xml_writer);
00718
00719
00720 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00721 $ilBench->start("ContentObjectExport", "exportPageObjects");
00722 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00723 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00724 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00725
00726
00727 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00728 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00729 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00730 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00731 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00732
00733
00734 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00735 $ilBench->start("ContentObjectExport", "exportFileItems");
00736 $this->exportFileItems($a_target_dir, $expLog);
00737 $ilBench->stop("ContentObjectExport", "exportFileItems");
00738 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00739
00740 $a_xml_writer->xmlEndTag("ContentObject");
00741 }
00742
00749 function exportXMLMetaData(&$a_xml_writer)
00750 {
00751 $nested = new ilNestedSetXML();
00752 $nested->setParameterModifier($this, "modifyExportIdentifier");
00753 $a_xml_writer->appendXML($nested->export($this->getId(),
00754 $this->getType()));
00755 }
00756
00757 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00758 {
00759 if ($a_tag == "Identifier" && $a_param == "Entry")
00760 {
00761 $a_value = ilUtil::insertInstIntoID($a_value);
00762 }
00763
00764 return $a_value;
00765 }
00766
00767
00774 function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00775 {
00776 global $ilBench;
00777
00778 include_once "./content/classes/class.ilLMPageObject.php";
00779
00780 foreach ($questions as $question_id)
00781 {
00782 $ilBench->start("ContentObjectExport", "exportPageObject");
00783 $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00784
00785 $attrs = array();
00786 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00787
00788
00789
00790 $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00791 $page_object = new ilPageObject("qpl", $question_id);
00792 $page_object->buildDom();
00793 $page_object->insertInstIntoIDs($a_inst);
00794 $mob_ids = $page_object->collectMediaObjects(false);
00795 $file_ids = $page_object->collectFileItems();
00796 $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00797 $xml = str_replace("&","&", $xml);
00798 $a_xml_writer->appendXML($xml);
00799 $page_object->freeDom();
00800 unset ($page_object);
00801
00802 $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00803
00804
00805 $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00806
00807 foreach($mob_ids as $mob_id)
00808 {
00809 $this->mob_ids[$mob_id] = $mob_id;
00810 }
00811 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00812
00813
00814 $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00815
00816 foreach($file_ids as $file_id)
00817 {
00818 $this->file_ids[$file_id] = $file_id;
00819 }
00820 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00821
00822 $a_xml_writer->xmlEndTag("PageObject");
00823
00824
00825 $ilBench->stop("ContentObjectExport", "exportPageObject");
00826
00827
00828 }
00829 }
00830
00837 function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00838 {
00839 include_once("content/classes/Media/class.ilObjMediaObject.php");
00840
00841 foreach ($this->mob_ids as $mob_id)
00842 {
00843 $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00844 $media_obj = new ilObjMediaObject($mob_id);
00845 $media_obj->exportXML($a_xml_writer, $a_inst);
00846 $media_obj->exportFiles($a_target_dir);
00847 unset($media_obj);
00848 }
00849 }
00850
00855 function exportFileItems($a_target_dir, &$expLog)
00856 {
00857 include_once("classes/class.ilObjFile.php");
00858
00859 foreach ($this->file_ids as $file_id)
00860 {
00861 $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00862 $file_obj = new ilObjFile($file_id, false);
00863 $file_obj->export($a_target_dir);
00864 unset($file_obj);
00865 }
00866 }
00867
00873 function createExportDirectory()
00874 {
00875 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00876 ilUtil::makeDir($qpl_data_dir);
00877 if(!is_writable($qpl_data_dir))
00878 {
00879 $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00880 .") not writeable.",$this->ilias->error_obj->FATAL);
00881 }
00882
00883
00884 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00885 ilUtil::makeDir($qpl_dir);
00886 if(!@is_dir($qpl_dir))
00887 {
00888 $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00889 }
00890
00891 $export_dir = $qpl_dir."/export";
00892 ilUtil::makeDir($export_dir);
00893 if(!@is_dir($export_dir))
00894 {
00895 $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00896 }
00897 }
00898
00902 function getExportDirectory()
00903 {
00904 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00905
00906 return $export_dir;
00907 }
00908
00912 function getExportFiles($dir)
00913 {
00914
00915 if (!@is_dir($dir) or
00916 !is_writeable($dir))
00917 {
00918 return array();
00919 }
00920
00921
00922 $dir = dir($dir);
00923
00924
00925 $file = array();
00926
00927
00928 while ($entry = $dir->read())
00929 {
00930 if ($entry != "." and
00931 $entry != ".." and
00932 substr($entry, -4) == ".zip" and
00933 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl_)*[0-9]+\.zip\$", $entry))
00934 {
00935 $file[] = $entry;
00936 }
00937 }
00938
00939
00940 $dir->close();
00941
00942
00943 sort ($file);
00944 reset ($file);
00945
00946 return $file;
00947 }
00948
00954 function createImportDirectory()
00955 {
00956 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00957 ilUtil::makeDir($qpl_data_dir);
00958
00959 if(!is_writable($qpl_data_dir))
00960 {
00961 $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00962 .") not writeable.",$this->ilias->error_obj->FATAL);
00963 }
00964
00965
00966 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00967 ilUtil::makeDir($qpl_dir);
00968 if(!@is_dir($qpl_dir))
00969 {
00970 $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00971 }
00972
00973
00974 $import_dir = $qpl_dir."/import";
00975 ilUtil::makeDir($import_dir);
00976 if(!@is_dir($import_dir))
00977 {
00978 $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
00979 }
00980 }
00981
00985 function getImportDirectory()
00986 {
00987 $import_dir = ilUtil::getDataDir()."/qpl_data".
00988 "/qpl_".$this->getId()."/import";
00989 if(@is_dir($import_dir))
00990 {
00991 return $import_dir;
00992 }
00993 else
00994 {
00995 return false;
00996 }
00997 }
00998
00999 function &getAllQuestionIds()
01000 {
01001 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s",
01002 $this->ilias->db->quote($this->getId())
01003 );
01004 $query_result = $this->ilias->db->query($query);
01005 $questions = array();
01006 if ($query_result->numRows())
01007 {
01008 while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01009 {
01010 array_push($questions, $row["question_id"]);
01011 }
01012 }
01013 return $questions;
01014 }
01015
01020 function getImportMapping()
01021 {
01022 if (!is_array($this->import_mapping))
01023 {
01024 return array();
01025 }
01026 else
01027 {
01028 return $this->import_mapping;
01029 }
01030 }
01031
01041 function to_xml($questions)
01042 {
01043 $xml = "";
01044
01045 if (count($questions) > 0)
01046 {
01047 foreach ($questions as $key => $value)
01048 {
01049 $question =& $this->createQuestion("", $value);
01050 $xml .= $question->object->to_xml();
01051 }
01052 if (count($questions) > 1)
01053 {
01054 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01055 }
01056 }
01057 return $xml;
01058 }
01059
01060 function importObject($source)
01061 {
01062 $this->import_mapping = array();
01063 if (is_file($source))
01064 {
01065
01066 $fh = fopen($source, "r") or die("");
01067 $xml = fread($fh, filesize($source));
01068 fclose($fh) or die("");
01069 if (preg_match_all("/(<item[^>]*>.*?<\/item>)/si", $xml, $matches))
01070 {
01071 foreach ($matches[1] as $index => $item)
01072 {
01073
01074 if (preg_match("/(<item[^>]*>)/is", $item, $start_tag))
01075 {
01076 if (preg_match("/(ident=\"([^\"]*)\")/is", $start_tag[1], $ident))
01077 {
01078 $ident = $ident[2];
01079 }
01080 }
01081 $question = "";
01082 if (preg_match("/<qticomment>Questiontype\=(.*?)<\/qticomment>/is", $item, $questiontype))
01083 {
01084 switch ($questiontype[1])
01085 {
01086 case CLOZE_TEST_IDENTIFIER:
01087 $question = new ASS_ClozeTest();
01088 break;
01089 case IMAGEMAP_QUESTION_IDENTIFIER:
01090 $question = new ASS_ImagemapQuestion();
01091 break;
01092 case MATCHING_QUESTION_IDENTIFIER:
01093 $question = new ASS_MatchingQuestion();
01094 break;
01095 case MULTIPLE_CHOICE_QUESTION_IDENTIFIER:
01096 $question = new ASS_MultipleChoice();
01097 break;
01098 case ORDERING_QUESTION_IDENTIFIER:
01099 $question = new ASS_OrderingQuestion();
01100 break;
01101 case JAVAAPPLET_QUESTION_IDENTIFIER:
01102 $question = new ASS_JavaApplet();
01103 break;
01104 case TEXT_QUESTION_IDENTIFIER:
01105 $question = new ASS_TextQuestion();
01106 break;
01107 }
01108 if ($question)
01109 {
01110 $question->setObjId($this->getId());
01111 if ($question->from_xml("<questestinterop>$item</questestinterop>"))
01112 {
01113 $question->saveToDb();
01114 $this->import_mapping[$ident] = array(
01115 "pool" => $question->getId(), "test" => 0);
01116 }
01117 else
01118 {
01119 $this->ilias->raiseError($this->lng->txt("error_importing_question"), $this->ilias->error_obj->MESSAGE);
01120 }
01121 }
01122 }
01123 }
01124 }
01125 }
01126 }
01127
01138 function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01139 {
01140 global $ilDB;
01141 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01142 $ilDB->quote($questionpool_id . "")
01143 );
01144 if ($complete_questions_only)
01145 {
01146 $query .= " AND complete = '1'";
01147 }
01148 $result = $ilDB->query($query);
01149 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01150 return $row["question_count"];
01151 }
01152
01153 }
01154 ?>