mirror of
https://github.com/moodle/moodle.git
synced 2025-03-15 05:00:06 +01:00
MDL-69773 block_section_links: Add an option to display section name
This commit is contained in:
parent
c8d33eb9ce
commit
53663f2ea1
blocks/section_links
@ -105,6 +105,9 @@ class block_section_links extends block_base {
|
||||
}
|
||||
}
|
||||
|
||||
// Whether or not section name should be displayed.
|
||||
$showsectionname = !empty($config->showsectionname) ? true : false;
|
||||
|
||||
// Prepare an array of sections to create links for.
|
||||
$sections = array();
|
||||
$canviewhidden = has_capability('moodle/course:update', $context);
|
||||
@ -126,13 +129,17 @@ class block_section_links extends block_base {
|
||||
$sections[$i]->highlight = true;
|
||||
$sectiontojumpto = $section->section;
|
||||
}
|
||||
if ($showsectionname) {
|
||||
$sections[$i]->name = $courseformat->get_section_name($i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($sections)) {
|
||||
// Render the sections.
|
||||
$renderer = $this->page->get_renderer('block_section_links');
|
||||
$this->content->text = $renderer->render_section_links($this->page->course, $sections, $sectiontojumpto);
|
||||
$this->content->text = $renderer->render_section_links($this->page->course, $sections,
|
||||
$sectiontojumpto, $showsectionname);
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
|
@ -82,5 +82,8 @@ class block_section_links_edit_form extends block_edit_form {
|
||||
$mform->addHelpButton('config_incby'.$i, 'incby'.$i, 'block_section_links');
|
||||
}
|
||||
|
||||
$mform->addElement('selectyesno', 'config_showsectionname', get_string('showsectionname', 'block_section_links'));
|
||||
$mform->setDefault('config_showsectionname', !empty($config->showsectionname) ? 1 : 0);
|
||||
$mform->addHelpButton('config_showsectionname', 'showsectionname', 'block_section_links');
|
||||
}
|
||||
}
|
@ -34,6 +34,8 @@ $string['numsections2'] = 'Alternative number of sections';
|
||||
$string['numsections2_help'] = 'Once the number of sections in the course reaches this number then the Alternative increment by value is used.';
|
||||
$string['pluginname'] = 'Section links';
|
||||
$string['section_links:addinstance'] = 'Add a new section links block';
|
||||
$string['showsectionname'] = 'Display section name';
|
||||
$string['showsectionname_help'] = 'Display section name in addition to section number';
|
||||
$string['topics'] = 'Topics';
|
||||
$string['weeks'] = 'Weeks';
|
||||
$string['privacy:metadata'] = 'The Section links block only shows data stored in other locations.';
|
||||
|
@ -38,10 +38,12 @@ class block_section_links_renderer extends plugin_renderer_base {
|
||||
* @param stdClass $course The course we are rendering for.
|
||||
* @param array $sections An array of section objects to render.
|
||||
* @param bool|int The section to provide a jump to link for.
|
||||
* @param bool $showsectionname Whether or not section name should be displayed.
|
||||
* @return string The HTML to display.
|
||||
*/
|
||||
public function render_section_links(stdClass $course, array $sections, $jumptosection = false) {
|
||||
$html = html_writer::start_tag('ol', array('class' => 'inline-list'));
|
||||
public function render_section_links(stdClass $course, array $sections, $jumptosection = false, $showsectionname = false) {
|
||||
$olparams = $showsectionname ? ['class' => 'unlist'] : ['class' => 'inline-list'];
|
||||
$html = html_writer::start_tag('ol', $olparams);
|
||||
foreach ($sections as $section) {
|
||||
$attributes = array();
|
||||
if (!$section->visible) {
|
||||
@ -49,6 +51,9 @@ class block_section_links_renderer extends plugin_renderer_base {
|
||||
}
|
||||
$html .= html_writer::start_tag('li');
|
||||
$sectiontext = $section->section;
|
||||
if ($showsectionname) {
|
||||
$sectiontext .= ': ' . $section->name;
|
||||
}
|
||||
if ($section->highlight) {
|
||||
$sectiontext = html_writer::tag('strong', $sectiontext);
|
||||
}
|
||||
|
@ -48,4 +48,9 @@ if ($ADMIN->fulltree) {
|
||||
get_string('incby'.$i.'_help', 'block_section_links'),
|
||||
$selected[$i][1], $increments));
|
||||
}
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('block_section_links/showsectionname',
|
||||
get_string('showsectionname', 'block_section_links'),
|
||||
get_string('showsectionname_help', 'block_section_links'),
|
||||
0));
|
||||
}
|
43
blocks/section_links/tests/behat/show_section_name.feature
Normal file
43
blocks/section_links/tests/behat/show_section_name.feature
Normal file
@ -0,0 +1,43 @@
|
||||
@block @block_section_links
|
||||
Feature: The Section links block can be configured to display section name in addition to section number
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category | numsections | coursedisplay |
|
||||
| Course 1 | C1 | 0 | 10 | 1 |
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | idnumber | section |
|
||||
| assign | First assignment | C1 | assign1 | 7 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And I log in as "admin"
|
||||
And I set the following administration settings values:
|
||||
| showsectionname | 1 |
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
And I add the "Section links" block
|
||||
And I log out
|
||||
|
||||
Scenario: Student can see section name under the Section links block
|
||||
Given I log in as "student1"
|
||||
When I am on "Course 1" course homepage
|
||||
Then I should see "7: Topic 7" in the "Section links" "block"
|
||||
And I follow "7: Topic 7"
|
||||
And I should see "First assignment"
|
||||
|
||||
Scenario: Teacher can configure existing Section links block to display section number or section name
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
When I configure the "Section links" block
|
||||
And I set the following fields to these values:
|
||||
| Display section name | No |
|
||||
And I click on "Save changes" "button"
|
||||
Then I should not see "7: Topic 7" in the "Section links" "block"
|
||||
And I should see "7" in the "Section links" "block"
|
||||
And I follow "7"
|
||||
And I should see "First assignment"
|
6
blocks/section_links/upgrade.txt
Normal file
6
blocks/section_links/upgrade.txt
Normal file
@ -0,0 +1,6 @@
|
||||
This file describes API changes in the section_links block code.
|
||||
|
||||
=== 3.11 ===
|
||||
|
||||
* New optional parameter $showsectionname has been added to render_section_links(). Setting this to true will display
|
||||
section name in addition to section number.
|
@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2021052500; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2021052501; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2021052500; // Requires this Moodle version
|
||||
$plugin->component = 'block_section_links'; // Full name of the plugin (used for diagnostics)
|
||||
|
Loading…
x
Reference in New Issue
Block a user