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_admin\reportbuilder\datasource;
20
 
21
use core_admin\reportbuilder\local\entities\task_log;
22
use core_reportbuilder\datasource;
23
use core_reportbuilder\local\entities\user;
24
use core_reportbuilder\local\filters\select;
25
 
26
/**
27
 * Task logs datasource
28
 *
29
 * @package     core_admin
30
 * @copyright   2022 Paul Holden <paulh@moodle.com>
31
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class task_logs extends datasource {
34
 
35
    /**
36
     * Return user friendly name of the report source
37
     *
38
     * @return string
39
     */
40
    public static function get_name(): string {
41
        return get_string('tasklogs', 'core_admin');
42
    }
43
 
44
    /**
45
     * Initialise report
46
     */
47
    protected function initialise(): void {
48
        $tasklogentity = new task_log();
49
 
50
        $tasklogalias = $tasklogentity->get_table_alias('task_log');
51
        $this->set_main_table('task_log', $tasklogalias);
52
 
53
        $this->add_entity($tasklogentity);
54
 
55
        // Join the user entity to represent the associated user.
56
        $userentity = new user();
57
        $useralias = $userentity->get_table_alias('user');
58
        $this->add_entity($userentity->add_join("
59
            LEFT JOIN {user} {$useralias}
60
                   ON {$useralias}.id = {$tasklogalias}.userid")
61
        );
62
 
63
        // Add report elements from each of the entities we added to the report.
64
        $this->add_all_from_entities();
65
    }
66
 
67
    /**
68
     * Return the columns that will be added to the report upon creation
69
     *
70
     * @return string[]
71
     */
72
    public function get_default_columns(): array {
73
        return [
74
            'task_log:name',
75
            'task_log:starttime',
76
            'task_log:duration',
77
            'task_log:result',
78
        ];
79
    }
80
 
81
    /**
82
     * Return the column sorting that will be added to the report upon creation
83
     *
84
     * @return int[]
85
     */
86
    public function get_default_column_sorting(): array {
87
        return [
88
            'task_log:starttime' => SORT_DESC,
89
        ];
90
    }
91
 
92
    /**
93
     * Return the filters that will be added to the report upon creation
94
     *
95
     * @return string[]
96
     */
97
    public function get_default_filters(): array {
98
        return [
99
            'task_log:timestart',
100
            'task_log:result',
101
        ];
102
    }
103
 
104
    /**
105
     * Return the conditions that will be added to the report upon creation
106
     *
107
     * @return string[]
108
     */
109
    public function get_default_conditions(): array {
110
        return [
111
            'task_log:type',
112
            'task_log:timestart',
113
            'task_log:result',
114
        ];
115
    }
116
 
117
    /**
118
     * Return the condition values that will be set for the report upon creation
119
     *
120
     * @return array
121
     */
122
    public function get_default_condition_values(): array {
123
        return [
124
            'task_log:type_operator' => select::EQUAL_TO,
125
            'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED,
126
        ];
127
    }
128
}