Source for file base_view.php

Documentation is available at base_view.php

  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.  
  15. /**
  16. * The base class for viewing a SLOODLE module or feature.
  17. * Should be inherited and overridden.
  18. * Child class MUST be named "sloodle_view_NAME", where NAME replaces the name of the feature or module.
  19. * For example, "sloodle_view_controller" or "sloodle_view_course".
  20. * For modules, the NAME must match the "type" specifier in the "sloodle" table, such as "controller", "distributor", or "presenter".
  21. * Modules should be automatically found, although special features (such as courses or users) will need to coded manually into the main view.php script.
  22. @package sloodle
  23. */
  24. {
  25.     /**
  26.     * Constructor.
  27.     */
  28.     function sloodle_base_view()
  29.     {
  30.     }
  31.  
  32.     /**
  33.     * The main viewing function.
  34.     * This gets called by the system to render the view of the module.
  35.     */
  36.     function view()
  37.     {
  38.         // Process basic incoming data
  39.         // (this fetches all necessary course and module data)
  40.         $this->process_request();
  41.  
  42.         // Check user permissions to access this resource.
  43.         // This first requires that the user is logged-in (for best results, DO NOT output anything before this).
  44.         // It then checks that the user has permission to view the course and module.
  45.         // It finally also checks to see if the user has edit permission.
  46.         $this->check_permission();
  47.  
  48.         // Process any form submission.
  49.         // It is useful to do this before any data is outputted, so that the user can be issued a header direct after form submission.
  50.         // This can be used to get rid of any form-related request parameters which break forward/back navigation and manual refreshes.
  51.         $this->process_form();
  52.  
  53.         // Output the page header.
  54.         // This normally includes standard SLOODLE stuff, such as a note of whether or not the course allows auto-registration.
  55.         $this->print_header();
  56.  
  57.         // Render the view of the module or feature itself
  58.         $this->render();
  59.  
  60.         // Output the page footer.
  61.         // This is normally very simple, but can include other data too.
  62.         $this->print_footer();
  63.     }
  64.  
  65.     /**
  66.     * Check for incoming request data identifying a particular course or module.
  67.     * This must be overridden to add functionality.
  68.     */
  69.     function process_request()
  70.     {
  71.     }
  72.  
  73.     /**
  74.     * Check that the user has permission to access the current resources.
  75.     * This must be overridden to add functionality.
  76.     */
  77.     function check_permission()
  78.     {
  79.     }
  80.  
  81.     /**
  82.     * Process any form data which has been submitted.
  83.     * This must be overridden to add functionality.
  84.     */
  85.     function process_form()
  86.     {
  87.     }
  88.  
  89.     /**
  90.     * Print the standard page header.
  91.     * This should usually be overridden to add additional information, such as page title, header, and navigation links.
  92.     */
  93.     function print_header()
  94.     {
  95.         print_header_simple();
  96.     }
  97.  
  98.     /**
  99.     * Render the view of the module or feature.
  100.     * This MUST be overridden to provide functionality.
  101.     */
  102.     function render()
  103.     {
  104.     }
  105.  
  106.     /**
  107.     * Output the page footer.
  108.     * This does not usually have to be overridden, unless there is something to be added or a block element to be closed.
  109.     */
  110.     function print_footer()
  111.     {
  112.         print_footer();
  113.     }
  114.  
  115. }
  116.  
  117.  
  118. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:01 +0100 by phpDocumentor 1.4.0