mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-73863 course: Add tertiary navigation in completion pages
This commit is contained in:
parent
01eb6d2e9b
commit
36fe5695fe
@ -298,6 +298,34 @@ class manager {
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the available completion options (url => name) for the current course and user.
|
||||
*
|
||||
* @param int $courseid The course id.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_available_completion_options(int $courseid): array {
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$options = [];
|
||||
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
$completionlink = new moodle_url('/course/completion.php', ['id' => $courseid]);
|
||||
$options[$completionlink->out(false)] = get_string('coursecompletion', 'completion');
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
|
||||
$defaultcompletionlink = new moodle_url('/course/defaultcompletion.php', ['id' => $courseid]);
|
||||
$options[$defaultcompletionlink->out(false)] = get_string('defaultcompletion', 'completion');
|
||||
}
|
||||
|
||||
if (self::can_edit_bulk_completion($courseid)) {
|
||||
$bulkcompletionlink = new moodle_url('/course/bulkcompletion.php', ['id' => $courseid]);
|
||||
$options[$bulkcompletionlink->out(false)] = get_string('bulkactivitycompletion', 'completion');
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies completion from the bulk edit form to all selected modules
|
||||
*
|
||||
|
@ -8,6 +8,8 @@ information provided here is intended especially for developers.
|
||||
tested. Currently contains - viewed, usegrade, passgrade. Any plugin that are dependent on these criteria can now check this array instead of retesting it.
|
||||
* The method \completion_criteria_completion::mark_complete() now has the optional $timecompleted parameter to specify when the
|
||||
criteria was completed.
|
||||
* New method get_available_completion_options() has been added in the core_completion\manager class. This method can be used
|
||||
to obtain an array with the available completion options ([url => name]) for the current course and user.
|
||||
|
||||
=== 3.11 ===
|
||||
* New Behat steps for activity completion in the behat_completion class:
|
||||
|
@ -69,9 +69,11 @@ $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
|
||||
|
||||
// Print the form.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
|
||||
|
||||
echo $renderer->navigation($course, 'bulkcompletion');
|
||||
$actionbar = new \core_course\output\completion_action_bar($course->id, $PAGE->url);
|
||||
echo $renderer->render_course_completion_action_bar($actionbar);
|
||||
|
||||
echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
|
||||
|
||||
$PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['theform']);
|
||||
|
||||
|
@ -112,4 +112,15 @@ class core_course_bulk_activity_completion_renderer extends plugin_renderer_base
|
||||
];
|
||||
return parent::render_from_template('core_course/editdefaultcompletion', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the course completion action bar.
|
||||
*
|
||||
* @param \core_course\output\completion_action_bar $actionbar
|
||||
* @return string The HTML output
|
||||
*/
|
||||
public function render_course_completion_action_bar(\core_course\output\completion_action_bar $actionbar): string {
|
||||
$data = $actionbar->export_for_template($this->output);
|
||||
return $this->output->render_from_template('core_course/completion_action_bar', $data);
|
||||
}
|
||||
}
|
||||
|
68
course/classes/output/completion_action_bar.php
Normal file
68
course/classes/output/completion_action_bar.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?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/>.
|
||||
|
||||
namespace core_course\output;
|
||||
|
||||
use core_completion\manager;
|
||||
use moodle_url;
|
||||
use renderable;
|
||||
use renderer_base;
|
||||
use templatable;
|
||||
use url_select;
|
||||
|
||||
/**
|
||||
* Renderable class for the action bar elements in the course completion pages.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class completion_action_bar implements templatable, renderable {
|
||||
|
||||
/** @var int $courseid The course id. */
|
||||
private $courseid;
|
||||
|
||||
/** @var moodle_url $currenturl The URL of the current page. */
|
||||
private $currenturl;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param int $courseid The course id.
|
||||
* @param moodle_url $pageurl The URL of the current page.
|
||||
*/
|
||||
public function __construct(int $courseid, moodle_url $pageurl) {
|
||||
$this->courseid = $courseid;
|
||||
$this->currenturl = $pageurl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the data for the mustache template.
|
||||
*
|
||||
* @param renderer_base $output renderer to be used to render the action bar elements.
|
||||
* @return array The array which contains the data required to output the tertiary navigation selector for the course
|
||||
* completion pages.
|
||||
*/
|
||||
public function export_for_template(renderer_base $output): array {
|
||||
$urlselect = new url_select(manager::get_available_completion_options($this->courseid),
|
||||
$this->currenturl->out(false), null, 'coursecompletionactionselect');
|
||||
$urlselect->set_label(get_string('coursecompletionnavigation', 'completion'), ['class' => 'sr-only']);
|
||||
|
||||
return [
|
||||
'urlselect' => $urlselect->export_for_template($output),
|
||||
];
|
||||
}
|
||||
}
|
@ -57,8 +57,9 @@ if ($id) {
|
||||
if (!has_capability('moodle/course:update', $context)) {
|
||||
// User is not allowed to modify course completion.
|
||||
// Check if they can see default completion or edit bulk completion and redirect there.
|
||||
if ($tabs = core_completion\manager::get_available_completion_tabs($course)) {
|
||||
redirect($tabs[0]->link);
|
||||
if ($options = core_completion\manager::get_available_completion_options($course->id)) {
|
||||
// Redirect to the first available completion page.
|
||||
redirect(array_key_first($options));
|
||||
} else {
|
||||
require_capability('moodle/course:update', $context);
|
||||
}
|
||||
@ -161,9 +162,11 @@ $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
|
||||
|
||||
// Print the form.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('editcoursecompletionsettings', 'core_completion'));
|
||||
|
||||
echo $renderer->navigation($course, 'completion');
|
||||
$actionbar = new \core_course\output\completion_action_bar($course->id, $PAGE->url);
|
||||
echo $renderer->render_course_completion_action_bar($actionbar);
|
||||
|
||||
echo $OUTPUT->heading(get_string('editcoursecompletionsettings', 'core_completion'));
|
||||
|
||||
$form->display();
|
||||
|
||||
|
@ -51,7 +51,7 @@ if ($id) {
|
||||
// Set up the page.
|
||||
navigation_node::override_active_url(new moodle_url('/course/completion.php', array('id' => $course->id)));
|
||||
$PAGE->set_course($course);
|
||||
$PAGE->set_url('/course/bulkcompletion.php', array('id' => $course->id));
|
||||
$PAGE->set_url('/course/defaultcompletion.php', array('id' => $course->id));
|
||||
$PAGE->set_title($course->shortname);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
@ -64,9 +64,11 @@ $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
|
||||
|
||||
// Print the form.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
|
||||
|
||||
echo $renderer->navigation($course, 'defaultcompletion');
|
||||
$actionbar = new \core_course\output\completion_action_bar($course->id, $PAGE->url);
|
||||
echo $renderer->render_course_completion_action_bar($actionbar);
|
||||
|
||||
echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
|
||||
|
||||
$PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['theform']);
|
||||
|
||||
|
@ -67,9 +67,8 @@ if ($form->is_cancelled()) {
|
||||
$renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
|
||||
|
||||
echo $renderer->navigation($course, 'bulkcompletion');
|
||||
echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
|
||||
|
||||
echo $renderer->edit_bulk_completion($form, $manager->get_activities(array_keys($cms)));
|
||||
|
||||
|
@ -65,9 +65,8 @@ if ($form->is_cancelled()) {
|
||||
$renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
|
||||
|
||||
echo $renderer->navigation($course, 'defaultcompletion');
|
||||
echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
|
||||
|
||||
echo $renderer->edit_default_completion($form, $modules);
|
||||
|
||||
|
@ -4125,12 +4125,11 @@ function course_get_user_administration_options($course, $context) {
|
||||
global $CFG;
|
||||
$isfrontpage = $course->id == SITEID;
|
||||
$completionenabled = $CFG->enablecompletion && $course->enablecompletion;
|
||||
$hascompletiontabs = count(core_completion\manager::get_available_completion_tabs($course, $context)) > 0;
|
||||
$hascompletionoptions = count(core_completion\manager::get_available_completion_options($course->id)) > 0;
|
||||
$options = new stdClass;
|
||||
$options->update = has_capability('moodle/course:update', $context);
|
||||
$options->editcompletion = $CFG->enablecompletion &&
|
||||
$course->enablecompletion &&
|
||||
($options->update || $hascompletiontabs);
|
||||
$options->editcompletion = $CFG->enablecompletion && $course->enablecompletion &&
|
||||
($options->update || $hascompletionoptions);
|
||||
$options->filters = has_capability('moodle/filter:manage', $context) &&
|
||||
count(filter_get_available_in_context($context)) > 0;
|
||||
$options->reports = has_capability('moodle/site:viewreports', $context);
|
||||
|
53
course/templates/completion_action_bar.mustache
Normal file
53
course/templates/completion_action_bar.mustache
Normal file
@ -0,0 +1,53 @@
|
||||
{{!
|
||||
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 core_course/completion_action_bar
|
||||
|
||||
Actions bar in the course completion pages.
|
||||
|
||||
Context variables required for this template:
|
||||
* urlselect - The data object containing the required properties to render core/url_select.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"urlselect": {
|
||||
"id": "url_select_test",
|
||||
"action": "https://example.com/post",
|
||||
"formid": "url_select_form",
|
||||
"sesskey": "sesskey",
|
||||
"classes": "urlselect",
|
||||
"label": "",
|
||||
"helpicon": false,
|
||||
"showbutton": null,
|
||||
"options": [
|
||||
{
|
||||
"name": "Some name",
|
||||
"value": "/mod/data/someurl.php",
|
||||
"selected": false
|
||||
}
|
||||
],
|
||||
"disabled": false,
|
||||
"title": null
|
||||
}
|
||||
}
|
||||
}}
|
||||
<div class="container-fluid tertiary-navigation">
|
||||
<div class="row">
|
||||
{{#urlselect}}
|
||||
<div class="navitem">
|
||||
{{>core/url_select}}
|
||||
</div>
|
||||
{{/urlselect}}
|
||||
</div>
|
||||
</div>
|
@ -129,6 +129,7 @@ $string['coursecompleted'] = 'Course completed';
|
||||
$string['coursecompletedmessage'] = '<p>Congratulations!</p><p>You have completed the course <a href="{$a->courselink}">{$a->coursename}</a>.</p>';
|
||||
$string['coursecompletion'] = 'Course completion';
|
||||
$string['coursecompletioncondition'] = 'Condition: {$a}';
|
||||
$string['coursecompletionnavigation'] = 'Course completion tertiary navigation';
|
||||
$string['coursegrade'] = 'Course grade';
|
||||
$string['coursesavailable'] = 'Courses available';
|
||||
$string['coursesavailableexplaination'] = 'Note: Course completion conditions must be set for a course to appear in the above list.';
|
||||
|
Loading…
x
Reference in New Issue
Block a user