Skip to content

Commit d113896

Browse files
committed
Merge branch '5882wolverine-master'
2 parents 3e6d7aa + a44fdd2 commit d113896

File tree

5 files changed

+203
-11
lines changed

5 files changed

+203
-11
lines changed

block_course_contents.php

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public function get_content() {
113113
$globalconfig = get_config('block_course_contents');
114114

115115
$text = html_writer::start_tag('ul', array('class' => 'section-list'));
116-
$r = 0;
117116
foreach ($sections as $section) {
118117
$i = $section->section;
119118
if (isset($course->numsections) && ($i > $course->numsections)) {
@@ -164,15 +163,87 @@ public function get_content() {
164163
$title = $format->get_section_name($section);
165164
}
166165

167-
$odd = $r % 2;
166+
// Check if we want to display a course link. Checked forced status from global config first,
167+
// then check block instance settings.
168+
if ($globalconfig->display_course_link === 'forced_off') {
169+
$displaycourselink = false;
170+
171+
} else if ($globalconfig->display_course_link === 'forced_on') {
172+
$displaycourselink = true;
173+
174+
} else if (empty($this->config) or !isset($this->config->display_course_link)) {
175+
// Instance not configured, use the globally defined default value.
176+
if ($globalconfig->display_course_link === 'optional_on') {
177+
$displaycourselink = true;
178+
} else {
179+
$displaycourselink = false;
180+
}
181+
} else if (!empty($this->config->display_course_link)) {
182+
$displaycourselink = true;
183+
184+
} else {
185+
$displaycourselink = false;
186+
187+
}
188+
189+
if (($i == 0) && ($displaycourselink)) {
190+
$sectionclass = 'section-item';
191+
192+
if (empty($selected)) {
193+
$sectionclass .= ' selected';
194+
}
195+
$text .= html_writer::start_tag('li', array('class' => $sectionclass));
196+
197+
$text .= html_writer::span('>', 'section-number');
198+
if (!empty($this->config->display_course_link_text)) {
199+
$anchortext = $this->config->display_course_link_text;
200+
} else if (!empty($globalconfig->display_course_link_text)) {
201+
$anchortext = $globalconfig->display_course_link_text;
202+
} else {
203+
$anchortext = $course->shortname;
204+
}
205+
206+
if (empty($selected)) {
207+
$text .= ' '.$anchortext;
208+
} else {
209+
$text .= ' '.html_writer::link(course_get_url($course), $anchortext);
210+
}
211+
212+
$text .= html_writer::end_tag('li');
213+
}
214+
215+
$sectionclass = 'section-item';
216+
217+
if (isset($selected) && $i == $selected) {
218+
$sectionclass .= ' selected';
219+
}
220+
168221
if ($format->is_section_current($section)) {
169-
$text .= html_writer::start_tag('li', array('class' => 'section-item current r'.$odd));
222+
$sectionclass .= ' current';
223+
}
224+
225+
$text .= html_writer::start_tag('li', array('class' => $sectionclass));
226+
227+
// Check if we want to enumerate section 0. Checked forced status from global config first,
228+
// then check block instance settings.
229+
if ($globalconfig->enumerate_section_0 === 'forced_off') {
230+
$enumeratesection0 = false;
231+
} else if ($globalconfig->enumerate_section_0 === 'forced_on') {
232+
$enumeratesection0 = true;
233+
} else if (empty($this->config) or !isset($this->config->enumerate_section_0 )) {
234+
// Instance not configured, use the globally defined default value.
235+
if ($globalconfig->enumerate_section_0 === 'optional_on') {
236+
$enumeratesection0 = true;
237+
} else {
238+
$enumeratesection0 = false;
239+
}
240+
} else if (!empty($this->config->enumerate_section_0 )) {
241+
$enumeratesection0 = true;
170242
} else {
171-
$text .= html_writer::start_tag('li', array('class' => 'section-item r'.$odd));
243+
$enumeratesection0 = false;
172244
}
173245

174-
if ($i == 0) {
175-
// Never enumerate the section number 0.
246+
if ( ($i == 0) && ($enumeratesection0 == false) ) {
176247
$enumerate = false;
177248

178249
} else if ($globalconfig->enumerate === 'forced_off') {
@@ -196,8 +267,15 @@ public function get_content() {
196267
$enumerate = false;
197268
}
198269

270+
$sectionnumber = $i;
271+
272+
// If enumerating and showing section 0, then increment section number.
273+
if ($enumerate && $enumeratesection0) {
274+
$sectionnumber++;
275+
}
276+
199277
if ($enumerate) {
200-
$title = html_writer::span($i, 'section-number').' '.html_writer::span($title, 'section-title');
278+
$title = html_writer::span($sectionnumber, 'section-number').' '.html_writer::span($title, 'section-title');
201279

202280
} else {
203281
$title = html_writer::span($title, 'section-title not-enumerated');
@@ -209,7 +287,6 @@ public function get_content() {
209287
$text .= $title;
210288
}
211289
$text .= html_writer::end_tag('li');
212-
$r++;
213290
}
214291
$text .= html_writer::end_tag('ul');
215292

@@ -258,4 +335,4 @@ private function node_plain_text($node) {
258335
}
259336
return $t;
260337
}
261-
}
338+
}

edit_form.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,65 @@ protected function specific_definition($mform) {
9898
}
9999

100100
$mform->setType('config_autotitle', PARAM_BOOL);
101+
102+
// Enumerate section 0.
103+
if ($config->enumerate_section_0 === 'forced_off') {
104+
$mform->addElement('static', 'config_enumerate_section_0_info', get_string('config_enumerate_section_0',
105+
'block_course_contents'), get_string('config_enumerate_section_0_forced_off', 'block_course_contents'));
106+
$mform->addHelpButton('config_enumerate_section_0_info', 'config_enumerate_section_0', 'block_course_contents');
107+
$mform->addElement('hidden', 'config_enumerate_section_0');
108+
109+
} else if ($config->enumerate_section_0 === 'forced_on') {
110+
$mform->addElement('static', 'config_enumerate_section_0_info', get_string('config_enumerate_section_0',
111+
'block_course_contents'), get_string('config_enumerate_section_0_forced_on', 'block_course_contents'));
112+
$mform->addHelpButton('config_enumerate_section_0_info', 'config_enumerate_section_0', 'block_course_contents');
113+
$mform->addElement('hidden', 'config_enumerate_section_0');
114+
115+
} else {
116+
$mform->addElement('advcheckbox', 'config_enumerate_section_0', get_string('config_enumerate_section_0',
117+
'block_course_contents'), get_string('config_enumerate_section_0_label', 'block_course_contents'));
118+
$mform->addHelpButton('config_enumerate_section_0', 'config_enumerate_section_0', 'block_course_contents');
119+
120+
if ($config->enumerate_section_0 === 'optional_on') {
121+
$mform->setDefault('config_enumerate_section_0', 1);
122+
123+
} else {
124+
$mform->setDefault('config_enumerate_section_0', 0);
125+
}
126+
}
127+
$mform->setType('config_enumerate_section_0', PARAM_BOOL);
128+
129+
// Display course page link.
130+
if ($config->display_course_link === 'forced_off') {
131+
$mform->addElement('static', 'config_display_course_link_info', get_string('config_display_course_link',
132+
'block_course_contents'), get_string('config_display_course_link_forced_off', 'block_course_contents'));
133+
$mform->addHelpButton('config_display_course_link_info', 'config_display_course_link', 'block_course_contents');
134+
$mform->addElement('hidden', 'config_display_course_link');
135+
136+
} else if ($config->display_course_link === 'forced_on') {
137+
$mform->addElement('static', 'config_display_course_link_info', get_string('config_display_course_link',
138+
'block_course_contents'), get_string('config_display_course_link_forced_on', 'block_course_contents'));
139+
$mform->addHelpButton('config_display_course_link_info', 'config_display_course_link', 'block_course_contents');
140+
$mform->addElement('hidden', 'config_display_course_link');
141+
142+
} else {
143+
$mform->addElement('advcheckbox', 'config_display_course_link', get_string('config_display_course_link',
144+
'block_course_contents'), get_string('config_display_course_link_desc', 'block_course_contents'));
145+
$mform->addHelpButton('config_display_course_link', 'config_display_course_link', 'block_course_contents');
146+
147+
if ($config->display_course_link === 'optional_on') {
148+
$mform->setDefault('config_display_course_link', 1);
149+
150+
} else {
151+
$mform->setDefault('config_display_course_link', 0);
152+
}
153+
}
154+
$mform->setType('config_display_course_link', PARAM_BOOL);
155+
156+
$mform->addElement('text', 'config_display_course_link_text',
157+
get_string('config_display_course_link_text', 'block_course_contents'));
158+
$mform->addHelpButton('config_display_course_link_text', 'config_display_course_link_text', 'block_course_contents');
159+
$mform->setDefault('config_display_course_link_text', '');
160+
$mform->setType('config_display_course_link_text', PARAM_RAW);
101161
}
102162
}

lang/en/block_course_contents.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,21 @@
4646
$string['config_enumerate_optional_on'] = 'Optional, enabled by default';
4747
$string['course_contents:addinstance'] = 'Add a new course contents block';
4848
$string['notusingsections'] = 'This course format does not use sections.';
49-
$string['pluginname'] = 'Course contents';
49+
$string['pluginname'] = 'Course contents';
50+
51+
$string['config_enumerate_section_0'] = 'Enumerate general section';
52+
$string['config_enumerate_section_0_desc'] = 'This setting controls the enumeration mode for the general section, also known as section 0.';
53+
$string['config_enumerate_section_0_help'] = 'Setting this option will enumerate from the first section, usually known as section 0 or general section.';
54+
$string['config_enumerate_section_0_label'] = 'Start enumerating from the general section.';
55+
56+
$string['config_display_course_link'] = 'Course page link';
57+
$string['config_display_course_link_desc'] = 'Display course home page link at the top of all sections.';
58+
$string['config_display_course_link_forced_off'] = 'Disabled in all blocks';
59+
$string['config_display_course_link_forced_on'] = 'Enabled in all blocks';
60+
$string['config_display_course_link_optional_off'] = 'Optional, disabled by default';
61+
$string['config_display_course_link_optional_on'] = 'Optional, enabled by default';
62+
$string['config_display_course_link_help'] = 'This will display a link to the course home page above all course section links.';
63+
64+
$string['config_display_course_link_text'] = 'Custom course page link text';
65+
$string['config_display_course_link_text_desc'] = 'Default value of the course home page link anchor text. If left empty, the course shortname will be used.';
66+
$string['config_display_course_link_text_help'] = 'Course home page link anchor text. If left empty, the site-level default value will be used, unless it is also empty. In that case, the course shortname will be used.';

settings.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@
4141
$enumerate
4242
));
4343

44+
$settings->add(new admin_setting_configselect(
45+
'block_course_contents/enumerate_section_0',
46+
get_string('config_enumerate_section_0', 'block_course_contents'),
47+
get_string('config_enumerate_section_0_desc', 'block_course_contents'),
48+
'optional_off',
49+
$enumerate
50+
));
51+
52+
// Display course page link.
53+
$displaycourselink = [
54+
'forced_on' => get_string('config_display_course_link_forced_on', 'block_course_contents'),
55+
'optional_on' => get_string('config_display_course_link_optional_on', 'block_course_contents'),
56+
'optional_off' => get_string('config_display_course_link_optional_off', 'block_course_contents'),
57+
'forced_off' => get_string('config_display_course_link_forced_off', 'block_course_contents'),
58+
];
59+
60+
$settings->add(new admin_setting_configselect(
61+
'block_course_contents/display_course_link',
62+
get_string('config_display_course_link', 'block_course_contents'),
63+
get_string('config_display_course_link_desc', 'block_course_contents'),
64+
'optional_off',
65+
$displaycourselink
66+
));
67+
68+
// Course page link custom text.
69+
$settings->add(new admin_setting_configtext('block_course_contents/display_course_link_text',
70+
new lang_string('config_display_course_link_text', 'block_course_contents'),
71+
new lang_string('config_display_course_link_text_desc', 'block_course_contents'), ''));
72+
4473
$autotitle = [
4574
'forced_on' => get_string('config_autotitle_forced_on', 'block_course_contents'),
4675
'optional_on' => get_string('config_autotitle_optional_on', 'block_course_contents'),

styles.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
margin-bottom: 6px;
99
}
1010

11+
.block_course_contents .section-item.selected {
12+
font-weight: bold;
13+
}
14+
1115
.block_course_contents .section-item.current {
1216
font-weight: bold;
1317
}
1418

1519
.block_course_contents .section-number {
1620
padding: 2px 4px;
21+
margin-right: 5px;
1722
font-size: 80%;
1823
font-weight: bold;
1924
color: white;
@@ -24,10 +29,14 @@
2429
-webkit-border-radius: 3px 3px 3px 3px;
2530
}
2631

27-
.block_course_contents .section-item.current .section-number {
32+
.block_course_contents .section-item.selected .section-number {
2833
background-color: #0070a8;
2934
}
3035

36+
.block_course_contents .section-item.current .section-number {
37+
background-color: #999;
38+
}
39+
3140
.block_course_contents a.dimmed:link,
3241
.block_course_contents a.dimmed:visited {
3342
color: #aaa;

0 commit comments

Comments
 (0)