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>