MDL-86699 reportbuilder: new entities for obtaining course modules data.
These entities are intended to be used/extended in reports specific to course module data (forums, assignments, etc), in order to provide a baseline in terms of module reporting and API usage.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
issueNumber: MDL-86699
|
||||
notes:
|
||||
core_reportbuilder:
|
||||
- message: >-
|
||||
There are two new entities intended for reports specific to course
|
||||
module data, in order to provide a baseline in terms of module reporting
|
||||
and API usage:
|
||||
|
||||
|
||||
*
|
||||
`core_course\reportbuilder\local\entities\{course_module,course_module_base}`
|
||||
type: improved
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_course\reportbuilder\local\entities;
|
||||
|
||||
use core\lang_string;
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\filters\{boolean_select, date, text};
|
||||
use core_reportbuilder\local\helpers\format;
|
||||
use core_reportbuilder\local\report\{column, filter};
|
||||
|
||||
/**
|
||||
* Course module entity
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2025 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_module extends base {
|
||||
/**
|
||||
* Database tables that this entity uses
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_default_tables(): array {
|
||||
return [
|
||||
'course_modules',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The default title for this entity
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
protected function get_default_entity_title(): lang_string {
|
||||
return new lang_string('coursemodule', 'core_course');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of all available columns
|
||||
*
|
||||
* @return column[]
|
||||
*/
|
||||
protected function get_available_columns(): array {
|
||||
$coursemodulealias = $this->get_table_alias('course_modules');
|
||||
|
||||
// ID number.
|
||||
$columns[] = (new column(
|
||||
'idnumber',
|
||||
new lang_string('idnumber'),
|
||||
$this->get_entity_name(),
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->add_field("{$coursemodulealias}.idnumber")
|
||||
->set_is_sortable(true);
|
||||
|
||||
// Visible.
|
||||
$columns[] = (new column(
|
||||
'visible',
|
||||
new lang_string('visible'),
|
||||
$this->get_entity_name(),
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_BOOLEAN)
|
||||
->add_field("{$coursemodulealias}.visible")
|
||||
->set_is_sortable(true)
|
||||
->add_callback([format::class, 'boolean_as_text']);
|
||||
|
||||
// Time created.
|
||||
$columns[] = (new column(
|
||||
'timecreated',
|
||||
new lang_string('timecreated', 'core_reportbuilder'),
|
||||
$this->get_entity_name(),
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TIMESTAMP)
|
||||
->add_field("{$coursemodulealias}.added")
|
||||
->set_is_sortable(true)
|
||||
->add_callback([format::class, 'userdate']);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of all available filters
|
||||
*
|
||||
* @return filter[]
|
||||
*/
|
||||
protected function get_available_filters(): array {
|
||||
$coursemodulealias = $this->get_table_alias('course_modules');
|
||||
|
||||
// ID number.
|
||||
$filters[] = (new filter(
|
||||
text::class,
|
||||
'idnumber',
|
||||
new lang_string('idnumber'),
|
||||
$this->get_entity_name(),
|
||||
"{$coursemodulealias}.idnumber",
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Visible.
|
||||
$filters[] = (new filter(
|
||||
boolean_select::class,
|
||||
'visible',
|
||||
new lang_string('visible'),
|
||||
$this->get_entity_name(),
|
||||
"{$coursemodulealias}.visible",
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Time created.
|
||||
$filters[] = (new filter(
|
||||
date::class,
|
||||
'timecreated',
|
||||
new lang_string('timecreated', 'core_reportbuilder'),
|
||||
$this->get_entity_name(),
|
||||
"{$coursemodulealias}.added",
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
return $filters;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_course\reportbuilder\local\entities;
|
||||
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\helpers\database;
|
||||
|
||||
/**
|
||||
* Abstract base course module entity, to be extended by all course module specific entities
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2025 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class course_module_base extends base {
|
||||
/**
|
||||
* Database tables that this entity uses
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_default_tables(): array {
|
||||
return [
|
||||
'context',
|
||||
'course_modules',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return course modules joins
|
||||
*
|
||||
* @param string $modulename Name of the module, e.g. "forum"
|
||||
* @param string $modulefieldid Field used to select the module ID, e.g. "f.id"
|
||||
* @return string[]
|
||||
*/
|
||||
final public function get_course_modules_joins(string $modulename, string $modulefieldid): array {
|
||||
[
|
||||
'context' => $contextalias,
|
||||
'course_modules' => $coursemodulesalias,
|
||||
] = $this->get_table_aliases();
|
||||
|
||||
$modulesalias = database::generate_alias();
|
||||
|
||||
return [
|
||||
"JOIN {course_modules} {$coursemodulesalias}
|
||||
ON {$coursemodulesalias}.instance = {$modulefieldid}",
|
||||
"JOIN {modules} {$modulesalias}
|
||||
ON {$modulesalias}.id = {$coursemodulesalias}.module AND {$modulesalias}.name = '{$modulename}'",
|
||||
"JOIN {context} {$contextalias}
|
||||
ON {$contextalias}.contextlevel = " . CONTEXT_MODULE . " AND {$contextalias}.instanceid = {$coursemodulesalias}.id",
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,7 @@ $string['coursecontentnotifupdate'] = '{$a->coursename} content change';
|
||||
$string['coursecontentnotifupdatebody'] = '<p>{$a->moduletypename} <a href="{$a->link}">{$a->modulename}</a> has been changed in the course <a href="{$a->courselink}">{$a->coursename}</a>.</p><p><a href="{$a->notificationpreferenceslink}">Change your notification preferences</a></p>';
|
||||
$string['coursecontentnotification_help'] = 'Tick the box to notify course participants about this new or changed activity or resource. Only users who can access the activity or resource will receive the notification.';
|
||||
$string['coursecount'] = 'Course count';
|
||||
$string['coursemodule'] = 'Course module';
|
||||
$string['coursenotyetstarted'] = 'The course has not yet started';
|
||||
$string['coursenotyetfinished'] = 'The course has not yet finished';
|
||||
$string['courseparticipants'] = 'Course participants';
|
||||
|
||||
Reference in New Issue
Block a user