mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-59613-master' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
266959a41e
@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use renderable;
|
||||
use templatable;
|
||||
use url_select;
|
||||
|
||||
/**
|
||||
* The class activity navigation renderable.
|
||||
@ -47,13 +48,19 @@ class activity_navigation implements renderable, templatable {
|
||||
*/
|
||||
public $nextlink = null;
|
||||
|
||||
/**
|
||||
* @var url_select The url select object for the activity selector menu.
|
||||
*/
|
||||
public $activitylist = 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.
|
||||
* @param array $activitylist The list of activity URLs (as key) and names (as value) for the activity dropdown menu.
|
||||
*/
|
||||
public function __construct($prevmod, $nextmod) {
|
||||
public function __construct($prevmod, $nextmod, $activitylist = array()) {
|
||||
global $OUTPUT;
|
||||
|
||||
// Check if there is a previous module to display.
|
||||
@ -87,6 +94,14 @@ class activity_navigation implements renderable, templatable {
|
||||
];
|
||||
$this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes);
|
||||
}
|
||||
|
||||
// Render the activity list dropdown menu if available.
|
||||
if (!empty($activitylist)) {
|
||||
$select = new url_select($activitylist, '', array('' => get_string('jumpto')));
|
||||
$select->set_label(get_string('jumpto'), array('class' => 'sr-only'));
|
||||
$select->attributes = array('id' => 'jump-to-activity');
|
||||
$this->activitylist = $select;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,6 +120,10 @@ class activity_navigation implements renderable, templatable {
|
||||
$data->nextlink = $this->nextlink->export_for_template($output);
|
||||
}
|
||||
|
||||
if ($this->activitylist) {
|
||||
$data->activitylist = $this->activitylist->export_for_template($output);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
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.
|
||||
* activitylist Object - The data for the activity selector menu. Corresponds with the core/url_select context.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
@ -50,16 +51,31 @@
|
||||
}
|
||||
],
|
||||
"text": "Activity C ►"
|
||||
},
|
||||
"activitylist": {
|
||||
"id": "url_select_test",
|
||||
"action": "#",
|
||||
"options": [
|
||||
{"name": "Jump to...", "value": "#0"},
|
||||
{"name": "Activity A", "value": "#1"},
|
||||
{"name": "Activity B", "value": "#2"},
|
||||
{"name": "Activity C", "value": "#3"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}}
|
||||
<div>
|
||||
<div class="m-t-2 m-b-1">
|
||||
{{< core/columns-1to1to1}}
|
||||
{{$column1}}
|
||||
<div class="pull-left">
|
||||
{{#prevlink}}{{> core/action_link }}{{/prevlink}}
|
||||
</div>
|
||||
{{/column1}}
|
||||
{{$column2}}
|
||||
<div class="mdl-align">
|
||||
{{#activitylist}}{{> core/url_select }}{{/activitylist}}
|
||||
</div>
|
||||
{{/column2}}
|
||||
{{$column3}}
|
||||
<div class="pull-right">
|
||||
{{#nextlink}}{{> core/action_link }}{{/nextlink}}
|
||||
|
@ -837,12 +837,24 @@ class core_renderer extends renderer_base {
|
||||
|
||||
// Put the modules into an array in order by the position they are shown in the course.
|
||||
$mods = [];
|
||||
$activitylist = [];
|
||||
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;
|
||||
|
||||
// Module name.
|
||||
$modname = $module->name;
|
||||
// Display the hidden text if necessary.
|
||||
if (!$module->visible) {
|
||||
$modname .= ' ' . get_string('hiddenwithbrackets');
|
||||
}
|
||||
// Module URL.
|
||||
$linkurl = new moodle_url($module->url, array('forceview' => 1));
|
||||
// Add module URL (as key) and name (as value) to the activity list array.
|
||||
$activitylist[$linkurl->out(false)] = $modname;
|
||||
}
|
||||
|
||||
$nummods = count($mods);
|
||||
@ -871,7 +883,7 @@ class core_renderer extends renderer_base {
|
||||
$nextmod = $mods[$modids[$position + 1]];
|
||||
}
|
||||
|
||||
$activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod);
|
||||
$activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod, $activitylist);
|
||||
$renderer = $this->page->get_renderer('core', 'course');
|
||||
return $renderer->render($activitynav);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user