Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/filters/user_filter_forms.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once($CFG->libdir.'/formslib.php');
00004 
00005 class user_add_filter_form extends moodleform {
00006 
00007     function definition() {
00008         $mform       =& $this->_form;
00009         $fields      = $this->_customdata['fields'];
00010         $extraparams = $this->_customdata['extraparams'];
00011 
00012         $mform->addElement('header', 'newfilter', get_string('newfilter','filters'));
00013 
00014         foreach($fields as $ft) {
00015             $ft->setupForm($mform);
00016         }
00017 
00018         // in case we wasnt to track some page params
00019         if ($extraparams) {
00020             foreach ($extraparams as $key=>$value) {
00021                 $mform->addElement('hidden', $key, $value);
00022                 $mform->setType($key, PARAM_RAW);
00023             }
00024         }
00025 
00026         // Add button
00027         $mform->addElement('submit', 'addfilter', get_string('addfilter','filters'));
00028 
00029         // Don't use last advanced state
00030         $mform->setShowAdvanced(false);
00031     }
00032 }
00033 
00034 class user_active_filter_form extends moodleform {
00035 
00036     function definition() {
00037         global $SESSION; // this is very hacky :-(
00038 
00039         $mform       =& $this->_form;
00040         $fields      = $this->_customdata['fields'];
00041         $extraparams = $this->_customdata['extraparams'];
00042 
00043         if (!empty($SESSION->user_filtering)) {
00044             // add controls for each active filter in the active filters group
00045             $mform->addElement('header', 'actfilterhdr', get_string('actfilterhdr','filters'));
00046 
00047             foreach ($SESSION->user_filtering as $fname=>$datas) {
00048                 if (!array_key_exists($fname, $fields)) {
00049                     continue; // filter not used
00050                 }
00051                 $field = $fields[$fname];
00052                 foreach($datas as $i=>$data) {
00053                     $description = $field->get_label($data);
00054                     $mform->addElement('checkbox', 'filter['.$fname.']['.$i.']', null, $description);
00055                 }
00056             }
00057 
00058             if ($extraparams) {
00059                 foreach ($extraparams as $key=>$value) {
00060                     $mform->addElement('hidden', $key, $value);
00061                     $mform->setType($key, PARAM_RAW);
00062                 }
00063             }
00064 
00065             $objs = array();
00066             $objs[] = &$mform->createElement('submit', 'removeselected', get_string('removeselected','filters'));
00067             $objs[] = &$mform->createElement('submit', 'removeall', get_string('removeall','filters'));
00068             $mform->addElement('group', 'actfiltergrp', '', $objs, ' ', false);
00069         }
00070     }
00071 }
 All Data Structures Namespaces Files Functions Variables Enumerations