Skip to content

Commit

Permalink
Fixed: #161
Browse files Browse the repository at this point in the history
  • Loading branch information
davidherney committed May 9, 2024
1 parent 565786c commit 60d658a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
44 changes: 24 additions & 20 deletions classes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(\format_onetopic $format) {
/**
* Export this data so it can be used as the context for a mustache template (core/inplace_editable).
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output) {
Expand Down Expand Up @@ -164,31 +164,36 @@ public function export_for_template(\renderer_base $output) {
* @return \format_onetopic\tabs an object with tabs information
*/
private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \format_onetopic\tabs {
global $PAGE;
global $section;

if ($section && $section > 0) {
$displaysection = $section;
} else {
$displaysection = $this->format->get_section_number();
}

$course = $this->format->get_course();
$sections = $modinfo->get_section_info_all();
$numsections = count($sections);
$displaysection = $this->format->get_section_number();
$enablecustomstyles = get_config('format_onetopic', 'enablecustomstyles');

// Init custom tabs.
$section = 0;
$localsection = 0;

$tabs = new \format_onetopic\tabs();
$selectedparent = null;
$parenttab = null;
$firstsection = ($course->realcoursedisplay == COURSE_DISPLAY_MULTIPAGE) ? 1 : 0;

while ($section < $numsections) {
while ($localsection < $numsections) {
$inactivetab = false;

if ($course->realcoursedisplay == COURSE_DISPLAY_MULTIPAGE && $section == 0) {
$section++;
if ($course->realcoursedisplay == COURSE_DISPLAY_MULTIPAGE && $localsection == 0) {
$localsection++;
continue;
}

$thissection = $sections[$section];
$thissection = $sections[$localsection];

// Can we view the section in question?
if ($thissection->uservisible || $course->hiddensections != 1) {
Expand Down Expand Up @@ -220,19 +225,19 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
}
}

if (isset($formatoptions['level']) && $section > $firstsection) {
if (isset($formatoptions['level']) && $localsection > $firstsection) {
$level = $formatoptions['level'];
}
}

if ($section == 0) {
if ($localsection == 0) {
$url = new \moodle_url('/course/view.php', ['id' => $course->id, 'section' => 0]);
} else {
$url = course_get_url($course, $section);
$url = course_get_url($course, $localsection);
}

$specialclass = 'tab_position_' . $section . ' tab_level_' . $level;
if ($course->marker == $section) {
$specialclass = 'tab_position_' . $localsection . ' tab_level_' . $level;
if ($course->marker == $localsection) {
$specialclass .= ' marker ';
}

Expand All @@ -247,7 +252,6 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
// Check if display available message is required.
$availablemessage = null;
if ($course->hiddensections == 2) {
$sectiontpl = new content_base\section($this->format, $thissection);
$availabilityclass = $this->format->get_output_classname('content\\section\\availability');
$availability = new $availabilityclass($this->format, $thissection);
$availabledata = $availability->export_for_template($output);
Expand All @@ -257,11 +261,11 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
}
}

$newtab = new \format_onetopic\singletab($section, $sectionname, $url, $title,
$newtab = new \format_onetopic\singletab($localsection, $sectionname, $url, $title,
$availablemessage, $customstyles, $specialclass);
$newtab->active = !$inactivetab;

if ($displaysection == $section) {
if ($displaysection == $localsection) {
$newtab->selected = true;
}

Expand All @@ -282,7 +286,7 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
$parenttab->customstyles,
$specialclasstmp);

$prevsectionindex = $section - 1;
$prevsectionindex = $localsection - 1;
do {
$parentsection = $sections[$prevsectionindex];
$parentformatoptions = course_get_format($course)->get_format_options($parentsection);
Expand All @@ -309,7 +313,7 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
// Load subtabs.
$parenttab->add_child($newtab);

if ($displaysection == $section) {
if ($displaysection == $localsection) {
$selectedparent = $parenttab;
$parenttab->selected = true;
}
Expand All @@ -321,7 +325,7 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for

}

$section++;
$localsection++;
}

if ($this->format->show_editor()) {
Expand All @@ -346,7 +350,7 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
$selectedsubtabs = $selectedparent ? $tabs->get_tab($selectedparent->index) : null;
$showsubtabs = $selectedsubtabs && $selectedsubtabs->has_childs();

if ($showsubtabs) {
if ($showsubtabs && $selectedparent) {
// Increase number of sections in child tabs.
$paramstotabs['aschild'] = 1;
$url = new \moodle_url('/course/format/onetopic/changenumsections.php', $paramstotabs);
Expand Down
2 changes: 0 additions & 2 deletions format.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@

$renderer = $PAGE->get_renderer('format_onetopic');

$section = $displaysection;

$disableajax = optional_param('onetopic_da', -1, PARAM_INT);

if (!isset($USER->onetopic_da)) {
Expand Down
6 changes: 5 additions & 1 deletion styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@

foreach ($orderedtabs as $type => $styles) {

$important = false;
switch ($type) {
case 'active':
$csscontent .= '#tabs-tree-start .verticaltabs .format_onetopic-tabs .nav-item a.nav-link.active, ';
$csscontent .= '#tabs-tree-start .nav-tabs a.nav-link.active, ';
$csscontent .= '#tabs-tree-start .onetopic-tab-body .nav-tabs a.nav-link.active, ';
$csscontent .= '#tabs-tree-start .onetopic-tab-body .nav-tabs .nav-item.subtopic a.nav-link.active';
$important = true;
break;
case 'parent':
$csscontent .= '#tabs-tree-start .verticaltabs .format_onetopic-tabs .nav-item.haschilds a.nav-link, ';
Expand All @@ -65,12 +67,14 @@
$csscontent .= '#tabs-tree-start .nav-tabs .nav-item.marker a.nav-link, ';
$csscontent .= '#tabs-tree-start .onetopic-tab-body .nav-tabs .nav-item.marker a.nav-link';
$csscontent .= '#tabs-tree-start .onetopic-tab-body .nav-tabs .nav-item.subtopic.marker a.nav-link';
$important = true;
break;
case 'disabled':
$csscontent .= '#tabs-tree-start .verticaltabs .format_onetopic-tabs .nav-item.disabled a.nav-link, ';
$csscontent .= '#tabs-tree-start .nav-tabs .nav-item.disabled a.nav-link, ';
$csscontent .= '#tabs-tree-start .onetopic-tab-body .nav-tabs .nav-item.disabled a.nav-link';
$csscontent .= '#tabs-tree-start .onetopic-tab-body .nav-tabs .nav-item.subtopic.disabled a.nav-link';
$important = true;
break;
case 'hover':
$csscontent .= '#tabs-tree-start .verticaltabs .format_onetopic-tabs .nav-item a.nav-link:hover, ';
Expand Down Expand Up @@ -119,7 +123,7 @@
if ($key == 'others') {
$csscontent .= $value . ';';
} else {
$csscontent .= $key . ':' . $value . ';';
$csscontent .= $key . ':' . $value . ($important ? '!important' : '') . ';';
}
}

Expand Down

0 comments on commit 60d658a

Please sign in to comment.