├── .travis.yml ├── CHANGES.txt ├── README.txt ├── classes ├── mqxml2xhtml.xsl ├── mqxmlconverter.php ├── privacy │ └── provider.php └── xhtml2mqxml.xsl ├── db ├── install.php └── upgrade.php ├── format.php ├── lang └── en │ └── qformat_wordtable.php ├── tests └── qformat_wordtable_export_test.php └── version.php /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | os: linux 4 | dist: xenial 5 | 6 | services: 7 | - mysql 8 | - postgresql 9 | 10 | addons: 11 | firefox: "47.0.1" 12 | apt: 13 | packages: 14 | - openjdk-8-jre-headless 15 | - chromium-chromedriver 16 | 17 | cache: 18 | directories: 19 | - $HOME/.composer/cache 20 | - $HOME/.npm 21 | 22 | matrix: 23 | include: 24 | - php: 7.3 25 | env: 26 | - MOODLE_BRANCH=master 27 | - DB=mysqli 28 | 29 | - php: 7.3 30 | env: 31 | - MOODLE_BRANCH=MOODLE_38_STABLE 32 | - DB=pgsql 33 | - CHECK_GRUNT=yes 34 | 35 | - php: 7.2 36 | env: 37 | - MOODLE_BRANCH=MOODLE_37_STABLE 38 | - DB=mysqli 39 | 40 | - php: 7.1 41 | env: 42 | - MOODLE_BRANCH=MOODLE_36_STABLE 43 | - DB=pgsql 44 | - NODE=8.9 45 | 46 | before_install: 47 | - phpenv config-rm xdebug.ini 48 | 49 | - if [ -z $CHECK_GRUNT ]; then 50 | export CHECK_GRUNT=no; 51 | fi 52 | 53 | - if [ -z $NODE ]; then 54 | export NODE=14; 55 | fi 56 | - nvm install $NODE 57 | - nvm use $NODE 58 | 59 | - cd ../.. 60 | - composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2 61 | - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" 62 | 63 | install: 64 | - moodle-plugin-ci install 65 | 66 | script: 67 | - moodle-plugin-ci phplint 68 | - moodle-plugin-ci phpcpd 69 | - moodle-plugin-ci phpmd 70 | - moodle-plugin-ci codechecker 71 | - moodle-plugin-ci validate 72 | - moodle-plugin-ci savepoints 73 | - moodle-plugin-ci mustache 74 | - moodle-plugin-ci grunt || [ "$CHECK_GRUNT" = 'no' ] 75 | - moodle-plugin-ci phpunit 76 | - moodle-plugin-ci behat 77 | -------------------------------------------------------------------------------- /CHANGES.txt: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | Date Version Comment 4 | 2025/04/23 3.9.7 Relax Moodle version requirement back to 3.9, not 5.0, as uploadlib was obsolete then anyway. 5 | 2025/04/04 3.9.6 Remove dependency on uploadlib library. 6 | 2022/10/26 3.9.5 Fix bug in checking for versions before 3.11.6. 7 | 2022/04/05 3.9.4 Support file validation on import for Moodle 3.11.6 and higher. 8 | 2022/04/04 3.9.3 Support "Import questions" command in Lesson activity (thanks to drobayo for the code). 9 | 2021/08/31 3.9.2 Improve support for Lesson question imports. 10 | 2021/08/23 3.9.1 Fix dependency on Book Word converter. 11 | 2021/08/21 3.9.0 Use Book Word import wordconverter class for import/export of Word files. 12 | 2020/12/08 3.7.1 Add support for letter-groups in Select Missing Word questions. 13 | 2020/07/10 3.6.3 Stop leaving temporary files lying around. 14 | 2020/07/10 3.6.2 Add support for Office MML m:deg element, which caused an error. 15 | 2020/06/18 3.6.1 Add support for 'No online text' responses and accepted file types. 16 | 2019/07/15 3.6.0 Add support for optional ID number field in Moodle 3.6, plus small Missing Word type bug-fixes. 17 | 2018/08/03 3.5.23 Clean Moodle question type explanatory text XHTML exported to Word, for more robust operation. 18 | 2018/06/04 3.5.22 Support Privacy API for GDPR compliance. 19 | 2017/09/02 3.5.21 Fix handling of hints. 20 | 2017/08/31 3.5.20 Don't raise the memory limit for XSLT any more, fix roman uppercase numbering import bug. 21 | 2017/08/14 3.5.19 Handle list item duplication bug inside adjacent table cells 22 | 2017/08/06 3.5.18 Handle Bootstrap Alert components. 23 | 2017/05/21 3.5.17 Handle penalty value of 0% on multiple tries. 24 | 2017/04/17 3.5.16 Use canonical reference to temp directory, start using PHPStorm IDE. 25 | 2017/01/05 3.5.15 Fix error when handling empty table cells. 26 | 2016/12/16 3.5.14 Improve RTL language support again. 27 | 2016/11/14 3.5.13 Improve localisation by adding more strings for use in Word template, improve RTL language support. 28 | 2016/11/05 3.5.12 Fix Hebrew support for True/False question import. 29 | 2016/11/02 3.5.11 Replace "
" with "
" in the Moodle text strings used for exporting Word files (for Polish issue). 30 | 2016/10/31 3.5.10 Retain table border style, handle WMF images better, support pre-formatted text. 31 | 2016/09/09 3.5.9 Strip out OfficeMath revision control markup from Word 2010 files. 32 | 2016/09/08 3.5.8 Strip out VML/drawingML markup from Word 2010 files. 33 | 2016/06/12 3.5.7 Fix equation problem, improve table handling and Cloze question formatting. 34 | 2016/01/14 3.5.6 Add PHPUnit tests for exports, remove debugging. 35 | 2016/01/08 3.5.5 Fix incorrect conversion of Cloze text. 36 | 2016/01/05 3.5.4 Improve handling of exported images to avoid bookmark name clashes. 37 | 2016/01/05 3.5.3 Improve handling of adjacent bold/italic formatting when importing Cloze questions. 38 | 2015/12/30 3.5.2 Fix error in Cloze MC/SA subquestion import processing, and '--' in text in export processing. 39 | 2015/12/15 3.5.1 Fix error in non-ASCII characters and alignment when exporting questions. 40 | 2015/12/14 3.5.0 Support OU question types 'Drag and drop onto image,' 'Drag and drop markers', 41 | 'Drag and drop into text' and 'Select missing words', 42 | clean code to pass Travis codechecker. 43 | 2015/09/30 3.4.3 Support RTL equations in MathML conversion. 44 | 2015/09/24 3.4.2 Minimise empty attributes in Pass 1 of conversion. 45 | 2015/09/21 3.4.1 Handle unusual WordML markup (w:dir) in RTL (e.g. Arabic) text. 46 | 2015/09/21 3.4.0 Convert Microsoft Equation Editor equations into MathML for display by MathJax. 47 | 2015/09/16 3.3.2 Improve code formatting to comply better with Moodle guidelines. 48 | 2015/09/16 3.3.1 Support target attribute in hyperlinks to allow links to open in new window. 49 | 2015/09/01 3.3.0 Improve reliability of the question exports if question text content is badly formatted. 50 | 2015/08/19 3.2.2 Grab extra memory to allow very large Word files to be exported, handle HTML markup in exports better. 51 | 2015/08/04 3.2.1 Grab extra memory to allow very large Word files to be imported, 52 | fix Essay and All-or-Nothing question type issues. 53 | 2015/08/01 3.2.0 Support All-or-Nothing Multiple Choice import and export. 54 | 2015/07/27 3.1.11 Support question export for all built-in question types. 55 | 2015/07/25 3.1.10 Support question import in Lessons. 56 | 2015/07/17 3.1.9 Minor change to delete old and unused configuration values from config_plugins table. 57 | 2015/07/15 3.1.8 Improve export formatting to handle paragraph attributes better (alignment, etc.). 58 | 2015/07/13 3.1.7 On import, retain the size of images as defined within Word, and retain text alignment. 59 | 2015/07/04 3.1.6 Support the new 'Require text' field added to Essay questions in Moodle 2.9. 60 | 2015/07/03 3.1.5 Improve export of far-eastern languages like Chinese and Japanese. 61 | 2015/04/02 3.1.4 Fix text direction in non-Arabic Word templates, handle strikethrough better. 62 | 2015/03/11 3.1.3 Fix image handling, including external images not embedded in Word file, and hyperlinked images. 63 | 2015/03/03 3.1.2 Fix for Moodle 2.7/2.8 to improve handling of attachments in essay questions. 64 | 2015/03/03 3.1.1 Fix for Moodle 2.7/2.8 to enable question import, by deleting superfluous namespace attributes. 65 | 2015/03/02 3.1.0 Keep original uploaded Word file in debug mode. Fix handling of Cloze questions. 66 | Handle hyperlinks and other character formatting properly, support questions created 67 | in Word language versions other than English, fix Cloze questions. 68 | 2015/02/20 3.0.0 Support import of Word 2010 (.docx) documents, remove all question import limits, 69 | and use of an external conversion server. 70 | Also add support for tables and lists inside item components. 71 | 72 | 2014/10/08 2.10.1 Fix bug in handling of image filenames containing spaces. 73 | 2014/08/12 2.10 Support case-sensitivity and selection style and orientation in Cloze SA and MC subquestions. 74 | Support specification of default mark in Cloze questions. Fix merging of paragraphs. 75 | 2014/07/10 2.9.2 Fix syntax error in db/install.php. 76 | 2014/07/10 2.9.1 Fix error in registration process set-up, which prevented registration to set 10-question limit. 77 | 78 | 2014/06/17 2.9 Use default username and password for importing Word files to make Registration optional. 79 | Handle named numeric entities (e.g.  ) by converting them to numeric entities 80 | instead (i.e.  ) to avoid XSLT processing errors. 81 | 82 | 2014/05/12 2.8.5 Handle invalid 'complete="true"' attribute in images, fix loop through all CDATA 83 | sections, keep tr elements when cleaning HTML manually. 84 | 85 | 2014/05/07 2.8.4 Fix error in image handling in Moodle 1.9, add work-around to cope with XSLT 86 | idiosyncrasies that insert namespace declaration on wrong element, breaking the 87 | Word export facility. Fix mishandling of Hints in Short Answer export. 88 | 89 | 2014/05/04 2.8.3 Improve image handling to properly export any images used inside feedback text. 90 | 91 | 2014/05/03 2.8.2 Handle images with names that include spaces or other non-alphanumeric characters. 92 | 93 | 2014/05/02 2.8.1 CONTRIB-5028: clean up HTML markup better (using strip_tags) if the PHP tidy 94 | extension is not installed. 95 | 96 | 2014/04/28 2.8 Use the PHP tidy extension to ensure that any HTML inside CDATA sections is well-formed 97 | XHTML, otherwise Word export fails. 98 | 99 | 2014/02/27 2.7.1 Add Word export support for RTL languages such as Arabic and Hebrew. 100 | 101 | 2014/02/03 2.7 Add Word export support for languages other than English, using labels in the language 102 | of the users' current interface language selection. Also support new Moodle 2.x 103 | question features such as Hints and Tags. 104 | 105 | 2014/01/03 2.6 Add support for including any images used in questions exported into a Word file, in a 106 | two-stage process that also requires using a command in the Moodle2Word Word template to 107 | embed the encoded images into the file. 108 | 109 | 2013/12/20 2.5 Improve handling of CDATA text that includes HTML markup, and the Moodle 1.9 question 110 | textancillary image element. 111 | 112 | 2013/03/15 2.4 Improve handling of Cloze question formatting when exporting to Word format. 113 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | # Description 2 | Moodle2Word is a plugin that allows quiz questions to be exported from Moodle into a Word file. 3 | The Word file can then be used to quickly review large numbers of questions 4 | (either online or in print), or to prepare paper tests (where the answers and feedback are hidden). 5 | 6 | Moodle2Word also supports importing questions from structured tables in Word directly into the Moodle question bank. 7 | The tables support all the question components (stem, answer options, option-specific and general feedback, 8 | hints, tags and question meta-data such as penalties grades and other options), as well as embedded images. 9 | 10 | All the main question types except Numerical and Calculated questions are fully supported. 11 | Numerical and Calculated questions are exported, but cannot be imported. 12 | 13 | Some OU question types added to core in Moodle 3.0 are also supported: Drag and drop onto image, 14 | Drag and drop markers, Drag and drop into text and Select missing words. 15 | All-or-Nothing Multiple Choice is also supported. These additional question types all require that 16 | custom versions of the questions be installed to replace the defaults, however. 17 | 18 | The Cloze question syntax is particularly useful, as it does not require any knowledge of the 19 | arcane Moodle syntax; instead, use bold for drop-down menu items, and italic for fill-in text fields. 20 | 21 | # Language support 22 | Exported questions are labelled in the language of the current Moodle user interface, and the spell-check language is 23 | also set to the correct language. 24 | Similarly, questions can be imported in the same language, not just English. 25 | Both left-to-right and right-to-left languages (such as Arabic and Hebrew) are supported. 26 | 27 | # Supporting Word templates 28 | Word templates to support the plugin can be downloaded from the demonstration website 29 | www.Moodle2Word.net, and are available for Word 2003, 2007, 2010 and 2013 (Windows), 30 | and Word 2004 and 2011 (MacOSX). The Windows templates also support a simple question preview facility, 31 | as well as uploading questions from within Word. 32 | 33 | If questions contain images, then you need to install the Word template in order to be able to convert 34 | the images in exported questions into embedded images in Word, as they are not automatically visible. 35 | 36 | The Word templates are available in most major languages, including English, Spanish and Chinese. 37 | Templates for other languages can be easily added, so feel free to ask. 38 | -------------------------------------------------------------------------------- /classes/mqxml2xhtml.xsl: -------------------------------------------------------------------------------- 1 | 2 | 25 | 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 | 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 | <xsl:value-of select="concat($course_name, ', ', $category_label, $colon_string, ' ', $category)"/> 262 | 263 | 264 | 265 |

266 | 267 | 268 | 269 |
270 | 271 | 272 | 273 | 274 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 |

294 |
295 | 296 | 297 | 298 | 299 | 300 | CA 301 | CM 302 | CS 303 | CL 304 | DE 305 | ES 306 | MW 307 | MAT 308 | MA 309 | MC 310 | MS 311 | NUM 312 | SA 313 | TF 314 | DDI 315 | DDM 316 | DDT 317 | TF 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 1 342 | 343 | 344 | 345 | 346 | 347 | 0 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 | 100 384 | 50 385 | 33.3 386 | 25 387 | 20 388 | 10 389 | 0 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 | D 459 | 460 | 0 461 | 462 | 463 | 464 | 465 | 466 | 467 | 1 468 | 469 | 0 470 | 471 | 472 | 473 | 474 | 475 | 476 | 1 477 | 478 | 0 479 | 480 | 481 | 482 | 483 | 484 | 485 | 1 486 | 487 | 0 488 | 489 | 490 | 491 | 492 | 493 | 494 | 1 495 | 496 | 0 497 | 498 | 499 | 500 | 501 | 502 | 503 | 1 504 | 0 505 | 506 | 507 | 508 | 509 | V 510 | H 511 | D 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 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 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 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 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 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 867 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 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 | 955 | 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 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1147 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 |
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 |

601 |

602 | 603 |

604 | 605 | 606 | 607 |

633 |

634 | 635 |

636 |

651 |

652 | 653 |

654 |

662 |

663 | 664 |

665 |

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 |

736 |

737 | 738 | 739 | 740 | 741 | 15 742 | 743 |

744 |

752 |

753 | 754 | 755 | 756 | 757 | 0 758 | 759 |

760 |

776 |

777 | 778 | 779 | 780 | 781 | 0 782 | 783 |

784 |

792 |

793 | 794 | 795 | 796 | 797 | 798 | 799 |

800 |

837 | 838 | 839 | 840 | 841 | 842 | 843 |

858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 |

868 |

869 | 870 | 871 | 872 | 873 | 874 | 875 |

876 |

895 |

896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 |

905 |

939 | 940 | 941 |

942 |
943 | 944 | 945 | 946 | 947 |

948 |
949 | 950 | 951 |

952 |
953 |
954 |
956 | 957 | 958 |

959 |
960 | 961 | 962 | 963 | 964 |

965 |
966 | 967 | 968 |

969 |
970 |
971 |

#

#

1026 | 1027 | 1028 |

1029 |
1030 | 1031 | 1032 | 1033 |
1034 |

1046 | 1047 | 1048 |

1049 |
1050 | 1051 |
1052 |

1060 | 1061 | 1062 |

1063 |
1064 | 1065 |
1066 |

1077 | 1078 | 1079 |

1080 |
1081 | 1082 |
1083 |

1097 | 1098 |

1108 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 |

1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 |

1136 |

1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 |

1146 |

1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 |

1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 |

1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 |

1238 |

1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | , 1250 | 1251 | 1252 | 1253 | 1254 | 1255 |

1256 |

1264 | 1265 | 1266 |

1267 | 1268 |

1269 |
1270 | 1271 |

1272 |
1273 |
1274 | 1275 |

1282 |
1283 | 1284 |

1285 |
1286 | 1287 | 1288 | 1289 | 1290 | 1291 | 1292 | 1293 |

1294 | 1295 | 1296 | 1297 |

1298 |
1299 | 1300 |

1301 |
1302 | 1303 | 1304 | 1305 | 1306 |
1307 | 1308 |

1309 |

1310 | 1311 |
1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | MsoListNumber 1323 | 1324 | 1325 | Cell 1326 | 1327 | QFOption 1328 | 1329 | 1330 | 1331 | 1332 | 1333 | 1334 | 83.3 1335 | 66.6 1336 | 33.3 1337 | 16.6 1338 | 14.3 1339 | 11.1 1340 | -83.3 1341 | -66.6 1342 | -33.3 1343 | -16.6 1344 | -14.3 1345 | -11.1 1346 | 1347 | 1348 | 1349 | 1350 | 1351 | 1352 |

1353 | 1354 | 1355 |

1356 |
1357 | 1358 |
1359 |
1360 |
1361 | 1362 | 1363 | 1364 | 1365 |

1366 |

1367 |
1368 | 1369 |

1370 |

1371 |
1372 |
1373 | 1374 |
1375 | 1376 | 1377 | 1378 | 1379 | 1380 | 1381 | 1382 | 1383 | 1384 | 1385 | 1386 | 1387 | 1388 | 1389 | 1390 | 1391 | 1392 | 1393 | 1394 | 1395 | 1396 | 1397 | 1398 | 1399 | 1400 | 1401 | 1402 | 1403 | 1404 | 1405 | 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | 1415 | 1416 | 1417 | 1418 | 1419 | 1420 | 1421 | 1422 | 1423 | 1424 | 1425 | 1426 | 1427 | 1428 | 1429 | 1430 | 1431 | 1432 | 1433 | 1434 | 1435 | 1436 | 1437 | 1438 | 1439 | 1440 | 1441 | 1442 | 1443 | 1448 | 1449 | 1450 | 1451 | 1452 | 1453 | 1454 | 1455 | 1456 | 1457 | 1458 | 1459 | 1460 | 1461 | 1462 | 1463 | 1464 | 1465 | 1466 | 1467 | 1468 | 1469 | 1470 | 1471 | 1472 | 1473 | 1474 | 1475 | 1476 | 1477 | 1478 | 1479 | 1480 | 1481 | 1482 | 1483 | 1484 | 1485 | 1486 | 1487 | 1488 | 1489 | 1490 | 1491 | 1492 | 1493 | 1494 | 1495 | 1496 | 1497 | 1498 | 1499 | 1500 | 1501 | 1502 | 1503 | 1504 | 1505 | 1506 | 1507 | 1508 | 1509 | 1510 | 1511 | 1512 | 1513 | 1514 | 1515 | 1516 | 1517 | 1518 | 1519 | 1520 | 1521 | 1522 | 1523 | 1524 | 1525 | 1526 | 1527 | 1528 | 1529 | 1530 | 1531 | 1532 | 1533 | 1534 | 1535 | 1536 | 1537 | 1538 | 1539 | 1540 | 1541 | 1542 | 1543 | 1544 | 1545 | 1546 | 1547 | 1548 | 1549 | 1550 | 1551 | 1552 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1563 | 1564 | 1565 | 1566 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | 1581 | 1582 | 1583 | 1584 | 1585 | 1586 | 1587 | 1588 | 1589 | 1590 | 1591 | 1592 | 1593 | 1594 | 1595 | 1596 | 1597 | 1598 | 1599 | 1600 | 1601 | 1602 | 1603 | 1604 | 1605 | 1606 | 1607 | 1608 | 1609 | 1610 | 1611 | 1612 | 1613 | 1614 | 1615 | 1616 | 1617 | 1618 | 1619 | 1620 | 1621 | 1622 | 1623 | 1624 | 1625 | 1626 | 1627 | 1628 | 1629 | 1630 | 1631 | 1632 | 1633 | 1634 | 1635 | 1636 | 1637 | 1638 | 1639 | 1640 | 1641 | 1642 | 1643 | 1644 | 1645 | 1646 | 1647 | 1648 | 1649 | 1650 | 1651 | 1652 | 1653 | 1654 | 1655 | 1656 | 1657 | 1658 | 1659 | 1660 | 1661 | 1662 | 1663 | 1664 | 1665 | 1666 | 1667 | 1668 | 1669 | 1670 | 1671 | 1678 | 1679 | 1680 | 1681 | 1682 | 1683 | 1684 | 1685 | 1686 | 1687 | 1 1688 | 1689 | 1690 | 1691 | 1696 | 1697 | 1698 | 1699 | 1700 | 1701 | 1702 | 1703 | 1704 | 1705 | 1706 | 1707 | 1708 | 1709 | 1710 | 1711 | 1712 | 1713 | 1714 | 1715 | 1716 | 1717 | 1718 | 1719 | 1720 | 1721 | 1722 |

1723 |

1724 |

1725 |

1726 | 1727 | 1728 | 1729 | 1730 | 1731 |

1732 | 1733 |
1734 | 1735 | 1736 | 1737 | 1738 |

1739 |

1740 | 1741 |

1742 | 1743 | 1744 | 1745 | 1746 | 1747 | 1748 | 1749 | 1750 |

1751 | 1752 |

1753 | 1754 |
1755 | 1756 | 1757 | 1758 | 1759 |

1760 | 1761 |

1762 | 1763 | 1764 | 1765 | 1766 | 1767 | 1768 | 1769 | 1770 | 1771 | {normalize-space(text)} 1772 | 1773 | 1774 | 1775 | 1776 | 1777 | 1778 | 1779 | 1780 |

1781 | 1782 | 1783 |

1784 | 1785 | 1786 | 1787 | 1788 | 1789 | 1790 | 1791 | 1792 |

1793 | 1794 |

1795 | 1796 |
1797 | 1798 | 1799 | 1800 | 1801 |

1802 |

1803 |

1804 | 1805 |

1806 | 1807 | 1808 | 1809 | 1810 |

1811 | 1812 | 1813 |
1814 | 1815 | 1816 | 1817 |

1818 | 1819 |

1820 | 1821 | 1822 | 1823 | 1824 | 1825 | 1826 | 1827 | 1828 | 1829 | 1830 | 1831 | 1832 | 1833 | 1834 |

1835 | 1836 |

1837 |

1838 | 1839 |
1840 | 1841 | 1842 | 1843 |

1844 |

1845 |

1846 |

1847 | 1848 |
1849 | 1850 | 1851 | 1852 | 1853 | 1854 | 1855 | 1856 | 1857 | 1858 | 1859 | 1860 | 1861 | 1862 | 1863 | 1864 |
1865 | 1866 | 1867 | 1868 | 1869 | 1870 |
1871 |
1872 | 1873 | 1874 | 1875 | 1876 | 1877 | 1878 | 1879 | 1880 | 1881 | 1882 | 1883 | 1884 | 1885 | 1886 | 1887 | 1888 | 1889 | 1890 | 1891 | 1892 | 1893 | 1894 | 1895 | 1896 | 1897 | 1898 | 1899 | 1900 | 1901 | 1902 | 1903 | 1904 |
1905 | -------------------------------------------------------------------------------- /classes/mqxmlconverter.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Import/Export Moodle Question XML library. 19 | * 20 | * @package qformat_wordtable 21 | * @copyright 2021 Eoin Campbell 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | namespace qformat_wordtable; 26 | 27 | use booktool_wordimport\wordconverter; 28 | use moodle_exception; 29 | 30 | /** 31 | * Convert XHTML into XML and vice versa. 32 | * 33 | * Class to convert XHTML strings into Moodle Question XML (import), and convert Moodle Question XML into XHTML strings (export). 34 | */ 35 | class mqxmlconverter { 36 | /** @var string Stylesheet to export Moodle Question XML into XHTML */ 37 | private $mqxml2xhtmlstylesheet = __DIR__ . "/mqxml2xhtml.xsl"; 38 | 39 | /** @var string Stylesheet to import XHTML into question XML */ 40 | private $xhtml2mqxmlstylesheet = __DIR__ . "/xhtml2mqxml.xsl"; 41 | 42 | /** 43 | * Class constructor 44 | * 45 | * @param string $plugin Name of plugin module 46 | */ 47 | public function __construct(string $plugin = 'qformat_wordtable') { 48 | global $CFG, $USER, $COURSE; 49 | 50 | // Set common parameters for all XSLT transformations. 51 | $this->xsltparameters = [ 52 | 'course_id' => $COURSE->id, 53 | 'course_name' => $COURSE->fullname, 54 | 'author_name' => $USER->firstname . ' ' . $USER->lastname, 55 | 'moodle_country' => $USER->country, 56 | 'moodle_language' => current_language(), 57 | 'moodle_textdirection' => (right_to_left()) ? 'rtl' : 'ltr', 58 | 'moodle_release' => $CFG->release, // Moodle version, e.g. 3.5, 3.10. 59 | 'moodle_release_date' => substr($CFG->version, 0, 8), // The Moodle major version release date, for testing. 60 | 'moodle_url' => $CFG->wwwroot . "/", 61 | 'moodle_username' => $USER->username, 62 | 'imagehandling' => 'embedded', // Question banks are embedded, Lessons are referenced. 63 | 'heading1stylelevel' => 1, // Question banks are 1, Lessons should be overridden to 3. 64 | 'pluginname' => $plugin, 65 | 'debug_flag' => (debugging(null, DEBUG_DEVELOPER)) ? '1' : '0', 66 | ]; 67 | } 68 | 69 | /** 70 | * Convert XHTML into Moodle Question XML. 71 | * 72 | * @param string $xhtmldata XHTML-formatted content 73 | * @param string $imagedata Base64-encoded images 74 | * @param array $parameters Extra XSLT parameters, if any 75 | * @return string Processed XML content 76 | */ 77 | public function import(string $xhtmldata, string $imagedata, array $parameters = []) { 78 | global $CFG; 79 | 80 | // Set common parameters for all XSLT transformations. Note that the XSLT processor doesn't support $arguments. 81 | $this->xsltparameters = array_merge($this->xsltparameters, $parameters); 82 | 83 | // Check that the XSLT stylesheet exists. 84 | if (!file_exists($this->xhtml2mqxmlstylesheet)) { 85 | throw new \moodle_exception(get_string('stylesheetunavailable', 'qformat_wordtable', $this->xhtml2mqxmlstylesheet)); 86 | } 87 | 88 | // Merge and wrap all the required input data into a single string to simplify XSLT processing. 89 | $xhtmldata = "\n" . $xhtmldata . 90 | "\n" . $imagedata . "\n" . 91 | $this->get_question_labels() . "\n"; 92 | 93 | // Use the Book tool wordimport plugin to do the actual XSLT transformation. 94 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 95 | $mqxml = $word2xml->xsltransform($xhtmldata, $this->xhtml2mqxmlstylesheet); 96 | return $mqxml; 97 | } // End import function. 98 | 99 | /** 100 | * Export Moodle Question XML into Word-compatible XHTML 101 | * 102 | * This export function is for Question bank questions only, not for Lesson questions. 103 | * It exports all questions in a category. 104 | * 105 | * @param string $mqxml Moodle Question XML 106 | * @param string $imagehandling Embedded or encoded image data 107 | * @return string XHTML text 108 | */ 109 | public function export(string $mqxml, string $imagehandling = 'embedded') { 110 | $this->xsltparameters['exportimagehandling'] = $imagehandling; 111 | // Check that the XSLT stylesheet exists. 112 | if (!file_exists($this->mqxml2xhtmlstylesheet)) { 113 | throw new \moodle_exception(get_string('stylesheetunavailable', 'qformat_wordtable', $this->mqxml2xhtmlstylesheet)); 114 | } 115 | 116 | // Clean up the Question XML to ensure it is well-formed XML and won't break the XSLT processing. 117 | $mqxml = $this->clean_all_questions($mqxml); 118 | 119 | // Merge and wrap all the required input data into a single string to simplify XSLT processing. 120 | $moodlelabels = $this->get_question_labels(); 121 | $mqxml = "\n" . $mqxml . "\n" . $moodlelabels . "\n"; 122 | 123 | // Use the Book tool wordimport plugin to do the actual XSLT transformation. 124 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 125 | $xhtmldata = $word2xml->xsltransform($mqxml, $this->mqxml2xhtmlstylesheet); 126 | 127 | // Embed the XHTML tables into a Word-compatible template document with styling information, etc. 128 | $content = $word2xml->export($xhtmldata, $this->xsltparameters['pluginname'], $moodlelabels, 'embedded'); 129 | return $content; 130 | } // End export function. 131 | 132 | /** 133 | * Convert Moodle Question XML into generic XHTML 134 | * 135 | * This function converts a single Lesson question into generic XHTML. 136 | * 137 | * @param string $mqxml Moodle Question XML 138 | * @param string $imagehandling Embedded or encoded image data 139 | * @return string XHTML text 140 | */ 141 | public function convert_mqx2htm(string $mqxml, string $imagehandling = 'embedded') { 142 | $this->xsltparameters['exportimagehandling'] = $imagehandling; 143 | // Check that the XML to XHTML conversion XSLT stylesheet exists. 144 | if (!file_exists($this->mqxml2xhtmlstylesheet)) { 145 | throw new \moodle_exception(get_string('stylesheetunavailable', 'qformat_wordtable', $this->mqxml2xhtmlstylesheet)); 146 | } 147 | 148 | // Clean up the Question XML to ensure it is well-formed XML and won't break the XSLT processing. 149 | $mqxml = $this->clean_all_questions($mqxml); 150 | 151 | // Merge and wrap all the required input data into a single string to simplify XSLT processing. 152 | $moodlelabels = $this->get_core_question_labels(); 153 | $mqxml = "\n" . $mqxml . "\n" . $moodlelabels . "\n"; 154 | 155 | // Use the Book tool wordimport plugin to do the actual XSLT transformation. 156 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 157 | $xhtmldata = $word2xml->xsltransform($mqxml, $this->mqxml2xhtmlstylesheet, $this->xsltparameters); 158 | $matches = null; 159 | if (preg_match('/]*>(.+)<\/div>/is', $xhtmldata, $matches)) { 160 | $xhtmldata = $matches[1]; 161 | } 162 | return $xhtmldata; 163 | } // End convert_mqx2htm function. 164 | 165 | /** 166 | * Convert a question in a generic XHTML table into Moodle Question XML 167 | * 168 | * This function converts a single XHTML question table into a question. 169 | * 170 | * @param string $xhtmltable Question table 171 | * @param string $imagehandling Embedded or encoded image data 172 | * @return string XHTML text 173 | */ 174 | public function convert_htm2mqx(string $xhtmltable, string $imagehandling = 'referenced') { 175 | $this->xsltparameters['imagehandling'] = $imagehandling; 176 | // Check that the XML to XHTML conversion XSLT stylesheet exists. 177 | if (!file_exists($this->xhtml2mqxmlstylesheet)) { 178 | throw new \moodle_exception(get_string('stylesheetunavailable', 'qformat_wordtable', $this->xhtml2mqxmlstylesheet)); 179 | } 180 | 181 | // Merge and wrap all the required input data into a single string to simplify XSLT processing. 182 | $moodlelabels = $this->get_core_question_labels(); 183 | $xhtmltable = "\n" . $xhtmltable . "\n" . 184 | $moodlelabels . "\n"; 185 | 186 | // Use the Book tool wordimport plugin to do the actual XSLT transformation. 187 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 188 | $mqxml = $word2xml->xsltransform($xhtmltable, $this->xhtml2mqxmlstylesheet, $this->xsltparameters); 189 | return $mqxml; 190 | } // End convert_htm2mqx function. 191 | 192 | /** 193 | * Get the core question text strings needed to fill in table labels 194 | * 195 | * A string containing XML data, populated from the language folders, is returned 196 | * 197 | * @return string 198 | */ 199 | public function get_core_question_labels() { 200 | global $CFG; 201 | 202 | // Release-independent list of all strings required in the XSLT stylesheets for labels etc. 203 | $textstrings = [ 204 | 'grades' => ['item'], 205 | 'moodle' => ['categoryname', 'no', 'yes', 'feedback', 'format', 'formathtml', 'formatmarkdown', 206 | 'formatplain', 'formattext', 'gradenoun', 'question', 'tags'], 207 | 'qformat_wordtable' => ['cloze_instructions', 'cloze_distractor_column_label', 'cloze_feedback_column_label', 208 | 'cloze_mcformat_label', 'description_instructions', 'essay_instructions', 209 | 'interface_language_mismatch', 'multichoice_instructions', 'truefalse_instructions', 210 | 'transformationfailed', 'unsupported_instructions'], 211 | 'qtype_description' => ['pluginnamesummary'], 212 | 'qtype_ddimageortext' => ['pluginnamesummary', 'bgimage', 'dropbackground', 'dropzoneheader', 213 | 'draggableitem', 'infinite', 'label', 'shuffleimages', 'xleft', 'ytop'], 214 | 'qtype_ddmarker' => ['pluginnamesummary', 'bgimage', 'clearwrongparts', 'coords', 215 | 'dropbackground', 'dropzoneheader', 'infinite', 'marker', 'noofdrags', 'shape_circle', 216 | 'shape_polygon', 'shape_rectangle', 'shape', 'showmisplaced', 'stateincorrectlyplaced'], 217 | 'qtype_ddwtos' => ['pluginnamesummary', 'infinite'], 218 | 'qtype_essay' => ['acceptedfiletypes', 'allowattachments', 'attachmentsrequired', 'formatnoinline', 219 | 'graderinfo', 'formateditor', 'formateditorfilepicker', 220 | 'formatmonospaced', 'formatplain', 'pluginnamesummary', 'responsefieldlines', 'responseformat', 221 | 'responseisrequired', 'responsenotrequired', 222 | 'responserequired', 'responsetemplate', 'responsetemplate_help'], 223 | 'qtype_gapselect' => ['pluginnamesummary', 'errornoslots', 'group', 'shuffle'], 224 | 'qtype_match' => ['blanksforxmorequestions', 'filloutthreeqsandtwoas'], 225 | 'qtype_multichoice' => ['answernumbering', 'choiceno', 'correctfeedback', 'incorrectfeedback', 226 | 'partiallycorrectfeedback', 'pluginnamesummary', 'shuffleanswers'], 227 | 'qtype_shortanswer' => ['casesensitive', 'filloutoneanswer'], 228 | 'qtype_truefalse' => ['false', 'true'], 229 | 'question' => ['addmorechoiceblanks', 'category', 'clearwrongparts', 'correctfeedbackdefault', 230 | 'defaultmark', 'generalfeedback', 'hintn', 'hintnoptions', 'idnumber', 231 | 'incorrectfeedbackdefault', 'partiallycorrectfeedbackdefault', 232 | 'penaltyforeachincorrecttry', 'questioncategory', 'shownumpartscorrect', 233 | 'shownumpartscorrectwhenfinished'], 234 | 'quiz' => ['answer', 'answers', 'casesensitive', 'correct', 'correctanswers', 235 | 'defaultgrade', 'incorrect', 'shuffle'], 236 | ]; 237 | 238 | // Get the question type field labels, to populate table cell labels on export, recognise cell labels on import. 239 | $questionlabels = "\n"; 240 | foreach ($textstrings as $typegroup => $grouparray) { 241 | foreach ($grouparray as $stringid) { 242 | // Use 'grade' instead of 'gradenoun' in Moodle versions prior to 3.11.6. 243 | if ($CFG->version < 2021051706 && $stringid === 'gradenoun') { 244 | $labeltext = get_string('grade', 'moodle'); 245 | } else { 246 | $labeltext = get_string($stringid, $typegroup); 247 | } 248 | $namestring = $typegroup . '_' . $stringid; 249 | $questionlabels .= '' . $labeltext . "\n"; 250 | } 251 | } 252 | $questionlabels .= ""; 253 | 254 | // Ensure the XML is well-formed, as the standard label and help text strings may have been overridden on some sites. 255 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 256 | $questionlabels = $word2xml->convert_to_xml($questionlabels); 257 | $questionlabels = str_replace("
", "
", $questionlabels); 258 | 259 | return $questionlabels; 260 | } 261 | 262 | /** 263 | * Get the core and contributed question text strings needed to fill in table labels 264 | * 265 | * A string containing XML data, populated from the language folders, is returned. 266 | * We need to split core from contributed questions to support the Core questions in Lessons. 267 | * 268 | * @return string 269 | */ 270 | private function get_question_labels() { 271 | global $CFG; 272 | 273 | // Get the core question labels first. 274 | $questionlabels = $this->get_core_question_labels(); 275 | 276 | // Append All-or-Nothing MCQ question type strings if present. 277 | if (\question_bank::is_qtype_installed('multichoiceset')) { 278 | // Strip out the closing element first so that we can insert the extra labels. 279 | $questionlabels = str_replace("", "", $questionlabels); 280 | 281 | $textstrings['qtype_multichoiceset'] = ['pluginnamesummary', 'showeachanswerfeedback']; 282 | foreach ($textstrings as $typegroup => $grouparray) { 283 | foreach ($grouparray as $stringid) { 284 | $namestring = $typegroup . '_' . $stringid; 285 | // Get the question type field label text. 286 | $labeltext = get_string($stringid, $typegroup); 287 | $questionlabels .= '' . $labeltext . "\n"; 288 | } 289 | } 290 | $questionlabels .= ""; 291 | } 292 | 293 | // Ensure the XML is well-formed, as the standard label and help text strings may have been overridden on some sites. 294 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 295 | $questionlabels = $word2xml->convert_to_xml($questionlabels); 296 | $questionlabels = str_replace("
", "
", $questionlabels); 297 | 298 | return $questionlabels; 299 | } 300 | 301 | /** 302 | * Clean HTML markup inside question text element content 303 | * 304 | * A string containing Moodle Question XML with clean HTML inside the text elements is returned. 305 | * 306 | * @param string $questionxmlstring Question XML text 307 | * @return string 308 | */ 309 | private function clean_all_questions($questionxmlstring) { 310 | // Start assembling the cleaned output string, starting with empty. 311 | $cleanquestionxml = ""; 312 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 313 | 314 | // Split the string into questions in order to check the text fields for clean HTML. 315 | $foundquestions = preg_match_all('~(.*?)]*>(.*?)~s', $questionxmlstring, 316 | $questionmatches, PREG_SET_ORDER); 317 | $numquestions = count($questionmatches); 318 | if ($foundquestions === false || $foundquestions == 0) { 319 | return $questionxmlstring; 320 | } 321 | 322 | // Split the questions into text strings to check the HTML. 323 | for ($i = 0; $i < $numquestions; $i++) { 324 | $qtype = $questionmatches[$i][2]; 325 | $questioncontent = $questionmatches[$i][3]; 326 | // Split the question into chunks at CDATA boundaries, using ungreedy (?) and matching across newlines (s modifier). 327 | $foundcdatasections = preg_match_all('~(.*?)<\!\[CDATA\[(.*?)\]\]>~s', $questioncontent, $cdatamatches, PREG_SET_ORDER); 328 | if ($foundcdatasections === false) { 329 | $cleanquestionxml .= $questionmatches[$i][0]; 330 | } else if ($foundcdatasections != 0) { 331 | $numcdatasections = count($cdatamatches); 332 | // Found CDATA sections, so first add the question start tag and then process the body. 333 | $cleanquestionxml .= ''; 334 | 335 | // Process content of each CDATA section to clean the HTML. 336 | for ($j = 0; $j < $numcdatasections; $j++) { 337 | $cleancdatacontent = $word2xml->clean_html_text($cdatamatches[$j][2]); 338 | 339 | // Add all the text before the first CDATA start boundary, and the cleaned string, to the output string. 340 | $cleanquestionxml .= $cdatamatches[$j][1] . ''; 341 | } // End CDATA section loop. 342 | 343 | // Add the text after the last CDATA section closing delimiter. 344 | $textafterlastcdata = substr($questionmatches[$i][0], strrpos($questionmatches[$i][0], "]]>") + 3); 345 | $cleanquestionxml .= $textafterlastcdata; 346 | } else { 347 | $cleanquestionxml .= $questionmatches[$i][0]; 348 | } 349 | } // End question element loop. 350 | 351 | return $cleanquestionxml; 352 | } 353 | } 354 | -------------------------------------------------------------------------------- /classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Privacy Subsystem implementation for qformat_wordtable. 19 | * 20 | * @package qformat_wordtable 21 | * @copyright 2018 Eoin Campbell 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | namespace qformat_wordtable\privacy; 26 | 27 | /** 28 | * Privacy Subsystem for qformat_wordtable implementing null_provider. 29 | * 30 | * @copyright 2018 Eoin Campbell 31 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 | */ 33 | class provider implements \core_privacy\local\metadata\null_provider { 34 | 35 | /** 36 | * Get the language string identifier with the component's language 37 | * file to explain why this plugin stores no data. 38 | * 39 | * @return string 40 | */ 41 | public static function get_reason(): string { 42 | return 'privacy:metadata'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /db/install.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Post-install script for manual graded question behaviour. 19 | * @package qformat_wordtable 20 | * @copyright 2014 Eoin Campbell 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | /** 25 | * Post-install script 26 | */ 27 | function xmldb_qformat_wordtable_install() { 28 | // Don't add anything to the plugins configuration table. 29 | } 30 | -------------------------------------------------------------------------------- /db/upgrade.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Short-answer question type upgrade code. 19 | * 20 | * @package qformat_wordtable 21 | * @copyright 2014 Eoin Campbell 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | /** 26 | * Upgrade code for the wordtable question format. 27 | * @param int $oldversion the version we are upgrading from. 28 | */ 29 | function xmldb_qformat_wordtable_upgrade($oldversion) { 30 | 31 | if (get_config('converter_url', 'qformat_wordtable') !== false) { 32 | unset_config('converter_url', 'qformat_wordtable'); 33 | unset_config('registration_url', 'qformat_wordtable'); 34 | unset_config('username', 'qformat_wordtable'); 35 | unset_config('password', 'qformat_wordtable'); 36 | } 37 | 38 | return true; 39 | } 40 | -------------------------------------------------------------------------------- /format.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Convert Word tables into Moodle Question XML format 19 | * 20 | * The wordtable class inherits from the XML question import class, rather than the 21 | * default question format class, as this minimises code duplication. 22 | * 23 | * This code converts quiz questions between structured Word tables and Moodle 24 | * Question XML format. 25 | * 26 | * The export facility also converts questions into Word files using an XSLT script 27 | * and an XSLT processor. The Word files are really just XHTML files with some 28 | * extra markup to get Word to open them and apply styles and formatting properly. 29 | * 30 | * @package qformat_wordtable 31 | * @copyright 2010-2021 Eoin Campbell 32 | * @author Eoin Campbell 33 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5) 34 | */ 35 | 36 | defined('MOODLE_INTERNAL') || die(); 37 | 38 | require_once("$CFG->libdir/xmlize.php"); 39 | 40 | // Development: turn on all debug messages and strict warnings. 41 | // The wordtable plugin just extends XML import/export. 42 | require_once("$CFG->dirroot/question/format/xml/format.php"); 43 | 44 | // Include Book tool Word import plugin wordconverter class and utility functions. 45 | use booktool_wordimport\wordconverter; 46 | use qformat_wordtable\mqxmlconverter; 47 | 48 | /** 49 | * Importer for Microsoft Word table question format. 50 | * 51 | * See {@link https://docs.moodle.org/en/Word_table_format} for a description of the format. 52 | * 53 | * @copyright 2010-2021 Eoin Campbell 54 | * @author Eoin Campbell 55 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5) 56 | */ 57 | class qformat_wordtable extends qformat_xml { 58 | /** @var array Overrides to default XSLT parameters used for conversion */ 59 | private $xsltparameters = ['pluginname' => 'qformat_wordtable', 60 | 'heading1stylelevel' => 1, // Map "Heading 1" style to

element. 61 | 'imagehandling' => 'embedded', // Embed image data directly into the generated Moodle Question XML. 62 | ]; 63 | /** @var array Lesson questions are stored here if importing a lesson Word file. */ 64 | private $lessonquestions = []; 65 | 66 | /** 67 | * Define required MIME-Type 68 | * 69 | * @return string MIME-Type 70 | */ 71 | public function mime_type() { 72 | return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; 73 | } 74 | 75 | /** 76 | * Validate the given file. 77 | * 78 | * Check that the file has a .docx suffix, should also check it's in Zip file format. 79 | * 80 | * @param stored_file $file the file to check 81 | * @return string the error message that occurred while validating the given file 82 | */ 83 | public function validate_file(stored_file $file): string { 84 | if (!preg_match('#\.docx$#i', $file->get_filename())) { 85 | return get_string('errorfilenamemustbedocx', 'qformat_wordtable'); 86 | } 87 | return ''; 88 | } 89 | 90 | // IMPORT FUNCTIONS START HERE. 91 | 92 | /** 93 | * Perform required pre-processing, i.e. convert Word file into Moodle Question XML 94 | * 95 | * Extract the WordProcessingML XML files from the .docx file, and use a sequence of XSLT 96 | * steps to convert it into Moodle Question XML 97 | * 98 | * @return bool Success 99 | */ 100 | public function importpreprocess() { 101 | global $CFG; 102 | $realfilename = ""; 103 | $filename = ""; 104 | 105 | // Handle question imports in Lesson module by using mform, not the question/format.php qformat_default class. 106 | if (property_exists('qformat_default', 'realfilename')) { 107 | $realfilename = $this->realfilename; 108 | } else { 109 | global $mform; 110 | $realfilename = $mform->get_new_filename('questionfile'); 111 | } 112 | if (property_exists('qformat_default', 'filename')) { 113 | $filename = $this->filename; 114 | } else { 115 | global $mform, $USER; 116 | 117 | if (property_exists('qformat_default', 'importcontext')) { 118 | // We have to check if this request is made from the lesson interface. 119 | $cm = get_coursemodule_from_id('lesson', $this->importcontext->instanceid); 120 | if ($cm) { 121 | $draftid = optional_param('questionfile', '', PARAM_FILE); 122 | $dir = make_temp_directory('forms'); 123 | $tempfile = tempnam($dir, 'tempup_'); 124 | 125 | $fs = get_file_storage(); 126 | $context = context_user::instance($USER->id); 127 | if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { 128 | throw new \moodle_exception(get_string('cannotwritetotempfile', 'qformat_wordtable', '')); 129 | } 130 | $file = reset($files); 131 | 132 | $filename = $file->copy_content_to($tempfile); 133 | $filename = $tempfile; 134 | } else { 135 | $filename = "{$CFG->tempdir}/questionimport/{$realfilename}"; 136 | } 137 | } else { 138 | $filename = "{$CFG->tempdir}/questionimport/{$realfilename}"; 139 | } 140 | } 141 | $basefilename = basename($filename); 142 | $baserealfilename = basename($realfilename); 143 | 144 | // Check that the file is in Word 2010 format, not HTML, XML, or Word 2003. 145 | if ((substr($realfilename, -3, 3) == 'doc')) { 146 | throw new \moodle_exception(get_string('docnotsupported', 'qformat_wordtable', $baserealfilename)); 147 | return false; 148 | } else if ((substr($realfilename, -3, 3) == 'xml')) { 149 | throw new \moodle_exception(get_string('xmlnotsupported', 'qformat_wordtable', $baserealfilename)); 150 | return false; 151 | } else if ((stripos($realfilename, 'htm'))) { 152 | throw new \moodle_exception(get_string('htmlnotsupported', 'qformat_wordtable', $baserealfilename)); 153 | return false; 154 | } else if ((stripos(file_get_contents($filename, 0, null, 0, 100), 'html'))) { 155 | throw new \moodle_exception(get_string('htmldocnotsupported', 'qformat_wordtable', $baserealfilename)); 156 | return false; 157 | } 158 | 159 | // Import the Word file into XHTML and an array of images. 160 | $imagesforzipping = []; 161 | $word2xml = new wordconverter($this->xsltparameters['pluginname']); 162 | $word2xml->set_heading1styleoffset($this->xsltparameters['heading1stylelevel']); 163 | $word2xml->set_imagehandling($this->xsltparameters['imagehandling']); 164 | $xhtmldata = $word2xml->import($filename, $imagesforzipping, true); 165 | 166 | // Convert the returned array of images, if any, into a string. 167 | $imagestring = ""; 168 | foreach ($imagesforzipping as $imagename => $imagedata) { 169 | $filetype = strtolower(pathinfo($imagename, PATHINFO_EXTENSION)); 170 | $base64data = base64_encode($imagedata); 171 | $filedata = 'data:image/' . $filetype . ';base64,' . $base64data; 172 | // Embed the image name and data into the HTML. 173 | $imagestring .= ''; 174 | } 175 | 176 | // Convert XHTML into Moodle Question XML. 177 | $xhtml2mqxml = new mqxmlconverter($this->xsltparameters['pluginname']); 178 | $mqxmldata = $xhtml2mqxml->import($xhtmldata, $imagestring, $this->xsltparameters); 179 | 180 | if ((strpos($mqxmldata, "") === false)) { 181 | throw new \moodle_exception(get_string('noquestionsinfile', 'question')); 182 | } 183 | 184 | // Now over-write the original Word file with the XML file, so that default XML file handling will work. 185 | if (($fp = fopen($filename, "wb"))) { 186 | if (($nbytes = fwrite($fp, $mqxmldata)) == 0) { 187 | throw new moodle_exception(get_string('cannotwritetotempfile', 'qformat_wordtable', $basefilename)); 188 | } 189 | fclose($fp); 190 | } 191 | 192 | // This part of the code is a copy of "readdata" function developed in format.php question/import.php 193 | // and mod/lesson/import.php, to return the structure of the file. 194 | // This patch is required because the lesson logic file uses its own file that it consumes in the form 195 | // and does not do so like question import which shares a file at the class level. 196 | if (is_readable($filename) && isset($cm)) { 197 | $filearray = file($filename); 198 | // Check for Macintosh OS line returns (ie file on one line), and fix. 199 | if (preg_match("/\r/", $filearray[0]) && !preg_match("/\n/", $filearray[0])) { 200 | $this->lessonquestions = explode("\r", $filearray[0]); 201 | } else { 202 | $this->lessonquestions = $filearray; 203 | } 204 | } 205 | 206 | return true; 207 | } // End importpreprocess function. 208 | 209 | // EXPORT FUNCTIONS START HERE. 210 | 211 | /** 212 | * Use a .doc file extension when exporting, so that Word is used to open the file 213 | * @return string file extension 214 | */ 215 | public function export_file_extension() { 216 | return ".doc"; 217 | } 218 | 219 | /** 220 | * Convert the Moodle Question XML into Word-compatible XHTML format 221 | * just prior to the file being saved 222 | * 223 | * Use an XSLT script to do the job, as it is much easier to implement this, 224 | * and Moodle sites are guaranteed to have an XSLT processor available (I think). 225 | * 226 | * @param string $content Question XML text 227 | * @return string Word-compatible XHTML text 228 | */ 229 | public function presave_process($content) { 230 | // Check that there are questions to convert. 231 | if (strpos($content, "") === false) { 232 | throw new moodle_exception(get_string('noquestions', 'qformat_wordtable')); 233 | return $content; 234 | } 235 | 236 | // Convert the Moodle Question XML into Word-compatible XHTML. 237 | $mqxml2xhtml = new mqxmlconverter($this->xsltparameters['pluginname']); 238 | $xhtmldata = $mqxml2xhtml->export($content, $this->xsltparameters['pluginname'], $this->xsltparameters['imagehandling']); 239 | return $xhtmldata; 240 | } // End presave_process function. 241 | 242 | /** 243 | * Return content of all files containing questions as an array with one element for each file found, 244 | * For each file, the corresponding element is an array of lines. 245 | * 246 | * @param string $filename name of file 247 | * @return mixed array of content if successful, false on failure 248 | */ 249 | public function readdata($filename) { 250 | 251 | if (property_exists('qformat_default', 'importcontext')) { 252 | // We have to check if this request is made from the lesson interface. 253 | $cm = get_coursemodule_from_id('lesson', $this->importcontext->instanceid); 254 | if ($cm) { 255 | // Since we have already developed the logic of this file above, we only need to return the result. 256 | return $this->lessonquestions; 257 | } else { 258 | // In case it is not a lesson request then we must return the core solution. 259 | return parent::readdata($filename); 260 | } 261 | } else { 262 | // In case it is not a lesson request then we must return the core solution. 263 | return parent::readdata($filename); 264 | } 265 | 266 | return false; 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /lang/en/qformat_wordtable.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Strings for component 'qformat_wordtable', language 'en', branch 'MOODLE_20_STABLE' 19 | * 20 | * @package qformat_wordtable 21 | * @copyright 2010-2021 Eoin Campbell 22 | * @author Eoin Campbell 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5) 24 | */ 25 | 26 | // Strings used in format.php. 27 | 28 | 29 | $string['cannotopentempfile'] = 'Cannot open temporary file {$a}'; 30 | $string['cannotreadzippedfile'] = 'Cannot read Zipped file {$a}'; 31 | $string['cannotwritetotempfile'] = 'Cannot write to temporary file {$a}'; 32 | $string['cloze_distractor_column_label'] = 'Distractors'; 33 | $string['cloze_feedback_column_label'] = 'Distractor Feedback'; 34 | $string['cloze_instructions'] = 'Use bold for Multichoice, italic for Short Answer, and Underline for Numerical questions.'; 35 | $string['cloze_mcformat_label'] = 'Orientation (D = dropdown; V = vertical, H = horizontal radio buttons)'; 36 | $string['description_instructions'] = 'This is not actually a question. Instead it is a way to add some instructions, rubric or other content to the activity. This is similar to the way that labels can be used to add content to the course page.'; 37 | $string['docnotsupported'] = 'Files in Word 2003 format not supported: {$a}, use Moodle2Word 3.x instead'; 38 | $string['essay_instructions'] = 'Allows a response of a few sentences or paragraphs. This must then be graded manually.'; 39 | $string['htmldocnotsupported'] = 'Incorrect Word format: please use File>Save As... to save {$a} in native Word 2010 (.docx) format and import again'; 40 | $string['htmlnotsupported'] = 'Files in HTML format not supported: {$a}'; 41 | $string['interface_language_mismatch'] = 'No questions imported because the language of the labels in the Word file does not match your current Moodle interface language.'; 42 | $string['multichoice_instructions'] = 'Allows the selection of a single or multiple responses from a pre-defined list.'; 43 | $string['noquestions'] = 'No questions to export'; 44 | $string['pluginname'] = 'Microsoft Word 2010 table format (wordtable)'; 45 | $string['pluginname_help'] = 'This is a front-end for converting Microsoft Word 2010 files into Moodle Question XML format for import, and converting Moodle Question XML format into a format suitable for editing in Microsoft Word.'; 46 | $string['pluginname_link'] = 'qformat/wordtable'; 47 | $string['preview_question_not_found'] = 'Preview question not found, name / course ID: {$a}'; 48 | $string['privacy:metadata'] = 'The WordTable question format plugin does not store any personal data.'; 49 | $string['stylesheetunavailable'] = 'XSLT Stylesheet {$a} is not available'; 50 | $string['transformationfailed'] = 'XSLT transformation failed ({$a})'; 51 | $string['truefalse_instructions'] = 'Set grade \'100\' to the correct answer.'; 52 | $string['unsupported_instructions'] = 'Importing this question type is not supported.'; 53 | $string['word_about_moodle2word'] = 'About Moodle2Word'; 54 | $string['word_about_moodle2word_screentip'] = 'About the Moodle2Word Word templates and Moodle plug-in'; 55 | $string['word_addcategory_supertip'] = 'Category names use the Heading 1 style'; 56 | $string['word_currentquestion'] = ' (Current Question)'; 57 | $string['word_gapselect_screentip'] = 'Warning: customised Select missing words Moodle plugin required for this question type.'; 58 | $string['word_import'] = 'Import'; 59 | $string['word_multiple_answer'] = 'Multiple answer'; 60 | $string['word_new_question_file'] = 'New Question File'; 61 | $string['word_new_question_file_screentip'] = 'Questions must be saved in Word 2010 (.docx) format'; 62 | $string['word_new_question_file_supertip'] = 'Each Word file may contain multiple categories'; 63 | $string['word_setunset_assessment_view'] = 'Set/Unset Assessment View'; 64 | $string['word_showhide_assessment_screentip'] = 'Show question metadata to edit, hide to preview printed assessment'; 65 | $string['word_showhide_assessment_supertip'] = 'Shows or hides the hidden text'; 66 | $string['word_showhide_assessment_view'] = 'Show/Hide Assessment View'; 67 | $string['word_shuffle_screentip'] = 'Shuffle the answers to MCQ/TF/MA questions'; 68 | $string['word_shuffle_supertip'] = 'A few shuffles is better than 1'; 69 | $string['word_view'] = 'View'; 70 | $string['wordtable'] = 'Microsoft Word 2010 table format (wordtable)'; 71 | $string['wordtable_help'] = 'This is a front-end for converting Microsoft Word 2010 files into Moodle Question XML format for import, and converting Moodle Question XML format into an enhanced XHTML format for exporting into a format suitable for editing in Microsoft Word.'; 72 | $string['xmlnotsupported'] = 'Files in XML format not supported: {$a}'; 73 | $string['xsltunavailable'] = 'You need the XSLT library installed in PHP to save this Word file'; 74 | -------------------------------------------------------------------------------- /tests/qformat_wordtable_export_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Unit tests for the Moodle WordTable format. 19 | * 20 | * @package qformat_wordtable 21 | * @copyright 2016 Eoin Campbell 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | global $CFG; 29 | require_once($CFG->libdir . '/questionlib.php'); 30 | require_once($CFG->dirroot . '/question/format/xml/format.php'); 31 | require_once($CFG->dirroot . '/question/format/wordtable/format.php'); 32 | require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); 33 | require_once($CFG->dirroot . '/question/format/xml/tests/xmlformat_test.php'); 34 | require_once($CFG->dirroot . '/tag/lib.php'); 35 | 36 | namespace qformat_wordtable 37 | 38 | /** 39 | * Unit tests for exporting questions into Word (via XML). 40 | * 41 | * Each test has a question in XML format, which is converted to HTML using 42 | * the qformat_wordtable::presave_process method, and then compared to the expected output. 43 | * @copyright 2016 Eoin Campbell 44 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 45 | * @group qformat_wordtable 46 | */ 47 | final class qformat_wordtable_export_test extends question_testcase { 48 | 49 | /** 50 | * Test if the exported HTML output is the same as the expected HTML (ignoring newlines). 51 | * 52 | * @param string $expectedhtml as defined. 53 | * @param string $html as returned by presave_process. 54 | */ 55 | public function assert_same_html($expectedhtml, $html): void { 56 | // Only test the question content, assuming a single question. 57 | $html = substr($html, strpos($html, '

assertEquals($expectedhtml, $html); 64 | } 65 | 66 | /** 67 | * Test if the exported HTML for a Description question matches the expected output. 68 | */ 69 | public function test_export_description(): void { 70 | $descriptionxml = ' 71 | 72 | A description 73 | 74 | 75 | The question text. 76 | 77 | 78 | Here is some general feedback. 79 | 80 | 0 81 | 0 82 | 0 83 | '; 84 | 85 | $expectedhtml = '

A description

' . 86 | '

87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 112 | 113 |
The question text.

DE

ID number:

Tags:

' . 109 | 'This is not actually a question. ' . 110 | 'Instead it is a way to add some instructions, rubric or other content to the activity. ' . 111 | 'This is similar to the way that labels can be used to add content to the course page.

114 | 115 | 116 | 117 | 118 | '; 119 | $this->resetAfterTest(true); 120 | $this->setGuestUser(); 121 | $exporter = new qformat_wordtable(); 122 | $html = $exporter->presave_process($descriptionxml); 123 | 124 | $this->assert_same_html($expectedhtml, $html); 125 | } 126 | 127 | 128 | /** 129 | * Test if the exported HTML for an Essay question matches the expected output. 130 | */ 131 | public function test_export_essay29(): void { 132 | $descriptionxml = ' 133 | Moodle 2.9 Essay Question 134 | 135 | Essay question text.

]]>
136 |
137 | 138 | General Feedback led the charge

]]>
139 |
140 | 1.0000000 141 | 0.0000000 142 | 0 143 | editor 144 | 15 145 | 1 146 | 147 | Grader information. 148 | 149 | 150 | Optional response template. 151 | 152 |
'; 153 | 154 | $expectedhtml = '

Moodle 2.9 Essay Question

' . 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 |

Essay question text.

ES

Default mark:

1

Response format:

HTML editor

Require text:

Yes

Input box size:

15

Allow attachments:

1

Require attachments:

0

Accepted file types:

ID number:

Response template

Information for graders

Optional response template.

Grader information.

General feedback:

General Feedback led the charge

Tags:

Allows a response of a file upload and/or online text. This must then be graded manually.

210 | 211 | 212 | 213 | 214 | '; 215 | $this->resetAfterTest(true); 216 | $this->setGuestUser(); 217 | $exporter = new qformat_wordtable(); 218 | $html = $exporter->presave_process($descriptionxml); 219 | 220 | $this->assert_same_html($expectedhtml, $html); 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Word table question import format 19 | * 20 | * This fragment is called by moodle_needs_upgrading() and /admin/index.php 21 | * 22 | * @package qformat_wordtable 23 | * @copyright 2010-2021 Eoin Campbell 24 | * @author Eoin Campbell 25 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5) 26 | **/ 27 | 28 | 29 | defined('MOODLE_INTERNAL') || die(); 30 | 31 | $plugin->version = 2025042400; // The current plugin version (Date: YYYYMMDDXX). 32 | $plugin->maturity = MATURITY_STABLE; // Maturity level. 33 | $plugin->component = 'qformat_wordtable'; // Plugin name. 34 | $plugin->release = '3.9.7 (Build: 2025042400)'; // The current module release in human-readable form (x.y). 35 | $plugin->requires = 2023041800; // Requires Moodle 4.2 or higher. 36 | $plugin->dependencies = ['booktool_wordimport' => 2020061500]; 37 | --------------------------------------------------------------------------------