renderer.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * Renderer for outputting parts of a question belonging to the interactive
  18. * behaviour.
  19. *
  20. * @package qbehaviour
  21. * @subpackage interactive
  22. * @copyright 2009 The Open University
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. defined('MOODLE_INTERNAL') || die();
  26. /**
  27. * Interactive behaviour renderer.
  28. *
  29. * @copyright 2009 The Open University
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class qbehaviour_interactive_renderer extends qbehaviour_renderer {
  33. public function controls(question_attempt $qa, question_display_options $options) {
  34. if ($options->readonly === qbehaviour_interactive::READONLY_EXCEPT_TRY_AGAIN) {
  35. return '';
  36. }
  37. return $this->submit_button($qa, $options);
  38. }
  39. public function feedback(question_attempt $qa, question_display_options $options) {
  40. if (!$qa->get_state()->is_active() || !$options->readonly) {
  41. return '';
  42. }
  43. $attributes = array(
  44. 'type' => 'submit',
  45. 'id' => $qa->get_behaviour_field_name('tryagain'),
  46. 'name' => $qa->get_behaviour_field_name('tryagain'),
  47. 'value' => get_string('tryagain', 'qbehaviour_interactive'),
  48. 'class' => 'submit btn',
  49. );
  50. if ($options->readonly !== qbehaviour_interactive::READONLY_EXCEPT_TRY_AGAIN) {
  51. $attributes['disabled'] = 'disabled';
  52. }
  53. $output = html_writer::empty_tag('input', $attributes);
  54. if (empty($attributes['disabled'])) {
  55. $this->page->requires->js_init_call('M.core_question_engine.init_submit_button',
  56. array($attributes['id'], $qa->get_slot()));
  57. }
  58. return $output;
  59. }
  60. }