Skip to content

Commit

Permalink
Merge pull request #132 from dmitriim/issue131
Browse files Browse the repository at this point in the history
issue #131: add reports for mod_customcert archived records
  • Loading branch information
danmarsden authored Nov 27, 2023
2 parents 1fc718e + 6822204 commit 9489d6d
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 2 deletions.
108 changes: 108 additions & 0 deletions classes/reportbuilder/datasource/archived_customcert_issues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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/>.

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 <[email protected]>
* @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 [];
}
}
128 changes: 128 additions & 0 deletions classes/reportbuilder/entities/customcert_issues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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/>.

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 <[email protected]>
* @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;
}
}
2 changes: 2 additions & 0 deletions lang/en/local_recompletion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2023112600;
$plugin->release = 2023112600;
$plugin->version = 2023112700;
$plugin->release = 2023112700;
$plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2022112805; // Requires 4.1.
$plugin->component = 'local_recompletion';
Expand Down

0 comments on commit 9489d6d

Please sign in to comment.