Skip to content

Commit 6a61c20

Browse files
committed
Active tabs in subsection activity context
1 parent 9003868 commit 6a61c20

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

classes/header.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ public function export_for_template(\renderer_base $output) {
122122

123123
// If the tabsectionbackground is not defined in the section check the parent section.
124124
if ($currentsection != $activetab->section) {
125-
$formatoptionssub = course_get_format($course)->get_format_options($currentsection);
125+
$activesubtab = $activetab->get_childs()->get_active();
126+
127+
if ($activesubtab) {
128+
$formatoptionssub = course_get_format($course)->get_format_options($activesubtab->section);
129+
} else {
130+
$formatoptionssub = course_get_format($course)->get_format_options($currentsection);
131+
}
132+
126133
$subtabsectionbackground = $formatoptionssub['tabsectionbackground'] ?? '';
127134

128135
if (!empty($subtabsectionbackground)) {
@@ -243,6 +250,23 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
243250
// Can we view the section in question?
244251
if ((!$thissection->uservisible && $course->hiddensections == 1) || !empty($thissection->component)) {
245252
$localsection++;
253+
254+
if (!empty($thissection->component) && $thissection->section == $displaysection) {
255+
$subsectioncm = \mod_subsection\manager::create_from_id($course->id, $thissection->itemid);
256+
$cm = $subsectioncm->get_coursemodule();
257+
258+
// Find the tab.
259+
$childtab = $tabs->get_childbysection($cm->sectionnum);
260+
if ($childtab) {
261+
$childtab->selected = true;
262+
$childtab->cssstyles = 'color: red;';
263+
264+
if ($childtab->parenttab) {
265+
$childtab->parenttab->selected = true;
266+
}
267+
}
268+
}
269+
246270
continue;
247271
}
248272

@@ -483,11 +507,11 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
483507
$insertposition = $displaysection + 1;
484508

485509
$paramstotabs = [
486-
'courseid' => $course->id,
487-
'increase' => true,
488-
'sesskey' => sesskey(),
489-
'insertsection' => $insertposition,
490-
];
510+
'courseid' => $course->id,
511+
'increase' => true,
512+
'sesskey' => sesskey(),
513+
'insertsection' => $insertposition,
514+
];
491515

492516
// Define if subtabs are displayed (a subtab is selected or the selected tab has subtabs).
493517
$selectedsubtabs = $selectedparent ? $tabs->get_tab($selectedparent->index) : null;

classes/tabs.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public function __construct() {
4949
* To get a specific tab by index.
5050
*
5151
* @param int $index The tabs position or index. Null: if not found the index.
52+
* @return \format_onetopic\singletab|null The tab object.
5253
*/
53-
public function get_tab($index) {
54+
public function get_tab($index): ?singletab {
5455
return isset($this->tabslist[$index]) ? $this->tabslist[$index] : null;
5556
}
5657

@@ -192,6 +193,24 @@ public function get_list(bool $assubtabs = false): array {
192193
return $tabstree;
193194
}
194195

196+
/**
197+
* To get a child tab by section number.
198+
*
199+
* @param int $sectionnumber The section number.
200+
* @return \format_onetopic\singletab|null The tab object.
201+
*/
202+
public function get_childbysection(int $sectionnumber): ?singletab {
203+
foreach ($this->tabslist as $tab) {
204+
if ($tab->section == $sectionnumber) {
205+
return $tab;
206+
} else if ($found = $tab->get_childs()->get_childbysection($sectionnumber)) {
207+
return $found;
208+
}
209+
}
210+
211+
return null;
212+
}
213+
195214
/**
196215
* Check if exist tabs.
197216
*

styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
padding-bottom: 10px;
4242
}
4343

44+
.format-onetopic #page.drawers .onetopic-withsectionbg div[role="main"],
4445
.format-onetopic .onetopic-withsectionbg .course-section,
4546
.format-onetopic .onetopic-withsubsectionbg .course-section {
4647
margin-top: 0;
@@ -49,6 +50,10 @@
4950
border-radius: 5px;
5051
}
5152

53+
.format-onetopic #page.drawers .onetopic-withsectionbg div[role="main"] {
54+
margin: 0 10px;
55+
}
56+
5257
.format-onetopic .onetopic-withsectionbg ul.section .activity-item,
5358
.format-onetopic .onetopic-withsectionbg .content .summarytext {
5459
background-color: transparent;

0 commit comments

Comments
 (0)