Commit cac0068d authored by Paul Holden's avatar Paul Holden
Browse files

MDL-72961 reportbuilder: move category elements to correct entity.

parent 677c2df9
......@@ -99,6 +99,21 @@ class course_category extends base {
->add_fields("{$tablealias}.name")
->set_is_sortable(true);
// Path column.
$columns[] = (new column(
'path',
new lang_string('categorypath'),
$this->get_entity_name()
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_fields("{$tablealias}.name, {$tablealias}.id")
->add_callback(static function(string $name, stdClass $category): string {
return core_course_category::get($category->id, MUST_EXIST, true)->get_nested_name(false);
})
->set_disabled_aggregation(['groupconcat', 'groupconcatdistinct'])
->set_is_sortable(true);
// ID number column.
$columns[] = (new column(
'idnumber',
......
......@@ -243,6 +243,7 @@ $string['categoryheader'] = 'Category menu';
$string['categoryhidden'] = '(hidden)';
$string['categorymodifiedcancel'] = 'Category was modified! Please cancel and try again.';
$string['categoryname'] = 'Category name';
$string['categorypath'] = 'Category path';
$string['categorysubcategoryof'] = '{$a->category} - subcategory of {$a->parentcategory}';
$string['idnumbercoursecategory'] = 'Category ID number';
$string['idnumbercoursecategory_help'] = 'The ID number of a course category is only used when matching the category against external systems and is not displayed anywhere on the site. If the category has an official code name it may be entered, otherwise the field can be left blank.';
......
......@@ -20,7 +20,6 @@ namespace core_reportbuilder\local\entities;
use context_course;
use context_helper;
use core_course_category;
use core_reportbuilder\local\filters\boolean_select;
use core_reportbuilder\local\filters\course_selector;
use core_reportbuilder\local\filters\date;
......@@ -124,7 +123,6 @@ class course extends base {
return [
'fullname' => new lang_string('fullnamecourse'),
'shortname' => new lang_string('shortnamecourse'),
'category' => new lang_string('coursecategory'),
'idnumber' => new lang_string('idnumbercourse'),
'summary' => new lang_string('coursesummary'),
'format' => new lang_string('format'),
......@@ -177,7 +175,6 @@ class course extends base {
case 'summary':
$fieldtype = column::TYPE_LONGTEXT;
break;
case 'category':
case 'groupmode':
$fieldtype = column::TYPE_INTEGER;
break;
......@@ -356,15 +353,6 @@ class course extends base {
];
}
/**
* List of options for the field category.
*
* @return array
*/
public static function get_options_for_category(): array {
return core_course_category::make_categories_list('moodle/category:viewcourselist');
}
/**
* List of options for the field format.
*
......
......@@ -44,7 +44,7 @@ use core_reportbuilder\local\helpers\user_filter_manager;
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_testcase extends advanced_testcase {
class course_test extends advanced_testcase {
/**
* Load required classes
......@@ -142,7 +142,6 @@ class course_testcase extends advanced_testcase {
});
$courserow = reset($courserows);
$this->assertEquals($coursecategory1->name, $courserow['category']);
$this->assertEquals('Course 1', $courserow['fullname']);
$this->assertEquals('C1', $courserow['shortname']);
$this->assertEquals('IDNumber1', $courserow['idnumber']);
......@@ -227,16 +226,6 @@ class course_testcase extends advanced_testcase {
'Course 1',
], array_column($tablerows, 'fullname'));
// Filter by category field.
$filtervalues = [
'course:category_operator' => select::EQUAL_TO,
'course:category_value' => $coursecategory1->id,
];
$tablerows = $this->get_report_table_rows($filtervalues);
$this->assertEquals([
'Course 1',
], array_column($tablerows, 'fullname'));
// Filter by group mode field.
$filtervalues = [
'course:groupmode_operator' => select::EQUAL_TO,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment