Skip to content

Commit 2930d9f

Browse files
author
Gareth Barnard
committed
Single page section image.
1 parent d60cd59 commit 2930d9f

8 files changed

+238
-61
lines changed

Changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ History
33
Version 3.10.1.1 - TBR
44
============================
55
1. Fix 'Site default not applied to setsection0ownpagenogridonesection'.
6+
2. Add new 'single page summary image' functionality (with settings) to show the section image in the section summary on a
7+
single section page.
68

79
Version 3.10.1.0 - 29/3/2021
810
============================

db/upgrade.php

+5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ function xmldb_format_grid_upgrade($oldversion = 0) {
143143
$value = get_config('format_grid', 'defaultsection0ownpagenogridonesection');
144144
set_config('defaultsetsection0ownpagenogridonesection', $value, 'format_grid');
145145

146+
global $CFG;
147+
require_once($CFG->dirroot.'/course/format/grid/lib.php'); // For format_grid.
148+
149+
format_grid::update_displayed_images_callback();
150+
146151
upgrade_plugin_savepoint(true, 2020111402, 'format', 'grid');
147152
}
148153

lang/en/format_grid.php

+9
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@
159159
$string['setnewactivity'] = 'Show new activity notification image';
160160
$string['setnewactivity_help'] = "Show the new activity notification image when a new activity or resource are added to a section.";
161161

162+
$string['singlepagesummaryimage'] = 'Show the grid image in the section summary on a single page.';
163+
$string['singlepagesummaryimage_help'] = "When the 'Course layout' is set to 'Show one section per page' then show the grid image for that section in the section summary when there is a summary in the position stated.";
164+
$string['defaultsinglepagesummaryimage'] = 'Show the grid image in the section summary on a single page.';
165+
$string['defaultsinglepagesummaryimage_desc'] = "When the 'Course layout' is set to 'Show one section per page' then show the grid image for that section in the section summary when there is a summary in the position stated.";
166+
162167
$string['setfitsectioncontainertowindow'] = 'Fit the section popup to the window';
163168
$string['setfitsectioncontainertowindow_help'] = 'If enabled, the popup box with the contents of the section will fit to the size of the window and will scroll inside if necessary. If disabled, the entire page will scroll instead.';
164169

@@ -271,6 +276,10 @@
271276
$string['resetnewactivity_help'] = 'Resets the new activity notification image to follow the site default value.';
272277
$string['resetallnewactivity'] = 'New activities';
273278
$string['resetallnewactivity_help'] = 'Resets the new activity notification images to follow the site default value.';
279+
$string['resetsinglepagesummaryimage'] = 'Single page summary image';
280+
$string['resetsinglepagesummaryimage_help'] = 'Resets the single page summary image to follow the site default value.';
281+
$string['resetallsinglepagesummaryimage'] = 'Single page summary images';
282+
$string['resetallsinglepagesummaryimage_help'] = 'Resets the single page summary images to follow the site default value.';
274283
$string['resetfitpopup'] = 'Fit section popup to the window';
275284
$string['resetfitpopup_help'] = 'Resets the \'Fit section popup to the window\' to follow the site default value.';
276285
$string['resetallfitpopup'] = 'Fit section popups to the window';

lib.php

+84-51
Large diffs are not rendered by default.

renderer.php

+68-6
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,21 @@ protected function section_nav_selection($course, $sections, $displaysection) {
207207
* @return string HTML to output.
208208
*/
209209
protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
210-
if (($section->section == 0) && ($onsectionpage)) {
210+
if ($onsectionpage) {
211211
return $this->section_header_onsectionpage($section, $course, $sectionreturn);
212212
} else {
213213
return parent::section_header($section, $course, $onsectionpage, $sectionreturn);
214214
}
215215
}
216216

217217
/**
218-
* Generate the display of the header part of a section before course modules are included for
219-
* when section 0 is used with a single section page.
218+
* Generate the display of the header part of a section before course modules are included
219+
* with a single section page.
220220
*
221221
* @param stdClass $section The course_section entry from DB
222222
* @param stdClass $course The course entry from DB
223-
* @param int $sectionreturn The section to return to after an action
223+
* @param int $sectionreturn The section to return to after an action.
224+
*
224225
* @return string HTML to output.
225226
*/
226227
protected function section_header_onsectionpage($section, $course, $sectionreturn = null) {
@@ -247,7 +248,8 @@ protected function section_header_onsectionpage($section, $course, $sectionretur
247248
);
248249

249250
// Create a span that contains the section title to be used to create the keyboard section move menu.
250-
$o .= html_writer::tag('span', get_section_name($course, $section), array('class' => 'hidden sectionname', 'id' => "sectionid-{$section->id}-title"));
251+
$sectionname = get_section_name($course, $section);
252+
$o .= html_writer::tag('span', $sectionname, array('class' => 'hidden sectionname', 'id' => "sectionid-{$section->id}-title"));
251253

252254
$leftcontent = $this->section_left_content($section, $course, true);
253255
$o .= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
@@ -257,14 +259,72 @@ protected function section_header_onsectionpage($section, $course, $sectionretur
257259
$o .= html_writer::start_tag('div', array('class' => 'content'));
258260

259261
$o .= html_writer::start_tag('div', array('class' => 'summary'));
260-
$o .= $this->format_summary_text($section);
262+
$o .= $this->single_section_page_summary($section, $sectionname, $course);
261263
$o .= html_writer::end_tag('div');
262264

263265
$o .= $this->section_availability($section);
264266

265267
return $o;
266268
}
267269

270+
/**
271+
* Generate the single section page summary.
272+
*
273+
* @param stdClass $section The course_section entry from DB.
274+
* @param string $sectionname The section name.
275+
* @param stdClass $course The course entry from DB.
276+
*
277+
* @return string HTML to output.
278+
*/
279+
protected function single_section_page_summary($section, $sectionname, $course) {
280+
$summary = $this->format_summary_text($section);
281+
$o = '';
282+
283+
if ($this->settings['singlepagesummaryimage'] > 1) { // I.e. not 'off'.
284+
if (!empty($summary)) {
285+
$data = new stdClass;
286+
switch($this->settings['singlepagesummaryimage']) {
287+
case 2:
288+
$data->left = true;
289+
break;
290+
case 3:
291+
$data->centre = true;
292+
break;
293+
case 4:
294+
$data->right = true;
295+
break;
296+
default:
297+
$data->left = true;
298+
}
299+
300+
$sectionimage = $this->courseformat->get_image($course->id, $section->id);
301+
$coursecontext = context_course::instance($course->id);
302+
/* If the image is set then check that displayedimageindex is greater than 0 otherwise create the displayed image.
303+
This is a catch-all for existing courses. */
304+
if (isset($sectionimage->image) && ($sectionimage->displayedimageindex < 1)) {
305+
// Set up the displayed image:...
306+
$sectionimage->newimage = $sectionimage->image;
307+
$icbc = $this->courseformat->hex2rgb($this->settings['imagecontainerbackgroundcolour']);
308+
$sectionimage = $this->courseformat->setup_displayed_image($sectionimage, $coursecontext->id,
309+
$this->settings, $icbc);
310+
}
311+
312+
$gridimagepath = $this->courseformat->get_image_path();
313+
$iswebp = (get_config('format_grid', 'defaultdisplayedimagefiletype') == 2);
314+
315+
$data->image = $this->courseformat->output_section_image(
316+
$section->id, $sectionname, $sectionimage, $coursecontext->id, $section, $gridimagepath, $this, $iswebp);
317+
$data->summary = $summary;
318+
319+
$o = $this->render_from_template('format_grid/singlepagesummaryimage', $data);
320+
}
321+
} else {
322+
$o = $summary;
323+
}
324+
325+
return $o;
326+
}
327+
268328
/**
269329
* Output the html for a single section page.
270330
*
@@ -279,6 +339,8 @@ public function print_single_section_page($course, $sections, $mods, $modnames,
279339
if (($this->section0attop) && ($this->settings['setsection0ownpagenogridonesection'] == 1)) {
280340
return parent::print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection);
281341
} else {
342+
/* Output the single section page without section 0 at the top.
343+
Thus when section 0 is on its own page, it won't be displayed twice. */
282344
$modinfo = get_fast_modinfo($course);
283345
$course = course_get_format($course)->get_course();
284346

settings.php

+13
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@
284284
);
285285
$settings->add(new admin_setting_configselect($name, $title, $description, $default, $choices));
286286

287+
// Show the grid image in the section summary on a single page.
288+
$name = 'format_grid/defaultsinglepagesummaryimage';
289+
$title = get_string('defaultsinglepagesummaryimage', 'format_grid');
290+
$description = get_string('defaultsinglepagesummaryimage_desc', 'format_grid');
291+
$default = 1;
292+
$choices = array(
293+
1 => new lang_string('off', 'format_grid'),
294+
2 => new lang_string('left', 'format_grid'),
295+
3 => new lang_string('centre', 'format_grid'),
296+
4 => new lang_string('right', 'format_grid')
297+
);
298+
$settings->add(new admin_setting_configselect($name, $title, $description, $default, $choices));
299+
287300
// Fix the section container popup to the screen. 1 = no, 2 = yes.
288301
$name = 'format_grid/defaultfitsectioncontainertowindow';
289302
$title = get_string('defaultfitsectioncontainertowindow', 'format_grid');

styles.css

+8-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
padding: 0;
3535
padding-bottom: 5px;
3636
}
37+
3738
.course-content ul.gtopics-0 #section-0 {
3839
background: transparent;
3940
border: 0 none;
@@ -141,7 +142,9 @@ div#gridmiddle-column > ul {
141142
text-overflow: inherit;
142143
white-space: pre-wrap;
143144
word-wrap: break-word;
145+
z-index: 1;
144146
}
147+
145148
.course-content ul.gridicons li .icon_content.content_inside.top {
146149
left: 0;
147150
right: 0;
@@ -194,12 +197,13 @@ div#gridmiddle-column > ul {
194197
box-sizing: content-box;
195198
overflow: visible;
196199
position: relative;
197-
text-align: center;
198-
vertical-align: middle;
199200
}
200201

201-
.course-content ul.gridicons li img {
202-
margin-top: 0;
202+
.course-content ul.gridicons li .image_holder img {
203+
left: 50%;
204+
position: absolute;
205+
top: 50%;
206+
transform: translate(-50%, -50%);
203207
}
204208

205209
.course-content ul.gridicons li img.info {
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{!
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+
@template format_grid/singlepagesummaryimage
19+
20+
Single page summary image.
21+
22+
Context variables required for this template:
23+
* centre - If true, centre the content.
24+
* image - Image markup.
25+
* left - If true, align the content to the left.
26+
* right - If true, align the content to the right.
27+
* summary - Summary markup.
28+
29+
Example context (json):
30+
{
31+
"centre": true,
32+
"image": "Image markup",
33+
"left": false,
34+
"right": false,
35+
"summary": "Summary markup"
36+
}
37+
}}
38+
{{#left}}
39+
<div class="d-flex flex-row">
40+
{{/left}}
41+
{{#centre}}
42+
<div class="d-flex flex-column align-items-center">
43+
{{/centre}}
44+
{{#right}}
45+
<div class="d-flex flex-row-reverse">
46+
{{/right}}
47+
<div class="p-1">{{{image}}}</div>
48+
<div class="p-1{{^centre}} w-100{{/centre}}">{{{summary}}}</div>
49+
</div>

0 commit comments

Comments
 (0)