Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 file contains the user selector for already excluded users
19
 *
20
 * File         current.php
21
 * Encoding     UTF-8
22
 * @copyright   Sebsoft.nl
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace tool_usersuspension\exclude\user\selector;
27
 
28
defined('MOODLE_INTERNAL') || die;
29
 
30
require_once($CFG->dirroot . '/user/selector/lib.php');
31
 
32
/**
33
 * tool_usersuspension\exclude\user\selector\current
34
 *
35
 * @package     tool_usersuspension
36
 *
37
 * @copyright   Sebsoft.nl
38
 * @author      R.J. van Dongen <rogier@sebsoft.nl>
39
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
41
class current extends \user_selector_base {
42
 
43
    /**
44
     * Candidate users
45
     * @param string $search
46
     * @return array
47
     */
48
    public function find_users($search) {
49
        global $DB;
50
 
51
        $excludeids = \tool_usersuspension\util::get_user_exclusion_list();
52
        if (empty($excludeids)) {
53
            return array();
54
        }
55
 
56
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
57
        list($wherecondition, $params) = $this->search_sql($search, 'u');
58
 
59
        $fields      = 'SELECT ' . $this->required_fields_sql('u');
60
        $countfields = 'SELECT COUNT(1)';
61
 
62
        list($insql, $uparams) = $DB->get_in_or_equal($excludeids, SQL_PARAMS_NAMED, 'exclude', true, 0);
63
        $params = array_merge($params, $uparams);
64
 
65
        $sql = " FROM {user} u WHERE {$wherecondition} AND u.id {$insql}";
66
 
67
        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
68
        $order = ' ORDER BY ' . $sort;
69
 
70
        if (!$this->is_validating()) {
71
            $counter = $DB->count_records_sql($countfields . $sql, $params);
72
            if ($counter > $this->maxusersperpage) {
73
                return $this->too_many_results($search, $counter);
74
            }
75
        }
76
 
77
        $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));
78
 
79
        if (empty($availableusers)) {
80
            return array();
81
        }
82
 
83
        return array($availableusers);
84
    }
85
 
86
    /**
87
     * Return the options to recreate this selector
88
     *
89
     * @return array
90
     */
91
    protected function get_options() {
92
        $options = parent::get_options();
93
        return $options;
94
    }
95
 
96
}