See how to use this class

  1. <?php
  2. /**
  3.  * Filter controller
  4.  *
  5.  * @author Mark Nielsen
  6.  * @version $Id$
  7.  * @package blocks/helloworld
  8.  */
  9.  
  10. defined('MOODLE_INTERNAL'or die('Direct access to this script is forbidden.');
  11.  
  12. class block_helloworld_controller_filter extends mr_controller_block {
  13.     /**
  14.      * Default screen
  15.      *
  16.      * Demo of mr_filter et al
  17.      */
  18.     public function view_action({
  19.         global $COURSE;
  20.  
  21.         #### DEMO CODE ####
  22.         // Filter values are stored here
  23.         $preferences new mr_preferences($COURSE->id'blocks/helloworld');
  24.  
  25.         // Create the filter "manager"
  26.         $filter new mr_html_filter($preferences$this->url);
  27.  
  28.         // Add a filter
  29.         $filter->add(new mr_html_filter_text('foo''Foo'));
  30.  
  31.         // Add the same filter, shortcut way
  32.         $filter->new_text('bar''Bar');
  33.  
  34.         // You can chain these too (with add() as well)
  35.         $filter->new_select('baz''Baz'array('0' => 'No''1' => 'Yes'))
  36.                ->new_daterange('bat''Bat');
  37.  
  38.         // Render the filter: This should be done before the print_header() - may redirect
  39.         $output $this->mroutput->render($filter);
  40.  
  41.         // Generate SQL based on filter values
  42.         $output .= $this->helper->dump($filter->sql()'Filter SQL'true);
  43.  
  44.         // Access filter values through preferences
  45.         $output .= $this->helper->dump($preferences->get('foo''NOT SET')'Preference foo'true);
  46.         $output .= $this->helper->dump($preferences->get('bar''NOT SET')'Preference bar'true);
  47.         #### DEMO CODE ####
  48.  
  49.         return $this->output->heading('Demo of mr_filter_*').
  50.                $this->helper->highlight(__CLASS____FUNCTION__true).
  51.                $this->output->box($output'generalbox boxaligncenter boxwidthnormal');
  52.     }
  53. }

Documentation generated on Thu, 28 Jun 2012 16:33:48 -0700 by phpDocumentor 1.4.3