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 |
namespace theme_boost\output;
|
|
|
18 |
|
|
|
19 |
use moodle_url;
|
|
|
20 |
use html_writer;
|
|
|
21 |
use get_string;
|
|
|
22 |
|
|
|
23 |
defined('MOODLE_INTERNAL') || die;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Renderers to align Moodle's HTML with that expected by Bootstrap
|
|
|
27 |
*
|
|
|
28 |
* @package theme_boost
|
|
|
29 |
* @copyright 2012 Bas Brands, www.basbrands.nl
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class core_renderer extends \core_renderer {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Returns HTML to display a "Turn editing on/off" button in a form.
|
|
|
36 |
*
|
|
|
37 |
* @param moodle_url $url The URL + params to send through when clicking the button
|
|
|
38 |
* @param string $method
|
|
|
39 |
* @return string HTML the button
|
|
|
40 |
*/
|
|
|
41 |
public function edit_button(moodle_url $url, string $method = 'post') {
|
|
|
42 |
if ($this->page->theme->haseditswitch) {
|
|
|
43 |
return;
|
|
|
44 |
}
|
|
|
45 |
$url->param('sesskey', sesskey());
|
|
|
46 |
if ($this->page->user_is_editing()) {
|
|
|
47 |
$url->param('edit', 'off');
|
|
|
48 |
$editstring = get_string('turneditingoff');
|
|
|
49 |
} else {
|
|
|
50 |
$url->param('edit', 'on');
|
|
|
51 |
$editstring = get_string('turneditingon');
|
|
|
52 |
}
|
|
|
53 |
$button = new \single_button($url, $editstring, $method, \single_button::BUTTON_PRIMARY);
|
|
|
54 |
return $this->render_single_button($button);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Renders the "breadcrumb" for all pages in boost.
|
|
|
59 |
*
|
|
|
60 |
* @return string the HTML for the navbar.
|
|
|
61 |
*/
|
|
|
62 |
public function navbar(): string {
|
|
|
63 |
$newnav = new \theme_boost\boostnavbar($this->page);
|
|
|
64 |
return $this->render_from_template('core/navbar', $newnav);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Renders the context header for the page.
|
|
|
69 |
*
|
|
|
70 |
* @param array $headerinfo Heading information.
|
|
|
71 |
* @param int $headinglevel What 'h' level to make the heading.
|
|
|
72 |
* @return string A rendered context header.
|
|
|
73 |
*/
|
|
|
74 |
public function context_header($headerinfo = null, $headinglevel = 1): string {
|
|
|
75 |
global $DB, $USER, $CFG;
|
|
|
76 |
require_once($CFG->dirroot . '/user/lib.php');
|
|
|
77 |
$context = $this->page->context;
|
|
|
78 |
$heading = null;
|
|
|
79 |
$imagedata = null;
|
|
|
80 |
$userbuttons = null;
|
|
|
81 |
|
|
|
82 |
// Make sure to use the heading if it has been set.
|
|
|
83 |
if (isset($headerinfo['heading'])) {
|
|
|
84 |
$heading = $headerinfo['heading'];
|
|
|
85 |
} else {
|
|
|
86 |
$heading = $this->page->heading;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// The user context currently has images and buttons. Other contexts may follow.
|
|
|
90 |
if ((isset($headerinfo['user']) || $context->contextlevel == CONTEXT_USER) && $this->page->pagetype !== 'my-index') {
|
|
|
91 |
if (isset($headerinfo['user'])) {
|
|
|
92 |
$user = $headerinfo['user'];
|
|
|
93 |
} else {
|
|
|
94 |
// Look up the user information if it is not supplied.
|
|
|
95 |
$user = $DB->get_record('user', array('id' => $context->instanceid));
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
// If the user context is set, then use that for capability checks.
|
|
|
99 |
if (isset($headerinfo['usercontext'])) {
|
|
|
100 |
$context = $headerinfo['usercontext'];
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
// Only provide user information if the user is the current user, or a user which the current user can view.
|
|
|
104 |
// When checking user_can_view_profile(), either:
|
|
|
105 |
// If the page context is course, check the course context (from the page object) or;
|
|
|
106 |
// If page context is NOT course, then check across all courses.
|
|
|
107 |
$course = ($this->page->context->contextlevel == CONTEXT_COURSE) ? $this->page->course : null;
|
|
|
108 |
|
|
|
109 |
if (user_can_view_profile($user, $course)) {
|
|
|
110 |
// Use the user's full name if the heading isn't set.
|
|
|
111 |
if (empty($heading)) {
|
|
|
112 |
$heading = fullname($user);
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
$imagedata = $this->user_picture($user, array('size' => 100));
|
|
|
116 |
|
|
|
117 |
// Check to see if we should be displaying a message button.
|
|
|
118 |
if (!empty($CFG->messaging) && has_capability('moodle/site:sendmessage', $context)) {
|
|
|
119 |
$userbuttons = array(
|
|
|
120 |
'messages' => array(
|
|
|
121 |
'buttontype' => 'message',
|
|
|
122 |
'title' => get_string('message', 'message'),
|
|
|
123 |
'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
|
|
|
124 |
'image' => 'message',
|
|
|
125 |
'linkattributes' => \core_message\helper::messageuser_link_params($user->id),
|
|
|
126 |
'page' => $this->page
|
|
|
127 |
)
|
|
|
128 |
);
|
|
|
129 |
|
|
|
130 |
if ($USER->id != $user->id) {
|
|
|
131 |
$iscontact = \core_message\api::is_contact($USER->id, $user->id);
|
|
|
132 |
$contacttitle = $iscontact ? 'removefromyourcontacts' : 'addtoyourcontacts';
|
|
|
133 |
$contacturlaction = $iscontact ? 'removecontact' : 'addcontact';
|
|
|
134 |
$contactimage = $iscontact ? 'removecontact' : 'addcontact';
|
|
|
135 |
$userbuttons['togglecontact'] = array(
|
|
|
136 |
'buttontype' => 'togglecontact',
|
|
|
137 |
'title' => get_string($contacttitle, 'message'),
|
|
|
138 |
'url' => new moodle_url('/message/index.php', array(
|
|
|
139 |
'user1' => $USER->id,
|
|
|
140 |
'user2' => $user->id,
|
|
|
141 |
$contacturlaction => $user->id,
|
|
|
142 |
'sesskey' => sesskey())
|
|
|
143 |
),
|
|
|
144 |
'image' => $contactimage,
|
|
|
145 |
'linkattributes' => \core_message\helper::togglecontact_link_params($user, $iscontact),
|
|
|
146 |
'page' => $this->page
|
|
|
147 |
);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
$this->page->requires->string_for_js('changesmadereallygoaway', 'moodle');
|
|
|
151 |
}
|
|
|
152 |
} else {
|
|
|
153 |
$heading = null;
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
$prefix = null;
|
|
|
158 |
if ($context->contextlevel == CONTEXT_MODULE) {
|
|
|
159 |
if ($this->page->course->format === 'singleactivity') {
|
|
|
160 |
$heading = format_string($this->page->course->fullname, true, ['context' => $context]);
|
|
|
161 |
} else {
|
|
|
162 |
$heading = $this->page->cm->get_formatted_name();
|
|
|
163 |
$iconurl = $this->page->cm->get_icon_url();
|
|
|
164 |
$iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter';
|
|
|
165 |
$iconattrs = [
|
|
|
166 |
'class' => "icon activityicon $iconclass",
|
|
|
167 |
'aria-hidden' => 'true'
|
|
|
168 |
];
|
|
|
169 |
$imagedata = html_writer::img($iconurl->out(false), '', $iconattrs);
|
|
|
170 |
$purposeclass = plugin_supports('mod', $this->page->activityname, FEATURE_MOD_PURPOSE);
|
|
|
171 |
$purposeclass .= ' activityiconcontainer icon-size-6';
|
|
|
172 |
$purposeclass .= ' modicon_' . $this->page->activityname;
|
|
|
173 |
$isbranded = component_callback('mod_' . $this->page->activityname, 'is_branded', [], false);
|
|
|
174 |
$imagedata = html_writer::tag('div', $imagedata, ['class' => $purposeclass . ($isbranded ? ' isbranded' : '')]);
|
|
|
175 |
if (!empty($USER->editing)) {
|
|
|
176 |
$prefix = get_string('modulename', $this->page->activityname);
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
// Return the heading wrapped in an sr-only element so it is only visible to screen-readers.
|
|
|
182 |
if (!empty($this->page->layout_options['nocontextheader'])) {
|
|
|
183 |
return html_writer::div($heading, 'sr-only');
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
$contextheader = new \context_header($heading, $headinglevel, $imagedata, $userbuttons, $prefix);
|
|
|
187 |
return $this->render($contextheader);
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
/**
|
|
|
191 |
* See if this is the first view of the current cm in the session if it has fake blocks.
|
|
|
192 |
*
|
|
|
193 |
* (We track up to 100 cms so as not to overflow the session.)
|
|
|
194 |
* This is done for drawer regions containing fake blocks so we can show blocks automatically.
|
|
|
195 |
*
|
|
|
196 |
* @return boolean true if the page has fakeblocks and this is the first visit.
|
|
|
197 |
*/
|
|
|
198 |
public function firstview_fakeblocks(): bool {
|
|
|
199 |
global $SESSION;
|
|
|
200 |
|
|
|
201 |
$firstview = false;
|
|
|
202 |
if ($this->page->cm) {
|
|
|
203 |
if (!$this->page->blocks->region_has_fakeblocks('side-pre')) {
|
|
|
204 |
return false;
|
|
|
205 |
}
|
|
|
206 |
if (!property_exists($SESSION, 'firstview_fakeblocks')) {
|
|
|
207 |
$SESSION->firstview_fakeblocks = [];
|
|
|
208 |
}
|
|
|
209 |
if (array_key_exists($this->page->cm->id, $SESSION->firstview_fakeblocks)) {
|
|
|
210 |
$firstview = false;
|
|
|
211 |
} else {
|
|
|
212 |
$SESSION->firstview_fakeblocks[$this->page->cm->id] = true;
|
|
|
213 |
$firstview = true;
|
|
|
214 |
if (count($SESSION->firstview_fakeblocks) > 100) {
|
|
|
215 |
array_shift($SESSION->firstview_fakeblocks);
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
return $firstview;
|
|
|
220 |
}
|
|
|
221 |
}
|