-
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.
issue #95: add h5P activity data source
- Loading branch information
Showing
3 changed files
with
341 additions
and
1 deletion.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
classes/reportbuilder/datasource/archived_h5pactivities_atempts.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,114 @@ | ||
<?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\h5pactivity_attempts; | ||
|
||
/** | ||
* H5pactivity attempts 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_h5pactivities_atempts extends datasource { | ||
|
||
/** | ||
* Return user friendly name of the datasource | ||
* | ||
* @return string | ||
*/ | ||
public static function get_name(): string { | ||
return get_string('datasource:local_recompletion_h5p', 'local_recompletion'); | ||
} | ||
|
||
/** | ||
* Initialise. | ||
*/ | ||
protected function initialise(): void { | ||
$attempts = new h5pactivity_attempts(); | ||
$attemptsalias = $attempts->get_table_alias('local_recompletion_h5p'); | ||
$this->add_entity($attempts); | ||
|
||
$this->set_main_table('local_recompletion_h5p', $attemptsalias); | ||
|
||
// 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 = {$attemptsalias}.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 = {$attemptsalias}.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', | ||
'h5pactivity_attempts:h5pactivityid', | ||
'h5pactivity_attempts:attempt', | ||
'h5pactivity_attempts:rawscore', | ||
'h5pactivity_attempts:duration', | ||
'h5pactivity_attempts:completion', | ||
'h5pactivity_attempts:success', | ||
'h5pactivity_attempts:timecreated', | ||
'h5pactivity_attempts:timemodified', | ||
]; | ||
} | ||
|
||
/** | ||
* Return the filters that will be added to the report once is created | ||
* | ||
* @return string[] | ||
*/ | ||
public function get_default_filters(): array { | ||
return [ | ||
'course:fullname', | ||
'h5pactivity_attempts:success' | ||
]; | ||
} | ||
|
||
/** | ||
* Return the conditions that will be added to the report once is created | ||
* | ||
* @return string[] | ||
*/ | ||
public function get_default_conditions(): array { | ||
return []; | ||
} | ||
} |
223 changes: 223 additions & 0 deletions
223
classes/reportbuilder/entities/h5pactivity_attempts.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,223 @@ | ||
<?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\filters\select; | ||
use core_reportbuilder\local\helpers\format; | ||
use core_reportbuilder\local\report\column; | ||
use core_reportbuilder\local\report\filter; | ||
use core_renderer; | ||
use html_writer; | ||
use lang_string; | ||
|
||
/** | ||
* Report builder entity for archived h5pactivity attempts. | ||
* | ||
* @package local_recompletion | ||
* @author Dmitrii Metelkin <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class h5pactivity_attempts 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_h5p' => 'h5p' | ||
]; | ||
} | ||
|
||
/** | ||
* The default title for this entity | ||
* | ||
* @return lang_string | ||
*/ | ||
protected function get_default_entity_title(): lang_string { | ||
return new lang_string('entity:local_recompletion_h5p', '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 { | ||
$alias = $this->get_table_alias('local_recompletion_h5p'); | ||
|
||
$columns[] = (new column( | ||
'h5pactivityid', | ||
new lang_string('pluginname', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_fields("{$alias}.h5pactivityid, {$alias}.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('h5pactivity') | ||
&& !empty($modinfo->get_instances_of('h5pactivity')[$row->h5pactivityid]))) { | ||
$cm = $modinfo->get_instances_of('h5pactivity')[$row->h5pactivityid]; | ||
$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->h5pactivityid; | ||
} | ||
}); | ||
|
||
$columns[] = (new column( | ||
'attempt', | ||
new lang_string('attempt', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.attempt") | ||
->set_is_sortable(true); | ||
|
||
$columns[] = (new column( | ||
'rawscore', | ||
new lang_string('score', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.rawscore") | ||
->set_is_sortable(true); | ||
|
||
$columns[] = (new column( | ||
'maxscore', | ||
new lang_string('maxscore', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.maxscore") | ||
->set_is_sortable(true); | ||
|
||
$columns[] = (new column( | ||
'duration', | ||
new lang_string('duration', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.duration") | ||
->set_is_sortable(true); | ||
|
||
$columns[] = (new column( | ||
'completion', | ||
new lang_string('completion', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.completion") | ||
->set_is_sortable(true); | ||
|
||
$columns[] = (new column( | ||
'success', | ||
new lang_string('outcome', 'h5pactivity'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.success") | ||
->set_is_sortable(true) | ||
->add_callback(static function($success): string { | ||
if ($success === null) { | ||
return get_string('attempt_success_unknown', 'mod_h5pactivity'); | ||
} else if ($success) { | ||
return get_string('attempt_success_pass', 'mod_h5pactivity'); | ||
} else { | ||
return get_string('attempt_success_fail', 'mod_h5pactivity'); | ||
} | ||
}); | ||
|
||
$columns[] = (new column( | ||
'timecreated', | ||
new lang_string('timecreated', 'local_recompletion'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TIMESTAMP) | ||
->add_field("{$alias}.timecreated") | ||
->set_is_sortable(true) | ||
->add_callback([format::class, 'userdate']); | ||
|
||
$columns[] = (new column( | ||
'timemodified', | ||
new lang_string('timemodified', 'local_recompletion'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TIMESTAMP) | ||
->add_field("{$alias}.timemodified") | ||
->set_is_sortable(true) | ||
->add_callback([format::class, 'userdate']); | ||
|
||
return $columns; | ||
} | ||
|
||
/** | ||
* Return list of all available filters | ||
* | ||
* @return filter[] | ||
*/ | ||
protected function get_all_filters(): array { | ||
$alias = $this->get_table_alias('local_recompletion_h5p'); | ||
|
||
// Time completed filter. | ||
$filters[] = (new filter( | ||
select::class, | ||
'success', | ||
new lang_string('outcome', 'local_recompletion'), | ||
$this->get_entity_name(), | ||
"{$alias}.success" | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_options([ | ||
0 => get_string('attempt_success_fail', 'mod_h5pactivity'), | ||
]); | ||
|
||
return $filters; | ||
} | ||
} |
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