fix for MDL-8966, customizable role names

This commit is contained in:
toyomoyo 2007-03-22 08:11:30 +00:00
parent cddbd5d5fe
commit 0150c561c5
5 changed files with 65 additions and 3 deletions

View File

@ -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 {

View File

@ -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();
//--------------------------------------------------------------------------------

View File

@ -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.'&amp;course='.SITEID.'">'.$fullname.'</a>';
}
}

View File

@ -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);
}
}
?>

View File

@ -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.'&amp;contextid='.$context->id.'">';