Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
declare(strict_types=1);
17
declare(strict_types=1);
Línea 18... Línea 18...
18
 
18
 
19
namespace core_reportbuilder\local\aggregation;
19
namespace core_reportbuilder\local\aggregation;
Línea 20... Línea 20...
20
 
20
 
21
use lang_string;
21
use core\lang_string;
22
use core_reportbuilder\local\report\column;
22
use core_reportbuilder\local\report\column;
Línea 29... Línea 29...
29
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
30
 */
31
abstract class base {
31
abstract class base {
Línea 32... Línea 32...
32
 
32
 
-
 
33
    /**
-
 
34
     * Constructor
-
 
35
     *
-
 
36
     * @param array $options Aggregation type specific options
-
 
37
     */
-
 
38
    public function __construct(
-
 
39
        /** @var array Aggregation type specific options */
-
 
40
        protected readonly array $options = [],
-
 
41
    ) {
-
 
42
 
-
 
43
    }
-
 
44
 
33
    /**
45
    /**
34
     * Return the class name of the aggregation type
46
     * Return the class name of the aggregation type
35
     *
47
     *
36
     * @return string
48
     * @return string
37
     */
49
     */
Línea 89... Línea 101...
89
        string $delimeter = ',',
101
        string $delimeter = ',',
90
        string $coalescechar = ' '
102
        string $coalescechar = ' '
91
    ): string {
103
    ): string {
92
        global $DB;
104
        global $DB;
Línea 93... Línea 105...
93
 
105
 
94
        // We need to ensure all values are char.
106
        // We need to ensure all values are char in supported DBs.
Línea 95... Línea 107...
95
        $sqlfieldrequirescast = in_array($DB->get_dbfamily(), ['mssql', 'oracle', 'postgres']);
107
        $sqlfieldrequirescast = in_array($DB->get_dbfamily(), ['mssql', 'postgres']);
96
 
108
 
97
        $concatfields = [];
109
        $concatfields = [];
98
        foreach ($sqlfields as $sqlfield) {
110
        foreach ($sqlfields as $sqlfield) {
Línea 117... Línea 129...
117
     * @return string
129
     * @return string
118
     */
130
     */
119
    abstract public static function get_field_sql(string $field, int $columntype): string;
131
    abstract public static function get_field_sql(string $field, int $columntype): string;
Línea 120... Línea 132...
120
 
132
 
-
 
133
    /**
-
 
134
     * Whether the aggregation method is applied to a column, this method determines whether the report table should
-
 
135
     * group by the column fields or not
-
 
136
     *
-
 
137
     * @return bool
-
 
138
     */
-
 
139
    public static function column_groupby(): bool {
-
 
140
        return false;
-
 
141
    }
-
 
142
 
-
 
143
    /**
-
 
144
     * Return aggregated column type, that being one of the column TYPE_* constants like {@see column::get_type}
-
 
145
     *
-
 
146
     * Classes should override this method to define the type of data that the aggregated column value returns (e.g 'count'
-
 
147
     * returns a numeric value, regardless of the original column type to which it is applied)
-
 
148
     *
-
 
149
     * @param int $columntype The type of the column to which the aggregation is applied
-
 
150
     * @return int
-
 
151
     */
-
 
152
    public static function get_column_type(int $columntype): int {
-
 
153
        return column::TYPE_TEXT;
-
 
154
    }
-
 
155
 
121
    /**
156
    /**
122
     * Return formatted value for column when applying aggregation, by default executing all callbacks on the value
157
     * Return formatted value for column when applying aggregation, by default executing all callbacks on the value
123
     *
158
     *
124
     * Should be overridden in child classes that need to format the column value differently (e.g. 'sum' would just show
159
     * Should be overridden in child classes that need to format the column value differently (e.g. 'sum' would just show
125
     * a numeric count value)
160
     * a numeric count value)
Línea 128... Línea 163...
128
     * @param array $values
163
     * @param array $values
129
     * @param array $callbacks Array of column callbacks, {@see column::add_callback} for definition
164
     * @param array $callbacks Array of column callbacks, {@see column::add_callback} for definition
130
     * @param int $columntype The original type of the column, to ensure it is preserved for callbacks
165
     * @param int $columntype The original type of the column, to ensure it is preserved for callbacks
131
     * @return mixed
166
     * @return mixed
132
     */
167
     */
133
    public static function format_value($value, array $values, array $callbacks, int $columntype) {
168
    public function format_value($value, array $values, array $callbacks, int $columntype) {
134
        foreach ($callbacks as $callback) {
169
        foreach ($callbacks as $callback) {
135
            [$callable, $arguments] = $callback;
170
            [$callable, $arguments] = $callback;
136
            $value = ($callable)($value, (object) $values, $arguments, static::get_class_name());
171
            $value = ($callable)($value, (object) $values, $arguments, static::get_class_name());
137
        }
172
        }