Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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_badges\reportbuilder\local\systemreports;
20
 
21
use core_badges\reportbuilder\local\entities\badge_issued;
22
use core_reportbuilder\local\report\action;
23
use core_reportbuilder\system_report;
24
use lang_string;
25
use moodle_url;
26
use pix_icon;
27
 
28
/**
29
 * Badge recipients system report class implementation
30
 *
31
 * @package    core_badges
32
 * @copyright  2023 David Carrillo <davidmc@moodle.com>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class recipients extends system_report {
36
 
37
    /**
38
     * Initialise report, we need to set the main table, load our entities and set columns/filters
39
     */
40
    protected function initialise(): void {
41
        // Our main entity, it contains all of the column definitions that we need.
42
        $badgeissuedentity = new badge_issued();
43
        $entityalias = $badgeissuedentity->get_table_alias('badge_issued');
44
 
45
        $this->set_main_table('badge_issued', $entityalias);
46
        $this->add_entity($badgeissuedentity);
47
 
48
        $userentity = new \core_reportbuilder\local\entities\user();
49
        $entityuseralias = $userentity->get_table_alias('user');
50
        $this->add_entity($userentity
51
            ->add_joins($userentity->get_joins())
52
            ->add_join("JOIN {user} {$entityuseralias}
53
                ON {$entityuseralias}.id = {$entityalias}.userid")
54
        );
55
 
56
        $this->add_base_condition_simple('badgeid', $this->get_parameter('badgeid', 0, PARAM_INT));
57
 
58
        $this->add_base_fields("{$entityalias}.uniquehash");
59
 
60
        // Now we can call our helper methods to add the content we want to include in the report.
61
        $this->add_columns();
62
        $this->add_filters();
63
        $this->add_actions();
64
 
1441 ariadna 65
        $this->set_initial_sort_column('badge_issued:issued', SORT_DESC);
66
        $this->set_default_no_results_notice(new lang_string('nomatchingawards', 'core_badges'));
67
 
1 efrain 68
        // Set if report can be downloaded.
69
        $this->set_downloadable(false);
70
    }
71
 
72
    /**
73
     * Validates access to view this report
74
     *
75
     * @return bool
76
     */
77
    protected function can_view(): bool {
1441 ariadna 78
        $badgeid = $this->get_parameter('badgeid', 0, PARAM_INT);
79
        $badge = new \core_badges\badge($badgeid);
80
        return has_capability('moodle/badges:viewawarded', $badge->get_context());
1 efrain 81
    }
82
 
83
    /**
84
     * Adds the columns we want to display in the report
85
     *
86
     * They are provided by the entities we previously added in the {@see initialise} method, referencing each by their
87
     * unique identifier. If custom columns are needed just for this report, they can be defined here.
88
     */
1441 ariadna 89
    protected function add_columns(): void {
90
        $this->add_columns_from_entities([
1 efrain 91
            'user:fullnamewithlink',
92
            'badge_issued:issued',
1441 ariadna 93
        ]);
1 efrain 94
    }
95
 
96
    /**
97
     * Adds the filters we want to display in the report
98
     *
99
     * They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
100
     * unique identifier
101
     */
102
    protected function add_filters(): void {
1441 ariadna 103
        $this->add_filters_from_entities([
1 efrain 104
            'user:fullname',
105
            'badge_issued:issued',
1441 ariadna 106
        ]);
1 efrain 107
    }
108
 
109
    /**
110
     * Add the system report actions. An extra column will be appended to each row, containing all actions added here
111
     *
112
     * Note the use of ":uniquehash" placeholder which will be substituted according to actual values in the row
113
     */
114
    protected function add_actions(): void {
115
        $this->add_action((new action(
116
            new moodle_url('/badges/badge.php', [
117
                'hash' => ':uniquehash',
118
            ]),
119
            new pix_icon('i/search', '', 'core'),
120
            [],
121
            false,
122
            new lang_string('viewbadge', 'badges')
123
        )));
124
    }
125
}