-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from dmitriim/issue131
issue #131: add reports for mod_customcert archived records
- Loading branch information
Showing
4 changed files
with
240 additions
and
2 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
classes/reportbuilder/datasource/archived_customcert_issues.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters