]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-15502, added a filter to selec users who have never logged in, merged from 1...
authorDongsheng Cai <unoter@gmail.com>
Fri, 18 Dec 2009 05:37:41 +0000 (05:37 +0000)
committerDongsheng Cai <unoter@gmail.com>
Fri, 18 Dec 2009 05:37:41 +0000 (05:37 +0000)
lang/en_utf8/filters.php
user/filters/date.php
user/filters/lib.php

index e7c91d955cfee11ba305e2083733c382d7bdcdc7..d66215e5e691059eb82b38095eed6e58ca7f46af 100644 (file)
@@ -28,6 +28,7 @@ $string['filtersettingsin'] = 'Filter settings in $a';
 $string['firstaccess'] = 'First access';
 $string['globalrolelabel'] = '$a->label is $a->value';
 $string['isactive'] = 'Active?';
+$string['includenever'] = 'Never included';
 $string['isanyvalue'] = 'is any value';
 $string['isafter'] = 'is after';
 $string['isbefore'] = 'is before';
index 905a32e1f080cd6f2a0111a40d8caec13e637de1..e5162a567dc199340e6200a962c41fb06961c27b 100755 (executable)
@@ -32,8 +32,11 @@ class user_filter_date extends user_filter_type {
 
         $objs[] =& $mform->createElement('checkbox', $this->_name.'_sck', null, get_string('isafter', 'filters'));
         $objs[] =& $mform->createElement('date_selector', $this->_name.'_sdt', null);
+        $objs[] =& $mform->createElement('static', $this->_name.'_break', null, '<br>');
         $objs[] =& $mform->createElement('checkbox', $this->_name.'_eck', null, get_string('isbefore', 'filters'));
         $objs[] =& $mform->createElement('date_selector', $this->_name.'_edt', null);
+        $objs[] = & $mform->createElement('checkbox', $this->_name.'_never', null, get_string('includenever', 'filters'));
+        
         $grp =& $mform->addElement('group', $this->_name.'_grp', $this->_label, $objs, '', false);
         $grp->setHelpButton(array('date',$this->_label,'filters'));
 
@@ -41,12 +44,19 @@ class user_filter_date extends user_filter_type {
             $mform->setAdvanced($this->_name.'_grp');
         }
 
+        if ($this->_advanced) {
+            $mform->setAdvanced($this->_name.'_grp');
+        }
+
+
         $mform->disabledIf($this->_name.'_sdt[day]', $this->_name.'_sck', 'notchecked');
         $mform->disabledIf($this->_name.'_sdt[month]', $this->_name.'_sck', 'notchecked');
         $mform->disabledIf($this->_name.'_sdt[year]', $this->_name.'_sck', 'notchecked');
         $mform->disabledIf($this->_name.'_edt[day]', $this->_name.'_eck', 'notchecked');
         $mform->disabledIf($this->_name.'_edt[month]', $this->_name.'_eck', 'notchecked');
         $mform->disabledIf($this->_name.'_edt[year]', $this->_name.'_eck', 'notchecked');
+
+        $mform->disabledIf($this->_name.'_never', $this->_name.'_eck', 'notchecked');
     }
 
     /**
@@ -59,6 +69,7 @@ class user_filter_date extends user_filter_type {
         $sdt = $this->_name.'_sdt';
         $eck = $this->_name.'_eck';
         $edt = $this->_name.'_edt';
+        $never = $this->_name.'_never';
 
         if (!array_key_exists($sck, $formdata) and !array_key_exists($eck, $formdata)) {
             return false;
@@ -75,6 +86,12 @@ class user_filter_date extends user_filter_type {
         } else {
             $data['before'] = 0;
         }
+        if (array_key_exists($never, $formdata)) {
+            $data['never'] = $formdata->$never;
+        } else {
+            $data['never'] = 0;
+        }
+        
         return $data;
     }
 
@@ -86,17 +103,26 @@ class user_filter_date extends user_filter_type {
     function get_sql_filter($data) {
         $after  = (int)$data['after'];
         $before = (int)$data['before'];
+        $never  = (int)$data['never'];
+
         $field  = $this->_field;
 
         if (empty($after) and empty($before)) {
             return array('', array());
         }
 
-        $res = "$field > 0" ;
+        $res = '';
+
+        if (!empty($never)) {
+            $res .= " $field >= 0 " ;
+        } else {
+            $res .= " $field > 0 " ;
+        }
 
         if ($after) {
             $res .= " AND $field >= $after";
         }
+
         if ($before) {
             $res .= " AND $field <= $before";
         }
@@ -111,21 +137,28 @@ class user_filter_date extends user_filter_type {
     function get_label($data) {
         $after  = $data['after'];
         $before = $data['before'];
+        $never = $data['never'];
         $field  = $this->_field;
 
         $a = new object();
         $a->label  = $this->_label;
         $a->after  = userdate($after);
         $a->before = userdate($before);
-
+        
+        if ($never) {
+            $strnever = ' ('.get_string('includenever', 'filters').')';
+        } else {
+            $strnever = '';
+        }
+        
         if ($after and $before) {
-            return get_string('datelabelisbetween', 'filters', $a);
+            return get_string('datelabelisbetween', 'filters', $a).$strnever;
 
         } else if ($after) {
-            return get_string('datelabelisafter', 'filters', $a);
+            return get_string('datelabelisafter', 'filters', $a).$strnever;;
 
         } else if ($before) {
-            return get_string('datelabelisbefore', 'filters', $a);
+            return get_string('datelabelisbefore', 'filters', $a).$strnever;;
         }
         return '';
     }
index 1f8e235c9976d6dbae2517504156884bafc6e7e8..9be889bd3e129a19d12c451aef282e092c1fa7af 100644 (file)
@@ -35,7 +35,7 @@ class user_filtering {
         if (empty($fieldnames)) {
             $fieldnames = array('realname'=>0, 'lastname'=>1, 'firstname'=>1, 'email'=>1, 'city'=>1, 'country'=>1,
                                 'confirmed'=>1, 'profile'=>1, 'courserole'=>1, 'systemrole'=>1,
-                                'firstaccess'=>1, 'lastaccess'=>1, 'lastlogin'=>1, 'username'=>1, 'auth'=>1, 'mnethostid'=>1);
+                                'firstaccess'=>1, 'lastaccess'=>1, 'lastlogin'=>1, 'timemodified'=>1, 'username'=>1, 'auth'=>1, 'mnethostid'=>1);
         }
 
         $this->_fields  = array();
@@ -114,6 +114,7 @@ class user_filtering {
             case 'firstaccess': return new user_filter_date('firstaccess', get_string('firstaccess', 'filters'), $advanced, 'firstaccess');
             case 'lastaccess':  return new user_filter_date('lastaccess', get_string('lastaccess'), $advanced, 'lastaccess');
             case 'lastlogin':   return new user_filter_date('lastlogin', get_string('lastlogin'), $advanced, 'lastlogin');
+            case 'timemodified': return new user_filter_date('timemodified', get_string('lastmodified'), $advanced, 'timemodified');
             case 'auth':
                 $plugins = get_plugin_list('auth');
                 $choices = array();