1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* File containing the class activity navigation renderable.
|
|
|
19 |
*
|
|
|
20 |
* @package core_course
|
|
|
21 |
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
namespace core_course\output;
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die();
|
|
|
27 |
|
|
|
28 |
use renderable;
|
|
|
29 |
use templatable;
|
|
|
30 |
use url_select;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* The class activity navigation renderable.
|
|
|
34 |
*
|
|
|
35 |
* @package core_course
|
|
|
36 |
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
*/
|
|
|
39 |
class activity_navigation implements renderable, templatable {
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* @var \action_link The action link object for the prev link.
|
|
|
43 |
*/
|
|
|
44 |
public $prevlink = null;
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* @var \action_link The action link object for the next link.
|
|
|
48 |
*/
|
|
|
49 |
public $nextlink = null;
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* @var url_select The url select object for the activity selector menu.
|
|
|
53 |
*/
|
|
|
54 |
public $activitylist = null;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Constructor.
|
|
|
58 |
*
|
|
|
59 |
* @param \cm_info|null $prevmod The previous module to display, null if none.
|
|
|
60 |
* @param \cm_info|null $nextmod The next module to display, null if none.
|
|
|
61 |
* @param array $activitylist The list of activity URLs (as key) and names (as value) for the activity dropdown menu.
|
|
|
62 |
*/
|
|
|
63 |
public function __construct($prevmod, $nextmod, $activitylist = array()) {
|
|
|
64 |
global $OUTPUT;
|
|
|
65 |
|
|
|
66 |
// Check if there is a previous module to display.
|
|
|
67 |
if ($prevmod) {
|
|
|
68 |
$linkurl = new \moodle_url($prevmod->url, array('forceview' => 1));
|
|
|
69 |
$linkname = $prevmod->get_formatted_name();
|
|
|
70 |
if (!$prevmod->visible) {
|
|
|
71 |
$linkname .= ' ' . get_string('hiddenwithbrackets');
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
$attributes = [
|
|
|
75 |
'class' => 'btn btn-link',
|
|
|
76 |
'id' => 'prev-activity-link',
|
|
|
77 |
];
|
|
|
78 |
$this->prevlink = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname, null, $attributes);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// Check if there is a next module to display.
|
|
|
82 |
if ($nextmod) {
|
|
|
83 |
$linkurl = new \moodle_url($nextmod->url, array('forceview' => 1));
|
|
|
84 |
$linkname = $nextmod->get_formatted_name();
|
|
|
85 |
if (!$nextmod->visible) {
|
|
|
86 |
$linkname .= ' ' . get_string('hiddenwithbrackets');
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
$attributes = [
|
|
|
90 |
'class' => 'btn btn-link',
|
|
|
91 |
'id' => 'next-activity-link',
|
|
|
92 |
];
|
|
|
93 |
$this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
// Render the activity list dropdown menu if available.
|
|
|
97 |
if (!empty($activitylist)) {
|
|
|
98 |
$select = new url_select($activitylist, '', array('' => get_string('jumpto')));
|
|
|
99 |
$select->set_label(get_string('jumpto'), array('class' => 'sr-only'));
|
|
|
100 |
$select->attributes = array('id' => 'jump-to-activity');
|
|
|
101 |
$this->activitylist = $select;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Export this data so it can be used as the context for a mustache template.
|
|
|
107 |
*
|
|
|
108 |
* @param \renderer_base $output Renderer base.
|
|
|
109 |
* @return \stdClass
|
|
|
110 |
*/
|
|
|
111 |
public function export_for_template(\renderer_base $output) {
|
|
|
112 |
$data = new \stdClass();
|
|
|
113 |
if ($this->prevlink) {
|
|
|
114 |
$data->prevlink = $this->prevlink->export_for_template($output);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
if ($this->nextlink) {
|
|
|
118 |
$data->nextlink = $this->nextlink->export_for_template($output);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
if ($this->activitylist) {
|
|
|
122 |
$data->activitylist = $this->activitylist->export_for_template($output);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
return $data;
|
|
|
126 |
}
|
|
|
127 |
}
|