Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion block_groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 26 additions & 6 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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'
Expand All @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading