Sara Arjona 6fb09beb86
MDL-69225 h5pactivity: Review when and which banners display
The UX team proposal is to display two different notifications, to avoid confusion:

1. When the user is in preview mode:
Message: 'You are in preview mode.'
Notification Type: Information (blue), with the information permanently visible and not dismissible,
ensuring continuous awareness.

2. When activity tracking is disabled:
Message: 'Attempt tracking is not enabled for this activity. You can enable it in Settings.'
Notification Type: Warning (yellow) with a close icon for dismissal if tracking is intentionally disabled.

These notifications should only be visible to teachers and content creators, not students.
If a teacher also has a student role, this information should not appear when logged in as a student.

That's why the pre-existing is_tracking_enabled() function has been updated to only check if tracking
is on for an activity, without considering user capabilities (that's why the $user parameter has been
removed from this function too). Besides, a new function called can_submit() has been created to find
out if users are allowed to submit an activity.
2024-01-25 17:46:36 +01:00

96 lines
3.3 KiB
PHP

<?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/>.
/**
* Prints an instance of mod_h5pactivity.
*
* @package mod_h5pactivity
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_h5pactivity\local\manager;
use core_h5p\factory;
use core_h5p\player;
use core_h5p\helper;
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
$id = required_param('id', PARAM_INT);
list ($course, $cm) = get_course_and_cm_from_cmid($id, 'h5pactivity');
require_login($course, true, $cm);
$manager = manager::create_from_coursemodule($cm);
$moduleinstance = $manager->get_instance();
$context = $manager->get_context();
// Trigger module viewed event and completion.
$manager->set_module_viewed($course);
// Convert display options to a valid object.
$factory = new factory();
$core = $factory->get_core();
$config = core_h5p\helper::decode_display_options($core, $moduleinstance->displayoptions);
// Instantiate player.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_h5pactivity', 'package', 0, 'id', false);
$file = reset($files);
$fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(),
$file->get_filearea(), $file->get_itemid(), $file->get_filepath(),
$file->get_filename(), false);
$PAGE->set_url('/mod/h5pactivity/view.php', ['id' => $cm->id]);
$shortname = format_string($course->shortname, true, ['context' => $context]);
$pagetitle = strip_tags($shortname.': '.format_string($moduleinstance->name));
$PAGE->set_title(format_string($pagetitle));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);
echo $OUTPUT->header();
$instance = $manager->get_instance();
// Only users without permission to submit can see the warning messages.
if (!$manager->can_submit()) {
// Show preview mode message.
$message = get_string('previewmode', 'mod_h5pactivity');
echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_INFO, false);
// If tracking is disabled, show a warning.
if (!$manager->is_tracking_enabled()) {
if (has_capability('moodle/course:manageactivities', $context)) {
$url = new moodle_url('/course/modedit.php', ['update' => $cm->id]);
$message = get_string('trackingdisabled_enable', 'mod_h5pactivity', $url->out());
} else {
$message = get_string('trackingdisabled', 'mod_h5pactivity');
}
echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
}
}
echo player::display($fileurl, $config, true, 'mod_h5pactivity', true);
echo $OUTPUT->footer();