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 |
* User dedication datasource.
|
|
|
19 |
* @package block_dedication
|
|
|
20 |
* @copyright 2022 University of Canterbury
|
|
|
21 |
* @author Pramith Dayananda <pramithd@catalyst.net.nz>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
declare(strict_types=1);
|
|
|
27 |
|
|
|
28 |
namespace block_dedication\reportbuilder\datasource;
|
|
|
29 |
|
|
|
30 |
use core_reportbuilder\datasource;
|
|
|
31 |
use core_reportbuilder\local\entities\course;
|
|
|
32 |
use core_reportbuilder\local\entities\user;
|
|
|
33 |
use block_dedication\local\entities\dedication;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* User dedication datasource.
|
|
|
37 |
*/
|
|
|
38 |
class user_dedication extends datasource {
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Return user friendly name of the datasource
|
|
|
42 |
*
|
|
|
43 |
* @return string
|
|
|
44 |
*/
|
|
|
45 |
public static function get_name(): string {
|
|
|
46 |
return get_string('user_dedication_datasource', 'block_dedication');
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Initialise report
|
|
|
51 |
*/
|
|
|
52 |
protected function initialise(): void {
|
|
|
53 |
$dedication = new dedication();
|
|
|
54 |
$dedicationalias = $dedication->get_table_alias('block_dedication');
|
|
|
55 |
$this->set_main_table('block_dedication', $dedicationalias);
|
|
|
56 |
$this->add_entity($dedication);
|
|
|
57 |
|
|
|
58 |
// Add core user join.
|
|
|
59 |
$usercore = new user();
|
|
|
60 |
$usercorealias = $usercore->get_table_alias('user');
|
|
|
61 |
$usercorejoin = "JOIN {user} {$usercorealias} ON {$usercorealias}.id = {$dedicationalias}.userid";
|
|
|
62 |
$this->add_entity($usercore->add_join($usercorejoin));
|
|
|
63 |
|
|
|
64 |
$coursecore = new course();
|
|
|
65 |
$coursecorealias = $coursecore->get_table_alias('course');
|
|
|
66 |
$coursecorejoin = "JOIN {course} {$coursecorealias} ON {$coursecorealias}.id = {$dedicationalias}.courseid";
|
|
|
67 |
$this->add_entity($coursecore->add_join($coursecorejoin));
|
|
|
68 |
|
|
|
69 |
$this->add_columns_from_entity($usercore->get_entity_name());
|
|
|
70 |
$this->add_columns_from_entity($coursecore->get_entity_name());
|
|
|
71 |
$this->add_columns_from_entity($dedication->get_entity_name());
|
|
|
72 |
|
|
|
73 |
$this->add_filters_from_entity($usercore->get_entity_name());
|
|
|
74 |
$this->add_filters_from_entity($coursecore->get_entity_name());
|
|
|
75 |
$this->add_filters_from_entity($dedication->get_entity_name());
|
|
|
76 |
|
|
|
77 |
$this->add_conditions_from_entity($usercore->get_entity_name());
|
|
|
78 |
$this->add_conditions_from_entity($coursecore->get_entity_name());
|
|
|
79 |
$this->add_conditions_from_entity($dedication->get_entity_name());
|
|
|
80 |
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Return the columns that will be added to the report once is created
|
|
|
86 |
*
|
|
|
87 |
* @return string[]
|
|
|
88 |
*/
|
|
|
89 |
public function get_default_columns(): array {
|
|
|
90 |
return ['user:fullname', 'user:username', 'course:shortname', 'dedication:timespent'];
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Return the filters that will be added to the report once is created
|
|
|
95 |
*
|
|
|
96 |
* @return string[]
|
|
|
97 |
*/
|
|
|
98 |
public function get_default_filters(): array {
|
|
|
99 |
return ['user:fullname', 'user:username', 'course:shortname', 'user:email'];
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* Return the conditions that will be added to the report once is created
|
|
|
104 |
*
|
|
|
105 |
* @return string[]
|
|
|
106 |
*/
|
|
|
107 |
public function get_default_conditions(): array {
|
|
|
108 |
return [];
|
|
|
109 |
}
|
|
|
110 |
}
|