[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Simple value select filter. 19 * 20 * @package core_user 21 * @category user 22 * @copyright 1999 Martin Dougiamas http://dougiamas.com 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once($CFG->dirroot.'/user/filters/lib.php'); 27 28 /** 29 * Generic filter based on a list of values. 30 * @copyright 1999 Martin Dougiamas http://dougiamas.com 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class user_filter_simpleselect extends user_filter_type { 34 /** 35 * options for the list values 36 * @var array 37 */ 38 public $_options; 39 40 /** 41 * @var string 42 */ 43 public $_field; 44 45 /** 46 * Constructor 47 * @param string $name the name of the filter instance 48 * @param string $label the label of the filter instance 49 * @param boolean $advanced advanced form element flag 50 * @param string $field user table filed name 51 * @param array $options select options 52 */ 53 public function user_filter_simpleselect($name, $label, $advanced, $field, $options) { 54 parent::user_filter_type($name, $label, $advanced); 55 $this->_field = $field; 56 $this->_options = $options; 57 } 58 59 /** 60 * Adds controls specific to this filter in the form. 61 * @param moodleform $mform a MoodleForm object to setup 62 */ 63 public function setupForm(&$mform) { 64 $choices = array('' => get_string('anyvalue', 'filters')) + $this->_options; 65 $mform->addElement('select', $this->_name, $this->_label, $choices); 66 if ($this->_advanced) { 67 $mform->setAdvanced($this->_name); 68 } 69 } 70 71 /** 72 * Retrieves data from the form data 73 * @param object $formdata data submited with the form 74 * @return mixed array filter data or false when filter not set 75 */ 76 public function check_data($formdata) { 77 $field = $this->_name; 78 79 if (array_key_exists($field, $formdata) and $formdata->$field !== '') { 80 return array('value' => (string)$formdata->$field); 81 } 82 83 return false; 84 } 85 86 /** 87 * Returns the condition to be used with SQL where 88 * @param array $data filter settings 89 * @return array sql string and $params 90 */ 91 public function get_sql_filter($data) { 92 static $counter = 0; 93 $name = 'ex_simpleselect'.$counter++; 94 95 $value = $data['value']; 96 $params = array(); 97 $field = $this->_field; 98 if ($value == '') { 99 return ''; 100 } 101 return array("$field=:$name", array($name => $value)); 102 } 103 104 /** 105 * Returns a human friendly description of the filter used as label. 106 * @param array $data filter settings 107 * @return string active filter label 108 */ 109 public function get_label($data) { 110 $value = $data['value']; 111 112 $a = new stdClass(); 113 $a->label = $this->_label; 114 $a->value = '"'.s($this->_options[$value]).'"'; 115 $a->operator = get_string('isequalto', 'filters'); 116 117 return get_string('selectlabel', 'filters', $a); 118 } 119 } 120
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |