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