Skip to content

Commit

Permalink
MDL-69773 block_section_links: Add an option to display section name
Browse files Browse the repository at this point in the history
  • Loading branch information
golenkovm committed Nov 24, 2020
1 parent c8d33eb commit 53663f2
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 4 deletions.
9 changes: 8 additions & 1 deletion blocks/section_links/block_section_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public function get_content() {
}
}

// 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);
Expand All @@ -126,13 +129,17 @@ public function get_content() {
$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;
Expand Down
3 changes: 3 additions & 0 deletions blocks/section_links/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@ protected function specific_definition($mform) {
$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');
}
}
2 changes: 2 additions & 0 deletions blocks/section_links/lang/en/block_section_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
$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.';
9 changes: 7 additions & 2 deletions blocks/section_links/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ 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) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::start_tag('li');
$sectiontext = $section->section;
if ($showsectionname) {
$sectiontext .= ': ' . $section->name;
}
if ($section->highlight) {
$sectiontext = html_writer::tag('strong', $sectiontext);
}
Expand Down
5 changes: 5 additions & 0 deletions blocks/section_links/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@
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 changes: 43 additions & 0 deletions blocks/section_links/tests/behat/show_section_name.feature
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions blocks/section_links/upgrade.txt
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion blocks/section_links/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 53663f2

Please sign in to comment.