Skip to content

Commit

Permalink
MDL-73448 scorm: Update scorm tertiary navigation
Browse files Browse the repository at this point in the history
* Left align scorm content
* Add headings
* Remove exit buttons when in separate window
  • Loading branch information
Peter Dias committed Feb 10, 2022
1 parent e63604f commit 8f16a4d
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 73 deletions.
2 changes: 2 additions & 0 deletions mod/scorm/classes/output/actionbar.php
Expand Up @@ -107,8 +107,10 @@ public function export_for_template(renderer_base $output): array {

$url = new moodle_url('/mod/scorm/report.php', $PAGE->url->remove_params('attemptsmode'));
$urlselect = new url_select($reportmenu, $url->out(false), null, 'selectscormreports');
$heading = $reportmenu[$url->out(false)] ?? null;

$data = [
'heading' => $heading,
'scormreports' => $urlselect->export_for_template($output),
'candownload' => $this->download,
'downloadods' => ($this->download) ? $downloadodslink->out(false) : '',
Expand Down
1 change: 1 addition & 0 deletions mod/scorm/classes/output/userreportsactionbar.php
Expand Up @@ -94,6 +94,7 @@ public function export_for_template(renderer_base $output): array {
}
$urlselect = new url_select($reportmenu, $userreporturl, [], 'userscormreport');
$data ['userreport'] = $urlselect->export_for_template($output);
$data ['heading'] = $reportmenu[$userreporturl] ?? null;
}

return $data;
Expand Down
3 changes: 0 additions & 3 deletions mod/scorm/index.php
Expand Up @@ -48,9 +48,6 @@
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strscorms);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading($strscorms);
}

$usesections = course_format_uses_sections($course->format);

Expand Down
30 changes: 14 additions & 16 deletions mod/scorm/locallib.php
Expand Up @@ -936,7 +936,7 @@ function scorm_print_launch ($user, $scorm, $action, $cm) {
$organization = optional_param('organization', '', PARAM_INT);

if ($scorm->displaycoursestructure == 1) {
echo $OUTPUT->box_start('generalbox boxaligncenter toc container', 'toc');
echo $OUTPUT->box_start('generalbox boxaligncenter toc', 'toc');
echo html_writer::div(get_string('contents', 'scorm'), 'structurehead');
}
if (empty($organization)) {
Expand Down Expand Up @@ -992,31 +992,29 @@ function scorm_print_launch ($user, $scorm, $action, $cm) {
echo html_writer::start_div('scorm-center');
echo html_writer::start_tag('form', array('id' => 'scormviewform',
'method' => 'post',
'action' => $CFG->wwwroot.'/mod/scorm/player.php',
'class' => 'container'));
'action' => $CFG->wwwroot.'/mod/scorm/player.php'));
if ($scorm->hidebrowse == 0) {
echo html_writer::empty_tag('button',
[
'class' => 'btn btn-secondary mr-1', 'name' => 'mode',
'type' => 'submit', 'id' => 'b', 'value' => 'browse']) .
get_string('browse', 'scorm') . html_writer::end_tag('button');
echo html_writer::empty_tag('button',
[
'class' => 'btn btn-primary mx-1', 'name' => 'mode',
'type' => 'submit', 'id' => 'n', 'value' => 'normal']) .
get_string('enter', 'scorm') . html_writer::end_tag('button');
echo html_writer::tag('button', get_string('browse', 'scorm'),
['class' => 'btn btn-secondary mr-1', 'name' => 'mode',
'type' => 'submit', 'id' => 'b', 'value' => 'browse'])
. html_writer::end_tag('button');
} else {
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'mode', 'value' => 'normal'));
}
echo html_writer::tag('button', get_string('enter', 'scorm'),
['class' => 'btn btn-primary mx-1', 'name' => 'mode',
'type' => 'submit', 'id' => 'n', 'value' => 'normal'])
. html_writer::end_tag('button');
if (!empty($scorm->forcenewattempt)) {
if ($scorm->forcenewattempt == SCORM_FORCEATTEMPT_ALWAYS ||
($scorm->forcenewattempt == SCORM_FORCEATTEMPT_ONCOMPLETE && $incomplete === false)) {
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'newattempt', 'value' => 'on'));
}
} else if (!empty($attemptcount) && ($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) {
echo html_writer::empty_tag('br');
echo html_writer::checkbox('newattempt', 'on', false, '', array('id' => 'a'));
echo html_writer::label(get_string('newattempt', 'scorm'), 'a');
echo html_writer::start_div('pt-1');
echo html_writer::checkbox('newattempt', 'on', false, '', array('id' => 'a'));
echo html_writer::label(get_string('newattempt', 'scorm'), 'a', true, ['class' => 'pl-1']);
echo html_writer::end_div();
}
if (!empty($scorm->popup)) {
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'display', 'value' => 'popup'));
Expand Down
4 changes: 3 additions & 1 deletion mod/scorm/mod_form.php
Expand Up @@ -276,7 +276,9 @@ public function definition() {
$this->standard_coursemodule_elements();

// A SCORM module should define this within itself and is not needed here.
$mform->removeElement('completionpassgrade');
if ($mform->elementExists('completionpassgrade')) {
$mform->removeElement('completionpassgrade');
}

// Buttons.
$this->add_action_buttons();
Expand Down
39 changes: 23 additions & 16 deletions mod/scorm/player.php
Expand Up @@ -160,21 +160,20 @@
$completion = new completion_info($course);
$completion->set_module_viewed($cm);

// Print the page header.
// Generate the exit button.
$exiturl = "";
if (empty($scorm->popup) || $displaymode == 'popup') {
if ($course->format == 'singleactivity' && $scorm->skipview == SCORM_SKIPVIEW_ALWAYS
&& !has_capability('mod/scorm:viewreport', context_module::instance($cm->id))) {
// Redirect students back to site home to avoid redirect loop.
$exiturl = $CFG->wwwroot;
} else {
// Redirect back to the correct section if one section per page is being used.
$exiturl = course_get_url($course, $cm->sectionnum);
$exiturl = course_get_url($course, $cm->sectionnum)->out();
}

$exitlink = html_writer::link($exiturl, $strexit, array('title' => $strexit, 'class' => 'btn btn-secondary'));
$PAGE->set_button($exitlink);
}

// Print the page header.
$PAGE->requires->data_for_js('scormplayerdata', Array('launch' => false,
'currentorg' => '',
'sco' => 0,
Expand All @@ -191,11 +190,16 @@
} else {
$PAGE->requires->js('/mod/scorm/datamodels/scorm_12.js', true);
}

echo $OUTPUT->header();
if (!empty($scorm->displayactivityname) && !$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($scorm->name));
$activityheader = $PAGE->activityheader;
$headerconfig = [
'description' => '',
'hidecompletion' => true
];
if ($activityheader->is_title_allowed() && empty($scorm->displayactivityname)) {
$headerconfig['title'] = '';
}
$activityheader->set_attrs($headerconfig);
echo $OUTPUT->header();

$PAGE->requires->string_for_js('navigation', 'scorm');
$PAGE->requires->string_for_js('toc', 'scorm');
Expand All @@ -205,19 +209,22 @@

$name = false;

$scrompagestyle = "margin-top: 1em";
if ($mode === 'normal') {
$scrompagestyle = "margin-top: 3em";
// Exit button should ONLY be displayed when in the current window.
if ($displaymode !== 'popup') {
$renderer = $PAGE->get_renderer('mod_scorm');
echo $renderer->generate_exitbar($exiturl);
}
echo html_writer::start_div('', array('id' => 'scormpage', 'style' => $scrompagestyle));

echo html_writer::start_div('', array('id' => 'scormpage'));
echo html_writer::start_div('', array('id' => 'tocbox'));
echo html_writer::div(html_writer::tag('script', '', array('id' => 'external-scormapi', 'type' => 'text/JavaScript')), '',
array('id' => 'scormapi-parent'));

if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode == 'browse' or $mode == 'review') {
echo html_writer::start_div('', array('id' => 'scormtop'));
echo $mode == 'browse' ? html_writer::div(get_string('browsemode', 'scorm'), 'scorm-left', array('id' => 'scormmode')) : '';
echo $mode == 'review' ? html_writer::div(get_string('reviewmode', 'scorm'), 'scorm-left', array('id' => 'scormmode')) : '';
echo html_writer::start_div('mb-3', array('id' => 'scormtop'));
if ($mode == 'browse' || $mode == 'review') {
echo html_writer::div(get_string("{$mode}mode", 'scorm'), 'scorm-left h3', ['id' => 'scormmode']);
}
if ($scorm->hidetoc == SCORM_TOC_POPUP) {
echo html_writer::div($result->tocmenu, 'scorm-right', array('id' => 'scormnav'));
}
Expand Down
10 changes: 10 additions & 0 deletions mod/scorm/renderer.php
Expand Up @@ -95,6 +95,16 @@ public function report_actionbar(\mod_scorm\output\actionbar $actionbar): string
public function user_report_actionbar(\mod_scorm\output\userreportsactionbar $userreportsactionbar): string {
return $this->render_from_template('mod_scorm/user_report_actionbar', $userreportsactionbar->export_for_template($this));
}

/**
* Generate the SCORM's "Exit activity" button
*
* @param string $url The url to be hooked up to the exit button
* @return string
*/
public function generate_exitbar(string $url): string {
return $this->render_from_template('mod_scorm/player_exitbar', ['action' => $url]);
}
}

/**
Expand Down
9 changes: 5 additions & 4 deletions mod/scorm/report/userreport.php
Expand Up @@ -77,11 +77,12 @@
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
$PAGE->navbar->add(fullname($user). " - $strattempt $attempt");

$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($scorm->name));
}

// End of Print the page header.
$currenttab = 'scoes';

Expand Down
7 changes: 6 additions & 1 deletion mod/scorm/report/userreportinteractions.php
Expand Up @@ -94,8 +94,13 @@

$PAGE->navbar->add(fullname($user). " - $strattempt $attempt");

$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);

echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($scorm->name));

// End of Print the page header.
$currenttab = 'interactions';

Expand Down
7 changes: 4 additions & 3 deletions mod/scorm/report/userreporttracks.php
Expand Up @@ -97,10 +97,11 @@
$table = new flexible_table('mod_scorm-userreporttracks');

if (!$table->is_downloading($download, $exportfilename)) {
$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($scorm->name));
}
$currenttab = '';
$renderer = $PAGE->get_renderer('mod_scorm');
$useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'attempt', $mode, $scoid);
Expand Down
32 changes: 32 additions & 0 deletions mod/scorm/templates/player_exitbar.mustache
@@ -0,0 +1,32 @@
{{!
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/>.
}}
{{!
@template mod_scorm/player_exitbar
Actions bar for the user reports page UI.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* action
Example context (json):
{
"action": "http://localhost/moodle/mod/scorm/report.php?id=70&mode=interactions"
}
}}
<div class="d-flex flex-row-reverse mb-2">
<a class="btn btn-secondary" href="{{{action}}}" title="{{#str}}exitactivity, mod_scorm{{/str}}">
{{#str}}exitactivity, mod_scorm{{/str}}
</a>
</div>
36 changes: 19 additions & 17 deletions mod/scorm/templates/report_actionbar.mustache
Expand Up @@ -22,6 +22,7 @@
* see mod/scorm/classes/output/actionbar.php
Example context (json):
{
"heading": "Heading",
"scormreports": {
"id": "url_select_test",
"options": [
Expand All @@ -39,25 +40,26 @@
}}
<div class="container-fluid mb-3">
<div class="row justify-content-between">
<div class="mr-5">
{{#scormreports}}
{{>core/url_select}}
{{/scormreports}}
{{#scormreports}}
<div>
{{>core/url_select}}
</div>
<div class="mr-5">
{{#candownload}}
<div class="dropdown show">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{#str}} download {{/str}}
</a>
{{/scormreports}}

<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="{{ downloadods }}">{{#str}} downloadods {{/str}}</a>
<a class="dropdown-item" href="{{ downloadexcel }}">{{#str}} downloadexcel {{/str}}</a>
<a class="dropdown-item" href="{{ downloadtext }}">{{#str}} downloadtext {{/str}}</a>
</div>
</div>
{{/candownload}}
{{#candownload}}
<div class="dropdown show">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{#str}} download {{/str}}
</a>

<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="{{ downloadods }}">{{#str}} downloadods {{/str}}</a>
<a class="dropdown-item" href="{{ downloadexcel }}">{{#str}} downloadexcel {{/str}}</a>
<a class="dropdown-item" href="{{ downloadtext }}">{{#str}} downloadtext {{/str}}</a>
</div>
</div>
{{/candownload}}

</div>
</div>
{{#heading}}<h2>{{heading}}</h2>{{/heading}}
4 changes: 3 additions & 1 deletion mod/scorm/templates/user_report_actionbar.mustache
Expand Up @@ -29,7 +29,8 @@
{"name": "Interactions", "value": "/mod/scorm/report/userreportinteractions.php?id=70&user=13&attempt=1"}
]
},
"backurl": "http://localhost/moodle/mod/scorm/report.php?id=70&mode=interactions"
"backurl": "http://localhost/moodle/mod/scorm/report.php?id=70&mode=interactions",
"heading": "Sub page heading"
}
}}
<div class="container-fluid mb-3">
Expand All @@ -40,3 +41,4 @@
{{/userreport}}
</div>
</div>
{{#heading}}<h2>{{heading}}</h2>{{/heading}}
12 changes: 5 additions & 7 deletions mod/scorm/view.js
Expand Up @@ -64,11 +64,9 @@ M.mod_scormform.init = function(Y) {
}

// Set mode and newattempt correctly.
var setlaunchoptions = function() {
var mode = Y.one('#scormviewform input[name=mode]:checked');
var setlaunchoptions = function(mode) {
if (mode) {
var modevalue = mode.get('value');
launch_url += '&mode=' + (modevalue ? modevalue : 'normal');
launch_url += '&mode=' + (mode ? mode : 'normal');
} else {
launch_url += '&mode=normal';
}
Expand All @@ -86,13 +84,13 @@ M.mod_scormform.init = function(Y) {
}
// Listen for view form submit and generate popup on user interaction.
if (scormform) {
Y.on('submit', function(e) {
setlaunchoptions();
scormform.delegate('click', function(e) {
setlaunchoptions(e.currentTarget.getAttribute('value'));
winobj = window.open(launch_url, 'Popup', poptions);
this.target = 'Popup';
scormredirect(winobj);
winobj.opener = null;
e.preventDefault();
}, scormform);
}, 'button[name=mode]');
}
}

0 comments on commit 8f16a4d

Please sign in to comment.