mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-59613 course: Add dropdown menu for activity list
Part of MDL-59313.
This commit is contained in:
parent
ed765cfad1
commit
4698e169e5
3 changed files with 50 additions and 3 deletions
|
@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
use renderable;
|
use renderable;
|
||||||
use templatable;
|
use templatable;
|
||||||
|
use url_select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class activity navigation renderable.
|
* The class activity navigation renderable.
|
||||||
|
@ -47,13 +48,19 @@ class activity_navigation implements renderable, templatable {
|
||||||
*/
|
*/
|
||||||
public $nextlink = null;
|
public $nextlink = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var url_select The url select object for the activity selector menu.
|
||||||
|
*/
|
||||||
|
public $activitylist = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param \cm_info|null $prevmod The previous module to display, null if none.
|
* @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 \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;
|
global $OUTPUT;
|
||||||
|
|
||||||
// Check if there is a previous module to display.
|
// 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);
|
$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);
|
$data->nextlink = $this->nextlink->export_for_template($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->activitylist) {
|
||||||
|
$data->activitylist = $this->activitylist->export_for_template($output);
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
Context variables required for this template:
|
Context variables required for this template:
|
||||||
* prevlink Object - The action link data for the previous activity link. Corresponds with the core/action_link context.
|
* 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.
|
* 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):
|
Example context (json):
|
||||||
{
|
{
|
||||||
|
@ -50,16 +51,31 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"text": "Activity C ►"
|
"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}}
|
{{< core/columns-1to1to1}}
|
||||||
{{$column1}}
|
{{$column1}}
|
||||||
<div class="pull-left">
|
<div class="pull-left">
|
||||||
{{#prevlink}}{{> core/action_link }}{{/prevlink}}
|
{{#prevlink}}{{> core/action_link }}{{/prevlink}}
|
||||||
</div>
|
</div>
|
||||||
{{/column1}}
|
{{/column1}}
|
||||||
|
{{$column2}}
|
||||||
|
<div class="mdl-align">
|
||||||
|
{{#activitylist}}{{> core/url_select }}{{/activitylist}}
|
||||||
|
</div>
|
||||||
|
{{/column2}}
|
||||||
{{$column3}}
|
{{$column3}}
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
{{#nextlink}}{{> core/action_link }}{{/nextlink}}
|
{{#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.
|
// Put the modules into an array in order by the position they are shown in the course.
|
||||||
$mods = [];
|
$mods = [];
|
||||||
|
$activitylist = [];
|
||||||
foreach ($modules as $module) {
|
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).
|
// 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)) {
|
if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$mods[$module->id] = $module;
|
$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);
|
$nummods = count($mods);
|
||||||
|
@ -871,7 +883,7 @@ class core_renderer extends renderer_base {
|
||||||
$nextmod = $mods[$modids[$position + 1]];
|
$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');
|
$renderer = $this->page->get_renderer('core', 'course');
|
||||||
return $renderer->render($activitynav);
|
return $renderer->render($activitynav);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue