Skip to content

Commit

Permalink
Merge branch 'MDL-79543-main' of https://github.com/sarjona/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Feb 27, 2024
2 parents ca75778 + ec8f84d commit 4dd7066
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 32 deletions.

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions h5p/classes/player.php
Expand Up @@ -158,11 +158,17 @@ public function __construct(string $url, \stdClass $config, bool $preventredirec
* @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 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.
*/
public static function display(string $url, \stdClass $config, bool $preventredirect = true,
string $component = '', bool $displayedit = false): string {
public static function display(
string $url, \stdClass $config,
bool $preventredirect = true,
string $component = '',
bool $displayedit = false,
array $extraactions = [],
): string {
global $OUTPUT, $CFG;

$params = [
Expand Down Expand Up @@ -192,6 +198,10 @@ public static function display(string $url, \stdClass $config, bool $preventredi
}
}

$template->extraactions = [];
foreach ($extraactions as $action) {
$template->extraactions[] = $action->export_for_template($OUTPUT);
}
$result = $OUTPUT->render_from_template('core_h5p/h5pembed', $template);
$result .= self::get_resize_code();
return $result;
Expand Down
46 changes: 35 additions & 11 deletions h5p/templates/h5pembed.mustache
Expand Up @@ -28,20 +28,44 @@
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">
<a href="{{editurl}}" class="btn text-primary">
{{#pix}}i/edit, core{{/pix}}
{{#str}}editcontent, core_h5p{{/str}}
</a>
{{#extraactions}}
<a href="{{url}}" class="btn text-primary">
{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}
{{text}}
</a>
{{/extraactions}}
{{#editurl}}
<a href="{{editurl}}" class="btn text-primary">
{{#pix}}i/edit, core{{/pix}}
{{#str}}editcontent, core_h5p{{/str}}
</a>
{{/editurl}}
</div>
{{/editurl}}

<iframe src="{{embedurl}}" name="h5player" width=":w" height=":h"
allowfullscreen="allowfullscreen" class="h5p-player w-100 border-0"
style="height: 0px;" id="{{uniqid}}-h5player">
</iframe>
<iframe
src="{{embedurl}}"
name="h5player"
width=":w"
height=":h"
allowfullscreen="allowfullscreen"
class="h5p-player w-100 border-0"
style="height: 0px;"
id="{{uniqid}}-h5player"
></iframe>
1 change: 1 addition & 0 deletions lib/classes/output/icon_system_fontawesome.php
Expand Up @@ -215,6 +215,7 @@ public function get_core_icon_map() {
'core:i/contentbank' => 'fa-paint-brush',
'core:i/dashboard' => 'fa-tachometer',
'core:i/categoryevent' => 'fa-cubes',
'core:i/chartbar' => 'fa-chart-bar',
'core:i/course' => 'fa-graduation-cap',
'core:i/courseevent' => 'fa-graduation-cap',
'core:i/customfield' => 'fa-hand-o-right',
Expand Down
2 changes: 1 addition & 1 deletion mod/h5pactivity/lang/en/h5pactivity.php
Expand Up @@ -127,7 +127,6 @@
$string['result_sequencing_choice'] = 'Positions';
$string['result_sequencing_answer'] = 'Position value';
$string['result_sequencing_position'] = '#{$a}';
$string['review_all_attempts'] = 'View all attempts ({$a} submitted)';
$string['review_mode'] = 'Review attempts';
$string['review_my_attempts'] = 'View my attempts';
$string['review_user_attempts'] = 'View user attempts ({$a})';
Expand All @@ -147,4 +146,5 @@
$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['view'] = 'View';
$string['viewattempts'] = 'View attempts ({$a})';
$string['view_report'] = 'View report';
60 changes: 44 additions & 16 deletions mod/h5pactivity/tests/behat/attempt_options.feature
Expand Up @@ -8,6 +8,7 @@ Feature: Attempts review settings.
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com |
| teacher2 | Teacher | 2 | teacher2@example.com |
And the following "courses" exist:
Expand All @@ -16,6 +17,7 @@ Feature: Attempts review settings.
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
| teacher1 | C1 | editingteacher |
| teacher2 | C1 | teacher |

Expand All @@ -28,7 +30,45 @@ Feature: Attempts review settings.
| idnumber | h5ppackage |
| enabletracking | <enabletracking> |
| 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 |
| h5pactivity | H5P package |
| attempt | 1 |
Expand All @@ -38,18 +78,6 @@ Feature: Attempts review settings.
| duration | 4 |
| completion | 1 |
| success | 1 |
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."

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 |
And I am on the "H5P package" "h5pactivity activity" page
And I follow "View attempts (1)"
And I should see "View user attempts"
13 changes: 12 additions & 1 deletion mod/h5pactivity/view.php
Expand Up @@ -87,9 +87,20 @@
}
echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
}
}

$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);
echo player::display($fileurl, $config, true, 'mod_h5pactivity', true, $extraactions);

echo $OUTPUT->footer();
1 change: 1 addition & 0 deletions pix/i/chartbar.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4dd7066

Please sign in to comment.