behaviour.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * Fake question behaviour that is used when the actual behaviour was not
  18. * available.
  19. *
  20. * @package qbehaviour
  21. * @subpackage missing
  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. * Fake question behaviour that is used when the actual behaviour
  28. * is not available.
  29. *
  30. * Imagine, for example, that a quiz attempt has been restored from another
  31. * Moodle site with more behaviours installed, or a behaviour
  32. * that used to be available in this site has been uninstalled. Obviously all we
  33. * can do is have some code to prevent fatal errors.
  34. *
  35. * The approach we take is: The rendering code is still implemented, as far as
  36. * possible. A warning is shown that behaviour specific bits may be missing.
  37. * Any attempt to process anything causes an exception to be thrown.
  38. *
  39. * @copyright 2009 The Open University
  40. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41. */
  42. class qbehaviour_missing extends question_behaviour {
  43. public function is_compatible_question(question_definition $question) {
  44. return true;
  45. }
  46. public function summarise_action(question_attempt_step $step) {
  47. return '';
  48. }
  49. public function init_first_step(question_attempt_step $step, $variant) {
  50. throw new coding_exception('The behaviour used for this question is not available. ' .
  51. 'No processing is possible.');
  52. }
  53. public function process_action(question_attempt_pending_step $pendingstep) {
  54. throw new coding_exception('The behaviour used for this question is not available. ' .
  55. 'No processing is possible.');
  56. }
  57. public function get_min_fraction() {
  58. throw new coding_exception('The behaviour used for this question is not available. ' .
  59. 'No processing is possible.');
  60. }
  61. public function get_max_fraction() {
  62. throw new coding_exception('The behaviour used for this question is not available. ' .
  63. 'No processing is possible.');
  64. }
  65. }