Skip to content

Commit

Permalink
Merge branch 'MDL-59663-33' of git://github.com/junpataleta/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_33_STABLE
  • Loading branch information
stronk7 committed Aug 22, 2017
2 parents a35a27e + b24ffdb commit f434892
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions course/renderer.php
Expand Up @@ -49,6 +49,14 @@ class core_course_renderer extends plugin_renderer_base {
*/
protected $strings;

/**
* Whether a category content is being initially rendered with children. This is mainly used by the
* core_course_renderer::corsecat_tree() to render the appropriate action for the Expand/Collapse all link on
* page load.
* @var bool
*/
protected $categoryexpandedonload = false;

/**
* Override the constructor so that we can initialise the string cache
*
Expand Down Expand Up @@ -1511,6 +1519,8 @@ protected function coursecat_category(coursecat_helper $chelper, $coursecat, $de
$classes[] = 'loaded';
if (!empty($categorycontent)) {
$classes[] = 'with_children';
// Category content loaded with children.
$this->categoryexpandedonload = true;
}
}

Expand Down Expand Up @@ -1557,6 +1567,8 @@ protected function coursecat_category(coursecat_helper $chelper, $coursecat, $de
* @return string
*/
protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
// Reset the category expanded flag for this course category tree first.
$this->categoryexpandedonload = false;
$categorycontent = $this->coursecat_category_content($chelper, $coursecat, 0);
if (empty($categorycontent)) {
return '';
Expand All @@ -1572,10 +1584,17 @@ protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
'collapseexpand',
);

// Check if the category content contains subcategories with children's content loaded.
if ($this->categoryexpandedonload) {
$classes[] = 'collapse-all';
$linkname = get_string('collapseall');
} else {
$linkname = get_string('expandall');
}

// Only show the collapse/expand if there are children to expand.
$content .= html_writer::start_tag('div', array('class' => 'collapsible-actions'));
$content .= html_writer::link('#', get_string('expandall'),
array('class' => implode(' ', $classes)));
$content .= html_writer::link('#', $linkname, array('class' => implode(' ', $classes)));
$content .= html_writer::end_tag('div');
$this->page->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle');
}
Expand Down

0 comments on commit f434892

Please sign in to comment.