Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 19... Línea 19...
19
namespace core_reportbuilder\local\report;
19
namespace core_reportbuilder\local\report;
Línea 20... Línea 20...
20
 
20
 
21
use lang_string;
21
use lang_string;
22
use moodle_exception;
22
use moodle_exception;
23
use core_reportbuilder\local\filters\base;
23
use core_reportbuilder\local\filters\base;
24
use core_reportbuilder\local\helpers\database;
24
use core_reportbuilder\local\helpers\{database, join_trait};
Línea 25... Línea 25...
25
use core_reportbuilder\local\models\filter as filter_model;
25
use core_reportbuilder\local\models\filter as filter_model;
26
 
26
 
27
/**
27
/**
Línea 31... Línea 31...
31
 * @copyright   2021 Paul Holden <paulh@moodle.com>
31
 * @copyright   2021 Paul Holden <paulh@moodle.com>
32
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
33
 */
34
final class filter {
34
final class filter {
Línea 35... Línea -...
35
 
-
 
36
    /** @var string $filterclass */
35
 
37
    private $filterclass;
-
 
38
 
-
 
39
    /** @var string $name */
-
 
40
    private $name;
-
 
41
 
-
 
42
    /** @var lang_string $header */
-
 
43
    private $header;
-
 
44
 
-
 
45
    /** @var string $entity */
-
 
Línea 46... Línea 36...
46
    private $entityname;
36
    use join_trait;
47
 
37
 
Línea 48... Línea 38...
48
    /** @var string $fieldsql */
38
    /** @var string $fieldsql */
49
    private $fieldsql = '';
39
    private $fieldsql = '';
Línea 50... Línea -...
50
 
-
 
51
    /** @var array $fieldparams */
-
 
52
    private $fieldparams = [];
-
 
53
 
40
 
54
    /** @var string[] $joins */
41
    /** @var array $fieldparams */
Línea 55... Línea 42...
55
    protected $joins = [];
42
    private $fieldparams = [];
56
 
43
 
Línea 57... Línea 44...
57
    /** @var bool $available */
44
    /** @var bool $available */
58
    protected $available = true;
45
    private $available = true;
Línea 59... Línea 46...
59
 
46
 
60
    /** @var bool $deprecated */
47
    /** @var bool $deprecated */
Línea 61... Línea 48...
61
    protected $deprecated = false;
48
    private $deprecated = false;
62
 
49
 
Línea 63... Línea 50...
63
    /** @var string $deprecatedmessage */
50
    /** @var string $deprecatedmessage */
64
    protected $deprecatedmessage;
51
    private $deprecatedmessage;
Línea 65... Línea 52...
65
 
52
 
66
    /** @var mixed $options */
53
    /** @var mixed $options */
67
    protected $options;
54
    private $options;
68
 
55
 
Línea 84... Línea 71...
84
     * @param string $fieldsql SQL clause to use for filtering, {@see set_field_sql}
71
     * @param string $fieldsql SQL clause to use for filtering, {@see set_field_sql}
85
     * @param array $fieldparams
72
     * @param array $fieldparams
86
     * @throws moodle_exception For invalid filter class
73
     * @throws moodle_exception For invalid filter class
87
     */
74
     */
88
    public function __construct(
75
    public function __construct(
-
 
76
        /** @var string Filter type class to use, must extend {@see base} filter class */
89
        string $filterclass,
77
        private readonly string $filterclass,
-
 
78
        /** @var string Internal name of the filter */
90
        string $name,
79
        private readonly string $name,
-
 
80
        /** @var lang_string Title of the filter used in reports */
91
        lang_string $header,
81
        private lang_string $header,
-
 
82
        /** @var string Name of the entity this filter belongs to */
92
        string $entityname,
83
        private readonly string $entityname,
93
        string $fieldsql = '',
84
        string $fieldsql = '',
94
        array $fieldparams = []
85
        array $fieldparams = [],
95
    ) {
86
    ) {
96
        if (!class_exists($filterclass) || !is_subclass_of($filterclass, base::class)) {
87
        if (!class_exists($filterclass) || !is_subclass_of($filterclass, base::class)) {
97
            throw new moodle_exception('filterinvalid', 'reportbuilder', '', null, $filterclass);
88
            throw new moodle_exception('filterinvalid', 'reportbuilder', '', null, $filterclass);
98
        }
89
        }
Línea 99... Línea -...
99
 
-
 
100
        $this->filterclass = $filterclass;
-
 
101
        $this->name = $name;
-
 
102
        $this->header = $header;
-
 
103
        $this->entityname = $entityname;
-
 
104
 
90
 
105
        if ($fieldsql !== '') {
91
        if ($fieldsql !== '') {
106
            $this->set_field_sql($fieldsql, $fieldparams);
92
            $this->set_field_sql($fieldsql, $fieldparams);
107
        }
93
        }
Línea 162... Línea 148...
162
    public function get_unique_identifier(): string {
148
    public function get_unique_identifier(): string {
163
        return $this->get_entity_name() . ':' . $this->get_name();
149
        return $this->get_entity_name() . ':' . $this->get_name();
164
    }
150
    }
Línea 165... Línea 151...
165
 
151
 
166
    /**
-
 
167
     * Return joins
-
 
168
     *
-
 
169
     * @return string[]
-
 
170
     */
-
 
171
    public function get_joins(): array {
-
 
172
        return array_values($this->joins);
-
 
173
    }
-
 
174
 
-
 
175
    /**
-
 
176
     * Add join clause required for this filter to join to existing tables/entities
-
 
177
     *
-
 
178
     * This is necessary in the case where {@see set_field_sql} is selecting data from a table that isn't otherwise queried
-
 
179
     *
-
 
180
     * @param string $join
-
 
181
     * @return self
-
 
182
     */
-
 
183
    public function add_join(string $join): self {
-
 
184
        $this->joins[trim($join)] = trim($join);
-
 
185
        return $this;
-
 
186
    }
-
 
187
 
-
 
188
    /**
-
 
189
     * Add multiple join clauses required for this filter, passing each to {@see add_join}
-
 
190
     *
-
 
191
     * Typically when defining filters in entities, you should pass {@see \core_reportbuilder\local\report\base::get_joins} to
-
 
192
     * this method, so that all entity joins are included in the report when your filter is used in it
-
 
193
     *
-
 
194
     * @param string[] $joins
-
 
195
     * @return self
-
 
196
     */
-
 
197
    public function add_joins(array $joins): self {
-
 
198
        foreach ($joins as $join) {
-
 
199
            $this->add_join($join);
-
 
200
        }
-
 
201
        return $this;
-
 
202
    }
-
 
203
 
-
 
204
    /**
152
    /**
205
     * Get SQL expression for the field
153
     * Get SQL expression for the field
206
     *
154
     *
207
     * @return string
155
     * @return string
208
     */
156
     */