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_cohort\reportbuilder\local\entities;
20
 
21
use lang_string;
22
use core_reportbuilder\local\entities\base;
23
use core_reportbuilder\local\filters\date;
24
use core_reportbuilder\local\helpers\format;
25
use core_reportbuilder\local\report\column;
26
use core_reportbuilder\local\report\filter;
27
 
28
/**
29
 * Cohort member entity
30
 *
31
 * @package     core_cohort
32
 * @copyright   2021 Paul Holden <paulh@moodle.com>
33
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class cohort_member extends base {
36
 
37
    /**
38
     * Database tables that this entity uses
39
     *
40
     * @return string[]
41
     */
42
    protected function get_default_tables(): array {
43
        return [
44
            'cohort_members',
45
        ];
46
    }
47
 
48
    /**
49
     * The default title for this entity
50
     *
51
     * @return lang_string
52
     */
53
    protected function get_default_entity_title(): lang_string {
54
        return new lang_string('cohortmember', 'core_cohort');
55
    }
56
 
57
    /**
58
     * Initialise the entity
59
     *
60
     * @return base
61
     */
62
    public function initialise(): base {
63
        $columns = $this->get_all_columns();
64
        foreach ($columns as $column) {
65
            $this->add_column($column);
66
        }
67
 
68
        // All the filters defined by the entity can also be used as conditions.
69
        $filters = $this->get_all_filters();
70
        foreach ($filters as $filter) {
71
            $this
72
                ->add_filter($filter)
73
                ->add_condition($filter);
74
        }
75
 
76
        return $this;
77
    }
78
 
79
    /**
80
     * Returns list of all available columns
81
     *
82
     * @return column[]
83
     */
84
    protected function get_all_columns(): array {
85
        $tablealias = $this->get_table_alias('cohort_members');
86
 
87
        // Time added column.
88
        $columns[] = (new column(
89
            'timeadded',
90
            new lang_string('timeadded', 'core_reportbuilder'),
91
            $this->get_entity_name()
92
        ))
93
            ->add_joins($this->get_joins())
94
            ->set_type(column::TYPE_TIMESTAMP)
95
            ->add_fields("{$tablealias}.timeadded")
96
            ->set_is_sortable(true)
97
            ->set_callback([format::class, 'userdate']);
98
 
99
        return $columns;
100
    }
101
 
102
    /**
103
     * Return list of all available filters
104
     *
105
     * @return filter[]
106
     */
107
    protected function get_all_filters(): array {
108
        $tablealias = $this->get_table_alias('cohort_members');
109
 
110
        // Time added filter.
111
        $filters[] = (new filter(
112
            date::class,
113
            'timeadded',
114
            new lang_string('timeadded', 'core_reportbuilder'),
115
            $this->get_entity_name(),
116
            "{$tablealias}.timeadded"
117
        ))
118
            ->add_joins($this->get_joins());
119
 
120
        return $filters;
121
    }
122
}