1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | <?php /** * Class to create the GUI for the VTQuestionGUI * @author Lukas Block * ... * @version $Id: class.assVTQuestionGUI.php 1318 2013-08-21 10:19:37Z aifbkitstuds $ * @ingroup ModulesTestQuestionPool * @ilctrl_iscalledby assVTQuestionGUI: ilObjQuestionPoolGUI, ilObjTestGUI, ilQuestionEditGUI, ilTestExpressPageObjectGUI */ include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php"; include_once "./Modules/Test/classes/inc.AssessmentConstants.php"; class assVTQuestionGUI extends assQuestionGUI { /** * Constructor * @Override */ public function __construct($id = -1) { parent::__construct(); include_once "./Services/Component/classes/class.ilPlugin.php"; $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "TestQuestionPool", "qst", "assVTQuestion"); $pl->includeClass("class.assVTQuestion.php"); $this->object = new assVTQuestion(); if ($id >= 0) { $this->object->loadFromDb($id); } } /** * Manipulate command * @Override */ function getCommand($cmd) { //preg_match done because edit pool delivers the pool id after the "_" if(preg_match("/editPool_([0-9a-zA-z]+)/", $cmd, $matches)) { $cmd = "editPool"; } else if(preg_match("/deletePool_([0-9a-zA-Z]+)/", $cmd, $matches)) { $cmd = "deletePool"; } else if (preg_match("/saveNewPool/", $cmd, $matches)) { $cmd = "addPool"; } return $cmd; } /** * Proceed submitted changes in the test author panel * @Override */ public function writePostData($always = false) { $hasErrors = (!$always) ? $this->editQuestion(true) : false; if(!$hasErrors) { //Set the "normal" contents $this->object->setTitle($_POST["title"]); $this->object->setAuthor($_POST["author"]); $this->object->setComment($_POST["comment"]); $this->object->setPointsPerGap($_POST["points_per_gap"]); $this->object->setNrOfGaps($_POST["nr_of_gaps"]); include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php"; $this->object->setEstimatedWorkingTime( $_POST["Estimated"]["hh"], $_POST["Estimated"]["mm"], $_POST["Estimated"]["ss"] ); //Set the word pools if(isset($_POST["pool_fis"])) { $pool_fis = array(); foreach($_POST["pool_fis"] as $key => $value) { array_push($pool_fis, $value); } $this->object->setPoolFis($pool_fis); } //Set case sensitivity if(isset($_POST["case"])) { $this->object->setCaseSensitive(true); } else { $this->object->setCaseSensitive(false); } //Set the texts $newTexts = array(); foreach($_POST["txt"] as $key => $value) { $value = strip_tags($value); $newTexts[] = $value; } $this->object->setTexts($newTexts); return 0; } else { return 1; } } /** * Function to show the best solution and the solution of the participant * @Override */ public function getSolutionOutput( $active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE, $show_manual_scoring = FALSE, $show_question_text = TRUE ) { //Get the solution of the user for the active pass or from the last pass if allowed $user_solution = null; if($show_question_text && $result_output) { return $this->getPreview(); } else { //Last pass if($active_id) { //Get infos for current pass $solutions = NULL; include_once "./Modules/Test/classes/class.ilObjTest.php"; if(is_null($pass)) $pass = ilObjTest::_getPass($active_id); $user_solution["active_id"] = $active_id; $user_solution["pass"] = $pass; $solutions =& $this->object->getSolutionValues($active_id, $pass); $solution_id = $solutions[0]["value1"]; $entries = unserialize($solutions[0]["value2"]); $q_text = $this->object->getSolutionText($solution_id); $q_text = $this->object->prepareTextareaOutput($q_text, TRUE); //Build up GUI foreach($entries as $key => $entry) { $anzeige = ""; $bestArray = $this->object->getBestPractice($solution_id); $best = $bestArray[$key]; if($show_correct_solution) { $anzeige = $best; } else { $anzeige = $entry; if($result_output) { $anzeige = $anzeige . " / " . $best; } } if($this->object->getCaseSensitive() > 0) { $best = strtolower($best); $entry = strtolower($entry); } //Include images if ($show_correct_solution){ $icon = ""; } else if ($entry == $best) { $icon = '<img src="' . ilUtil::getImagePath('icon_ok.png') . '" title="" alt="" />'; }else { $icon = '<img src="' . ilUtil::getImagePath('icon_not_ok.png') . '" title="" alt="" />'; } //Set up GUI in gaps $q_text = str_replace("#:" . $key . ":#", '<span class="solutionbox">' . $anzeige . '</span>' . $icon, $q_text); } } //Generate the question output from the template $pl = $this->object->getPlugin(); $template = $pl->getTemplate("tpl.il_as_qpl_assVTQuestion_output.html"); $template->setVariable("QUESTIONTEXT", $q_text); $questionoutput = $template->get(); $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput); return $pageoutput; } } /** * Saves the feedback * @Override */ public function saveFeedback() { parent::saveFeedback(); } /** * Sets and adds the tabs for the questions * @Override */ public function setQuestionTabs() { global $rbacsystem, $ilTabs; //Initlialize Tabs $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]); include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $q_type = $this->object->getQuestionType(); if(strlen($q_type)) { $classname = $q_type . "GUI"; $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type); $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]); } if($_GET["q_id"]) { //check permission if($rbacsystem->checkAccess('write', $_GET["ref_id"])) { // edit page $ilTabs->addTarget("edit_content", $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"), array("edit", "insert", "exec_pg"), "", "", $force_active); } // Preview $ilTabs->addTarget("preview", $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"), array("preview"), "ilPageObjectGUI", "", $force_active); } //Set force_active here to false, because used to force the word_pools tab to be active if shown... $force_active = false; if($rbacsystem->checkAccess('write', $_GET["ref_id"])) { $url = ""; if($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion"); //Check whether "editPool" or "deletePool" command has been proceeded $commands = $_POST["cmd"]; if(is_array($commands)) { foreach($commands as $key => $value) { if(preg_match("/editPool_([0-9a-zA-z]+)/", $this->ctrl->getCmd(), $matches)) { $force_active = true; } else if(preg_match("/deletePool_([0-9a-zA-z]+)/", $this->ctrl->getCmd(), $matches)) { $force_active = true; } } } //Edit question properties $ilTabs->addTarget("edit_properties", $url, array( "editQuestion", "save", "cancel", "addSuggestedSolution", "cancelExplorer", "linkChilds", "removeSuggestedSolution", "parseQuestion", "saveEdit", "suggestRange" ), $classname, ""); //Pool editor if($_GET["q_id"]) { //The first is responsible for the naming of the tab //The second parameter is the function which is called, clicking it $ilTabs->addTarget("qpl_qst_assVTQuestion_word_pools", $this->ctrl->getLinkTargetByClass($classname, "showPoolList"), array("showPoolList", "savePools", "addPool", "saveNewPool", "savePoolChanges", "savePoolChangesAndReturn"), $classname, "", $force_active); } } //Assessment of questions sub menu entry if($_GET["q_id"]) { $ilTabs->addTarget("statistics", $this->ctrl->getLinkTargetByClass($classname, "assessment"), array("assessment"), $classname, ""); } if(($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0)) { $ref_id = $_GET["calling_test"]; if(strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"]; $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id"); } else { $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions")); } } /** * Represents and builds up the word list word pools tab * @param a possible message to be shown like "Saving successfull" */ function showPoolList($message = "") { global $ilDB; //Create Form... include_once("./Services/Form/classes/class.ilPropertyFormGUI.php"); $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->object->getPlugin()->txt("word_pools")); $form->setMultipart(FALSE); $form->setTableWidth("100%"); $form->setId("assvtquestion_pool"); //Add buttons $form->addCommandButton("addPool", $this->object->getPlugin()->txt("add_pool")); include_once("./Customizing/global/plugins/Modules/TestQuestionPool/Questions/assVTQuestion/classes/class.ilVTPoolGUI.php"); $all_pools = $ilDB->queryF("SELECT * FROM il_qpl_qst_assVTQuestion_pool", array(), array()); for($i = 0; $i < $all_pools->numRows(); $i++) { $data = $ilDB->fetchAssoc($all_pools); $word_fis = unserialize($data["word_fis"]); $words = array(); foreach($word_fis as $key => $value) { $word_db = $ilDB->queryF("SELECT word FROM il_qpl_qst_assVTQuestion_word WHERE word_id=%s", array("integer"), array($value)); $word_data = $ilDB->fetchAssoc($word_db); array_push($words, $word_data["word"]); } $pool = new ilVTPoolGUI($data["title"], "", $data["pool_id"], $this->object->getPlugin(), $words); $pool->setRequired(FALSE); $form->addItem($pool); } $gui = $message . $form->getHTML(); $this->tpl->setVariable("ADM_CONTENT", $gui); include_once "./Services/YUI/classes/class.ilYuiUtil.php"; ilYuiUtil::initDomEvent(); ilYuiUtil::initDragDropList(); } /** * Called to add a new word pool */ function addPool() { $save = strcmp($this->ctrl->getCmd(), "saveNewPool") == 0; $checkAgain = !$save; $form = $this->buildAddForm(); if ($save) { $form->setValuesByPost(); $errors = !$form->checkInput(); $form->setValuesByPost(); //Again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes if ($errors) { $checkAgain = true; } } if((!$save || $checkAgain)) { $this->tpl->setVariable("ADM_CONTENT", $form->getHTML()); include_once "./Services/YUI/classes/class.ilYuiUtil.php"; ilYuiUtil::initDomEvent(); ilYuiUtil::initDragDropList(); } else { $this->saveNewPool($_POST["title"]); } } /** * Creates the form to enter the name of the new word pool */ function buildAddForm() { //Create Form... include_once("./Services/Form/classes/class.ilPropertyFormGUI.php"); $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->object->getPlugin()->txt("create_new_pool")); $form->setMultipart(FALSE); $form->setTableWidth("100%"); $form->setId("assvtquestion_pool"); //Title $title = new ilTextInputGUI($this->object->getPlugin()->txt("pool_title"), "title"); $title->setValue(""); $title->setRequired(TRUE); $form->addItem($title); //Add buttons $form->addCommandButton("saveNewPool", $this->object->getPlugin()->txt("save_new_pool")); $form->addCommandButton("showPoolList", $this->object->getPlugin()->txt("cancel")); return $form; } /** * Creates a new pool from the submitted data * Can only be called from addPool because of $_POST * @param the title of the new pool */ function saveNewPool($title) { global $ilDB; //insert new entry //Get actual time $date = new DateTime(); $next_id = $ilDB->nextId('il_qpl_qst_assVTQuestion_pool'); $emptyArray = array(); $ilDB->insert("il_qpl_qst_assVTQuestion_pool", array( "pool_id" => array("integer", $next_id), "author" => array("clob", $this->object->getAuthor()), "owner" => array("clob", $this->object->getOwner()), "title" => array("clob", $title), "tstamp" => array("integer", $date->getTimestamp()), "word_fis" => array("clob", serialize($emptyArray)), )); //Go back to the list... $this->showPoolList($this->getMessage("success", "info", "pool_xyz_has_been_created", "xyz", $title)); } /** * Called to edit a pool */ function editPool() { global $ilDB; preg_match("/editPool_([0-9a-zA-z]+)/", $this->ctrl->getCmd(), $matches); //$poolId represents either pool id (load from db) or the word "post" => load from post, check and save $poolId = $matches[1]; $post = ((strpos($poolId, "post") !== false) ? TRUE : FALSE); $return = ((strpos($poolId, "return") !== false) ? TRUE : FALSE); if($post) { //Load from post data $poolId = $_POST["pool_id"]; $poolTitle = $_POST["title"]; $words = $_POST["word"]; } else { //Load from db $db_pool = $ilDB->queryF("SELECT * FROM il_qpl_qst_assVTQuestion_pool WHERE pool_id = %s", array("integer"), array($poolId)); $data = $ilDB->fetchAssoc($db_pool); $poolTitle = $data["title"]; $word_fis = unserialize($data["word_fis"]); $words = array(); foreach($word_fis as $key => $value) { $db_word = $ilDB->queryF("SELECT word FROM il_qpl_qst_assVTQuestion_word WHERE word_id = %s", array("integer"), array($value)); $word_data = $ilDB->fetchAssoc($db_word); array_push($words, $word_data["word"]); } } $form = $this->buildEditForm($poolId, $poolTitle, $words); if($post) { $form->setValuesByPost(); $wordNr = $this->checkRegex($words); $wordsOk = ($wordNr == -1); if($form->checkInput() && $wordsOk) { //Form okay save and eventually return $this->savePoolChanges($poolId, $poolTitle, $words); if(!$return) { //no return to pool list $form = $this->buildEditForm($poolId, $poolTitle, $words); $this->showEditForm($form, $this->getMessage("success", "info", "pool_changes_saved")); } else { //return to pool list $this->showPoolList($this->getMessage("success", "info", "pool_changes_saved")); } } else { $message = ""; //Form not okay, show Form again if(!$wordsOk) { $message = $this->getMessage("failure", "info", "word_xyz_is_not_a_regular_expression_with_brace", "xyz", ($wordNr+1)); } $form = $this->buildEditForm($poolId, $poolTitle, $words); $this->showEditForm($form, $message); } } else { //Form is shown first time... $this->showEditForm($form); } } /** * Checks an array of words if they are in a proper regex format also containing the () * @words array of words to check * @return the number of the word (not the id) which is no regular regex, if all words are correct -1 */ function checkRegex($words) { $i = 0; foreach($words as $key => $value) { if(!$this->isEmptyWord($value)) { //Set to let preg_match throw an error not a warning set_error_handler(create_function( '$errno, $errstr, $errfile, $errline', 'throw new ErrorException($errstr, 0, $errno, $errfile, $errline);' )); //Check if regular expression is valid... try { preg_match($value, "Empty string"); } catch (Exception $e) { restore_error_handler(); return $i; } restore_error_handler(); //Check if braces exist if(!preg_match("/\(.+\)/", $value)) { return $i; } $i++; } } restore_error_handler(); return -1; } /** * Checks if an word ist empty * @param $word The word to be checked * @return true, if the word is empty, otherwise false */ function isEmptyWord($word) { if(preg_match("/[a-zA-Z0-9]+/", $word)) { return false; } else { return true; } } /** * Builds the edit-Form of a word pool - called from editPool and SavePoolChanges * @param $poolId the id of the pool to build * @param $poolTitle the title of the pool to build * @param $words the words the pool consists of * @return the form in HTML format */ function buildEditForm($poolId, $poolTitle, $words) { //Create Form... include_once("./Services/Form/classes/class.ilPropertyFormGUI.php"); $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->object->getPlugin()->txt("edit_pool")); $form->setMultipart(FALSE); $form->setTableWidth("100%"); $form->setId("assvtquestion_pool"); //Add buttons $form->addCommandButton("editPool_post", $this->object->getPlugin()->txt("save_pool")); $form->addCommandButton("editPool_post_return", $this->object->getPlugin()->txt("save_pool_and_return")); $form->addCommandButton("showPoolList", $this->object->getPlugin()->txt("cancel")); //Add the pool id to be submitted to work on the pool $hidden = new ilHiddenInputGUI("pool_id", "pool_id"); $hidden->setValue($poolId); $form->addItem($hidden); // title $title = new ilTextInputGUI($this->object->getPlugin()->txt("pool_title"), "title"); $title->setValue($poolTitle); $title->setRequired(TRUE); $form->addItem($title); //Show all the words include_once("./Customizing/global/plugins/Modules/TestQuestionPool/Questions/assVTQuestion/classes/class.ilVTTextInputGUI.php"); $no = 0; foreach($words as $key => $value) { if(!$this->isEmptyWord($value)) { $word = new ilVTTextInputGUI($this->object->getPlugin()->txt("word") . " " . ($key+1), "word[]", $key); $word->setValue($value); $word->setRequired(FALSE); $form->addItem($word); $no++; } } //If there are no words in the pool, provide at least one empty field if($no == 0) { $word = new ilVTTextInputGUI($this->object->getPlugin()->txt("word") . " 1", "word[]", 0); $word->setValue(""); $word->setRequired(FALSE); $form->addItem($word); } return $form; } /** * Shows the edit-Form of a word pool * @param $form the form to show * @param $messages the possible message which should be shown */ function showEditForm($form, $messages = "") { $gui = $messages . $form->getHTML() . '<br><br><i style="font-size:10pt;">' . $this->object->getPlugin()->txt("annotation_regex") .'</i>'; $this->tpl->setVariable("ADM_CONTENT", $gui); include_once "./Services/YUI/classes/class.ilYuiUtil.php"; ilYuiUtil::initDomEvent(); ilYuiUtil::initDragDropList(); $this->tpl->addJavascript($this->translateJs($this->object->getPlugin()->getDirectory() . "/templates/js/js_raw/vtpoolwizard.js")); } /** * Called from savePoolChanges and savePoolChangesAndReturn. * Because of $_POST can just be called when these functions are also called. * @param $poolId the id of the pool to save the changes * @param $poolTitle the new title of the pool * @param $words all words of the pool * @return the new pool id */ function savePoolChanges($poolId, $poolTitle, $words) { global $ilDB; //Delete old words $db_pool = $ilDB->queryF("SELECT * FROM il_qpl_qst_assVTQuestion_pool WHERE pool_id = %s", array("integer"), array($poolId)); $data = $ilDB->fetchAssoc($db_pool); $delete_words = unserialize($data["word_fis"]); foreach($delete_words as $key => $value) { $ilDB->manipulateF("DELETE FROM il_qpl_qst_assVTQuestion_word WHERE word_id = %s", array("integer"), array($value)); } //Write new ones $newWordsId = array(); $date = new DateTime(); foreach($words as $key => $value) { //Check if not empty if(preg_match("/[a-zA-Z0-9]+/", $value, $matches)) { $next_id = $ilDB->nextId('il_qpl_qst_assvtquestion_word'); $affectedRows = $ilDB->insert("il_qpl_qst_assvtquestion_word", array( "word_id" => array("integer", $next_id), "author" => array("clob", $this->object->getAuthor()), "tstamp" => array("integer", $date->getTimestamp()), "word" => array("clob", $value) )); array_push($newWordsId, $next_id); } } //Save changes to the pool itself... //Delete old entry $ilDB->manipulateF("DELETE FROM il_qpl_qst_assVTQuestion_pool WHERE pool_id = %s", array("integer"), array($poolId)); //Insert new entry //Keep id because of questions $ilDB->insert("il_qpl_qst_assVTQuestion_pool", array( "pool_id" => array("integer", $poolId), "author" => array("clob", $data["author"]), "owner" => array("clob", $data["owner"]), "title" => array("clob", $poolTitle), "tstamp" => array("integer", $date->getTimestamp()), "word_fis" => array("clob", serialize($newWordsId)), )); } /** * Called to delete a word pool */ function deletePool() { global $ilDB; preg_match("/deletePool_([0-9a-zA-Z]+)/", $this->ctrl->getCmd(), $matches); $poolId = $matches[1]; $confirmed = (($poolId == "confirmed") ? TRUE : FALSE); if(!$confirmed) { $db_pool = $ilDB->queryF("SELECT title FROM il_qpl_qst_assVTQuestion_pool WHERE pool_id = %s", array("integer"), array($poolId)); $data = $ilDB->fetchAssoc($db_pool); $this->showDeleteForm($poolId, $data["title"]); } else { $poolId = $_POST["pool_id"]; $pool = $ilDB->queryF("SELECT word_fis FROM il_qpl_qst_assVTQuestion_pool WHERE pool_id=%s", array("integer"), array($poolId)); $data = $ilDB->fetchAssoc($pool); //Delete words $words = unserialize($data["word_fis"]); foreach($words as $key => $value) { $ilDB->manipulateF("DELETE FROM il_qpl_qst_assVTQuestion_word WHERE word_id = %s", array("integer"), array($value)); } //Delete pool $ilDB->manipulateF("DELETE FROM il_qpl_qst_assVTQuestion_pool WHERE pool_id = %s", array("integer"), array($poolId)); //Show list $this->showPoolList($this->getMessage("success", "info", "pools_deleted")); } } /** * Function to create and show the form, which asks to delete the pool * @param $poolId the id of the word pool to delete * @param $poolTitle the title of the word pool to delete */ function showDeleteForm($poolId, $poolTitle) { //Create Form... include_once("./Services/Form/classes/class.ilPropertyFormGUI.php"); $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->object->getPlugin()->txt("delete_pool")); $form->setMultipart(FALSE); $form->setTableWidth("100%"); $form->setId("assvtquestion_pool"); //Add buttons $form->addCommandButton("deletePool_confirmed", $this->object->getPlugin()->txt("delete_pool")); $form->addCommandButton("showPoolList", $this->object->getPlugin()->txt("cancel")); //Add the pool id to be submitted to work on the pool $hidden = new ilHiddenInputGUI("pool_id", "pool_id"); $hidden->setValue($poolId); $form->addItem($hidden); include_once("./Customizing/global/plugins/Modules/TestQuestionPool/Questions/assVTQuestion/classes/class.ilVTDeleteGUI.php"); $pool = new ilVTDeleteGUI($poolTitle, "", $poolId, $this->object->getPlugin()); $pool->setRequired(FALSE); $form->addItem($pool); $gui = $this->getMessage("question", "decision", "really_delete_pools") . $form->getHTML(); $this->tpl->setVariable("ADM_CONTENT", $gui); include_once "./Services/YUI/classes/class.ilYuiUtil.php"; ilYuiUtil::initDomEvent(); ilYuiUtil::initDragDropList(); } /** * Function to create an info-, error-, failure,- oder success-Message * @param $a_type = "info" or "question" or "failure" or "success" * @param $title The title of the message * @param $txt The message text * @param $search a string for which should be searched and can be replaced * @param $replace the string which replaces the word for what to search * @return the message as an HTML-string */ function getMessage($a_type, $title, $txt, $search = "", $replace = "") { //$a_type = info, question, failure, success $mtpl = new ilTemplate("tpl.message.html", true, true, "Services/Utilities"); $mtpl->setCurrentBlock($a_type."_message"); $m_text = $this->object->getPlugin()->txt($txt); if(($search != "") && ($replace != "")) { $m_text = str_replace($search, $replace, $m_text); } $mtpl->setVariable("TEXT", $m_text); $mtpl->setVariable("MESSAGE_HEADING", $this->object->getPlugin()->txt($title)); $mtpl->setVariable("ALT_IMAGE", ""); $mtpl->setVariable("SRC_IMAGE", ilUtil::getImagePath("mess_".$a_type.".png")); $mtpl->parseCurrentBlock(); return $mtpl->get(); } /** * Returns feedback for test-participant if enabled in test * @Override */ public function getSpecificFeedbackOutput($active_id, $pass) { if($this->object->calculateReachedPoints($active_id, $pass) >= $this->object->getMaximumPoints()) { return $this->object->getPlugin()->txt("feedback_all_right"); } else { return $this->object->getPlugin()->txt("feedback_some_mistakes"); } } /** * Checks the questions for the number of gaps * @return error-string if not enough gaps otherwise "" */ function checkInput() { $key = $this->object->checkNrOfGaps(); if($key > -1) { return $this->getMessage("info", "info", "txt_xyz_has_insufficient_gaps", "xyz", $key+1); } return ""; } /** * Creates and shows the main edit-question-form * @Override */ public function editQuestion() { global $lng; global $ilDB; $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE; $this->getQuestionTemplate(); include_once("./Services/Form/classes/class.ilPropertyFormGUI.php"); $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->outQuestionType()); $form->setMultipart(FALSE); $form->setTableWidth("100%"); $form->setId("assvtquestion"); // title $title = new ilTextInputGUI($this->lng->txt("title"), "title"); $title->setValue($this->object->getTitle()); $title->setRequired(TRUE); $form->addItem($title); if (!$this->getSelfAssessmentEditingMode()) { // author $author = new ilTextInputGUI($this->lng->txt("author"), "author"); $author->setValue($this->object->getAuthor()); $author->setRequired(TRUE); $form->addItem($author); // description $description = new ilTextInputGUI($this->lng->txt("description"), "comment"); $description->setValue($this->object->getComment()); $description->setRequired(FALSE); $form->addItem($description); } else { // author as hidden field $hi = new ilHiddenInputGUI("author"); $author = ilUtil::prepareFormOutput($this->object->getAuthor()); if (trim($author) == "") { $author = "-"; } $hi->setValue($author); $form->addItem($hi); } if (!$this->getSelfAssessmentEditingMode()) { // duration $duration = new ilDurationInputGUI($this->lng->txt("working_time"), "Estimated"); $duration->setShowHours(TRUE); $duration->setShowMinutes(TRUE); $duration->setShowSeconds(TRUE); $ewt = $this->object->getEstimatedWorkingTime(); $duration->setHours($ewt["h"]); $duration->setMinutes($ewt["m"]); $duration->setSeconds($ewt["s"]); $duration->setRequired(FALSE); $form->addItem($duration); } else { // number of tries if (strlen($this->object->getNrOfTries())) { $nr_tries = $this->object->getNrOfTries(); } else { $nr_tries = $this->getDefaultNrOfTries(); } if ($nr_tries <= 0) { $nr_tries = 1; } $ni = new ilNumberInputGUI($this->lng->txt("qst_nr_of_tries"), "nr_of_tries"); $ni->setValue($nr_tries); $ni->setMinValue(1); $ni->setSize(5); $ni->setMaxLength(5); $ni->setRequired(true); $form->addItem($ni); } // points $points = new ilNumberInputGUI($this->object->getPlugin()->txt("points_per_gap"), "points_per_gap"); $points->setValue($this->object->getPointsPerGap()); $points->setRequired(TRUE); $points->setSize(3); $points->setMinValue(0.0); $form->addItem($points); //number of gaps $nr_of_gaps = new ilNumberInputGUI($this->object->getPlugin()->txt("nr_of_gaps"), "nr_of_gaps"); $nr_of_gaps->setValue($this->object->getNrOfGaps()); $nr_of_gaps->setRequired(TRUE); $nr_of_gaps->setSize(3); $nr_of_gaps->setMinValue(1); $form->addItem($nr_of_gaps); //Word-Pools $pools = new ilCheckboxGroupInputGUI($this->object->getPlugin()->txt("word_pools"), "pool_fis"); $pools->setRequired(true); $all_pools = $ilDB->queryF("SELECT * FROM il_qpl_qst_assVTQuestion_pool", array(), array()); $values = array(); for($i = 0; $i < $all_pools->numRows(); $i++) { $data = $ilDB->fetchAssoc($all_pools); $pools->addOption(new ilCheckboxOption($data["title"], $data["pool_id"], '')); if(in_array($data["pool_id"], $this->object->getPoolFis())) { array_push($values, $data["pool_id"]); } } $pools->setValue($values); $form->addItem($pools); //Case sensitivity $case = new ilCheckboxGroupInputGUI($this->object->getPlugin()->txt("case_sensitivity"), "case"); $case->setRequired(false); $checked = array(); $case->addOption(new ilCheckboxOption($this->object->getPlugin()->txt("case_insensitive"), 'caseSens', '')); if($this->object->getCaseSensitive() > 0) { array_push($checked, 'caseSens'); } $case->setValue($checked); $form->addItem($case); if ($this->object->getId()) { $hidden = new ilHiddenInputGUI("", "ID"); $hidden->setValue($this->object->getId()); $form->addItem($hidden); } $this->addQuestionFormCommandButtons($form); $errors = false; if ($save) { $form->setValuesByPost(); $errors = !$form->checkInput(); $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes if ($errors) $checkonly = false; } //Construct texts include_once("./Customizing/global/plugins/Modules/TestQuestionPool/Questions/assVTQuestion/classes/class.ilVTTextAreaInputGUI.php"); $texts = $this->object->getTexts(); if(sizeof($texts) == 0) { $texts[] = ""; } $texts_gui = ""; foreach($texts as $key => $value) { //Enter text $txt = new ilVTTextAreaInputGUI($this->object->getPlugin()->txt("text") . " " . ($key+1), "txt[]", $key); $txt->setRows(10); $txt->setCols(75); $txt->setValue($value); $txt->setRequired(FALSE); $form->addItem($txt); } $gui = $this->checkInput() . $form->getHTML(); if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $gui); include_once "./Services/YUI/classes/class.ilYuiUtil.php"; ilYuiUtil::initConnection(); ilYUIUtil::initDomEvent(); $this->tpl->addJavascript($this->translateJs($this->object->getPlugin()->getDirectory() . "/templates/js/js_raw/vtquestionwizard.js")); return $errors; } /** * Function to translate the plain text written in a .js file, writes other file one directory up * @param the path to translate * @return the path to the translated file (normally one directory up) */ function translateJs($pathToFile) { $info = new SplFileInfo($pathToFile); $path = $info->getPath(); $file = $info->getFilename(); $content = file_get_contents($path . "/" . $file); $matches; $found = preg_match_all("/#:#(.+)#:#/", $content, $matches); for($i = 0; $i < $found; $i++) { $content = str_replace($matches[0][$i], $this->object->getPlugin()->txt($matches[1][$i]), $content); } $newPath = str_replace(basename($path), "", $path) . $file; file_put_contents($newPath, $content); return $newPath; } /** * Shows question in preview-mode while editing test * @Override */ function getPreview($show_question_only = FALSE) { $pl = $this->object->getPlugin(); $template = $pl->getTemplate("tpl.il_as_qpl_assVTQuestion_output.html"); $txts = $this->object->getTexts(); //Randomly select one text $txt_index = rand(0, count($txts)-1); $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($txts[$txt_index], TRUE)); $questionoutput = $template->get(); //Putoutput into ilias page if(!$show_question_only) { // get page object output $questionoutput = $this->getILIASPage($questionoutput); } return $questionoutput; } /** * Creates the output for the test-participant * @Override */ function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE) { $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback); //Put question text into the template $this->tpl->setVariable("QUESTION_OUTPUT", $test_output); //Set the URL for the following question to the "Continue"-Button $this->tpl->setVariable("FORMACTION", $formaction); } /** * Helper-function to create the test-ouput for the participant * @param the same as outQuestionForTest except of $formaction * @return the question text in HTML-format */ function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE) { //Get the solution of the user for the active pass or from the last pass if allowed $user_solution = null; if($active_id) { //Get infos for current pass $solutions = NULL; include_once "./Modules/Test/classes/class.ilObjTest.php"; if(is_null($pass)) $pass = ilObjTest::_getPass($active_id); $user_solution["active_id"] = $active_id; $user_solution["pass"] = $pass; $solutions =& $this->object->getSolutionValues($active_id, $pass); //If value1 is empty, the question has not been shown yet -> Generate new question if($solutions[0]["value1"] == "") { $solution_id = $this->object->generateQuestion(); $entries = $this->object->getBestPractice($solution_id); //Clear the best practice foreach($entries as $key => $value) { $entries[$key] = ""; } } else { //Loading the old questions $solution_id = $solutions[0]["value1"]; $entries = unserialize($solutions[0]["value2"]); } $q_text = $this->object->getSolutionText($solution_id); $q_text = $this->object->prepareTextareaOutput($q_text, TRUE); foreach($entries as $key => $value) { $best = $this->object->getBestPractice($solution_id); $q_text = str_replace("#:" . $key . ":#", '<input type="text" maxlength="255" size="' . strlen($best[$key]) . '" name="data[' . $key . ']" value="' . $value . '" />', $q_text); } //Append hidden field for solution_id $q_text = $q_text . '<input type="hidden" id="" name="solution_id" value="' . $solution_id . '"/>'; } //Generate the question output $pl = $this->object->getPlugin(); $template = $pl->getTemplate("tpl.il_as_qpl_assVTQuestion_output.html"); $template->setVariable("QUESTIONTEXT", $q_text); $questionoutput = $template->get(); $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput); return $pageoutput; } } ?> |