Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 93... Línea 93...
93
     * Returns list of all available columns
93
     * Returns list of all available columns
94
     *
94
     *
95
     * @return column[]
95
     * @return column[]
96
     */
96
     */
97
    protected function get_all_columns(): array {
97
    protected function get_all_columns(): array {
98
        global $DB;
-
 
99
 
-
 
100
        $badgealias = $this->get_table_alias('badge');
98
        $badgealias = $this->get_table_alias('badge');
101
        $contextalias = $this->get_table_alias('context');
99
        $contextalias = $this->get_table_alias('context');
Línea 102... Línea 100...
102
 
100
 
103
        // Name.
101
        // Name.
Línea 128... Línea 126...
128
 
126
 
129
                $url = new moodle_url('/badges/overview.php', ['id' => $row->id]);
127
                $url = new moodle_url('/badges/overview.php', ['id' => $row->id]);
130
                return html_writer::link($url, $row->name);
128
                return html_writer::link($url, $row->name);
Línea -... Línea 129...
-
 
129
            });
-
 
130
 
-
 
131
        // Name with image and link.
-
 
132
        $columns[] = (new column(
-
 
133
            'namewithimagelink',
-
 
134
            new lang_string('namewithimagelink', 'core_badges'),
-
 
135
            $this->get_entity_name()
-
 
136
        ))
-
 
137
            ->add_joins($this->get_joins())
-
 
138
            ->add_join("LEFT JOIN {context} {$contextalias}
-
 
139
                    ON {$contextalias}.contextlevel = " . CONTEXT_COURSE . "
-
 
140
                   AND {$contextalias}.instanceid = {$badgealias}.courseid")
-
 
141
            ->add_fields(
-
 
142
                "{$badgealias}.name, {$badgealias}.id, {$badgealias}.type, {$badgealias}.courseid, {$badgealias}.imagecaption"
-
 
143
            )
-
 
144
            ->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
-
 
145
            ->set_is_sortable(true)
-
 
146
            ->add_callback(static function ($value, stdClass $badge): string {
-
 
147
                if ($badge->id === null) {
-
 
148
                    return '';
-
 
149
                }
-
 
150
                if ($badge->type == BADGE_TYPE_SITE) {
-
 
151
                    $context = context_system::instance();
-
 
152
                } else {
-
 
153
                    context_helper::preload_from_record($badge);
-
 
154
                    $context = context_course::instance($badge->courseid);
-
 
155
                }
-
 
156
 
-
 
157
                $badgeimage = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f2');
-
 
158
                $url = new moodle_url('/badges/overview.php', ['id' => $badge->id]);
-
 
159
                return html_writer::img($badgeimage, $badge->imagecaption) . ' ' . html_writer::link($url, $badge->name);
131
            });
160
            });
132
 
-
 
133
        // Description (note, this column contains plaintext so requires no post-processing).
-
 
134
        $descriptionfieldsql = "{$badgealias}.description";
-
 
135
        if ($DB->get_dbfamily() === 'oracle') {
-
 
136
            $descriptionfieldsql = $DB->sql_order_by_text($descriptionfieldsql, 1024);
161
 
137
        }
162
        // Description (note, this column contains plaintext so requires no post-processing).
138
        $columns[] = (new column(
163
        $columns[] = (new column(
139
            'description',
164
            'description',
140
            new lang_string('description', 'core_badges'),
165
            new lang_string('description', 'core_badges'),
141
            $this->get_entity_name()
166
            $this->get_entity_name()
142
        ))
167
        ))
143
            ->add_joins($this->get_joins())
168
            ->add_joins($this->get_joins())
-
 
169
            ->set_type(column::TYPE_LONGTEXT)
Línea 144... Línea 170...
144
            ->set_type(column::TYPE_LONGTEXT)
170
            ->add_field("{$badgealias}.description")
145
            ->add_field($descriptionfieldsql, 'description');
171
            ->set_is_sortable(true);
146
 
172
 
147
        // Criteria.
173
        // Criteria.
Línea 158... Línea 184...
158
                global $PAGE;
184
                global $PAGE;
159
                if (!$badgeid) {
185
                if (!$badgeid) {
160
                    return '';
186
                    return '';
161
                }
187
                }
162
                $badge = new \core_badges\badge($badgeid);
188
                $badge = new \core_badges\badge($badgeid);
163
 
-
 
-
 
189
                if (empty($badge->criteria)) {
-
 
190
                    return '<span class="no-criteria-set d-none"></span>';
-
 
191
                }
164
                $renderer = $PAGE->get_renderer('core_badges');
192
                $renderer = $PAGE->get_renderer('core_badges');
165
                return $renderer->print_badge_criteria($badge, 'short');
193
                return $renderer->print_badge_criteria($badge, 'short');
166
            });
194
            });
Línea 167... Línea 195...
167
 
195
 
Línea 173... Línea 201...
173
        ))
201
        ))
174
            ->add_joins($this->get_joins())
202
            ->add_joins($this->get_joins())
175
            ->add_join("LEFT JOIN {context} {$contextalias}
203
            ->add_join("LEFT JOIN {context} {$contextalias}
176
                    ON {$contextalias}.contextlevel = " . CONTEXT_COURSE . "
204
                    ON {$contextalias}.contextlevel = " . CONTEXT_COURSE . "
177
                   AND {$contextalias}.instanceid = {$badgealias}.courseid")
205
                   AND {$contextalias}.instanceid = {$badgealias}.courseid")
178
            ->set_type(column::TYPE_INTEGER)
-
 
179
            ->add_fields("{$badgealias}.id, {$badgealias}.type, {$badgealias}.courseid")
206
            ->add_fields("{$badgealias}.id, {$badgealias}.type, {$badgealias}.courseid, {$badgealias}.imagecaption")
180
            ->add_field($DB->sql_cast_to_char("{$badgealias}.imagecaption"), 'imagecaption')
-
 
181
            ->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
207
            ->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
182
            ->set_disabled_aggregation_all()
-
 
183
            ->add_callback(static function(?int $badgeid, stdClass $badge): string {
208
            ->add_callback(static function($value, stdClass $badge): string {
184
                if (!$badgeid) {
209
                if ($badge->id === null) {
185
                    return '';
210
                    return '';
186
                }
211
                }
187
                if ($badge->type == BADGE_TYPE_SITE) {
212
                if ($badge->type == BADGE_TYPE_SITE) {
188
                    $context = context_system::instance();
213
                    $context = context_system::instance();
189
                } else {
214
                } else {
190
                    context_helper::preload_from_record($badge);
215
                    context_helper::preload_from_record($badge);
191
                    $context = context_course::instance($badge->courseid);
216
                    $context = context_course::instance($badge->courseid);
192
                }
217
                }
Línea 193... Línea 218...
193
 
218
 
194
                $badgeimage = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badgeid, '/', 'f2');
219
                $badgeimage = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f2');
195
                return html_writer::img($badgeimage, $badge->imagecaption);
220
                return html_writer::img($badgeimage, $badge->imagecaption);
Línea 196... Línea 221...
196
            });
221
            });
197
 
222
 
Línea 205... Línea 230...
205
            ->set_type(column::TYPE_TEXT)
230
            ->set_type(column::TYPE_TEXT)
206
            ->add_field("{$badgealias}.language")
231
            ->add_field("{$badgealias}.language")
207
            ->set_is_sortable(true)
232
            ->set_is_sortable(true)
208
            ->add_callback(static function($language): string {
233
            ->add_callback(static function($language): string {
209
                $languages = get_string_manager()->get_list_of_languages();
234
                $languages = get_string_manager()->get_list_of_languages();
210
                return $languages[$language] ?? $language ?? '';
235
                return (string) ($languages[$language] ?? $language);
211
            });
236
            });
Línea 212... Línea 237...
212
 
237
 
213
        // Version.
238
        // Version.
214
        $columns[] = (new column(
239
        $columns[] = (new column(
Línea 260... Línea 285...
260
                } else {
285
                } else {
261
                    return get_string('never', 'core_badges');
286
                    return get_string('never', 'core_badges');
262
                }
287
                }
263
            });
288
            });
Línea 264... Línea -...
264
 
-
 
265
        // Image author details.
-
 
266
        foreach (['imageauthorname', 'imageauthoremail', 'imageauthorurl'] as $imageauthorfield) {
-
 
267
            $columns[] = (new column(
-
 
268
                $imageauthorfield,
-
 
269
                new lang_string($imageauthorfield, 'core_badges'),
-
 
270
                $this->get_entity_name()
-
 
271
            ))
-
 
272
                ->add_joins($this->get_joins())
-
 
273
                ->set_type(column::TYPE_TEXT)
-
 
274
                ->add_field("{$badgealias}.{$imageauthorfield}")
-
 
275
                ->set_is_sortable(true);
-
 
276
        }
-
 
277
 
289
 
278
        return $columns;
290
        return $columns;
Línea 279... Línea 291...
279
    }
291
    }
280
 
292
 
281
    /**
293
    /**
282
     * Return list of all available filters
294
     * Return list of all available filters
283
     *
295
     *
284
     * @return filter[]
296
     * @return filter[]
285
     */
-
 
286
    protected function get_all_filters(): array {
-
 
287
        global $DB;
297
     */
Línea 288... Línea 298...
288
 
298
    protected function get_all_filters(): array {
289
        $badgealias = $this->get_table_alias('badge');
299
        $badgealias = $this->get_table_alias('badge');
290
 
300
 
Línea 324... Línea 334...
324
                BADGE_STATUS_ACTIVE_LOCKED => new lang_string('badgestatus_3', 'core_badges'),
334
                BADGE_STATUS_ACTIVE_LOCKED => new lang_string('badgestatus_3', 'core_badges'),
325
                BADGE_STATUS_ARCHIVED => new lang_string('badgestatus_4', 'core_badges'),
335
                BADGE_STATUS_ARCHIVED => new lang_string('badgestatus_4', 'core_badges'),
326
            ]);
336
            ]);
Línea 327... Línea 337...
327
 
337
 
328
        // Expiry date/period.
338
        // Expiry date/period.
329
        [$parammaxint, $paramtime] = database::generate_param_names(2);
339
        $paramtime = database::generate_param_name();
330
        $filters[] = (new filter(
340
        $filters[] = (new filter(
331
            date::class,
341
            date::class,
332
            'expiry',
342
            'expiry',
333
            new lang_string('expirydate', 'core_badges'),
343
            new lang_string('expirydate', 'core_badges'),
334
            $this->get_entity_name(),
344
            $this->get_entity_name(),
335
            "CASE WHEN {$badgealias}.expiredate IS NULL AND {$badgealias}.expireperiod IS NULL
345
            "CASE WHEN {$badgealias}.expiredate IS NULL AND {$badgealias}.expireperiod IS NULL
336
                  THEN " . $DB->sql_cast_char2int(":{$parammaxint}") . "
346
                  THEN " . SQL_INT_MAX . "
337
                  ELSE COALESCE({$badgealias}.expiredate, {$badgealias}.expireperiod + :{$paramtime})
347
                  ELSE COALESCE({$badgealias}.expiredate, {$badgealias}.expireperiod + :{$paramtime})
338
             END",
348
             END",
339
            [$parammaxint => 2147483647, $paramtime => time()]
349
            [$paramtime => time()]
340
        ))
350
        ))
341
            ->add_joins($this->get_joins())
351
            ->add_joins($this->get_joins())
342
            ->set_limited_operators([
352
            ->set_limited_operators([
343
                date::DATE_ANY,
353
                date::DATE_ANY,