Skip to content

Commit

Permalink
MDL-72961 reportbuilder: move category elements to correct entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Nov 1, 2021
1 parent 677c2df commit cac0068
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
15 changes: 15 additions & 0 deletions course/classes/local/entities/course_category.php
Expand Up @@ -99,6 +99,21 @@ protected function get_all_columns(): array {
->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',
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -243,6 +243,7 @@
$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.';
Expand Down
12 changes: 0 additions & 12 deletions reportbuilder/classes/local/entities/course.php
Expand Up @@ -20,7 +20,6 @@

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;
Expand Down Expand Up @@ -124,7 +123,6 @@ protected function get_course_fields(): array {
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'),
Expand Down Expand Up @@ -177,7 +175,6 @@ protected function get_course_field_type(string $coursefield): int {
case 'summary':
$fieldtype = column::TYPE_LONGTEXT;
break;
case 'category':
case 'groupmode':
$fieldtype = column::TYPE_INTEGER;
break;
Expand Down Expand Up @@ -356,15 +353,6 @@ public static function get_options_for_groupmode(): array {
];
}

/**
* 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.
*
Expand Down
13 changes: 1 addition & 12 deletions reportbuilder/tests/local/entities/course_test.php
Expand Up @@ -44,7 +44,7 @@
* @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
Expand Down Expand Up @@ -142,7 +142,6 @@ public function test_get_columns_with_callbacks(): void {
});
$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']);
Expand Down Expand Up @@ -227,16 +226,6 @@ public function test_filters(): void {
'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,
Expand Down

0 comments on commit cac0068

Please sign in to comment.