PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/attempt/hp/6/rhubarb/xml/renderer.php

https://github.com/KieranRBriggs/moodle-mod_hotpot
PHP | 139 lines | 48 code | 16 blank | 75 comment | 3 complexity | 0092eb8cc6ce3a49460bd00d81a44c4e MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Render an attempt at a HotPot quiz
  18. * Output format: hp_6_rhubarb_xml
  19. *
  20. * @package mod-hotpot
  21. * @copyright 2010 Gordon Bateson <gordon.bateson@gmail.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. // get parent class
  26. require_once($CFG->dirroot.'/mod/hotpot/attempt/hp/6/rhubarb/renderer.php');
  27. /**
  28. * mod_hotpot_attempt_hp_6_rhubarb_xml_renderer
  29. *
  30. * @copyright 2010 Gordon Bateson
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. * @since Moodle 2.0
  33. */
  34. class mod_hotpot_attempt_hp_6_rhubarb_xml_renderer extends mod_hotpot_attempt_hp_6_rhubarb_renderer {
  35. /**
  36. * expand_JSRhubarb6
  37. *
  38. * @return xxx
  39. */
  40. function expand_JSRhubarb6() {
  41. return $this->expand_template('rhubarb6.js_');
  42. }
  43. /**
  44. * expand_Finished
  45. *
  46. * @return xxx
  47. */
  48. function expand_Finished() {
  49. return $this->hotpot->source->xml_value_js($this->hotpot->source->hbs_software.'-config-file,global,finished');
  50. }
  51. /**
  52. * expand_GuessHere
  53. *
  54. * @return xxx
  55. */
  56. function expand_GuessHere() {
  57. return $this->hotpot->source->xml_value_js($this->hotpot->source->hbs_software.'-config-file,global,type-your-guess-here');
  58. }
  59. /**
  60. * expand_IncorrectWords
  61. *
  62. * @return xxx
  63. */
  64. function expand_IncorrectWords() {
  65. return $this->hotpot->source->xml_value_js($this->hotpot->source->hbs_software.'-config-file,'.$this->hotpot->source->hbs_quiztype.',incorrect-words');
  66. }
  67. /**
  68. * expand_PreparingExercise
  69. *
  70. * @return xxx
  71. */
  72. function expand_PreparingExercise() {
  73. return $this->hotpot->source->xml_value_js($this->hotpot->source->hbs_software.'-config-file,global,preparing-exercise');
  74. }
  75. /**
  76. * expand_Solution
  77. *
  78. * @return xxx
  79. */
  80. function expand_Solution() {
  81. return $this->hotpot->source->xml_value_int($this->hotpot->source->hbs_software.'-config-file,'.$this->hotpot->source->hbs_quiztype.',include-solution');
  82. }
  83. /**
  84. * expand_WordsArray
  85. *
  86. * @return xxx
  87. */
  88. function expand_WordsArray() {
  89. $str = '';
  90. $space = ' \\x09\\x0A\\x0C\\x0D'; // " \t\n\r\l"
  91. $punc = preg_quote('!"#$%&()*+,-./:;+<=>?@[]\\^_`{|}~', '/'); // not apostrophe \'
  92. $search = '/([^'.$punc.$space.']+)|(['.$punc.']['.$punc.$space.']*)/s';
  93. if (preg_match_all($search, $this->hotpot->source->xml_value('data,rhubarb-text'), $matches)) {
  94. foreach ($matches[0] as $i => $word) {
  95. $str .= "Words[$i] = '".$this->hotpot->source->js_value_safe($word, true)."';\n";
  96. }
  97. }
  98. return $str;
  99. }
  100. /**
  101. * expand_FreeWordsArray
  102. *
  103. * @return xxx
  104. */
  105. function expand_FreeWordsArray() {
  106. $str = '';
  107. $i =0;
  108. $tags = 'data,free-words,free-word';
  109. while ($word = $this->hotpot->source->xml_value($tags, "[$i]['#']")) {
  110. $str .= "FreeWords[$i] = '".$this->hotpot->source->js_value_safe($word, true)."';\n";
  111. $i++;
  112. }
  113. return $str;
  114. }
  115. /**
  116. * expand_StyleSheet
  117. *
  118. * @return xxx
  119. */
  120. function expand_StyleSheet() {
  121. return $this->expand_template('tt3.cs_');
  122. }
  123. }