Skip to content

Commit 130ab46

Browse files
author
David Monllao
committed
Merge branch 'MDL-44646-master' of https://github.com/lucaboesch/moodle
2 parents e3037af + 78f6d02 commit 130ab46

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

admin/tests/behat/filter_users.feature

+17
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,20 @@ Feature: An administrator can filter user accounts by role, cohort and other pro
6565
And I should not see "User Two"
6666
And I should not see "User Three"
6767
And I should not see "User Four"
68+
69+
Scenario: Filter user accounts by enrolled in any course
70+
When I set the following fields to these values:
71+
| id_anycourses | Yes |
72+
And I press "Add filter"
73+
Then I should see "User One"
74+
And I should see "User Two"
75+
And I should see "User Three"
76+
And I should not see "User Four"
77+
And I press "Remove all filters"
78+
And I set the following fields to these values:
79+
| id_anycourses | No |
80+
And I press "Add filter"
81+
And I should not see "User One"
82+
And I should not see "User Two"
83+
And I should not see "User Three"
84+
And I should see "User Four"

lang/en/filters.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
$string['addfilter'] = 'Add filter';
2727
$string['anycategory'] = 'any category';
2828
$string['anycourse'] = 'any course';
29+
$string['anycourses'] = 'Enrolled in any course';
2930
$string['anyfield'] = 'any field';
3031
$string['anyrole'] = 'any role';
3132
$string['anyvalue'] = 'any value';

user/filters/anycourses.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
* This is filter is used to see which students are enroled on any courses
19+
*
20+
* @package core_user
21+
* @copyright 2014 Krister Viirsaar
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
/**
28+
* User filter to distinguish users with no or any enroled courses.
29+
* @copyright 2014 Krister Viirsaar
30+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31+
*/
32+
class user_filter_anycourses extends user_filter_yesno {
33+
34+
/**
35+
* Returns the condition to be used with SQL
36+
*
37+
* @param array $data filter settings
38+
* @return array sql string and $params
39+
*/
40+
public function get_sql_filter($data) {
41+
$value = $data['value'];
42+
43+
$not = $value ? '' : 'NOT';
44+
45+
return array("EXISTS ( SELECT userid FROM {user_enrolments} ) AND " .
46+
" id $not IN ( SELECT userid FROM {user_enrolments} )", array());
47+
}
48+
}
49+

user/filters/lib.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
require_once($CFG->dirroot.'/user/filters/globalrole.php');
3232
require_once($CFG->dirroot.'/user/filters/profilefield.php');
3333
require_once($CFG->dirroot.'/user/filters/yesno.php');
34+
require_once($CFG->dirroot.'/user/filters/anycourses.php');
3435
require_once($CFG->dirroot.'/user/filters/cohort.php');
3536
require_once($CFG->dirroot.'/user/filters/user_filter_forms.php');
3637
require_once($CFG->dirroot.'/user/filters/checkbox.php');
@@ -63,10 +64,11 @@ public function __construct($fieldnames = null, $baseurl = null, $extraparams =
6364
}
6465

6566
if (empty($fieldnames)) {
66-
$fieldnames = array('realname' => 0, 'lastname' => 1, 'firstname' => 1, 'username' => 1, 'email' => 1, 'city' => 1, 'country' => 1,
67-
'confirmed' => 1, 'suspended' => 1, 'profile' => 1, 'courserole' => 1, 'systemrole' => 1,
68-
'cohort' => 1, 'firstaccess' => 1, 'lastaccess' => 1, 'neveraccessed' => 1, 'timemodified' => 1,
69-
'nevermodified' => 1, 'auth' => 1, 'mnethostid' => 1, 'idnumber' => 1);
67+
$fieldnames = array('realname' => 0, 'lastname' => 1, 'firstname' => 1, 'username' => 1, 'email' => 1, 'city' => 1,
68+
'country' => 1, 'confirmed' => 1, 'suspended' => 1, 'profile' => 1, 'courserole' => 1,
69+
'anycourses' => 1, 'systemrole' => 1, 'cohort' => 1, 'firstaccess' => 1, 'lastaccess' => 1,
70+
'neveraccessed' => 1, 'timemodified' => 1, 'nevermodified' => 1, 'auth' => 1, 'mnethostid' => 1,
71+
'idnumber' => 1);
7072
}
7173

7274
$this->_fields = array();
@@ -142,6 +144,8 @@ public function get_field($fieldname, $advanced) {
142144
case 'suspended': return new user_filter_yesno('suspended', get_string('suspended', 'auth'), $advanced, 'suspended');
143145
case 'profile': return new user_filter_profilefield('profile', get_string('profilefields', 'admin'), $advanced);
144146
case 'courserole': return new user_filter_courserole('courserole', get_string('courserole', 'filters'), $advanced);
147+
case 'anycourses':
148+
return new user_filter_anycourses('anycourses', get_string('anycourses', 'filters'), $advanced, 'user_enrolments');
145149
case 'systemrole': return new user_filter_globalrole('systemrole', get_string('globalrole', 'role'), $advanced);
146150
case 'firstaccess': return new user_filter_date('firstaccess', get_string('firstaccess', 'filters'), $advanced, 'firstaccess');
147151
case 'lastaccess': return new user_filter_date('lastaccess', get_string('lastaccess'), $advanced, 'lastaccess');

0 commit comments

Comments
 (0)