mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
fix for MDL-8966, customizable role names
This commit is contained in:
parent
cddbd5d5fe
commit
0150c561c5
@ -218,6 +218,41 @@ function update_course($data) {
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
||||
blocks_remove_inappropriate($page);
|
||||
|
||||
// put custom role names into db
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
foreach ($data as $dname => $dvalue) {
|
||||
|
||||
// is this the right param?
|
||||
$dvalue = clean_param($dvalue, PARAM_NOTAGS);
|
||||
|
||||
if (!strstr($dname, 'role_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$dt = explode('_', $dname);
|
||||
$roleid = $dt[1];
|
||||
// make up our mind whether we want to delete, update or insert
|
||||
|
||||
if (empty($dvalue)) {
|
||||
|
||||
delete_records('role_names', 'contextid', $context->id, 'roleid', $roleid);
|
||||
|
||||
} else if ($t = get_record('role_names', 'contextid', $context->id, 'roleid', $roleid)) {
|
||||
|
||||
$t->text = $dvalue;
|
||||
update_record('role_names', $t);
|
||||
|
||||
} else {
|
||||
|
||||
$t->contextid = $context->id;
|
||||
$t->roleid = $roleid;
|
||||
$t->text = $dvalue;
|
||||
insert_record('role_names', $t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
redirect($CFG->wwwroot."/course/view.php?id=$course->id");
|
||||
|
||||
} else {
|
||||
|
@ -336,6 +336,21 @@ class course_edit_form extends moodleform {
|
||||
}
|
||||
$mform->setType('restrictmodules', PARAM_INT);
|
||||
|
||||
/// customizable role names in this course
|
||||
//--------------------------------------------------------------------------------
|
||||
$mform->addElement('header','', get_string('roles'));
|
||||
|
||||
if ($roles = get_records('role')) {
|
||||
foreach ($roles as $role) {
|
||||
$mform->addElement('text', 'role_'.$role->id, $role->name);
|
||||
if ($coursecontext) {
|
||||
if ($rolename = get_record('role_names', 'roleid', $role->id, 'contextid', $coursecontext->id)) {
|
||||
$mform->setDefault('role_'.$role->id, $rolename->text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
$this->add_action_buttons();
|
||||
//--------------------------------------------------------------------------------
|
||||
|
@ -1801,7 +1801,7 @@ function print_course($course) {
|
||||
if ($users = get_role_users($roleid, $context, true, '', 'u.lastname ASC', true)) {
|
||||
foreach ($users as $teacher) {
|
||||
$fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
|
||||
$namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
|
||||
$namesarray[] = role_get_name($role, $context).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
|
||||
$teacher->id.'&course='.SITEID.'">'.$fullname.'</a>';
|
||||
}
|
||||
}
|
||||
|
@ -3881,4 +3881,16 @@ function build_context_rel() {
|
||||
|
||||
$db->debug = $savedb;
|
||||
}
|
||||
|
||||
|
||||
// gets the custom name of the role in course
|
||||
// TODO: proper documentation
|
||||
function role_get_name($role, $context) {
|
||||
|
||||
if ($r = get_record('role_names','roleid', $role->id,'contextid', $context->id)) {
|
||||
return format_string($r->text);
|
||||
} else {
|
||||
return format_string($role->name);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -61,7 +61,7 @@
|
||||
unset($roles[$role->id]);
|
||||
continue;
|
||||
}
|
||||
$rolenames[$role->id] = strip_tags(format_string($role->name)); // Used in menus etc later on
|
||||
$rolenames[$role->id] = strip_tags(role_get_name($role, $context)); // Used in menus etc later on
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,7 +402,7 @@
|
||||
error('That role does not exist');
|
||||
}
|
||||
$a->number = $totalcount;
|
||||
$a->role = $currentrole->name;
|
||||
$a->role = role_get_name($currentrole, $context);
|
||||
$heading = get_string('xuserswiththerole', 'role', $a);
|
||||
if (user_can_assign($context, $roleid)) {
|
||||
$heading .= ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?roleid='.$roleid.'&contextid='.$context->id.'">';
|
||||
|
Loading…
x
Reference in New Issue
Block a user