Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 23... Línea 23...
23
use core_reportbuilder\local\helpers\database;
23
use core_reportbuilder\local\helpers\database;
Línea 24... Línea 24...
24
 
24
 
25
/**
25
/**
26
 * Duration report filter
26
 * Duration report filter
27
 *
27
 *
28
 * This filter accepts a number of seconds to perform filtering on
28
 * This filter accepts a number of seconds to perform filtering on (note that the value will be cast to float prior to comparison)
29
 *
29
 *
30
 * @package     core_reportbuilder
30
 * @package     core_reportbuilder
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
Línea 75... Línea 75...
75
 
75
 
76
        // Value.
76
        // Value.
Línea 77... Línea 77...
77
        $valuelabel = get_string('filterfieldvalue', 'core_reportbuilder', $this->get_header());
77
        $valuelabel = get_string('filterfieldvalue', 'core_reportbuilder', $this->get_header());
78
 
78
 
79
        $elements[] = $mform->createElement('text', "{$this->name}_value", $valuelabel, ['size' => 3]);
79
        $elements[] = $mform->createElement('text', "{$this->name}_value", $valuelabel, ['size' => 3]);
80
        $mform->setType("{$this->name}_value", PARAM_FLOAT);
80
        $mform->setType("{$this->name}_value", PARAM_LOCALISEDFLOAT);
Línea 81... Línea 81...
81
        $mform->setDefault("{$this->name}_value", 0);
81
        $mform->setDefault("{$this->name}_value", 0);
82
        $mform->hideIf("{$this->name}_value", "{$this->name}_operator", 'eq', self::DURATION_ANY);
82
        $mform->hideIf("{$this->name}_value", "{$this->name}_operator", 'eq', self::DURATION_ANY);
Línea 105... Línea 105...
105
     *
105
     *
106
     * @param array $values
106
     * @param array $values
107
     * @return array
107
     * @return array
108
     */
108
     */
109
    public function get_sql_filter(array $values): array {
109
    public function get_sql_filter(array $values): array {
-
 
110
        global $DB;
-
 
111
 
110
        $fieldsql = $this->filter->get_field_sql();
112
        $fieldsql = $this->filter->get_field_sql();
111
        $params = $this->filter->get_field_params();
113
        $params = $this->filter->get_field_params();
Línea -... Línea 114...
-
 
114
 
-
 
115
        $operator = (int) ($values["{$this->name}_operator"] ?? self::DURATION_ANY);
112
 
116
 
113
        $durationvalue = unformat_float($values["{$this->name}_value"] ?? 0);
117
        $durationvalue = unformat_float($values["{$this->name}_value"] ?? 0);
Línea -... Línea 118...
-
 
118
        $durationunit = (int) ($values["{$this->name}_unit"] ?? 0);
114
        $durationunit = (int) ($values["{$this->name}_unit"] ?? 0);
119
 
-
 
120
        $paramduration = database::generate_param_name();
115
 
121
        $params[$paramduration] = $durationvalue * $durationunit;
116
        $operator = $values["{$this->name}_operator"] ?? self::DURATION_ANY;
122
 
117
        switch ($operator) {
-
 
118
            case self::DURATION_MAXIMUM:
-
 
119
                $paramduration = database::generate_param_name();
123
        switch ($operator) {
120
 
-
 
121
                $sql = "{$fieldsql} <= :{$paramduration}";
-
 
122
                $params[$paramduration] = $durationvalue * $durationunit;
124
            case self::DURATION_MAXIMUM:
123
 
125
                $sql = $DB->sql_cast_char2real("({$fieldsql})") . " <= :{$paramduration}";
124
                break;
-
 
125
            case self::DURATION_MINIMUM:
-
 
126
                $paramduration = database::generate_param_name();
126
                break;
127
 
-
 
128
                $sql = "{$fieldsql} >= :{$paramduration}";
-
 
129
                $params[$paramduration] = $durationvalue * $durationunit;
127
            case self::DURATION_MINIMUM:
130
 
128
                $sql = $DB->sql_cast_char2real("({$fieldsql})") . " >= :{$paramduration}";
131
                break;
129
                break;
132
            default:
130
            default:
133
                // Invalid or inactive filter.
131
                // Invalid or inactive filter.