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\local\systemreports;
20
 
21
use core_reportbuilder\local\models\audience;
22
use core_reportbuilder\local\models\report;
23
use core_reportbuilder\permission;
24
use core_reportbuilder\system_report;
25
use core_reportbuilder\local\entities\user;
26
use core_reportbuilder\local\helpers\audience as audience_helper;
27
 
28
/**
29
 * Report access list
30
 *
31
 * @package     core_reportbuilder
32
 * @copyright   2021 David Matamoros <davidmc@moodle.com>
33
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class report_access_list extends system_report {
36
 
37
    /**
38
     * Initialise the report
39
     */
40
    protected function initialise(): void {
41
        $userentity = new user();
42
        $userentityalias = $userentity->get_table_alias('user');
43
 
44
        $this->set_main_table('user', $userentityalias);
45
        $this->add_entity($userentity);
46
 
47
        // Find users allowed to view the report thru the report audiences.
48
        $audiences = audience::get_records(['reportid' => $this->get_parameter('id', 0, PARAM_INT)]);
49
        [$wheres, $params] = audience_helper::user_audience_sql($audiences, $userentityalias);
50
 
51
        if (count($wheres) > 0) {
52
            $select = '(' . implode(' OR ', $wheres) . ')';
53
        } else {
54
            $select = "1=0";
55
        }
56
 
57
        $this->add_base_condition_sql($select, $params);
58
        $this->add_base_condition_simple("{$userentityalias}.deleted", 0);
59
 
60
        $this->add_columns($userentity);
61
        $this->add_filters($userentity);
62
 
63
        $this->set_downloadable(false);
64
    }
65
 
66
    /**
67
     * Ensure we can view the report
68
     *
69
     * @return bool
70
     */
71
    protected function can_view(): bool {
72
        $reportid = $this->get_parameter('id', 0, PARAM_INT);
73
        $report = report::get_record(['id' => $reportid], MUST_EXIST);
74
 
75
        return permission::can_edit_report($report);
76
    }
77
 
78
    /**
79
     * Add columns to report
80
     *
81
     * @param user $userentity
82
     */
83
    protected function add_columns(user $userentity): void {
84
        $this->add_column($userentity->get_column('fullnamewithpicturelink'));
85
 
86
        // Include all identity field columns.
87
        $identitycolumns = $userentity->get_identity_columns($this->get_context());
88
        foreach ($identitycolumns as $identitycolumn) {
89
            $this->add_column($identitycolumn);
90
        }
91
 
92
        $this->set_initial_sort_column('user:fullnamewithpicturelink', SORT_ASC);
93
    }
94
 
95
    /**
96
     * Add filters to report
97
     *
98
     * @param user $userentity
99
     */
100
    protected function add_filters(user $userentity): void {
101
        $this->add_filter($userentity->get_filter('fullname'));
102
 
103
        // Include all identity field filters.
104
        $identityfilters = $userentity->get_identity_filters($this->get_context());
105
        foreach ($identityfilters as $identityfilter) {
106
            $this->add_filter($identityfilter);
107
        }
108
    }
109
}