Merge branch 'wip-MDL-57769-master' of https://github.com/marinaglancy/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-04-05 01:31:08 +02:00
commit aa2b5b214d
43 changed files with 1365 additions and 388 deletions

View file

@ -81,35 +81,26 @@ class block_section_links extends block_base {
$course = $this->page->course;
$courseformat = course_get_format($course);
$courseformatoptions = $courseformat->get_format_options();
$numsections = $courseformat->get_last_section_number();
$context = context_course::instance($course->id);
// Course format options 'numsections' is required to display the block.
if (empty($courseformatoptions['numsections'])) {
if (empty($numsections)) {
return $this->content;
}
// Prepare the highlight value.
if ($course->format == 'weeks') {
$highlight = ceil((time() - $course->startdate) / 604800);
} else if ($course->format == 'topics') {
$highlight = $course->marker;
} else {
$highlight = 0;
}
// Prepare the increment value.
if (!empty($config->numsections1) and ($courseformatoptions['numsections'] > $config->numsections1)) {
if (!empty($config->numsections1) and ($numsections > $config->numsections1)) {
$inc = $config->incby1;
} else if ($courseformatoptions['numsections'] > 22) {
} else if ($numsections > 22) {
$inc = 2;
} else {
$inc = 1;
}
if (!empty($config->numsections2) and ($courseformatoptions['numsections'] > $config->numsections2)) {
if (!empty($config->numsections2) and ($numsections > $config->numsections2)) {
$inc = $config->incby2;
} else {
if ($courseformatoptions['numsections'] > 40) {
if ($numsections > 40) {
$inc = 5;
}
}
@ -119,8 +110,9 @@ class block_section_links extends block_base {
$canviewhidden = has_capability('moodle/course:update', $context);
$coursesections = $courseformat->get_sections();
$coursesectionscount = count($coursesections);
$sectiontojumpto = false;
for ($i = $inc; $i <= $coursesectionscount; $i += $inc) {
if ($i > $courseformatoptions['numsections'] || !isset($coursesections[$i])) {
if ($i > $numsections || !isset($coursesections[$i])) {
continue;
}
$section = $coursesections[$i];
@ -128,16 +120,16 @@ class block_section_links extends block_base {
$sections[$i] = (object)array(
'section' => $section->section,
'visible' => $section->visible,
'highlight' => ($section->section == $highlight)
'highlight' => false
);
if ($courseformat->is_section_current($section)) {
$sections[$i]->highlight = true;
$sectiontojumpto = $section->section;
}
}
}
if (!empty($sections)) {
$sectiontojumpto = false;
if ($highlight && isset($sections[$highlight]) && ($sections[$highlight]->visible || $canviewhidden)) {
$sectiontojumpto = $highlight;
}
// Render the sections.
$renderer = $this->page->get_renderer('block_section_links');
$this->content->text = $renderer->render_section_links($this->page->course, $sections, $sectiontojumpto);

View file

@ -6,8 +6,8 @@ Feature: The section links block allows users to quickly navigate around a moodl
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| fullname | shortname | category | numsections | coursedisplay |
| Course 1 | C1 | 0 | 20 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
@ -20,11 +20,6 @@ Feature: The section links block allows users to quickly navigate around a moodl
| Assignment name | Test assignment 1 |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
And I navigate to "Edit settings" node in "Course administration"
And I set the following fields to these values:
| id_numsections | 20 |
| id_coursedisplay | Show one section per page |
And I press "Save and display"
Scenario: Add the section links block to a course.
Given I add the "Section links" block