public function get_other_users_for_display(core_enrol_renderer $renderer, moodle_url $pageurl, $sort, $direction, $page, $perpage) {

        $userroles = $this->get_other_users($sort, $direction, $page, $perpage);
        $roles = $this->get_all_roles();
        $plugins = $this->get_enrolment_plugins(false);

        $context    = $this->get_context();
        $now = time();
        $extrafields = get_extra_user_fields($context);

        $users = array();
        foreach ($userroles as $userrole) {
            $contextid = $userrole->contextid;
            unset($userrole->contextid); // This would collide with user avatar.
            if (!array_key_exists($userrole->id, $users)) {
                $users[$userrole->id] = $this->prepare_user_for_display($userrole, $extrafields, $now);
            }
            $a = new stdClass;
            $a->role = $roles[$userrole->roleid]->localname;
            if ($contextid == $this->context->id) {
                $changeable = true;
                if ($userrole->component) {
                    $changeable = false;
                    if (strpos($userrole->component, 'enrol_') === 0) {
                        $plugin = substr($userrole->component, 6);
                        if (isset($plugins[$plugin])) {
                            $changeable = !$plugins[$plugin]->roles_protected();
                        }
                    }
                }
                $roletext = get_string('rolefromthiscourse', 'enrol', $a);
            } else {
                $changeable = false;
                switch ($userrole->contextlevel) {
                    case CONTEXT_COURSE :
                        // Meta course
                        $roletext = get_string('rolefrommetacourse', 'enrol', $a);
                        break;
                    case CONTEXT_COURSECAT :
                        $roletext = get_string('rolefromcategory', 'enrol', $a);
                        break;
                    case CONTEXT_SYSTEM:
                    default:
                        $roletext = get_string('rolefromsystem', 'enrol', $a);
                        break;
                }
            }
            if (!isset($users[$userrole->id]['roles'])) {
                $users[$userrole->id]['roles'] = array();
            }
            $users[$userrole->id]['roles'][$userrole->roleid] = array(
                'text' => $roletext,
                'unchangeable' => !$changeable
            );
        }
        return $users;
    }