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
declare(strict_types=1);
18
 
19
namespace core_reportbuilder\reportbuilder\audience;
20
 
21
use context_system;
22
use core_reportbuilder\local\audiences\base;
23
use core_reportbuilder\local\helpers\database;
24
use MoodleQuickForm;
25
 
26
/**
27
 * The backend class for All users audience type
28
 *
29
 * @package     core_reportbuilder
30
 * @copyright   2021 David Matamoros <davidmc@moodle.com>
31
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class allusers extends base {
34
 
35
    /**
36
     * Adds audience's elements to the given mform
37
     *
38
     * @param MoodleQuickForm $mform The form to add elements to
39
     */
40
    public function get_config_form(MoodleQuickForm $mform): void {
41
        $mform->addElement('static', 'allsiteusers', get_string('allsiteusers', 'core_reportbuilder'));
42
    }
43
 
44
    /**
45
     * Helps to build SQL to retrieve users that matches the current report audience
46
     *
47
     * @param string $usertablealias
48
     * @return array array of three elements [$join, $where, $params]
49
     */
50
    public function get_sql(string $usertablealias): array {
51
        global $CFG;
52
 
53
        $guestuser = database::generate_param_name();
54
        return ['', "$usertablealias.suspended = 0 AND $usertablealias.deleted = 0 AND $usertablealias.id <> :{$guestuser}",
55
            [$guestuser => $CFG->siteguest]];
56
    }
57
 
58
    /**
59
     * Return user friendly name of this audience type
60
     *
61
     * @return string
62
     */
63
    public function get_name(): string {
64
        return get_string('allusers', 'core_reportbuilder');
65
    }
66
 
67
    /**
68
     * Return the description for the audience.
69
     *
70
     * @return string
71
     */
72
    public function get_description(): string {
73
        return get_string('allsiteusers', 'core_reportbuilder');
74
    }
75
 
76
    /**
77
     * If the current user is able to add this audience.
78
     *
79
     * @return bool
80
     */
81
    public function user_can_add(): bool {
82
        return has_capability('moodle/user:viewalldetails', context_system::instance());
83
    }
84
 
85
    /**
86
     * If the current user is able to edit this audience.
87
     *
88
     * @return bool
89
     */
90
    public function user_can_edit(): bool {
91
        return has_capability('moodle/user:viewalldetails', context_system::instance());
92
    }
93
}