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_notes\reportbuilder\datasource;
20
 
21
use lang_string;
22
use core_reportbuilder\datasource;
23
use core_reportbuilder\local\entities\{course, user};
24
use core_notes\reportbuilder\local\entities\note;
25
 
26
defined('MOODLE_INTERNAL') || die;
27
 
28
global $CFG;
29
require_once("{$CFG->dirroot}/notes/lib.php");
30
 
31
/**
32
 * Notes datasource
33
 *
34
 * @package     core_notes
35
 * @copyright   2022 Paul Holden <paulh@moodle.com>
36
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class notes extends datasource {
39
 
40
    /**
41
     * Return user friendly name of the report source
42
     *
43
     * @return string
44
     */
45
    public static function get_name(): string {
46
        return get_string('notes', 'core_notes');
47
    }
48
 
49
    /**
50
     * Initialise report
51
     */
52
    protected function initialise(): void {
53
        $noteentity = new note();
54
 
55
        $postalias = $noteentity->get_table_alias('post');
56
        $this->set_main_table('post', $postalias);
57
        $this->add_base_condition_simple("{$postalias}.module", 'notes');
58
 
59
        $this->add_entity($noteentity);
60
 
61
        // Join the user entity to represent the note recipient.
62
        $recipiententity = (new user())
63
            ->set_entity_name('recipient')
64
            ->set_entity_title(new lang_string('recipient', 'core_notes'));
65
        $recipientalias = $recipiententity->get_table_alias('user');
66
        $this->add_entity($recipiententity->add_join("
67
            LEFT JOIN {user} {$recipientalias}
68
                   ON {$recipientalias}.id = {$postalias}.userid")
69
        );
70
 
71
        // Join the user entity to represent the note author.
72
        $authorentity = (new user())
73
            ->set_entity_name('author')
74
            ->set_entity_title(new lang_string('author', 'core_notes'));
75
        $authoralias = $authorentity->get_table_alias('user');
76
        $this->add_entity($authorentity->add_join("
77
            LEFT JOIN {user} {$authoralias}
78
                   ON {$authoralias}.id = {$postalias}.usermodified")
79
        );
80
 
81
        // Join the course entity for course notes.
82
        $courseentity = new course();
83
        $coursealias = $courseentity->get_table_alias('course');
84
        $this->add_entity($courseentity->add_join("
85
            LEFT JOIN {course} {$coursealias}
86
                   ON {$coursealias}.id = {$postalias}.courseid
87
                  AND {$postalias}.publishstate = '" . NOTES_STATE_PUBLIC . "'")
88
        );
89
 
90
        // Add report elements from each of the entities we added to the report.
91
        $this->add_all_from_entities();
92
    }
93
 
94
    /**
95
     * Return the columns that will be added to the report upon creation
96
     *
97
     * @return string[]
98
     */
99
    public function get_default_columns(): array {
100
        return [
101
            'recipient:fullname',
102
            'note:publishstate',
103
            'course:fullname',
104
            'note:content',
105
            'note:timecreated',
106
        ];
107
    }
108
 
109
    /**
110
     * Return the column sorting that will be added to the report upon creation
111
     *
112
     * @return int[]
113
     */
114
    public function get_default_column_sorting(): array {
115
        return [
116
            'recipient:fullname' => SORT_ASC,
117
            'note:timecreated' => SORT_ASC,
118
        ];
119
    }
120
 
121
    /**
122
     * Return the filters that will be added to the report upon creation
123
     *
124
     * @return string[]
125
     */
126
    public function get_default_filters(): array {
127
        return [
128
            'recipient:fullname',
129
        ];
130
    }
131
 
132
    /**
133
     * Return the conditions that will be added to the report upon creation
134
     *
135
     * @return string[]
136
     */
137
    public function get_default_conditions(): array {
138
        return [
139
            'note:publishstate',
140
            'course:fullname',
141
            'recipient:fullname',
142
        ];
143
    }
144
}