base_view.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Defines a base class for views of SLOODLE modules and features.
  4. * Module-/feature-specific functionality should be specified by inheriting and overidding specific functions.
  5. * When this file is included, it expects the Moodle library and config info to already be included too.
  6. *
  7. * @package sloodle
  8. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10. *
  11. * @contributor Peter R. Bloomfield
  12. */
  13. /**
  14. * The base class for viewing a SLOODLE module or feature.
  15. * Should be inherited and overridden.
  16. * Child class MUST be named "sloodle_view_NAME", where NAME replaces the name of the feature or module.
  17. * For example, "sloodle_view_controller" or "sloodle_view_course".
  18. * For modules, the NAME must match the "type" specifier in the "sloodle" table, such as "controller", "distributor", or "presenter".
  19. * Modules should be automatically found, although special features (such as courses or users) will need to coded manually into the main view.php script.
  20. * @package sloodle
  21. */
  22. class sloodle_base_view
  23. {
  24. /**
  25. * Constructor.
  26. */
  27. function sloodle_base_view()
  28. {
  29. }
  30. /**
  31. * The main viewing function.
  32. * This gets called by the system to render the view of the module.
  33. */
  34. function view()
  35. {
  36. // Process basic incoming data
  37. // (this fetches all necessary course and module data)
  38. $this->process_request();
  39. // Check user permissions to access this resource.
  40. // This first requires that the user is logged-in (for best results, DO NOT output anything before this).
  41. // It then checks that the user has permission to view the course and module.
  42. // It finally also checks to see if the user has edit permission.
  43. $this->check_permission();
  44. // Process any form submission.
  45. // It is useful to do this before any data is outputted, so that the user can be issued a header direct after form submission.
  46. // This can be used to get rid of any form-related request parameters which break forward/back navigation and manual refreshes.
  47. $this->process_form();
  48. // Output the page header.
  49. // This normally includes standard SLOODLE stuff, such as a note of whether or not the course allows auto-registration.
  50. $this->sloodle_print_header();
  51. // Render the view of the module or feature itself
  52. $this->render();
  53. // Output the page footer.
  54. // This is normally very simple, but can include other data too.
  55. $this->sloodle_print_footer();
  56. }
  57. /**
  58. * Check for incoming request data identifying a particular course or module.
  59. * This must be overridden to add functionality.
  60. */
  61. function process_request()
  62. {
  63. }
  64. /**
  65. * Check that the user has permission to access the current resources.
  66. * This must be overridden to add functionality.
  67. */
  68. function check_permission()
  69. {
  70. }
  71. /**
  72. * Process any form data which has been submitted.
  73. * This must be overridden to add functionality.
  74. */
  75. function process_form()
  76. {
  77. }
  78. /**
  79. * Print the standard page header.
  80. * This should usually be overridden to add additional information, such as page title, header, and navigation links.
  81. */
  82. function sloodle_print_header()
  83. {
  84. sloodle_print_header_simple();
  85. }
  86. /**
  87. * Render the view of the module or feature.
  88. * This MUST be overridden to provide functionality.
  89. */
  90. function render()
  91. {
  92. }
  93. /**
  94. * Output the page footer.
  95. * This does not usually have to be overridden, unless there is something to be added or a block element to be closed.
  96. */
  97. function sloodle_print_footer()
  98. {
  99. sloodle_print_footer();
  100. }
  101. }
  102. ?>