PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/source/html/xerte/class.php

https://github.com/KieranRBriggs/moodle-mod_hotpot
PHP | 132 lines | 85 code | 7 blank | 40 comment | 5 complexity | 4c1cb2b97371650e46b4b624340397d7 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. * Class to represent the source of a HotPot quiz
  18. * Source type: html_xerte
  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/source/html/class.php');
  27. /**
  28. * hotpot_source_html_xerte
  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 hotpot_source_html_xerte extends hotpot_source_html {
  35. // properties of the icon for this source file type
  36. var $icon = 'mod/hotpot/file/html/xerte/icon.gif';
  37. // xmlized content of template.xml
  38. var $template_xml = null;
  39. /**
  40. * is_quizfile
  41. * returns hotpot_file object if $filename is a quiz file, or false otherwise
  42. *
  43. * @return xxx
  44. */
  45. public static function is_quizfile($sourcefile) {
  46. if (! preg_match('/\.html?$/', $sourcefile->get_filename())) {
  47. // not an html file
  48. return false;
  49. }
  50. if (! $content = $sourcefile->get_content()) {
  51. // empty or non-existant file
  52. return false;
  53. }
  54. if (! preg_match('/<script[^>]*src\s*=\s*"[^"]*rloObject.js"[^>]*>/', $content)) {
  55. return false;
  56. }
  57. if (! preg_match("/myRLO = new rloObject\('\d*','\d*','[^']*.rl[to]'\)/", $content)) {
  58. return false;
  59. }
  60. return true;
  61. }
  62. /**
  63. * get_template_xml
  64. *
  65. * @return xxx
  66. */
  67. function get_template_xml() {
  68. if (is_null($this->template_xml)) {
  69. $this->template_xml = $this->get_sibling_filecontents('template.xml', true);
  70. }
  71. return $this->template_xml;
  72. }
  73. /**
  74. * get_template_value
  75. *
  76. * @param xxx $tags
  77. * @param xxx $default (optional, default=null)
  78. * @return xxx
  79. */
  80. function get_template_value($tags, $default=null) {
  81. $value = $this->get_template_xml();
  82. foreach($tags as $tag) {
  83. if (! is_array($value)) {
  84. return $default;
  85. }
  86. if(! array_key_exists($tag, $value)) {
  87. return $default;
  88. }
  89. $value = $value[$tag];
  90. }
  91. return $value;
  92. }
  93. /**
  94. * get_name
  95. *
  96. * @return xxx
  97. */
  98. function get_name() {
  99. if ($name = $this->get_template_value(array('learningObject', '@', 'name'))) {
  100. return $name;
  101. }
  102. return parent::get_name();
  103. }
  104. /**
  105. * get_displayMode
  106. *
  107. * @return xxx
  108. */
  109. function get_displayMode() {
  110. return $this->get_template_value(array('learningObject', '@', 'displayMode'), 'default');
  111. }
  112. /**
  113. * get_entrytext - returns the introduction text for a quiz
  114. *
  115. * @return xxx
  116. */
  117. function get_entrytext() {
  118. return '';
  119. }
  120. } // end class