protected function load_groups() {
        global $DB;

        $groupids = [];
        foreach ($this->events as $event) {
            if ($group = $event->get_group()) {
                $id = $group->get('id');
                $groupids[$id] = true;
            }
        }

        if (empty($groupids)) {
            $this->groups = [];
            return;
        }

        list($idsql, $params) = $DB->get_in_or_equal(array_keys($groupids));
        $sql = "SELECT * FROM {groups} WHERE id {$idsql}";

        $this->groups = $DB->get_records_sql($sql, $params);
    }