예제 #1
0
/**
 * @param stdClass $capability the information about a capability.
 * @return array role shortname => object with fields (role) shortname, (role) name,
 *      (role) description and permission (for this capability for that role).
 */
function tool_editrolesbycap_load_role_definitions($capability)
{
    global $DB;
    $data = $DB->get_records_sql('
                SELECT r.id AS roleid,
                       r.shortname,
                       r.name,
                       r.description,
                       r.archetype,
                       rc.permission
                  FROM {role} r
             LEFT JOIN {role_capabilities} rc ON rc.roleid = r.id
                                             AND rc.capability = :capability
                                             AND rc.contextid = :syscontextid
              ORDER BY r.sortorder, r.name', array('capability' => $capability->name, 'syscontextid' => context_system::instance()->id));
    foreach ($data as $role) {
        $role->name = role_get_name($role);
        $role->description = role_get_description($role);
        $role->defaultpermission = tool_editrolesbycap_get_default_permission($role, $capability);
    }
    return $data;
}
예제 #2
0
 protected function get_description_field($id)
 {
     return role_get_description($this->role);
 }
예제 #3
0
$table->colclasses = array('leftalign', 'leftalign', 'leftalign', 'leftalign');
$table->id = 'roles';
$table->attributes['class'] = 'admintable generaltable';
$table->head = array(get_string('role') . ' ' . $OUTPUT->help_icon('roles', 'core_role'), get_string('description'), get_string('roleshortname', 'core_role'), get_string('edit'));
// Get some strings outside the loop.
$stredit = get_string('edit');
$strdelete = get_string('delete');
$strmoveup = get_string('moveup');
$strmovedown = get_string('movedown');
// Print a list of roles with edit/copy/delete/reorder icons.
$table->data = array();
$firstrole = reset($roles);
$lastrole = end($roles);
foreach ($roles as $role) {
    // Basic data.
    $row = array('<a href="' . $defineurl . '?action=view&amp;roleid=' . $role->id . '">' . $role->localname . '</a>', role_get_description($role), s($role->shortname), '');
    // Move up.
    if ($role->sortorder != $firstrole->sortorder) {
        $row[3] .= get_action_icon($baseurl . '?action=moveup&amp;roleid=' . $role->id . '&amp;sesskey=' . sesskey(), 'up', $strmoveup, $strmoveup);
    } else {
        $row[3] .= get_spacer();
    }
    // Move down.
    if ($role->sortorder != $lastrole->sortorder) {
        $row[3] .= get_action_icon($baseurl . '?action=movedown&amp;roleid=' . $role->id . '&amp;sesskey=' . sesskey(), 'down', $strmovedown, $strmovedown);
    } else {
        $row[3] .= get_spacer();
    }
    // Edit.
    $row[3] .= get_action_icon($defineurl . '?action=edit&amp;roleid=' . $role->id, 'edit', $stredit, get_string('editxrole', 'core_role', $role->localname));
    // Delete.