public function user_groups_and_actions($userid, $groups, $allgroups, $canmanagegroups, $pageurl) {
        $groupicon = $this->output->pix_icon('i/group', get_string('addgroup', 'group'));

        $groupoutput = '';
        foreach($groups as $groupid=>$name) {
            if ($canmanagegroups and groups_remove_member_allowed($groupid, $userid)) {
                $icon = $this->output->pix_icon('t/delete', get_string('removefromgroup', 'group', $name));
                $url = new moodle_url($pageurl, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid));
                $groupoutput .= html_writer::tag('div', $name . html_writer::link($url, $icon), array('class'=>'group', 'rel'=>$groupid));
            } else {
                $groupoutput .= html_writer::tag('div', $name, array('class'=>'group', 'rel'=>$groupid));
            }
        }
        $output = '';
        if ($canmanagegroups && (count($groups) < count($allgroups))) {
            $url = new moodle_url($pageurl, array('action'=>'addmember', 'user'=>$userid));
            $output .= html_writer::tag('div', html_writer::link($url, $groupicon), array('class'=>'addgroup'));
        }
        $output = $output.html_writer::tag('div', $groupoutput, array('class'=>'groups'));
        return $output;
    }