Merge branch 'MDL-59612-master' of git://github.com/junpataleta/moodle

This commit is contained in:
David Monllao 2017-07-31 13:59:55 +02:00
commit 707f9beae1
16 changed files with 285 additions and 16 deletions

View file

@ -0,0 +1,110 @@
<?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/>.
/**
* File containing the class activity navigation renderable.
*
* @package core_course
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
/**
* The class activity navigation renderable.
*
* @package core_course
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity_navigation implements renderable, templatable {
/**
* @var \action_link The action link object for the prev link.
*/
public $prevlink = null;
/**
* @var \action_link The action link object for the next link.
*/
public $nextlink = null;
/**
* Constructor.
*
* @param \cm_info|null $prevmod The previous module to display, null if none.
* @param \cm_info|null $nextmod The previous module to display, null if none.
*/
public function __construct($prevmod, $nextmod) {
global $OUTPUT;
// Check if there is a previous module to display.
if ($prevmod) {
$linkurl = new \moodle_url($prevmod->url, array('forceview' => 1));
$linkname = $prevmod->name;
if (!$prevmod->visible) {
$linkname .= ' ' . get_string('hiddenwithbrackets');
}
$attributes = [
'classes' => 'btn btn-link',
'id' => 'prev-activity-link',
'title' => $linkname,
];
$this->prevlink = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname, null, $attributes);
}
// Check if there is a next module to display.
if ($nextmod) {
$linkurl = new \moodle_url($nextmod->url, array('forceview' => 1));
$linkname = $nextmod->name;
if (!$nextmod->visible) {
$linkname .= ' ' . get_string('hiddenwithbrackets');
}
$attributes = [
'classes' => 'btn btn-link',
'id' => 'next-activity-link',
'title' => $linkname,
];
$this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes);
}
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \renderer_base $output Renderer base.
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
$data = new \stdClass();
if ($this->prevlink) {
$data->prevlink = $this->prevlink->export_for_template($output);
}
if ($this->nextlink) {
$data->nextlink = $this->nextlink->export_for_template($output);
}
return $data;
}
}

View file

@ -157,11 +157,11 @@ if ($mform->is_cancelled()) {
}
if (isset($fromform->submitbutton)) {
$url = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule, 'forceview' => 1));
if (empty($fromform->showgradingmanagement)) {
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
redirect($url);
} else {
$returnurl = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule));
redirect($fromform->gradingman->get_management_url($returnurl));
redirect($fromform->gradingman->get_management_url($url));
}
} else {
redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));

View file

@ -2100,6 +2100,19 @@ class core_course_renderer extends plugin_renderer_base {
set_attributes(array('class' => 'frontpage-category-names'));
return $this->coursecat_tree($chelper, coursecat::get(0));
}
/**
* Renders the activity navigation.
*
* Defer to template.
*
* @param \core_course\output\activity_navigation $page
* @return string html for the page
*/
public function render_activity_navigation(\core_course\output\activity_navigation $page) {
$data = $page->export_for_template($this->output);
return $this->output->render_from_template('core_course/activity_navigation', $data);
}
}
/**

View file

@ -0,0 +1,69 @@
{{!
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/activity_navigation
Displays the activity navigation
Context variables required for this template:
* prevlink Object - The action link data for the previous activity link. Corresponds with the core/action_link context.
* nextlink Object - The action link data for the next activity link. Corresponds with the core/action_link context.
Example context (json):
{
"prevlink": {
"disabled": false,
"url": "#",
"id": "test-id-1",
"classes": "btn btn-link",
"attributes": [
{
"name": "title",
"value": "Activity A"
}
],
"text": "◄ Activity A"
},
"nextlink": {
"disabled": false,
"url": "#",
"id": "test-id-2",
"classes": "btn btn-link",
"attributes": [
{
"name": "title",
"value": "Activity C"
}
],
"text": "Activity C ►"
}
}
}}
<div>
{{< core/columns-1to1to1}}
{{$column1}}
<div class="pull-left">
{{#prevlink}}{{> core/action_link }}{{/prevlink}}
</div>
{{/column1}}
{{$column3}}
<div class="pull-right">
{{#nextlink}}{{> core/action_link }}{{/nextlink}}
</div>
{{/column3}}
{{/ core/columns-1to1to1}}
</div>

View file

@ -931,6 +931,7 @@ $string['hiddensections'] = 'Hidden sections';
$string['hiddensections_help'] = 'This setting determines whether hidden sections are displayed to students in collapsed form (perhaps for a course in weekly format to indicate holidays) or are completely hidden.';
$string['hiddensectionscollapsed'] = 'Hidden sections are shown in collapsed form';
$string['hiddensectionsinvisible'] = 'Hidden sections are completely invisible';
$string['hiddenwithbrackets'] = '(hidden)';
$string['hide'] = 'Hide';
$string['hideadvancedsettings'] = 'Hide advanced settings';
$string['hidechartdata'] = 'Hide chart data';

View file

@ -813,6 +813,69 @@ class core_renderer extends renderer_base {
return '<div role="main">'.$this->unique_main_content_token.'</div>';
}
/**
* Returns standard navigation between activities in a course.
*
* @return string the navigation HTML.
*/
public function activity_navigation() {
// First we should check if we want to add navigation.
$context = $this->page->context;
if (($this->page->pagelayout !== 'incourse' && $this->page->pagelayout !== 'frametop')
|| $context->contextlevel != CONTEXT_MODULE) {
return '';
}
// If the activity is in stealth mode, show no links.
if ($this->page->cm->is_stealth()) {
return '';
}
// Get a list of all the activities in the course.
$course = $this->page->cm->get_course();
$modules = get_fast_modinfo($course->id)->get_cms();
// Put the modules into an array in order by the position they are shown in the course.
$mods = [];
foreach ($modules as $module) {
// Only add activities the user can access, aren't in stealth mode and have a url (eg. mod_label does not).
if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
continue;
}
$mods[$module->id] = $module;
}
$nummods = count($mods);
// If there is only one mod then do nothing.
if ($nummods == 1) {
return '';
}
// Get an array of just the course module ids used to get the cmid value based on their position in the course.
$modids = array_keys($mods);
// Get the position in the array of the course module we are viewing.
$position = array_search($this->page->cm->id, $modids);
$prevmod = null;
$nextmod = null;
// Check if we have a previous mod to show.
if ($position > 0) {
$prevmod = $mods[$modids[$position - 1]];
}
// Check if we have a next mod to show.
if ($position < ($nummods - 1)) {
$nextmod = $mods[$modids[$position + 1]];
}
$activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod);
$renderer = $this->page->get_renderer('core', 'course');
return $renderer->render($activitynav);
}
/**
* The standard tags (typically script tags that are not needed earlier) that
* should be output after everything else. Designed to be called in theme layout.php files.

View file

@ -31,6 +31,7 @@ require_once($CFG->libdir.'/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$r = optional_param('r', 0, PARAM_INT); // Resource instance ID
$redirect = optional_param('redirect', 0, PARAM_BOOL);
$forceview = optional_param('forceview', 0, PARAM_BOOL);
if ($r) {
if (!$resource = $DB->get_record('resource', array('id'=>$r))) {
@ -76,12 +77,7 @@ if (count($files) < 1) {
$resource->mainfile = $file->get_filename();
$displaytype = resource_get_final_display_type($resource);
if ($displaytype == RESOURCELIB_DISPLAY_OPEN || $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD) {
// For 'open' and 'download' links, we always redirect to the content - except
// if the user just chose 'save and display' from the form then that would be
// confusing
if (strpos(get_local_referer(false), 'modedit.php') === false) {
$redirect = true;
}
}
// Don't redirect teachers, otherwise they can not access course or module settings.
@ -91,7 +87,7 @@ if ($redirect && !course_get_format($course)->has_view_page() &&
$redirect = false;
}
if ($redirect) {
if ($redirect && !$forceview) {
// coming from course page or url index page
// this redirect trick solves caching problems when tracking views ;-)
$path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$file->get_filepath().$file->get_filename();

View file

@ -1,6 +1,18 @@
This files describes API changes in /mod/* - activity modules,
information provided here is intended especially for developers.
=== 3.4 ===
* Navigation between activities via a previous and next link was added to Boost, Clean and Bootstrapbase. This
was made possible by a new function core_renderer->activity_navigation(). However, there was an issue when linking
to the mod_resource and mod_url view.php pages where it would automatically download the file, or redirect to
the URL. It was noticed that this was not the case when editing the module and clicking 'Save and display' which would
take you to the pages without downloading the file or redirecting to a link. The reason this worked was because of the
hard-coded check 'if (strpos(get_local_referer(false), 'modedit.php') === false) {' in the view.php files. This check
has been removed in favour of an optional_param('forceview'). If you are using the above hard-coded check in your
plugin it is recommended to remove it and use the optional param as it will prevent the navigation from working as
expected.
=== 3.3 ===
* External functions that were returning file information now return the following additional file fields:

View file

@ -31,6 +31,7 @@ require_once($CFG->libdir . '/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course module ID
$u = optional_param('u', 0, PARAM_INT); // URL instance id
$redirect = optional_param('redirect', 0, PARAM_BOOL);
$forceview = optional_param('forceview', 0, PARAM_BOOL);
if ($u) { // Two ways to specify the module
$url = $DB->get_record('url', array('id'=>$u), '*', MUST_EXIST);
@ -66,14 +67,10 @@ unset($exturl);
$displaytype = url_get_final_display_type($url);
if ($displaytype == RESOURCELIB_DISPLAY_OPEN) {
// For 'open' links, we always redirect to the content - except if the user
// just chose 'save and display' from the form then that would be confusing
if (strpos(get_local_referer(false), 'modedit.php') === false) {
$redirect = true;
}
}
if ($redirect) {
if ($redirect && !$forceview) {
// coming from course page or url index page,
// the redirection is needed for completion tracking and logging
$fullurl = str_replace('&amp;', '&', url_get_full_url($url, $cm, $course));

View file

@ -58,6 +58,7 @@
<div class="card card-block">
{{{ output.course_content_header }}}
{{{ output.main_content }}}
{{{ output.activity_navigation }}}
{{{ output.course_content_footer }}}
</div>
</section>

View file

@ -82,6 +82,7 @@
{{/hasregionmainsettingsmenu}}
{{{ output.course_content_header }}}
{{{ output.main_content }}}
{{{ output.activity_navigation }}}
{{{ output.course_content_footer }}}
</div>
</section>

View file

@ -63,6 +63,7 @@ echo $OUTPUT->doctype() ?>
<?php
echo $OUTPUT->course_content_header();
echo $OUTPUT->main_content();
echo $OUTPUT->activity_navigation();
echo $OUTPUT->course_content_footer();
?>
</section>

View file

@ -69,6 +69,7 @@ echo $OUTPUT->doctype() ?>
<?php
echo $OUTPUT->course_content_header();
echo $OUTPUT->main_content();
echo $OUTPUT->activity_navigation();
echo $OUTPUT->course_content_footer();
?>
</section>

View file

@ -65,6 +65,7 @@ echo $OUTPUT->doctype() ?>
<?php
echo $OUTPUT->course_content_header();
echo $OUTPUT->main_content();
echo $OUTPUT->activity_navigation();
echo $OUTPUT->course_content_footer();
?>
</section>

View file

@ -76,6 +76,7 @@ echo $OUTPUT->doctype() ?>
<?php
echo $OUTPUT->course_content_header();
echo $OUTPUT->main_content();
echo $OUTPUT->activity_navigation();
echo $OUTPUT->course_content_footer();
?>
</section>

View file

@ -9,6 +9,8 @@ information provided here is intended especially for theme designer.
the first one was renamed to loginform.mustache - see MDL-58970.
* The Boost flat navigation nodes now have several data-attributes which let plugin developers
access properties from the underlying navigation nodes in the browser - see MDL-59425.
* Navigation between activities via a previous and next link was added to Boost, Clean and Bootstrapbase. This
is made possible by a new function core_renderer->activity_navigation().
=== 3.3 ===