Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/filters/globalrole.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once($CFG->dirroot.'/user/filters/lib.php');
00004 
00008 class user_filter_globalrole extends user_filter_type {
00009 
00016     function user_filter_globalrole($name, $label, $advanced) {
00017         parent::user_filter_type($name, $label, $advanced);
00018     }
00019 
00024     function get_roles() {
00025         $context = get_context_instance(CONTEXT_SYSTEM);
00026         $roles = array(0=> get_string('anyrole','filters')) + get_assignable_roles($context);
00027         return $roles;
00028     }
00029 
00034     function setupForm(&$mform) {
00035         $obj =& $mform->addElement('select', $this->_name, $this->_label, $this->get_roles());
00036         $mform->setDefault($this->_name, 0);
00037         if ($this->_advanced) {
00038             $mform->setAdvanced($this->_name);
00039         }
00040     }
00041 
00047     function check_data($formdata) {
00048         $field = $this->_name;
00049 
00050         if (array_key_exists($field, $formdata) and !empty($formdata->$field)) {
00051             return array('value' => (int)$formdata->$field);
00052         }
00053         return false;
00054     }
00055 
00061     function get_sql_filter($data) {
00062         global $CFG;
00063         $value = (int)$data['value'];
00064 
00065         $timenow = round(time(), 100);
00066 
00067         $sql = "id IN (SELECT userid
00068                          FROM {role_assignments} a
00069                         WHERE a.contextid=".SYSCONTEXTID." AND a.roleid=$value)";
00070         return array($sql, array());
00071     }
00072 
00078     function get_label($data) {
00079         global $DB;
00080 
00081         $rolename = $DB->get_field('role', 'name', array('id'=>$data['value']));
00082 
00083         $a = new stdClass();
00084         $a->label = $this->_label;
00085         $a->value = '"'.format_string($rolename).'"';
00086 
00087         return get_string('globalrolelabel', 'filters', $a);
00088     }
00089 }
 All Data Structures Namespaces Files Functions Variables Enumerations