From 8c457a42d6dab0d36cb2c0dd8bfefbea7df2b675 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Sun, 26 Nov 2023 10:42:26 +1100 Subject: [PATCH] issue #131: add reports for mod_customcert archived records --- .../datasource/archived_customcert_issues.php | 108 +++++++++++++++ .../entities/customcert_issues.php | 128 ++++++++++++++++++ lang/en/local_recompletion.php | 2 + version.php | 4 +- 4 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 classes/reportbuilder/datasource/archived_customcert_issues.php create mode 100644 classes/reportbuilder/entities/customcert_issues.php diff --git a/classes/reportbuilder/datasource/archived_customcert_issues.php b/classes/reportbuilder/datasource/archived_customcert_issues.php new file mode 100644 index 0000000..9bdef22 --- /dev/null +++ b/classes/reportbuilder/datasource/archived_customcert_issues.php @@ -0,0 +1,108 @@ +. + +namespace local_recompletion\reportbuilder\datasource; + +use core_course\reportbuilder\local\entities\course_category; +use core_reportbuilder\datasource; +use core_reportbuilder\local\entities\course; +use core_reportbuilder\local\entities\user; +use local_recompletion\reportbuilder\entities\customcert_issues; + +/** + * Mod_customcert archive datasource. + * + * @package local_recompletion + * @author Dmitrii Metelkin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class archived_customcert_issues extends datasource { + + /** + * Return user friendly name of the datasource + * + * @return string + */ + public static function get_name(): string { + return get_string('datasource:local_recompletion_ccert_is', 'local_recompletion'); + } + + /** + * Initialise. + */ + protected function initialise(): void { + $certificates = new customcert_issues(); + $tablealias = $certificates->get_table_alias('local_recompletion_ccert_is'); + $this->add_entity($certificates); + + $this->set_main_table('local_recompletion_ccert_is', $tablealias); + + // Join the course entity. + $courseentity = new course(); + $coursealias = $courseentity->get_table_alias('course'); + $this->add_entity($courseentity + ->add_join("JOIN {course} {$coursealias} ON {$coursealias}.id = {$tablealias}.course")); + + // Join the course category entity. + $coursecatentity = new course_category(); + $categoriesalias = $coursecatentity->get_table_alias('course_categories'); + $this->add_entity($coursecatentity + ->add_join("JOIN {course_categories} {$categoriesalias} ON {$categoriesalias}.id = {$coursealias}.category")); + + // Join the user entity. + $userentity = new user(); + $useralias = $userentity->get_table_alias('user'); + $this->add_entity($userentity + ->add_join("JOIN {user} {$useralias} ON {$useralias}.id = {$tablealias}.userid")); + + $this->add_all_from_entities(); + } + + /** + * Return the columns that will be added to the report once is created + * + * @return string[] + */ + public function get_default_columns(): array { + return [ + 'user:fullnamewithlink', + 'course:coursefullnamewithlink', + 'customcert_issues:certificate', + 'customcert_issues:code', + 'customcert_issues:issueddate', + ]; + } + + /** + * Return the filters that will be added to the report once is created + * + * @return string[] + */ + public function get_default_filters(): array { + return [ + 'course:courseselector', + ]; + } + + /** + * Return the conditions that will be added to the report once is created + * + * @return string[] + */ + public function get_default_conditions(): array { + return []; + } +} diff --git a/classes/reportbuilder/entities/customcert_issues.php b/classes/reportbuilder/entities/customcert_issues.php new file mode 100644 index 0000000..8d8e16c --- /dev/null +++ b/classes/reportbuilder/entities/customcert_issues.php @@ -0,0 +1,128 @@ +. + +namespace local_recompletion\reportbuilder\entities; + +use core_reportbuilder\local\entities\base; +use core_reportbuilder\local\helpers\format; +use core_reportbuilder\local\report\column; +use core_renderer; +use html_writer; +use lang_string; + +/** + * Report builder entity for mod_customcert archived records. + * + * @package local_recompletion + * @author Dmitrii Metelkin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class customcert_issues extends base { + + /** + * Database tables that this entity uses and their default aliases + * + * @return string[] Array of $tablename => $alias + */ + protected function get_default_table_aliases(): array { + return [ + 'local_recompletion_ccert_is' => 'ccert' + ]; + } + + /** + * The default title for this entity + * + * @return lang_string + */ + protected function get_default_entity_title(): lang_string { + return new lang_string('entity:local_recompletion_ccert_is', 'local_recompletion'); + } + + /** + * Initialise. + * + * @return \core_reportbuilder\local\entities\base + */ + public function initialise(): base { + $columns = $this->get_all_columns(); + foreach ($columns as $column) { + $this->add_column($column); + } + + return $this; + } + + /** + * Returns list of available columns. + * + * @return column[] + */ + protected function get_all_columns(): array { + $tablealias = $this->get_table_alias('local_recompletion_ccert_is'); + + // Course module. + $columns[] = (new column( + 'certificate', + new lang_string('pluginname', 'customcert'), + $this->get_entity_name() + )) + ->add_joins($this->get_joins()) + ->set_type(column::TYPE_INTEGER) + ->add_fields("{$tablealias}.customcertid, {$tablealias}.course") + ->set_is_sortable(true) + ->add_callback(static function($value, $row): string { + global $PAGE; + + $renderer = new core_renderer($PAGE, RENDERER_TARGET_GENERAL); + $modinfo = get_fast_modinfo($row->course); + + if (!empty($modinfo) && !empty($modinfo->get_instances_of('customcert') + && !empty($modinfo->get_instances_of('customcert')[$row->customcertid]))) { + $cm = $modinfo->get_instances_of('customcert')[$row->customcertid]; + $modulename = get_string('modulename', $cm->modname); + $activityicon = $renderer->pix_icon('monologo', $modulename, $cm->modname, ['class' => 'icon']); + + return $activityicon . html_writer::link($cm->url, format_string($cm->name), []); + } else { + return (string) $row->customcertid; + } + }); + + $columns[] = (new column( + 'code', + new lang_string('code', 'customcert'), + $this->get_entity_name() + )) + ->add_joins($this->get_joins()) + ->set_type(column::TYPE_TEXT) + ->add_field("{$tablealias}.code") + ->set_is_sortable(true); + + $columns[] = (new column( + 'issueddate', + new lang_string('receiveddate', 'customcert'), + $this->get_entity_name() + )) + ->add_joins($this->get_joins()) + ->set_type(column::TYPE_TIMESTAMP) + ->add_field("{$tablealias}.timecreated") + ->set_is_sortable(true) + ->add_callback([format::class, 'userdate']); + + return $columns; + } +} diff --git a/lang/en/local_recompletion.php b/lang/en/local_recompletion.php index 8389fc8..4eb963b 100644 --- a/lang/en/local_recompletion.php +++ b/lang/en/local_recompletion.php @@ -275,3 +275,5 @@ $string['archivecertificate_help'] = 'Should issued certificates be archived?'; $string['entity:local_recompletion_cert'] = 'Archive of issued certificates (mod_certificate)'; $string['datasource:local_recompletion_cert'] = 'Archive of issued certificates (mod_certificate)'; +$string['entity:local_recompletion_ccert_is'] = 'Archive of issued certificates (mod_customcert)'; +$string['datasource:local_recompletion_ccert_is'] = 'Archive of issued certificates (mod_customcert)'; diff --git a/version.php b/version.php index 69818d7..db7c33a 100644 --- a/version.php +++ b/version.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2023112100; -$plugin->release = 2023112100; +$plugin->version = 2023112600; +$plugin->release = 2023112600; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2022112805; // Requires 4.1. $plugin->component = 'local_recompletion';