From b98ea6f547e04ce9550a3649aa98b5cf882ee7b2 Mon Sep 17 00:00:00 2001 From: Sujith Haridasan Date: Mon, 11 Oct 2021 08:06:29 +0530 Subject: [PATCH] MDL-71915 mod_scorm: Update tertiary nav Update the tertiary navigation for this activity. --- mod/scorm/classes/event/tracks_viewed.php | 4 +- mod/scorm/classes/output/actionbar.php | 120 ++++++++++++++++++ .../classes/output/userreportsactionbar.php | 101 +++++++++++++++ mod/scorm/index.php | 4 +- mod/scorm/lang/en/deprecated.txt | 3 +- mod/scorm/lang/en/scorm.php | 5 +- mod/scorm/lib.php | 19 +++ mod/scorm/locallib.php | 22 ++-- mod/scorm/player.php | 10 +- mod/scorm/renderer.php | 19 +++ mod/scorm/report.php | 9 +- mod/scorm/report/basic/classes/report.php | 34 ++--- mod/scorm/report/graphs/classes/report.php | 4 + .../report/interactions/classes/report.php | 45 ++----- .../report/objectives/classes/report.php | 40 ++---- mod/scorm/report/userreport.php | 20 ++- mod/scorm/report/userreportinteractions.php | 7 +- mod/scorm/report/userreporttabs.php | 47 ------- mod/scorm/report/userreporttracks.php | 15 ++- mod/scorm/tabs.php | 62 --------- mod/scorm/templates/report_actionbar.mustache | 63 +++++++++ .../templates/user_report_actionbar.mustache | 42 ++++++ mod/scorm/tests/events_test.php | 5 +- mod/scorm/view.php | 12 +- 24 files changed, 477 insertions(+), 235 deletions(-) create mode 100644 mod/scorm/classes/output/actionbar.php create mode 100644 mod/scorm/classes/output/userreportsactionbar.php delete mode 100644 mod/scorm/report/userreporttabs.php delete mode 100644 mod/scorm/tabs.php create mode 100644 mod/scorm/templates/report_actionbar.mustache create mode 100644 mod/scorm/templates/user_report_actionbar.mustache diff --git a/mod/scorm/classes/event/tracks_viewed.php b/mod/scorm/classes/event/tracks_viewed.php index 25364c3f741..6554bb85878 100644 --- a/mod/scorm/classes/event/tracks_viewed.php +++ b/mod/scorm/classes/event/tracks_viewed.php @@ -92,8 +92,8 @@ class tracks_viewed extends \core\event\base { */ protected function get_legacy_logdata() { return array($this->courseid, 'scorm', 'userreporttracks', 'report/userreporttracks.php?id=' . $this->contextinstanceid - . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'] . '&scoid=' . $this->other['scoid'], - $this->other['instanceid'], $this->contextinstanceid); + . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'] . '&scoid=' . $this->other['scoid'] + . '&mode=' . $this->other['mode'], $this->other['instanceid'], $this->contextinstanceid); } /** diff --git a/mod/scorm/classes/output/actionbar.php b/mod/scorm/classes/output/actionbar.php new file mode 100644 index 00000000000..ae2c278c18d --- /dev/null +++ b/mod/scorm/classes/output/actionbar.php @@ -0,0 +1,120 @@ +. + +namespace mod_scorm\output; + +use renderable; +use renderer_base; +use templatable; +use moodle_url; +use url_select; + +/** + * Render HTML elements for tertiary nav for scorm. + * + * @package mod_scorm + * @copyright 2021 Sujith Haridasan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class actionbar implements renderable, templatable { + /** @var int */ + private $id; + + /** @var string */ + private $download; + + /** @var int */ + private $attemptsmode; + + /** + * actionbar constructor. + * + * @param int $id The course module id. + * @param bool $download Show download button or not. + * @param int $attemptsmode attempts mode for scorm. + */ + public function __construct(int $id, bool $download = false, int $attemptsmode = 0) { + $this->id = $id; + $this->download = $download; + $this->attemptsmode = $attemptsmode; + } + + /** + * Provide data for the template + * + * @param renderer_base $output renderer_base object. + * @return array data for the template + */ + public function export_for_template(renderer_base $output): array { + global $PAGE; + + $basicreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'basic']); + $graphreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'graphs']); + $interactionreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'interactions']); + $objectivesreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'objectives']); + + $reportmenu = [ + $basicreportlink->out(false) => get_string('pluginname', 'scormreport_basic'), + $graphreportlink->out(false) => get_string('pluginname', 'scormreport_graphs'), + $interactionreportlink->out(false) => get_string('pluginname', 'scormreport_interactions'), + $objectivesreportlink->out(false) => get_string('pluginname', 'scormreport_objectives'), + ]; + + $sesskey = sesskey(); + if ($this->download) { + $mode = $PAGE->url->get_param('mode'); + if ($mode === 'basic') { + $options = [ + 'id' => $this->id, 'mode' => $mode, + 'attemptsmode' => $this->attemptsmode, 'sesskey' => $sesskey + ]; + } else if ($mode === 'interactions') { + $options = [ + 'id' => $this->id, 'mode' => $mode, 'qtext' => '0', + 'resp' => '1', 'right' => '0', 'result' => '0', + 'attemptsmode' => $this->attemptsmode, 'sesskey' => $sesskey + ]; + } else if ($mode === 'objectives') { + $options = [ + 'id' => $this->id, 'mode' => $mode, + 'attemptsmode' => $this->attemptsmode, 'objectivescore' => '0', + 'sesskey' => $sesskey + ]; + } + + $options['download'] = 'ODS'; + $downloadodslink = new moodle_url($PAGE->url, $options); + + $options['download'] = 'Excel'; + $downloadexcellink = new moodle_url($PAGE->url, $options); + + $options['download'] = 'CSV'; + $downloadtextlink = new moodle_url($PAGE->url, $options); + } + + $url = new moodle_url('/mod/scorm/report.php', $PAGE->url->remove_params('attemptsmode')); + $urlselect = new url_select($reportmenu, $url->out(false), null, 'selectscormreports'); + + $data = [ + 'scormreports' => $urlselect->export_for_template($output), + 'candownload' => $this->download, + 'downloadods' => ($this->download) ? $downloadodslink->out(false) : '', + 'downloadexcel' => ($this->download) ? $downloadexcellink->out(false) : '', + 'downloadtext' => ($this->download) ? $downloadtextlink->out(false) : '' + ]; + return $data; + } +} diff --git a/mod/scorm/classes/output/userreportsactionbar.php b/mod/scorm/classes/output/userreportsactionbar.php new file mode 100644 index 00000000000..443128124f3 --- /dev/null +++ b/mod/scorm/classes/output/userreportsactionbar.php @@ -0,0 +1,101 @@ +. + +namespace mod_scorm\output; + +use renderable; +use renderer_base; +use templatable; +use moodle_url; +use url_select; + +/** + * Render HTML elements for reports page on tertiary nav. + * + * @package mod_scorm + * @copyright 2021 Sujith Haridasan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class userreportsactionbar implements renderable, templatable { + /** @var int */ + private $id; + + /** @var int */ + private $userid; + + /** @var int */ + private $attempt; + + /** @var string */ + private $reporttype; + + /** @var string */ + private $mode; + + /** @var int */ + private $scoid; + + /** + * userreportsactionbar constructor + * + * @param int $id Course module id. + * @param int $userid User id. + * @param int $attempt Number of attempts. + * @param string $reporttype The report type can be either learning/interact. + * @param string $mode The mode view to set the back button. + * @param int|null $scoid The scorm id. + */ + public function __construct(int $id, int $userid, int $attempt, string $reporttype, string $mode, ?int $scoid = null) { + $this->id = $id; + $this->userid = $userid; + $this->attempt = $attempt; + $this->reporttype = $reporttype; + $this->mode = $mode; + $this->scoid = $scoid; + } + + /** + * Provide data for the template + * + * @param renderer_base $output renderer_base object. + * @return array data for the template. + */ + public function export_for_template(renderer_base $output): array { + $data = [ + 'backurl' => (new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => $this->mode]))->out(false) + ]; + + if (!$this->scoid) { + $learnobjects = new moodle_url('/mod/scorm/report/userreport.php', + ['id' => $this->id, 'user' => $this->userid, 'attempt' => $this->attempt, 'mode' => $this->mode]); + $interactions = new moodle_url('/mod/scorm/report/userreportinteractions.php', + ['id' => $this->id, 'user' => $this->userid, 'attempt' => $this->attempt, 'mode' => $this->mode]); + + $reportmenu[$learnobjects->out(false)] = get_string('scoes', 'scorm'); + $reportmenu[$interactions->out(false)] = get_string('interactions', 'scorm'); + + if ($this->reporttype === 'learning') { + $userreporturl = $learnobjects->out(false); + } else { + $userreporturl = $interactions->out(false); + } + $urlselect = new url_select($reportmenu, $userreporturl, [], 'userscormreport'); + $data ['userreport'] = $urlselect->export_for_template($output); + } + + return $data; + } +} diff --git a/mod/scorm/index.php b/mod/scorm/index.php index 34b8418423b..214b94c04c7 100644 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -48,7 +48,9 @@ $PAGE->set_title($strscorms); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($strscorms); echo $OUTPUT->header(); -echo $OUTPUT->heading($strscorms); +if (!$PAGE->has_secondary_navigation()) { + echo $OUTPUT->heading($strscorms); +} $usesections = course_format_uses_sections($course->format); diff --git a/mod/scorm/lang/en/deprecated.txt b/mod/scorm/lang/en/deprecated.txt index 32ff438da92..f6ed0081dd5 100644 --- a/mod/scorm/lang/en/deprecated.txt +++ b/mod/scorm/lang/en/deprecated.txt @@ -1 +1,2 @@ -duedate,mod_scorm \ No newline at end of file +duedate,mod_scorm +info,mod_scorm diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index a1265ae0f12..aa61d09f1a4 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -213,7 +213,7 @@ $string['indicator:socialbreadth_help'] = 'This indicator is based on the social $string['indicator:socialbreadthdef'] = 'SCORM social'; $string['indicator:socialbreadthdef_help'] = 'The participant has reached this percentage of the social engagement offered by the SCORM activities during this analysis interval (Levels = No participation, Participant alone)'; $string['indicator:socialbreadthdef_link'] = 'Learning_analytics_indicators#Social_breadth'; -$string['info'] = 'Info'; + $string['interactions'] = 'Interactions'; $string['masteryoverride'] = 'Mastery score overrides status'; $string['masteryoverride_help'] = 'If enabled and a mastery score is provided, when LMSFinish is called and a raw score has been set, status will be recalculated using the raw score and mastery score and any status provided by the SCORM (including "incomplete") will be overridden.'; @@ -458,3 +458,6 @@ $string['youmustselectastatus'] = 'You must select a status to require'; // Deprecated since Moodle 3.8. $string['duedate'] = 'Due date'; + +// Deprecated since Moodle 4.0. +$string['info'] = 'Info'; diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 99c5c7b33ba..b04179c83c7 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1828,3 +1828,22 @@ function mod_scorm_core_calendar_get_event_action_string(string $eventtype): str return get_string($identifier, 'scorm', $modulename); } + +/** + * This function extends the settings navigation block for the site. + * + * It is safe to rely on PAGE here as we will only ever be within the module + * context when this is called + * + * @param navigation_node $settings navigation_node object. + * @param navigation_node $scormnode navigation_node object. + * @return void + */ +function scorm_extend_settings_navigation(navigation_node $settings, navigation_node $scormnode): void { + global $PAGE; + + if (has_capability('mod/scorm:viewreport', $PAGE->cm->context)) { + $url = new moodle_url('/mod/scorm/report.php', ['id' => $PAGE->cm->id]); + $scormnode->add(get_string("reports", "scorm"), $url, navigation_node::TYPE_CUSTOM, null, 'scormreport'); + } +} diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 6647a2baa96..9508df7252b 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -995,16 +995,16 @@ function scorm_print_launch ($user, $scorm, $action, $cm) { 'action' => $CFG->wwwroot.'/mod/scorm/player.php', 'class' => 'container')); if ($scorm->hidebrowse == 0) { - print_string('mode', 'scorm'); - echo ': '.html_writer::empty_tag('input', array('type' => 'radio', 'id' => 'b', 'name' => 'mode', - 'value' => 'browse', 'class' => 'mr-1')). - html_writer::label(get_string('browse', 'scorm'), 'b'); - echo html_writer::empty_tag('input', array('type' => 'radio', - 'id' => 'n', 'name' => 'mode', - 'value' => 'normal', 'checked' => 'checked', - 'class' => 'mx-1')). - html_writer::label(get_string('normal', 'scorm'), 'n'); - + 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'); } else { echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'mode', 'value' => 'normal')); } @@ -1026,8 +1026,6 @@ function scorm_print_launch ($user, $scorm, $action, $cm) { echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scoid', 'value' => $launchsco)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'cm', 'value' => $cm->id)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'currentorg', 'value' => $orgidentifier)); - echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('enter', 'scorm'), - 'class' => 'btn btn-primary')); echo html_writer::end_tag('form'); echo html_writer::end_div(); } diff --git a/mod/scorm/player.php b/mod/scorm/player.php index f0cc78e674f..dcad9235939 100644 --- a/mod/scorm/player.php +++ b/mod/scorm/player.php @@ -83,6 +83,8 @@ if ($displaymode !== '') { $url->param('display', $displaymode); } $PAGE->set_url($url); +$PAGE->set_secondary_active_tab("modulepage"); + $forcejs = get_config('scorm', 'forcejavascript'); if (!empty($forcejs)) { $PAGE->add_body_class('forcejavascript'); @@ -191,7 +193,7 @@ if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js')) { } echo $OUTPUT->header(); -if (!empty($scorm->displayactivityname)) { +if (!empty($scorm->displayactivityname) && !$PAGE->has_secondary_navigation()) { echo $OUTPUT->heading(format_string($scorm->name)); } @@ -203,7 +205,11 @@ $PAGE->requires->string_for_js('popupsblocked', 'scorm'); $name = false; -echo html_writer::start_div('', array('id' => 'scormpage')); +$scrompagestyle = "margin-top: 1em"; +if ($mode === 'normal') { + $scrompagestyle = "margin-top: 3em"; +} +echo html_writer::start_div('', array('id' => 'scormpage', 'style' => $scrompagestyle)); 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')); diff --git a/mod/scorm/renderer.php b/mod/scorm/renderer.php index 4f5a2fa8c75..a3355873101 100644 --- a/mod/scorm/renderer.php +++ b/mod/scorm/renderer.php @@ -76,6 +76,25 @@ class mod_scorm_renderer extends plugin_renderer_base { return html_writer::tag('div', $output, array('class' => 'paging')); } + /** + * Rendered HTML for the report action is provided. + * + * @param \mod_scorm\output\actionbar $actionbar actionbar object. + * @return bool|string rendered HTML for the report action. + */ + public function report_actionbar(\mod_scorm\output\actionbar $actionbar): string { + return $this->render_from_template('mod_scorm/report_actionbar', $actionbar->export_for_template($this)); + } + + /** + * Rendered HTML for the user report action is provided + * + * @param \mod_scorm\output\userreportsactionbar $userreportsactionbar userreportsactionbar object + * @return string rendered HTML for the user report action. + */ + 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)); + } } /** diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 7e39f2ed1cf..8e4aeab26c7 100644 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -56,6 +56,9 @@ $PAGE->set_pagelayout('report'); require_capability('mod/scorm:viewreport', $contextmodule); +// Activate the secondary nav tab. +navigation_node::override_active_url(new moodle_url('/mod/scorm/report.php', ['id' => $id])); + if (count($reportlist) < 1) { print_error('erroraccessingreport', 'scorm'); } @@ -86,9 +89,9 @@ if (empty($noheader)) { $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id))); echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($scorm->name)); - $currenttab = 'reports'; - require($CFG->dirroot . '/mod/scorm/tabs.php'); + if (!$PAGE->has_secondary_navigation()) { + echo $OUTPUT->heading(format_string($scorm->name)); + } } // Open the selected Scorm report and display it. diff --git a/mod/scorm/report/basic/classes/report.php b/mod/scorm/report/basic/classes/report.php index d315929da83..a62e645ba46 100644 --- a/mod/scorm/report/basic/classes/report.php +++ b/mod/scorm/report/basic/classes/report.php @@ -43,6 +43,13 @@ class report extends \mod_scorm\report { $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT); $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); + // Scorm action bar for report. + if ($download === '') { + $actionbar = new \mod_scorm\output\actionbar($cm->id, true, $attemptsmode); + $renderer = $PAGE->get_renderer('mod_scorm'); + echo $renderer->report_actionbar($actionbar); + } + if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); @@ -401,7 +408,7 @@ class report extends \mod_scorm\report { } else { if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, - 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + 'user' => $scouser->userid, 'attempt' => $scouser->attempt, 'mode' => 'basic')); $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; @@ -445,7 +452,8 @@ class report extends \mod_scorm\report { } if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, - 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt, + 'mode' => 'basic')); $row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '
' . \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { @@ -488,28 +496,6 @@ class report extends \mod_scorm\report { echo \html_writer::end_tag('div'); echo \html_writer::end_tag('form'); } - echo \html_writer::end_div(); - if (!empty($attempts)) { - echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'ODS') + $displayoptions), - get_string('downloadods')); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'Excel') + $displayoptions), - get_string('downloadexcel')); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'CSV') + $displayoptions), - get_string('downloadtext')); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo \html_writer::end_tag('td'); - echo \html_writer::end_tag('tr').\html_writer::end_tag('table'); - } } } else { if ($candelete && !$download) { diff --git a/mod/scorm/report/graphs/classes/report.php b/mod/scorm/report/graphs/classes/report.php index b295f00c423..f88f013e5e3 100644 --- a/mod/scorm/report/graphs/classes/report.php +++ b/mod/scorm/report/graphs/classes/report.php @@ -135,6 +135,10 @@ class report extends \mod_scorm\report { $contextmodule = context_module::instance($cm->id); + $actionbar = new \mod_scorm\output\actionbar($cm->id, false, 0); + $renderer = $PAGE->get_renderer('mod_scorm'); + echo $renderer->report_actionbar($actionbar); + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. groups_print_activity_menu($cm, new moodle_url($PAGE->url)); } diff --git a/mod/scorm/report/interactions/classes/report.php b/mod/scorm/report/interactions/classes/report.php index 43fd42b5c1b..24e195739c4 100644 --- a/mod/scorm/report/interactions/classes/report.php +++ b/mod/scorm/report/interactions/classes/report.php @@ -44,6 +44,13 @@ class report extends \mod_scorm\report { $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT); $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); + // Scorm action bar for report. + if ($download === '') { + $actionbar = new \mod_scorm\output\actionbar($cm->id, true, $attemptsmode); + $renderer = $PAGE->get_renderer('mod_scorm'); + echo $renderer->report_actionbar($actionbar); + } + if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); @@ -446,9 +453,10 @@ class report extends \mod_scorm\report { } else { if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreport.php', - array('id' => $cm->id, - 'user' => $scouser->userid, - 'attempt' => $scouser->attempt)); + array('id' => $cm->id, + 'user' => $scouser->userid, + 'attempt' => $scouser->attempt, + 'mode' => 'interactions')); $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; @@ -486,7 +494,8 @@ class report extends \mod_scorm\report { } if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, - 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt, + 'mode' => 'interactions')); $row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '
' . \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { @@ -578,34 +587,6 @@ class report extends \mod_scorm\report { echo \html_writer::end_tag('div'); echo \html_writer::end_tag('form'); } - echo \html_writer::end_div(); - if (!empty($attempts)) { - echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'ODS') + $displayoptions), - get_string('downloadods'), - 'post', - ['class' => 'mt-1']); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'Excel') + $displayoptions), - get_string('downloadexcel'), - 'post', - ['class' => 'mt-1']); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'CSV') + $displayoptions), - get_string('downloadtext'), - 'post', - ['class' => 'mt-1']); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo \html_writer::end_tag('td'); - echo \html_writer::end_tag('tr').\html_writer::end_tag('table'); - } } } else { if ($candelete && !$download) { diff --git a/mod/scorm/report/objectives/classes/report.php b/mod/scorm/report/objectives/classes/report.php index f901d951764..eaaa4bb925b 100644 --- a/mod/scorm/report/objectives/classes/report.php +++ b/mod/scorm/report/objectives/classes/report.php @@ -50,6 +50,13 @@ class report extends \mod_scorm\report { $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT); $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); + // Scorm action bar for report. + if ($download === '') { + $actionbar = new \mod_scorm\output\actionbar($cm->id, true, $attemptsmode); + $renderer = $PAGE->get_renderer('mod_scorm'); + echo $renderer->report_actionbar($actionbar); + } + if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); @@ -436,7 +443,7 @@ class report extends \mod_scorm\report { } else { if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, - 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + 'user' => $scouser->userid, 'attempt' => $scouser->attempt, 'mode' => 'objectives')); $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; @@ -474,7 +481,8 @@ class report extends \mod_scorm\report { } if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, - 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt, + 'mode' => 'objectives')); $row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '
' . \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { @@ -577,34 +585,6 @@ class report extends \mod_scorm\report { echo \html_writer::end_tag('div'); echo \html_writer::end_tag('form'); } - echo \html_writer::end_div(); - if (!empty($attempts)) { - echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'ODS') + $displayoptions), - get_string('downloadods'), - 'post', - ['class' => 'mt-1']); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'Excel') + $displayoptions), - get_string('downloadexcel'), - 'post', - ['class' => 'mt-1']); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo $OUTPUT->single_button(new \moodle_url($PAGE->url, - array('download' => 'CSV') + $displayoptions), - get_string('downloadtext'), - 'post', - ['class' => 'mt-1']); - echo \html_writer::end_tag('td'); - echo \html_writer::start_tag('td'); - echo \html_writer::end_tag('td'); - echo \html_writer::end_tag('tr').\html_writer::end_tag('table'); - } } } else { if ($candelete && !$download) { diff --git a/mod/scorm/report/userreport.php b/mod/scorm/report/userreport.php index ec91a483be5..922a845f879 100644 --- a/mod/scorm/report/userreport.php +++ b/mod/scorm/report/userreport.php @@ -28,14 +28,16 @@ require_once($CFG->dirroot.'/mod/scorm/locallib.php'); $id = required_param('id', PARAM_INT); // Course Module ID. $userid = required_param('user', PARAM_INT); // User ID. $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number. +$mode = optional_param('mode', '', PARAM_ALPHA); // Scorm mode from which reached here. // Building the url to use for links.+ data details buildup. $url = new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, - 'user' => $userid, - 'attempt' => $attempt)); + 'user' => $userid, + 'attempt' => $attempt)); $tracksurl = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id, - 'user' => $userid, - 'attempt' => $attempt)); + 'user' => $userid, + 'attempt' => $attempt, + 'mode' => $mode)); $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST); $course = get_course($cm->course); $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST); @@ -44,6 +46,7 @@ $user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\ $attemptids = scorm_get_all_attempts($scorm->id, $userid); $PAGE->set_url($url); +$PAGE->set_secondary_active_tab('scormreport'); // END of url setting + data buildup. // Checking login +logging +getting context. @@ -76,10 +79,15 @@ $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id $PAGE->navbar->add(fullname($user). " - $strattempt $attempt"); echo $OUTPUT->header(); -echo $OUTPUT->heading(format_string($scorm->name)); +if (!$PAGE->has_secondary_navigation()) { + echo $OUTPUT->heading(format_string($scorm->name)); +} // End of Print the page header. $currenttab = 'scoes'; -require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php'); + +$renderer = $PAGE->get_renderer('mod_scorm'); +$useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'learning', $mode); +echo $renderer->user_report_actionbar($useractionreport); // Printing user details. $output = $PAGE->get_renderer('mod_scorm'); diff --git a/mod/scorm/report/userreportinteractions.php b/mod/scorm/report/userreportinteractions.php index 501bf7e710d..d03a5a66749 100644 --- a/mod/scorm/report/userreportinteractions.php +++ b/mod/scorm/report/userreportinteractions.php @@ -31,6 +31,7 @@ $id = required_param('id', PARAM_INT); // Course Module ID. $userid = required_param('user', PARAM_INT); // User ID. $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number. $download = optional_param('download', '', PARAM_ALPHA); +$mode = optional_param('mode', '', PARAM_ALPHA); // Scorm mode from which reached here. // Building the url to use for links.+ data details buildup. $url = new moodle_url('/mod/scorm/report/userreportinteractions.php', array('id' => $id, @@ -45,6 +46,7 @@ $user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\ $attemptids = scorm_get_all_attempts($scorm->id, $userid); $PAGE->set_url($url); +$PAGE->set_secondary_active_tab('scormreport'); // END of url setting + data buildup. // Checking login +logging +getting context. @@ -96,7 +98,10 @@ if (!$table->is_downloading($download, $exportfilename)) { echo $OUTPUT->heading(format_string($scorm->name)); // End of Print the page header. $currenttab = 'interactions'; - require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php'); + + $renderer = $PAGE->get_renderer('mod_scorm'); + $useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'interact', $mode); + echo $renderer->user_report_actionbar($useractionreport); // Printing user details. $output = $PAGE->get_renderer('mod_scorm'); diff --git a/mod/scorm/report/userreporttabs.php b/mod/scorm/report/userreporttabs.php deleted file mode 100644 index b54957b9c1e..00000000000 --- a/mod/scorm/report/userreporttabs.php +++ /dev/null @@ -1,47 +0,0 @@ -. - -/** - * Sets up the tabs used by the scorm pages based on the users capabilities. - * - * @author Dan Marsden and others. - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package mod_scorm - */ - -if (empty($scorm)) { - print_error('cannotaccess', 'mod_scorm'); -} -if (!isset($currenttab)) { - $currenttab = ''; -} -$tabs = array(); -$row = array(); -$inactive = array(); -$activated = array(); - -$scoesurl = new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, - 'user' => $userid, - 'attempt' => $attempt)); - -$interactionssurl = new moodle_url('/mod/scorm/report/userreportinteractions.php', array('id' => $id, - 'user' => $userid, - 'attempt' => $attempt)); -$row[] = new tabobject('scoes', $scoesurl, get_string('scoes', 'scorm')); -$row[] = new tabobject('interactions', $interactionssurl, get_string('interactions', 'scorm')); - -$tabs[] = $row; -print_tabs($tabs, $currenttab, $inactive, $activated); diff --git a/mod/scorm/report/userreporttracks.php b/mod/scorm/report/userreporttracks.php index 3856fd423b5..5b115756491 100644 --- a/mod/scorm/report/userreporttracks.php +++ b/mod/scorm/report/userreporttracks.php @@ -29,6 +29,7 @@ require_once($CFG->libdir.'/tablelib.php'); $id = required_param('id', PARAM_INT); // Course Module ID. $userid = required_param('user', PARAM_INT); // User ID. $scoid = required_param('scoid', PARAM_INT); // SCO ID. +$mode = required_param('mode', PARAM_ALPHA); // Scorm mode. $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number. $download = optional_param('download', '', PARAM_ALPHA); @@ -36,7 +37,8 @@ $download = optional_param('download', '', PARAM_ALPHA); $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt, - 'scoid' => $scoid)); + 'scoid' => $scoid, + 'mode' => $mode)); $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST); $course = get_course($cm->course); $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST); @@ -60,7 +62,7 @@ if (!groups_user_groups_visible($course, $userid, $cm)) { $event = \mod_scorm\event\tracks_viewed::create(array( 'context' => $contextmodule, 'relateduserid' => $userid, - 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid) + 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid, 'mode' => $mode) )); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('scorm', $scorm); @@ -76,6 +78,7 @@ $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id $PAGE->navbar->add("$strattempt $attempt - ".fullname($user), new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt))); $PAGE->navbar->add($selsco->title . ' - '. get_string('details', 'scorm')); +$PAGE->set_secondary_active_tab('scormreport'); if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) { if ($trackdata->status == '') { @@ -95,9 +98,13 @@ $table = new flexible_table('mod_scorm-userreporttracks'); if (!$table->is_downloading($download, $exportfilename)) { echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($scorm->name)); + if (!$PAGE->has_secondary_navigation()) { + echo $OUTPUT->heading(format_string($scorm->name)); + } $currenttab = ''; - require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php'); + $renderer = $PAGE->get_renderer('mod_scorm'); + $useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'attempt', $mode, $scoid); + echo $renderer->user_report_actionbar($useractionreport); echo $OUTPUT->box_start('generalbox boxaligncenter'); echo $OUTPUT->heading("$strattempt $attempt - ". fullname($user).': '. format_string($selsco->title). ' - '. get_string('details', 'scorm'), 3); diff --git a/mod/scorm/tabs.php b/mod/scorm/tabs.php deleted file mode 100644 index 8062949c580..00000000000 --- a/mod/scorm/tabs.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -/** - * Sets up the tabs used by the scorm pages based on the users capabilities. - * - * @author Dan Marsden and others. - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package mod_scorm - */ - -if (empty($scorm)) { - print_error('cannotaccess', 'mod_scorm'); -} -if (!isset($currenttab)) { - $currenttab = ''; -} -if (!isset($cm)) { - $cm = get_coursemodule_from_instance('scorm', $scorm->id); -} - -$contextmodule = context_module::instance($cm->id); - -$tabs = array(); -$row = array(); -$inactive = array(); -$activated = array(); - -if (has_capability('mod/scorm:savetrack', $contextmodule)) { - $row[] = new tabobject('info', "$CFG->wwwroot/mod/scorm/view.php?id=$cm->id", get_string('info', 'scorm')); -} -if (has_capability('mod/scorm:viewreport', $contextmodule)) { - $row[] = new tabobject('reports', "$CFG->wwwroot/mod/scorm/report.php?id=$cm->id", get_string('reports', 'scorm')); -} - -if (!($currenttab == 'info' && count($row) == 1)) { - $tabs[] = $row; -} - -if ($currenttab == 'reports' && !empty($reportlist) && count($reportlist) > 1) { - $row2 = array(); - foreach ($reportlist as $rep) { - $row2[] = new tabobject('scorm_'.$rep, $CFG->wwwroot."/mod/scorm/report.php?id=$cm->id&mode=$rep", - get_string('pluginname', 'scormreport_'.$rep)); - } - $tabs[] = $row2; -} - -print_tabs($tabs, $currenttab, $inactive, $activated); diff --git a/mod/scorm/templates/report_actionbar.mustache b/mod/scorm/templates/report_actionbar.mustache new file mode 100644 index 00000000000..78dc0ef49fe --- /dev/null +++ b/mod/scorm/templates/report_actionbar.mustache @@ -0,0 +1,63 @@ +{{! + 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 . +}} +{{! + @template mod_scorm/report_actionbar + Actions bar for the reports page UI. + Classes required for JS: + * none + Data attributes required for JS: + * none + Context variables required for this template: + * see mod/scorm/classes/output/actionbar.php + Example context (json): + { + "scormreports": { + "id": "url_select_test", + "options": [ + {"name": "Basic Report", "value": "/mod/scorm/report.php?id=69&mode=basic"}, + {"name": "Graph Report", "value": "/mod/scorm/report.php?id=69&mode=graphs"}, + {"name": "Interactions Report", "value": "/mod/scorm/report.php?id=69&mode=interactions"}, + {"name": "Objectives Report", "value": "/mod/scorm/report.php?id=69&mode=objectives"} + ] + }, + "candownload": true, + "downloadods": "http://localhost/moodle/mod/scorm/report.php?id=143&mode=basic&attemptsmode=0&sesskey=AmfcC7riSb&download=ODS", + "downloadexcel": "http://localhost/moodle/mod/scorm/report.php?id=143&mode=basic&attemptsmode=0&sesskey=AmfcC7riSb&download=Excel", + "downloadtext": "http://localhost/moodle/mod/scorm/report.php?id=143&mode=basic&attemptsmode=0&sesskey=AmfcC7riSb&download=CSV" + } +}} +
+
+
+ {{#scormreports}} + {{>core/url_select}} + {{/scormreports}} +
+ +
+
diff --git a/mod/scorm/templates/user_report_actionbar.mustache b/mod/scorm/templates/user_report_actionbar.mustache new file mode 100644 index 00000000000..5c81cb17841 --- /dev/null +++ b/mod/scorm/templates/user_report_actionbar.mustache @@ -0,0 +1,42 @@ +{{! + 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 . +}} +{{! + @template mod_scorm/report_actionbar + 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: + * see mod/scorm/classes/output/userreportsactionbar.php + Example context (json): + { + "userreport": { + "id": "url_select_test", + "options": [ + {"name": "Learning objects", "value": "/mod/scorm/report/userreport.php?id=70&user=13&attempt=1"}, + {"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" + } +}} +
+
+ {{#str}}back, core {{/str}} + {{#userreport}} + {{>core/url_select}} + {{/userreport}} +
+
diff --git a/mod/scorm/tests/events_test.php b/mod/scorm/tests/events_test.php index b7562792266..b5fc360fef5 100644 --- a/mod/scorm/tests/events_test.php +++ b/mod/scorm/tests/events_test.php @@ -271,7 +271,7 @@ class mod_scorm_event_testcase extends advanced_testcase { 'relateduserid' => 5, 'context' => context_module::instance($this->eventcm->id), 'courseid' => $this->eventcourse->id, - 'other' => array('attemptid' => 2, 'instanceid' => $this->eventscorm->id, 'scoid' => 3) + 'other' => array('attemptid' => 2, 'instanceid' => $this->eventscorm->id, 'scoid' => 3, 'mode' => 'interactions') )); // Trigger and capture the event. @@ -282,7 +282,8 @@ class mod_scorm_event_testcase extends advanced_testcase { // Check that the legacy log data is valid. $expected = array($this->eventcourse->id, 'scorm', 'userreporttracks', 'report/userreporttracks.php?id=' . - $this->eventcm->id . '&user=5&attempt=' . 2 . '&scoid=3', $this->eventscorm->id, $this->eventcm->id); + $this->eventcm->id . '&user=5&attempt=' . 2 . '&scoid=3' . '&mode=interactions', + $this->eventscorm->id, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 1311cad387e..f83ccef99f4 100644 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -137,7 +137,9 @@ if (empty($preventskip) && empty($launch) && (has_capability('mod/scorm:skipview $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); -echo $OUTPUT->heading(format_string($scorm->name)); +if (!$PAGE->has_secondary_navigation()) { + echo $OUTPUT->heading(format_string($scorm->name)); +} // Display any activity information (eg completion requirements / dates). $cminfo = cm_info::create($cm); @@ -159,16 +161,13 @@ if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownr } } -$currenttab = 'info'; -require($CFG->dirroot . '/mod/scorm/tabs.php'); - // Print the main part of the page. $attemptstatus = ''; if (empty($launch) && ($scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ALL || $scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY)) { $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm); } -echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'container', 'intro'); +echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id), 'container', 'intro'); // Check if SCORM available. No need to display warnings because activity dates are displayed at the top of the page. list($available, $warnings) = scorm_get_availability_status($scorm); @@ -176,6 +175,9 @@ list($available, $warnings) = scorm_get_availability_status($scorm); if ($available && empty($launch)) { scorm_print_launch($USER, $scorm, 'view.php?id='.$cm->id, $cm); } + +echo $OUTPUT->box($attemptstatus, 'container'); + if (!empty($forcejs)) { $message = $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "container forcejavascriptmessage"); echo html_writer::tag('noscript', $message);