mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 02:46:40 +02:00
MDL-79543 h5p: Include attempts info and link
Co-authored-by: Ferran Recio <ferran@moodle.com>
This commit is contained in:
parent
6e8d1454ba
commit
ec8f84d8af
5 changed files with 105 additions and 31 deletions
|
@ -158,11 +158,17 @@ class player {
|
||||||
* @param bool $preventredirect Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
|
* @param bool $preventredirect Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
|
||||||
* @param string $component optional moodle component to sent xAPI tracking
|
* @param string $component optional moodle component to sent xAPI tracking
|
||||||
* @param bool $displayedit Whether the edit button should be displayed below the H5P content.
|
* @param bool $displayedit Whether the edit button should be displayed below the H5P content.
|
||||||
|
* @param \action_link[] $extraactions Extra actions to display above the H5P content.
|
||||||
*
|
*
|
||||||
* @return string The embedable code to display a H5P file.
|
* @return string The embedable code to display a H5P file.
|
||||||
*/
|
*/
|
||||||
public static function display(string $url, \stdClass $config, bool $preventredirect = true,
|
public static function display(
|
||||||
string $component = '', bool $displayedit = false): string {
|
string $url, \stdClass $config,
|
||||||
|
bool $preventredirect = true,
|
||||||
|
string $component = '',
|
||||||
|
bool $displayedit = false,
|
||||||
|
array $extraactions = [],
|
||||||
|
): string {
|
||||||
global $OUTPUT, $CFG;
|
global $OUTPUT, $CFG;
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
|
@ -192,6 +198,10 @@ class player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$template->extraactions = [];
|
||||||
|
foreach ($extraactions as $action) {
|
||||||
|
$template->extraactions[] = $action->export_for_template($OUTPUT);
|
||||||
|
}
|
||||||
$result = $OUTPUT->render_from_template('core_h5p/h5pembed', $template);
|
$result = $OUTPUT->render_from_template('core_h5p/h5pembed', $template);
|
||||||
$result .= self::get_resize_code();
|
$result .= self::get_resize_code();
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -28,20 +28,44 @@
|
||||||
|
|
||||||
Example context (json):
|
Example context (json):
|
||||||
{
|
{
|
||||||
"embedurl": "http://example.com/h5p/embed.php?url=testurl"
|
"embedurl": "http://example.com/h5p/embed.php?url=testurl",
|
||||||
|
"editurl": "http://example.com/h5p/embed.php?url=testurl&edit=1",
|
||||||
|
"extraactions": [
|
||||||
|
{
|
||||||
|
"text": "View attempts (2)",
|
||||||
|
"url": "http://example.com/mod/h5pactivity/report.php?a=1",
|
||||||
|
"icon": {
|
||||||
|
"key": "i\/chartbar",
|
||||||
|
"component": "core",
|
||||||
|
"title": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
{{#editurl}}
|
|
||||||
<div class="d-flex justify-content-end mb-3">
|
<div class="d-flex justify-content-end mb-3">
|
||||||
<a href="{{editurl}}" class="btn text-primary">
|
{{#extraactions}}
|
||||||
{{#pix}}i/edit, core{{/pix}}
|
<a href="{{url}}" class="btn text-primary">
|
||||||
{{#str}}editcontent, core_h5p{{/str}}
|
{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}
|
||||||
</a>
|
{{text}}
|
||||||
|
</a>
|
||||||
|
{{/extraactions}}
|
||||||
|
{{#editurl}}
|
||||||
|
<a href="{{editurl}}" class="btn text-primary">
|
||||||
|
{{#pix}}i/edit, core{{/pix}}
|
||||||
|
{{#str}}editcontent, core_h5p{{/str}}
|
||||||
|
</a>
|
||||||
|
{{/editurl}}
|
||||||
</div>
|
</div>
|
||||||
{{/editurl}}
|
|
||||||
|
|
||||||
<iframe src="{{embedurl}}" name="h5player" width=":w" height=":h"
|
<iframe
|
||||||
allowfullscreen="allowfullscreen" class="h5p-player w-100 border-0"
|
src="{{embedurl}}"
|
||||||
style="height: 0px;" id="{{uniqid}}-h5player">
|
name="h5player"
|
||||||
</iframe>
|
width=":w"
|
||||||
|
height=":h"
|
||||||
|
allowfullscreen="allowfullscreen"
|
||||||
|
class="h5p-player w-100 border-0"
|
||||||
|
style="height: 0px;"
|
||||||
|
id="{{uniqid}}-h5player"
|
||||||
|
></iframe>
|
||||||
|
|
|
@ -146,4 +146,5 @@ $string['tracking_messages'] = 'Some H5P provide attempt tracking data for advan
|
||||||
$string['true'] = 'True';
|
$string['true'] = 'True';
|
||||||
$string['usecontentbank'] = 'Use the <a href="{$a}" target="_blank">content bank (opens in new window)</a> to manage your H5P files';
|
$string['usecontentbank'] = 'Use the <a href="{$a}" target="_blank">content bank (opens in new window)</a> to manage your H5P files';
|
||||||
$string['view'] = 'View';
|
$string['view'] = 'View';
|
||||||
|
$string['viewattempts'] = 'View attempts ({$a})';
|
||||||
$string['view_report'] = 'View report';
|
$string['view_report'] = 'View report';
|
||||||
|
|
|
@ -8,6 +8,7 @@ Feature: Attempts review settings.
|
||||||
Given the following "users" exist:
|
Given the following "users" exist:
|
||||||
| username | firstname | lastname | email |
|
| username | firstname | lastname | email |
|
||||||
| student1 | Student | 1 | student1@example.com |
|
| student1 | Student | 1 | student1@example.com |
|
||||||
|
| student2 | Student | 2 | student2@example.com |
|
||||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
| teacher2 | Teacher | 2 | teacher2@example.com |
|
| teacher2 | Teacher | 2 | teacher2@example.com |
|
||||||
And the following "courses" exist:
|
And the following "courses" exist:
|
||||||
|
@ -16,6 +17,7 @@ Feature: Attempts review settings.
|
||||||
And the following "course enrolments" exist:
|
And the following "course enrolments" exist:
|
||||||
| user | course | role |
|
| user | course | role |
|
||||||
| student1 | C1 | student |
|
| student1 | C1 | student |
|
||||||
|
| student2 | C1 | student |
|
||||||
| teacher1 | C1 | editingteacher |
|
| teacher1 | C1 | editingteacher |
|
||||||
| teacher2 | C1 | teacher |
|
| teacher2 | C1 | teacher |
|
||||||
|
|
||||||
|
@ -28,7 +30,45 @@ Feature: Attempts review settings.
|
||||||
| idnumber | h5ppackage |
|
| idnumber | h5ppackage |
|
||||||
| enabletracking | <enabletracking> |
|
| enabletracking | <enabletracking> |
|
||||||
| reviewmode | <reviewmode> |
|
| reviewmode | <reviewmode> |
|
||||||
And the following "mod_h5pactivity > attempt" exists:
|
And the following "mod_h5pactivity > attempts" exist:
|
||||||
|
| user | h5pactivity | attempt | interactiontype | rawscore | maxscore | duration | completion | success |
|
||||||
|
| student1 | H5P package | 1 | compound | 0 | 2 | 6 | 1 | 0 |
|
||||||
|
| student1 | H5P package | 2 | compound | 2 | 2 | 4 | 1 | 1 |
|
||||||
|
| student2 | H5P package | 1 | compound | 1 | 2 | 8 | 1 | 0 |
|
||||||
|
When I am on the "H5P package" "h5pactivity activity" page logged in as <user>
|
||||||
|
Then "Attempts report" "link" should <attemptsreportlink> in current page administration
|
||||||
|
And I should <previewmode> "You are in preview mode."
|
||||||
|
And I should <attempttracking> "Attempt tracking is not enabled for this activity."
|
||||||
|
And I should <attempttrackingsettings> "You can enable it in Settings."
|
||||||
|
And I should <viewattempts> "View attempts (3)"
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
| user | enabletracking | reviewmode | attemptsreportlink | previewmode | attempttracking | attempttrackingsettings | viewattempts |
|
||||||
|
| student1 | 1 | 1 | exist | not see | not see | not see | not see |
|
||||||
|
| student1 | 1 | 0 | not exist | not see | not see | not see | not see |
|
||||||
|
| student1 | 0 | 1 | not exist | not see | not see | not see | not see |
|
||||||
|
| teacher1 | 1 | 1 | exist | see | not see | not see | see |
|
||||||
|
| teacher1 | 1 | 0 | exist | see | not see | not see | see |
|
||||||
|
| teacher1 | 0 | 1 | not exist | see | see | see | not see |
|
||||||
|
| teacher2 | 0 | 1 | not exist | see | see | not see | not see |
|
||||||
|
# TODO: The non-editing teachers will be able to see attempts when MDL-80028 is fixed.
|
||||||
|
| teacher2 | 1 | 1 | not exist | see | not see | not see | not see |
|
||||||
|
|
||||||
|
Scenario: View attempts link behaviour
|
||||||
|
Given the following "activity" exists:
|
||||||
|
| activity | h5pactivity |
|
||||||
|
| name | H5P package |
|
||||||
|
| intro | Test H5P description |
|
||||||
|
| course | C1 |
|
||||||
|
| idnumber | h5ppackage |
|
||||||
|
| enabletracking | 1 |
|
||||||
|
| reviewmode | 1 |
|
||||||
|
When I am on the "H5P package" "h5pactivity activity" page logged in as teacher1
|
||||||
|
# The link is displayed with the correct number of attempts (in that case 0 because there are no attempts yet).
|
||||||
|
Then I should see "View attempts (0)"
|
||||||
|
Then I follow "View attempts (0)"
|
||||||
|
And I should not see "View user attempts"
|
||||||
|
But the following "mod_h5pactivity > attempt" exists:
|
||||||
| user | student1 |
|
| user | student1 |
|
||||||
| h5pactivity | H5P package |
|
| h5pactivity | H5P package |
|
||||||
| attempt | 1 |
|
| attempt | 1 |
|
||||||
|
@ -38,18 +78,6 @@ Feature: Attempts review settings.
|
||||||
| duration | 4 |
|
| duration | 4 |
|
||||||
| completion | 1 |
|
| completion | 1 |
|
||||||
| success | 1 |
|
| success | 1 |
|
||||||
When I am on the "H5P package" "h5pactivity activity" page logged in as <user>
|
And I am on the "H5P package" "h5pactivity activity" page
|
||||||
Then "Attempts report" "link" should <attemptsreportlink> in current page administration
|
And I follow "View attempts (1)"
|
||||||
And I should <previewmode> "You are in preview mode."
|
And I should see "View user attempts"
|
||||||
And I should <attempttracking> "Attempt tracking is not enabled for this activity."
|
|
||||||
And I should <attempttrackingsettings> "You can enable it in Settings."
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
| user | enabletracking | reviewmode | attemptsreportlink | previewmode | attempttracking | attempttrackingsettings |
|
|
||||||
| student1 | 1 | 1 | exist | not see | not see | not see |
|
|
||||||
| student1 | 1 | 0 | not exist | not see | not see | not see |
|
|
||||||
| student1 | 0 | 1 | not exist | not see | not see | not see |
|
|
||||||
| teacher1 | 1 | 1 | exist | see | not see | not see |
|
|
||||||
| teacher1 | 1 | 0 | exist | see | not see | not see |
|
|
||||||
| teacher1 | 0 | 1 | not exist | see | see | see |
|
|
||||||
| teacher2 | 0 | 1 | not exist | see | see | not see |
|
|
||||||
|
|
|
@ -87,9 +87,20 @@ if (!$manager->can_submit()) {
|
||||||
}
|
}
|
||||||
echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
|
echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo player::display($fileurl, $config, true, 'mod_h5pactivity', true);
|
$extraactions = [];
|
||||||
|
|
||||||
|
if ($manager->can_view_all_attempts() && $manager->is_tracking_enabled()) {
|
||||||
|
$extraactions[] = new action_link(
|
||||||
|
new moodle_url('/mod/h5pactivity/report.php', ['id' => $cm->id]),
|
||||||
|
get_string('viewattempts', 'mod_h5pactivity', $manager->count_attempts()),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
new pix_icon('i/chartbar', '', 'core')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo player::display($fileurl, $config, true, 'mod_h5pactivity', true, $extraactions);
|
||||||
|
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue