mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
Merge branch 'MDL-75119' of https://github.com/paulholden/moodle
This commit is contained in:
commit
5087f56905
@ -19,6 +19,7 @@ declare(strict_types=1);
|
||||
namespace core_badges\reportbuilder\local\entities;
|
||||
|
||||
use context_course;
|
||||
use context_helper;
|
||||
use context_system;
|
||||
use html_writer;
|
||||
use lang_string;
|
||||
@ -48,7 +49,10 @@ class badge extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_table_aliases(): array {
|
||||
return ['badge' => 'b'];
|
||||
return [
|
||||
'badge' => 'b',
|
||||
'context' => 'bctx',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,6 +93,7 @@ class badge extends base {
|
||||
*/
|
||||
protected function get_all_columns(): array {
|
||||
$badgealias = $this->get_table_alias('badge');
|
||||
$contextalias = $this->get_table_alias('context');
|
||||
|
||||
// Name.
|
||||
$columns[] = (new column(
|
||||
@ -101,7 +106,7 @@ class badge extends base {
|
||||
->add_field("{$badgealias}.name")
|
||||
->set_is_sortable(true);
|
||||
|
||||
// Description.
|
||||
// Description (note, this column contains plaintext so requires no post-processing).
|
||||
$columns[] = (new column(
|
||||
'description',
|
||||
new lang_string('description', 'core_badges'),
|
||||
@ -137,13 +142,20 @@ class badge extends base {
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->add_join("LEFT JOIN {context} {$contextalias}
|
||||
ON {$contextalias}.contextlevel = " . CONTEXT_COURSE . "
|
||||
AND {$contextalias}.instanceid = {$badgealias}.courseid")
|
||||
->set_type(column::TYPE_INTEGER)
|
||||
->add_fields("{$badgealias}.id, {$badgealias}.type, {$badgealias}.courseid, {$badgealias}.imagecaption")
|
||||
->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
|
||||
->set_disabled_aggregation_all()
|
||||
->add_callback(static function(int $badgeid, stdClass $badge): string {
|
||||
$context = $badge->type == BADGE_TYPE_SITE
|
||||
? context_system::instance()
|
||||
: context_course::instance($badge->courseid);
|
||||
if ($badge->type == BADGE_TYPE_SITE) {
|
||||
$context = context_system::instance();
|
||||
} else {
|
||||
context_helper::preload_from_record($badge);
|
||||
$context = context_course::instance($badge->courseid);
|
||||
}
|
||||
|
||||
$badgeimage = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badgeid, '/', 'f2');
|
||||
return html_writer::img($badgeimage, $badge->imagecaption);
|
||||
|
@ -45,7 +45,10 @@ class cohort extends base {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_table_aliases(): array {
|
||||
return ['cohort' => 'c'];
|
||||
return [
|
||||
'cohort' => 'c',
|
||||
'context' => 'chctx',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,6 +89,7 @@ class cohort extends base {
|
||||
*/
|
||||
protected function get_all_columns(): array {
|
||||
$tablealias = $this->get_table_alias('cohort');
|
||||
$contextalias = $this->get_table_alias('context');
|
||||
|
||||
// Category/context column.
|
||||
$columns[] = (new column(
|
||||
@ -94,11 +98,13 @@ class cohort extends base {
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->add_join("JOIN {context} {$contextalias} ON {$contextalias}.id = {$tablealias}.contextid")
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_fields("{$tablealias}.contextid")
|
||||
->add_fields("{$tablealias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias))
|
||||
->set_is_sortable(true)
|
||||
->add_callback(static function($contextid): string {
|
||||
return context::instance_by_id((int) $contextid)->get_context_name(false);
|
||||
->add_callback(static function($contextid, stdClass $cohort): string {
|
||||
context_helper::preload_from_record($cohort);
|
||||
return context::instance_by_id($cohort->contextid)->get_context_name(false);
|
||||
});
|
||||
|
||||
// Name column.
|
||||
@ -130,8 +136,10 @@ class cohort extends base {
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_join("JOIN {context} {$contextalias} ON {$contextalias}.id = {$tablealias}.contextid")
|
||||
->set_type(column::TYPE_LONGTEXT)
|
||||
->add_fields("{$tablealias}.description, {$tablealias}.descriptionformat, {$tablealias}.id, {$tablealias}.contextid")
|
||||
->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
|
||||
->add_callback(static function(?string $description, stdClass $cohort): string {
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/filelib.php");
|
||||
@ -140,12 +148,14 @@ class cohort extends base {
|
||||
return '';
|
||||
}
|
||||
|
||||
$description = file_rewrite_pluginfile_urls($description, 'pluginfile.php', $cohort->contextid, 'cohort',
|
||||
context_helper::preload_from_record($cohort);
|
||||
$context = context::instance_by_id($cohort->contextid);
|
||||
|
||||
$description = file_rewrite_pluginfile_urls($description, 'pluginfile.php', $context->id, 'cohort',
|
||||
'description', $cohort->id);
|
||||
|
||||
return format_text($description, $cohort->descriptionformat, ['context' => $cohort->contextid]);
|
||||
})
|
||||
->set_is_sortable(false);
|
||||
return format_text($description, $cohort->descriptionformat, ['context' => $context->id]);
|
||||
});
|
||||
|
||||
// Visible column.
|
||||
$columns[] = (new column(
|
||||
|
@ -18,6 +18,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace core_course\local\entities;
|
||||
|
||||
use context_coursecat;
|
||||
use context_helper;
|
||||
use lang_string;
|
||||
use stdClass;
|
||||
use core_course_category;
|
||||
@ -134,12 +136,12 @@ class course_category extends base {
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->add_join("
|
||||
JOIN {context} {$tablealiascontext}
|
||||
ON {$tablealiascontext}.instanceid = {$tablealias}.id
|
||||
AND {$tablealiascontext}.contextlevel = " . CONTEXT_COURSECAT)
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_fields("{$tablealias}.description, {$tablealias}.descriptionformat, {$tablealiascontext}.id AS contextid")
|
||||
->add_join("LEFT JOIN {context} {$tablealiascontext}
|
||||
ON {$tablealiascontext}.contextlevel = " . CONTEXT_COURSECAT . "
|
||||
AND {$tablealiascontext}.instanceid = {$tablealias}.id")
|
||||
->set_type(column::TYPE_LONGTEXT)
|
||||
->add_fields("{$tablealias}.description, {$tablealias}.descriptionformat, {$tablealias}.id")
|
||||
->add_fields(context_helper::get_preload_record_columns_sql($tablealiascontext))
|
||||
->add_callback(static function(?string $description, stdClass $category): string {
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/filelib.php");
|
||||
@ -148,12 +150,14 @@ class course_category extends base {
|
||||
return '';
|
||||
}
|
||||
|
||||
$description = file_rewrite_pluginfile_urls($description, 'pluginfile.php', $category->contextid, 'coursecat',
|
||||
context_helper::preload_from_record($category);
|
||||
$context = context_coursecat::instance($category->id);
|
||||
|
||||
$description = file_rewrite_pluginfile_urls($description, 'pluginfile.php', $context->id, 'coursecat',
|
||||
'description', null);
|
||||
|
||||
return format_text($description, $category->descriptionformat, ['context' => $category->contextid]);
|
||||
})
|
||||
->set_is_sortable(false);
|
||||
return format_text($description, $category->descriptionformat, ['context' => $context->id]);
|
||||
});
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user