/
renderer.php
353 lines (310 loc) · 15.4 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?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/>.
/**
* Renderer for outputting the turforlag course format.
*
* @package format_turforlag
* @since Moodle 2.3
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/format/renderer.php');
/**
* Basic renderer for turforlag format.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_turforlag_renderer extends format_section_renderer_base {
/**
* Generate the starting container html for a list of sections
* @return string HTML to output.
*/
protected function start_section_list() {
$html = html_writer::start_tag('div', array('id' => 'turforlag_wrapper'));
$html .= html_writer::start_tag('div', array('id' => 'tabs', 'class' => 'turforlag'));
return $html;
}
/**
* Generate the closing container html for a list of sections
* @return string HTML to output.
*/
protected function end_section_list() {
$html = html_writer::end_tag('div');
$html .= html_writer::end_tag('div');
return $html;
}
/**
* Generate the title for this section page
* @return string the page title
*/
protected function page_title() {
return get_string('topicoutline');
}
/**
* Generate the edit controls of a section
*
* @param stdClass $course The course entry from DB
* @param stdClass $section The course_section entry from DB
* @param bool $onsectionpage true if being printed on a section page
* @return array of links with edit controls
*/
protected function section_edit_controls($course, $section, $onsectionpage = false) {
global $PAGE;
if (!$PAGE->user_is_editing()) {
return array();
}
$coursecontext = context_course::instance($course->id);
if ($onsectionpage) {
$url = course_get_url($course, $section->section);
} else {
$url = course_get_url($course);
}
$url->param('sesskey', sesskey());
$controls = array();
if (has_capability('moodle/course:setcurrentsection', $coursecontext)) {
if ($course->marker == $section->section) { // Show the "light globe" on/off.
$url->param('marker', 0);
$controls[] = html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marked'),
'class' => 'icon ', 'alt' => get_string('markedthistopic'))),
array('title' => get_string('markedthistopic'), 'class' => 'editing_highlight'));
} else {
$url->param('marker', $section->section);
$controls[] = html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marker'),
'class' => 'icon', 'alt' => get_string('markthistopic'))),
array('title' => get_string('markthistopic'), 'class' => 'editing_highlight'));
}
}
return array_merge($controls, parent::section_edit_controls($course, $section, $onsectionpage));
}
/**
* Output the html for a multiple section page
*
* @param stdClass $course The course entry from DB
* @param array $sections (argument not used)
* @param array $mods (argument not used)
* @param array $modnames (argument not used)
* @param array $modnamesused (argument not used)
*/
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
global $PAGE;
$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();
$context = context_course::instance($course->id);
// Title with completion help icon.
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
echo $this->output->heading($this->page_title(), 2, 'accesshide');
// Copy activity clipboard..
echo $this->course_activity_clipboard($course, 0);
// Now the list of sections..
echo $this->start_section_list();
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section == 0) {
// 0-section is displayed a little different then the others
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
echo $this->section_header($thissection, $course, false, 0);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, 0, 0);
echo $this->section_footer();
}
continue;
}
if ($section > $course->numsections) {
// activities inside this section are 'orphaned', this section will be printed as 'stealth' below
continue;
}
// Show the section if the user is permitted to access it, OR if it's not available
// but there is some available info text which explains the reason & should display.
$showsection = $thissection->uservisible ||
($thissection->visible && !$thissection->available &&
!empty($thissection->availableinfo));
if (!$showsection) {
// If the hiddensections option is set to 'show hidden sections in collapsed
// form', then display the hidden section message - UNLESS the section is
// hidden by the availability system, which is set to hide the reason.
if (!$course->hiddensections && $thissection->available) {
echo $this->section_hidden($section, $course->id);
}
continue;
}
if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
// Display section summary only.
echo $this->section_summary($thissection, $course, null);
} else {
echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) {
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, $section, 0);
}
echo $this->section_footer();
}
}
if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
// Print stealth sections if present.
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section <= $course->numsections or empty($modinfo->sections[$section])) {
// this is not stealth section or it is empty
continue;
}
echo $this->stealth_section_header($section);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->stealth_section_footer();
}
echo $this->end_section_list();
echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
// Increase number of sections.
$straddsection = get_string('increasesections', 'moodle');
$url = new moodle_url('/course/changenumsections.php',
array('courseid' => $course->id,
'increase' => true,
'sesskey' => sesskey()));
$icon = $this->output->pix_icon('t/switch_plus', $straddsection);
echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
if ($course->numsections > 0) {
// Reduce number of sections sections.
$strremovesection = get_string('reducesections', 'moodle');
$url = new moodle_url('/course/changenumsections.php',
array('courseid' => $course->id,
'increase' => false,
'sesskey' => sesskey()));
$icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
}
echo html_writer::end_tag('div');
} else {
echo $this->end_section_list();
}
}
public function generate_turforlag_course_format_html($structure) {
echo html_writer::start_div('clearfix', array('id' => 'tabs'));
echo $this->generate_turforlag_tabs_html($structure);
echo $this->generate_turforlag_tabcontent_html($structure);
echo html_writer::end_div();
}
public function generate_turforlag_tabs_html($structure) {
$html = html_writer::start_tag('ul', array('class' => 'turforlag_tabs'));
$i = 0;
foreach ($structure as $sectionid => $section) {
$link = html_writer::link('#tabs-' . $sectionid, $section['section']);
$totaltabs = count($structure);
if ($totaltabs >= 26) {
$lineheight = '4px';
} else if ($totaltabs >= 21) {
$lineheight = '9px';
} else {
$lineheight = '13px';
}
$html .= html_writer::tag('li', $link,
array(
'class' => 'turforlag_status_' . $section['status'],
'style' => 'line-height: ' . $lineheight .';',
'data-turtab' => $i
));
$i++;
}
$html .= html_writer::end_tag('ul');
return $html;
}
public function generate_turforlag_tabcontent_html($structure) {
$html = '';
foreach ($structure as $sectionid => $section) {
$backgroundcontextid = null;
if (isset($structure[$sectionid]['backgroundcontextid'])) {
$backgroundcontextid = $structure[$sectionid]['backgroundcontextid'];
}
$html .= html_writer::start_div('turforlag_cf_content',
array(
'id' => 'tabs-' . $sectionid,
'style' => turforlag_tabcontent_background_style($backgroundcontextid)
));
$title = ($sectionid !=0 &&
!array_key_exists('parts', $structure[$sectionid])) ?
' - ' . get_string('no-section-parts-0', 'format_turforlag') : '';
$html .= html_writer::tag('h3', $section['section'] . $title);
if ($sectionid == 0) {
if ((isset($structure[0]['intromodulecontextid']) && $structure[0]['intromodulecontextid'])) {
if ($introimgurl = tur_get_course_intro_image($structure[0]['intromodulecontextid'])) {
$introimg = html_writer::empty_tag('img', array('src' => $introimgurl));
$html .= html_writer::div($introimg, 'turforlag_cf_tabbackground_image');
}
}
if (isset($structure[0]['courseid']) && $structure[0]['courseid']) {
if ($introhtml = tur_get_course_intro($structure[0]['courseid'])) {
$html .= html_writer::div($introhtml, 'turforlag_cf_tabbackground_text');
}
}
} else if (array_key_exists('parts', $structure[$sectionid])) {
$attributes = array('id' => 'subtabs-' . $sectionid);
$html .= html_writer::start_div('',
array('id' => 'subtabs-' . $sectionid, 'class' => 'turforlag_subtabs'));
$html .= $this->generate_turforlag_subtabs_html($structure, $sectionid);
$html .= $this->generate_turforlag_subtabcontent_html($structure, $sectionid);
$html .= html_writer::end_div();
} else {
$html .= html_writer::tag('p', get_string('no-section-parts-1', 'format_turforlag'));
$html .= html_writer::tag('p', get_string('no-section-parts-2', 'format_turforlag'));
}
$html .= html_writer::end_div();
}
return $html;
}
public function generate_turforlag_subtabs_html($structure, $sectionid) {
$html = html_writer::start_tag('ul', array('class' => 'turforlag_subtabs'));
$i = 0;
foreach ($structure[$sectionid]['parts'] as $subtabid => $subtab) {
$class = (array_key_exists('status', $subtab)) ?
'turforlag_status_' . $subtab['status'] : null;
if (!isset($subtab['modules'])) {
$url = new moodle_url("/mod/{$subtab['type']}/view.php",
array('id' => $subtab['moduleid']));
$link = html_writer::link($url, $subtab['name']);
$class .= ' turforlag_directlink';
} else {
$url = "#subtabs-{$sectionid}-{$subtabid}";
$link = html_writer::link($url, $subtab['name']);
}
$html .= html_writer::tag('li', $link, array(
'class' => $class,
'data-tursubtab' => $i));
$i++;
}
$html .= html_writer::end_tag('ul');
return $html;
}
public function generate_turforlag_subtabcontent_html($structure, $sectionid) {
$html = '';
foreach ($structure[$sectionid]['parts'] as $subtabid => $subtab) {
if (isset($structure[$sectionid]['parts'][$subtabid]['modules'])) {
$html .= html_writer::start_div('turforlag_cf_subcontent',
array('id' => "subtabs-{$sectionid}-{$subtabid}"));
$html .= html_writer::start_tag('ul');
if (isset($structure[$sectionid]['parts'][$subtabid]['modules'])) {
foreach ($structure[$sectionid]['parts'][$subtabid]['modules'] as $moduleid => $module) {
$url = new moodle_url("/mod/{$module['type']}/view.php",
array('id' => $moduleid));
$link = html_writer::link($url, $module['name']);
$html .= html_writer::tag('li', $link,
array('class' => 'turforlag_status_' . $module['status']));
}
}
$html .= html_writer::end_tag('ul');
$html .= html_writer::end_div();
}
}
return $html;
}
}