/** * Use this to add new filters to the filter model * * Example: * ->new_text(...args...); * * @param string $name The name of the filter * @param array $arguments Filter args * @return mixed|mr_html_filter */ public function __call($name, $arguments) { $parts = explode('_', $name); if (count($parts) == 2) { switch ($parts[0]) { case 'new': return $this->add($this->helper->load('html/filter/' . $parts[1], $arguments)); break; } } return parent::__call($name, $arguments); }
/** * Add a column format * * @param mixed $format This can be mr_format_abstract or a string * representing the format's name. If a string, then keep passing * args which will be passed to the format's constructor * @return mr_html_table_column * @throws coding_exception */ public function add_format($format) { if (is_string($format)) { // Get remaining args, burn format $args = func_get_args(); array_shift($args); $helper = new mr_helper(); $format = $helper->load("format/{$format}", $args); } else { if (!$format instanceof mr_format_abstract) { throw new coding_exception('Invalid format parameter'); } } $this->formats[] = $format; return $this; }
/** * Add a table column. This method is a shortcut for * adding different column types. Types are listed in * html/table/column/ * * @param string $type The column type * @param string $name Column SQL field name (see mr_html_table_column) * @param string $heading Column heading * @param array $config Column configuration * @return mr_html_table */ public function add_column_type($type, $name, $heading = '', $config = array()) { return $this->add_column($this->helper->load("html/table/column/{$type}", array($name, $heading, $config))); }
/** * Exporter setup * * There are many ways to define which exporters are available. The $exporters * param can be a string or an array of strings that get sent to the mr_helper_load class. * * Examples: * <code> * <?php * // Load all exporters * $export = new mr_file_export('**'); * * // Load only text exporters * $export = new mr_file_export('text/*'); * * // Load all spreadsheet and text/csv exporters * $export = new mr_file_export(array('text/csv', 'spreadsheet/*')); * * // Load an instance of a class that extends mr_file_export_abstract * $export = new mr_file_export(new blocks_dummy_file_export_csv()); * * // Load an instance and all text exporters * $export = new mr_file_export(array('text/*', new blocks_dummy_file_export_csv())); * * ?> * </code> * * @param mixed $exporters This can take on many forms, see above for examples. * @param boolean $requirefile If true, then no export plugin will be included that cannot generate a file * @param moodle_url $url Moodle URL for current page, used for rendering only * @param string $filename The exported file's name * @throws coding_exception */ public function __construct($exporters = '**', $requirefile = false, moodle_url $url = NULL, $filename = 'export') { // Store params $this->url = $url; $this->set_filename($filename); if (!is_array($exporters)) { $exporters = array($exporters); } // Load exporters $helper = new mr_helper(); foreach ($exporters as $exporter) { //check to see if $exporter is an instance of mr_file_export_absract if ($exporter instanceof mr_file_export_abstract) { //add the exporter instance the exporters data member $this->exporters[$exporter->type()] = $exporter; //next exporter continue; } $plugins = $helper->load("file/export/{$exporter}"); // Might return a single plugin if (!is_array($plugins)) { $plugins = array($plugins); } foreach ($plugins as $plugin) { $this->exporters[$plugin->type()] = $plugin; } } // Make sure we successfully loaded some if (empty($this->exporters)) { throw new coding_exception('Failed to load exporters, check the $exporters param value'); } // If files are requred, then weed out any exporters that cannot produce a file if ($requirefile) { foreach ($this->exporters as $name => $exporter) { if (!$exporter->generates_file()) { unset($this->exporters[$name]); } } if (empty($this->exporters)) { throw new coding_exception('All loaded exporters do not generate files, but files required'); } } // Auto-detect if we are exporting, if yes, fire 'er up! if ($exporter = optional_param('mrexporter', '', PARAM_PATH)) { $this->init($exporter); } }