Skip to content

Commit

Permalink
Merge branch 'MDL-75955' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Oct 14, 2022
2 parents b17679e + ffea186 commit 4f3d774
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
40 changes: 19 additions & 21 deletions grade/report/summary/classes/local/entities/grade_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
use grade_plugin_return;
use grade_report_summary;
use lang_string;
use stdClass;
use core_reportbuilder\local\entities\base;
use core_reportbuilder\local\report\column;
use core_reportbuilder\local\report\filter;
use core_grades\local\helpers\helpers;

defined('MOODLE_INTERNAL') || die;

Expand All @@ -40,12 +40,24 @@
*/
class grade_items extends base {

/** @var array Grade report. */
/** @var stdClass Course */
public $course;

/** @var grade_report_summary Grade report. */
public $report;

/** @var array Ungraded grade items counts with sql info. */
public $ungradedcounts;

/**
* Entity constructor
*
* @param stdClass $course
*/
public function __construct(stdClass $course) {
$this->course = $course;
}

/**
* Database tables that this entity uses and their default aliases
*
Expand All @@ -64,34 +76,23 @@ protected function get_default_entity_title(): lang_string {
return new lang_string('gradeitem', 'grades');
}

/**
* The default machine-readable name for this entity that will be used in the internal names of the columns/filters
*
* @return string
*/
protected function get_default_entity_name(): string {
return 'grade_items';
}

/**
* Initialise the entity
*
* @return base
*/
public function initialise(): base {
global $COURSE;

$context = \context_course::instance($COURSE->id);
$context = \context_course::instance($this->course->id);

$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'course' => $COURSE,
'course' => $this->course,
]
);

$this->report = new grade_report_summary($COURSE->id, $gpr, $context);
$this->report = new grade_report_summary($this->course->id, $gpr, $context);
$this->ungradedcounts = $this->report->ungraded_counts();

$columns = $this->get_all_columns();
Expand Down Expand Up @@ -252,12 +253,9 @@ protected function get_all_columns(): array {
* @return filter[]
*/
protected function get_all_filters(): array {
$filters = [];

$itemtypes = $this->report->item_types();
$tablealias = $this->get_table_alias('grade_items');

// Activity type filter.
// Activity type filter (for performance only load options on demand).
$filters[] = (new filter(
select::class,
'name',
Expand All @@ -266,7 +264,7 @@ protected function get_all_filters(): array {
"coalesce({$tablealias}.itemmodule,{$tablealias}.itemtype)"
))
->add_joins($this->get_joins())
->set_options($itemtypes);
->set_options_callback([$this->report, 'item_types']);

return $filters;
}
Expand Down
18 changes: 7 additions & 11 deletions grade/report/summary/classes/local/systemreports/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ class summary extends system_report {
* Initialise report, we need to set the main table, load our entities and set columns/filters
*/
protected function initialise(): void {
global $COURSE;
global $PAGE;

// Our main entity, it contains all of the column definitions that we need.
$entitymain = new grade_items();
$context = $this->get_context();
$COURSE = get_course($context->instanceid);
// We need to ensure page context is always set, as required by output and string formatting.
$course = get_course($this->get_context()->instanceid);
$PAGE->set_context($this->get_context());

// Our main entity, it contains all of the column definitions that we need.
$entitymain = new grade_items($course);
$entitymainalias = $entitymain->get_table_alias('grade_items');

$this->set_main_table('grade_items', $entitymainalias);
$this->add_entity($entitymain);

// Any columns required by actions should be defined here to ensure they're always available.
$this->add_base_fields("{$entitymainalias}.id");

$courseid = $this->get_context()->instanceid;

$param1 = database::generate_param_name();
$param2 = database::generate_param_name();
$param3 = database::generate_param_name();
Expand All @@ -66,7 +62,7 @@ protected function initialise(): void {
$wheresql .= " AND ($entitymainalias.gradetype = :$param2 OR $entitymainalias.gradetype = :$param3)";

$this->add_base_condition_sql($wheresql,
[$param1 => $courseid, $param2 => GRADE_TYPE_VALUE, $param3 => GRADE_TYPE_SCALE]);
[$param1 => $course->id, $param2 => GRADE_TYPE_VALUE, $param3 => GRADE_TYPE_SCALE]);

// Now we can call our helper methods to add the content we want to include in the report.
$this->add_columns();
Expand Down
4 changes: 2 additions & 2 deletions grade/report/summary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class grade_report_summary extends grade_report {
*
* @param int $courseid
* @param object $gpr grade plugin return tracking object
* @param string $context
* @param context_course $context
*/
public function __construct($courseid, $gpr, $context) {
parent::__construct($courseid, $gpr, $context);

$this->canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($this->course->id));
$this->canviewhidden = has_capability('moodle/grade:viewhidden', $context);
$this->setup_groups();
}

Expand Down

0 comments on commit 4f3d774

Please sign in to comment.