Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace core_ai\reportbuilder\local\entities;
18
 
19
use core_reportbuilder\local\entities\base;
20
use core_reportbuilder\local\filters\date;
21
use core_reportbuilder\local\helpers\format;
22
use core_reportbuilder\local\report\column;
23
use core_reportbuilder\local\report\filter;
24
use lang_string;
25
 
26
/**
27
 * AI policy register entity.
28
 *
29
 * Defines all the columns and filters that can be added to reports that use this entity.
30
 *
31
 * @package    core_ai
32
 * @copyright  2024 David Woloszyn <david.woloszyn@moodle.com>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class ai_policy_register extends base {
36
 
37
    #[\Override]
38
    protected function get_default_tables(): array {
39
        return [
40
            'ai_policy_register',
41
        ];
42
    }
43
 
44
    #[\Override]
45
    protected function get_default_entity_title(): lang_string {
46
        return new lang_string('aipolicyregister', 'core_ai');
47
    }
48
 
49
    #[\Override]
50
    public function initialise(): base {
51
        $columns = $this->get_all_columns();
52
        foreach ($columns as $column) {
53
            $this->add_column($column);
54
        }
55
 
56
        // All the filters defined by the entity can also be used as conditions.
57
        $filters = $this->get_all_filters();
58
        foreach ($filters as $filter) {
59
            $this
60
                ->add_filter($filter)
61
                ->add_condition($filter);
62
        }
63
 
64
        return $this;
65
    }
66
 
67
    /**
68
     * Returns list of all available columns.
69
     *
70
     * @return column[]
71
     */
72
    protected function get_all_columns(): array {
73
        $tablealias = $this->get_table_alias('ai_policy_register');
74
 
75
        // Time accepted column.
76
        $columns[] = (new column(
77
            'timeaccepted',
78
            new lang_string('dateaccepted', 'core_ai'),
79
            $this->get_entity_name(),
80
        ))
81
            ->add_joins($this->get_joins())
82
            ->set_type(column::TYPE_TIMESTAMP)
83
            ->add_field("{$tablealias}.timeaccepted")
84
            ->set_is_sortable(true)
85
            ->add_callback([format::class, 'userdate']);
86
 
87
        return $columns;
88
    }
89
 
90
    /**
91
     * Return list of all available filters.
92
     *
93
     * @return filter[]
94
     */
95
    protected function get_all_filters(): array {
96
        $tablealias = $this->get_table_alias('ai_policy_register');
97
 
98
        // Time accepted filter.
99
        $filters[] = (new filter(
100
            date::class,
101
            'timeaccepted',
102
            new lang_string('dateaccepted', 'core_ai'),
103
            $this->get_entity_name(),
104
            "{$tablealias}.timeaccepted",
105
        ))
106
            ->add_joins($this->get_joins())
107
            ->set_limited_operators([
108
                date::DATE_ANY,
109
                date::DATE_RANGE,
110
                date::DATE_PREVIOUS,
111
                date::DATE_CURRENT,
112
            ]);
113
 
114
        return $filters;
115
    }
116
}