[ 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 * Date 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 date. 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_date extends user_filter_type { 34 /** 35 * the fields available for comparisson 36 * @var string 37 */ 38 public $_field; 39 40 /** 41 * Constructor 42 * @param string $name the name of the filter instance 43 * @param string $label the label of the filter instance 44 * @param boolean $advanced advanced form element flag 45 * @param string $field user table filed name 46 */ 47 public function user_filter_date($name, $label, $advanced, $field) { 48 parent::user_filter_type($name, $label, $advanced); 49 $this->_field = $field; 50 } 51 52 /** 53 * Adds controls specific to this filter in the form. 54 * @param object $mform a MoodleForm object to setup 55 */ 56 public function setupForm(&$mform) { 57 $objs = array(); 58 59 $objs[] = $mform->createElement('static', $this->_name.'_sck', null, get_string('isafter', 'filters')); 60 $objs[] = $mform->createElement('date_selector', $this->_name.'_sdt', null, array('optional' => true)); 61 $objs[] = $mform->createElement('static', $this->_name.'_break', null, '<br/>'); 62 $objs[] = $mform->createElement('static', $this->_name.'_edk', null, get_string('isbefore', 'filters')); 63 $objs[] = $mform->createElement('date_selector', $this->_name.'_edt', null, array('optional' => true)); 64 65 $grp =& $mform->addElement('group', $this->_name.'_grp', $this->_label, $objs, '', false); 66 67 if ($this->_advanced) { 68 $mform->setAdvanced($this->_name.'_grp'); 69 } 70 } 71 72 /** 73 * Retrieves data from the form data 74 * @param object $formdata data submited with the form 75 * @return mixed array filter data or false when filter not set 76 */ 77 public function check_data($formdata) { 78 $sdt = $this->_name.'_sdt'; 79 $edt = $this->_name.'_edt'; 80 81 if (!$formdata->$sdt and !$formdata->$edt) { 82 return false; 83 } 84 85 $data = array(); 86 $data['after'] = $formdata->$sdt; 87 $data['before'] = $formdata->$edt; 88 89 return $data; 90 } 91 92 /** 93 * Returns the condition to be used with SQL where 94 * @param array $data filter settings 95 * @return array sql string and $params 96 */ 97 public function get_sql_filter($data) { 98 $after = (int)$data['after']; 99 $before = (int)$data['before']; 100 101 $field = $this->_field; 102 103 if (empty($after) and empty($before)) { 104 return array('', array()); 105 } 106 107 $res = " $field >= 0 "; 108 109 if ($after) { 110 $res .= " AND $field >= $after"; 111 } 112 113 if ($before) { 114 $res .= " AND $field <= $before"; 115 } 116 return array($res, array()); 117 } 118 119 /** 120 * Returns a human friendly description of the filter used as label. 121 * @param array $data filter settings 122 * @return string active filter label 123 */ 124 public function get_label($data) { 125 $after = $data['after']; 126 $before = $data['before']; 127 $field = $this->_field; 128 129 $a = new stdClass(); 130 $a->label = $this->_label; 131 $a->after = userdate($after); 132 $a->before = userdate($before); 133 134 if ($after and $before) { 135 return get_string('datelabelisbetween', 'filters', $a); 136 } else if ($after) { 137 return get_string('datelabelisafter', 'filters', $a); 138 } else if ($before) { 139 return get_string('datelabelisbefore', 'filters', $a); 140 } 141 return ''; 142 } 143 }
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 |