function display_default() { global $CURMAN, $DB, $OUTPUT; //the specific role we are asigning users to $roleid = $this->optional_param('role', '', PARAM_INT); //the specific context id we are assigning roles on $context = $this->get_context(); if ($roleid) { //make sure the current user can assign roles on the current context $assignableroles = get_assignable_roles($context, ROLENAME_BOTH); $roleids = array_keys($assignableroles); if (!in_array($roleid, $roleids)) { print_error('nopermissions', 'error'); } return parent::display_default(); } else { //use the standard link decorator to link role names to their specific sub-pages $decorators = array(new role_name_decorator($this), 'decorate'); //determine all apprlicable roles we can assign users as the current context $assignableroles = get_assignable_roles($context, ROLENAME_BOTH); if (count($assignableroles) > 0) { $roles = array(); foreach ($assignableroles as $roleid => $rolename) { $rec = new stdClass(); $rec->id = $roleid; $rec->name = $rolename; $rec->description = format_string($DB->get_field('role', 'description', array('id' => $roleid))); $rec->count = $this->count_role_users($roleid, $context); $roles[$roleid] = $rec; } $columns = array('name' => array('header' => get_string('name'), 'decorator' => $decorators), 'description' => array('header' => get_string('description')), 'count' => array('header' => get_string('users'))); $table = new nosort_table($roles, $columns, $this->url); echo $table->get_html(); } else { //determine if there are any roles whose assignments are not permitted for the current user //by the "Allow role assignments" tab $admin_assignable_roles = get_assignable_roles($context, ROLENAME_BOTH, false, get_admin()); if (count($admin_assignable_roles) > 0) { //denied based on configuration echo $OUTPUT->box(get_string('norolespermitted', 'local_elisprogram')); } else { //no roles are assignable at this context echo $OUTPUT->box(get_string('norolesexist', 'local_elisprogram')); } } } }