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 users that can potentially be excluded
19
 *
20
 * File         user.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\potential
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 potential extends \user_selector_base {
42
 
43
    /**
44
     * Create a new instance.
45
     *
46
     * @param string $name the control name/id for use in the HTML.
47
     * @param array $options other options needed to construct this selector.
48
     */
49
    public function __construct($name, $options) {
50
        parent::__construct($name, $options);
51
        $this->exclude = \tool_usersuspension\util::get_user_exclusion_list();
52
    }
53
 
54
    /**
55
     * Candidate users
56
     * @param string $search
57
     * @return array
58
     */
59
    public function find_users($search) {
60
        global $DB;
61
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
62
        list($wherecondition, $params) = $this->search_sql($search, 'u');
63
 
64
        $fields      = 'SELECT ' . $this->required_fields_sql('u');
65
        $countfields = 'SELECT COUNT(1)';
66
 
67
        $sql = " FROM {user} u WHERE {$wherecondition}";
68
 
69
        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
70
        $order = ' ORDER BY ' . $sort;
71
 
72
        if (!$this->is_validating()) {
73
            $counter = $DB->count_records_sql($countfields . $sql, $params);
74
            if ($counter > $this->maxusersperpage) {
75
                return $this->too_many_results($search, $counter);
76
            }
77
        }
78
 
79
        $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));
80
 
81
        if (empty($availableusers)) {
82
            return array();
83
        }
84
 
85
        return array($availableusers);
86
    }
87
 
88
    /**
89
     * Return the options to recreate this selector
90
     *
91
     * @return array
92
     */
93
    protected function get_options() {
94
        $options = parent::get_options();
95
        return $options;
96
    }
97
 
98
}