diff --git a/block_groups.php b/block_groups.php index f09b046..5b4476b 100644 --- a/block_groups.php +++ b/block_groups.php @@ -187,12 +187,38 @@ public function build_grouping_array($allgroupings, $courseid) { $countgroupingmember = $arrayofmembers[$value->id]->number; } - $groupingsarray[$g] = $renderer->get_grouping($value, $countgroupingmember); + $groupnames = $this->get_groups_for_grouping($value->id, $courseid); + + $groupingsarray[$g] = $renderer->get_grouping($value, $countgroupingmember, $groupnames); } } return $groupingsarray; } + /** + * Returns the names of all groups belonging to a grouping. + * + * @param integer $groupingid + * @param integer $courseid + * @return array + * @throws dml_exception + */ + private function get_groups_for_grouping($groupingid, $courseid) { + global $DB; + + $sql = "SELECT g.id, g.name + FROM {groups} g + JOIN {groupings_groups} gg ON gg.groupid = g.id + WHERE gg.groupingid = :groupingid + AND g.courseid = :courseid + ORDER BY g.name ASC"; + + return $DB->get_records_sql($sql, [ + 'groupingid' => $groupingid, + 'courseid' => $courseid, + ]); + } + /** * Tells moodle, that the groups block has a settings file. * @return bool true diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 11563d2..f99e0ba 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -41,9 +41,14 @@ public function teaching_groups_or_groupings_list($elementarray, $group) { } else { $type = 'grouping'; } - $contentgroups = html_writer::tag('input', '', ['type' => "checkbox", 'value' => "1", - 'class' => "blockgroupsandgroupingcheckbox", 'id' => 'checkbox' . $type]) . - html_writer::tag('label', get_string($type, 'block_groups'), ['for' => "checkbox" . $type]); + $labeltext = get_string($type, 'block_groups') . ' (' . count($elementarray) . ')'; + $contentgroups = html_writer::tag('input', '', [ + 'type' => "checkbox", + 'value' => "1", + 'class' => "blockgroupsandgroupingcheckbox", + 'id' => 'checkbox' . $type, + ]) . + html_writer::tag('label', $labeltext, ['for' => "checkbox" . $type]); $contentgroups .= html_writer::alist($elementarray, ['class' => 'wrapperlist' . $type]); return html_writer::tag('div', $contentgroups, ['class' => 'wrapperblockgroupsandgroupingcheckbox']); } @@ -90,13 +95,17 @@ public function get_string_group($value, $href, $countmembers, $visibility) { 'data-action' => $action]); return html_writer::span($line, 'group-' . $value->id); } + /** * Generates string for a grouping list item + * * @param stdClass $grouping * @param integer $counter - * @return string html-string + * @param array $groups + * @return string + * @throws \coding_exception */ - public function get_grouping($grouping, $counter) { + public function get_grouping($grouping, $counter, $groups = []) { $line = html_writer::span( $grouping->name . ' ' . get_string('brackets', 'block_groups', $counter), 'wrapperblockgroupsgrouping' @@ -105,7 +114,18 @@ public function get_grouping($grouping, $counter) { $showlink = $this->create_grouping_link('show', $grouping->id, false); $hidelink = $this->create_grouping_link('hide', $grouping->id, false); - return html_writer::span($line . $showlink . $hidelink, 'grouping-' . $grouping->id); + if (!empty($groups)) { + $groupitems = []; + + foreach ($groups as $group) { + $groupitems[] = s($group->name); + } + $groupslist = html_writer::alist($groupitems, [ + 'class' => 'wrapperlistgroupinggroups', + ]); + } + + return html_writer::span($line . $showlink . $hidelink . $groupslist, 'grouping-' . $grouping->id); } /** * Renders line to change all groups. diff --git a/styles.css b/styles.css index 13b7653..ea17e8b 100644 --- a/styles.css +++ b/styles.css @@ -48,3 +48,29 @@ .block_groups .block-groups-spinner { padding-right: 6px; } + +.block_groups input.blockgroupsandgroupingcheckbox { + cursor: pointer; + display: none; + text-align: left; +} + +.block_groups input.blockgroupsandgroupingcheckbox ~ label { + cursor: pointer; +} + +.block_groups input.blockgroupsandgroupingcheckbox ~ label::before { + content: "▸"; + display: inline-block; + width: 0.8em; + margin-right: 0.2rem; + font-size: 1.5em; +} + +.block_groups input.blockgroupsandgroupingcheckbox:checked ~ label::before { + content: "▾"; +} + +.block_groups .wrapperlistgroupinggroups { + opacity: 0.85; +} \ No newline at end of file