$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 {
}
$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();
//--------------------------------------------------------------------------------
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>';
}
}
$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);
+ }
+}
?>
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
}
}
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.'">';