Merge branch 'w28_MDL-8249_m24_roletranslations' of git://github.com/skodak/moodle

Conflicts:
	lib/db/upgrade.php
	version.php
This commit is contained in:
Dan Poltawski 2012-07-10 09:43:23 +08:00
commit e1980f8bb9
37 changed files with 631 additions and 422 deletions

View file

@ -256,19 +256,14 @@ class permissions_table extends capability_table_base {
* @param string $contextname print_context_name($context) - to save recomputing.
*/
public function __construct($context, $contextname, $allowoverrides, $allowsafeoverrides, $overridableroles) {
global $DB;
parent::__construct($context, 'permissions');
$this->contextname = $contextname;
$this->allowoverrides = $allowoverrides;
$this->allowsafeoverrides = $allowsafeoverrides;
$this->overridableroles = $overridableroles;
$roles = $DB->get_records('role', null, 'sortorder DESC');
foreach ($roles as $roleid=>$role) {
$roles[$roleid] = $role->name;
}
$this->roles = role_fix_names($roles, $context);
$roles = get_all_roles($context);
$this->roles = role_fix_names(array_reverse($roles, true), $context, ROLENAME_ALIAS, true);
}
@ -593,18 +588,6 @@ class define_role_table_advanced extends capability_table_with_risks {
global $DB;
$this->errors = array();
// Role name.
$name = optional_param('name', null, PARAM_MULTILANG);
if (!is_null($name)) {
$this->role->name = $name;
if (html_is_blank($this->role->name)) {
$this->errors['name'] = get_string('errorbadrolename', 'role');
}
}
if ($DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) {
$this->errors['name'] = get_string('errorexistsrolename', 'role');
}
// Role short name. We clean this in a special way. We want to end up
// with only lowercase safe ASCII characters.
$shortname = optional_param('shortname', null, PARAM_RAW);
@ -620,6 +603,20 @@ class define_role_table_advanced extends capability_table_with_risks {
$this->errors['shortname'] = get_string('errorexistsroleshortname', 'role');
}
// Role name.
$name = optional_param('name', null, PARAM_MULTILANG);
if (!is_null($name)) {
$this->role->name = $name;
// Hack: short names of standard roles are equal to archetypes, empty name means localised via lang packs.
$archetypes = get_role_archetypes();
if (!isset($archetypes[$shortname]) and html_is_blank($this->role->name)) {
$this->errors['name'] = get_string('errorbadrolename', 'role');
}
}
if ($this->role->name !== '' and $DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) {
$this->errors['name'] = get_string('errorexistsrolename', 'role');
}
// Description.
$description = optional_param('description', null, PARAM_RAW);
if (!is_null($description)) {
@ -779,9 +776,9 @@ class define_role_table_advanced extends capability_table_with_risks {
global $OUTPUT;
// Extra fields at the top of the page.
echo '<div class="topfields clearfix">';
$this->print_field('name', get_string('rolefullname', 'role'), $this->get_name_field('name'));
$this->print_field('shortname', get_string('roleshortname', 'role'), $this->get_shortname_field('shortname'));
$this->print_field('edit-description', get_string('description'), $this->get_description_field('description'));
$this->print_field('shortname', get_string('roleshortname', 'role').'&nbsp;'.$OUTPUT->help_icon('roleshortname', 'role'), $this->get_shortname_field('shortname'));
$this->print_field('name', get_string('customrolename', 'role').'&nbsp;'.$OUTPUT->help_icon('customrolename', 'role'), $this->get_name_field('name'));
$this->print_field('edit-description', get_string('customroledescription', 'role').'&nbsp;'.$OUTPUT->help_icon('customroledescription', 'role'), $this->get_description_field('description'));
$this->print_field('menuarchetype', get_string('archetype', 'role').'&nbsp;'.$OUTPUT->help_icon('archetype', 'role'), $this->get_archetype_field('archetype'));
$this->print_field('', get_string('maybeassignedin', 'role'), $this->get_assignable_levels_control());
echo "</div>";
@ -862,7 +859,7 @@ class view_role_definition_table extends define_role_table_advanced {
}
protected function get_name_field($id) {
return strip_tags(format_string($this->role->name));
return role_get_name($this->role);
}
protected function get_shortname_field($id) {
@ -870,7 +867,7 @@ class view_role_definition_table extends define_role_table_advanced {
}
protected function get_description_field($id) {
return format_text($this->role->description, FORMAT_HTML);
return role_get_description($this->role);
}
protected function get_archetype_field($id) {
@ -1273,8 +1270,7 @@ abstract class role_allow_role_page {
*/
protected function load_required_roles() {
/// Get all roles
$this->roles = get_all_roles();
role_fix_names($this->roles, get_context_instance(CONTEXT_SYSTEM), ROLENAME_ORIGINAL);
$this->roles = role_fix_names(get_all_roles(), get_context_instance(CONTEXT_SYSTEM), ROLENAME_ORIGINAL);
}
/**

View file

@ -53,8 +53,7 @@
admin_externalpage_setup('defineroles');
/// Get some basic data we are going to need.
$roles = get_all_roles();
role_fix_names($roles, $systemcontext, ROLENAME_ORIGINAL);
$roles = role_fix_names(get_all_roles(), $systemcontext, ROLENAME_ORIGINAL);
$undeletableroles = array();
$undeletableroles[$CFG->notloggedinroleid] = 1;
@ -214,7 +213,7 @@
/// Basic data.
$row = array(
'<a href="' . $defineurl . '?action=view&amp;roleid=' . $role->id . '">' . $role->localname . '</a>',
format_text($role->description, FORMAT_HTML),
role_get_description($role),
s($role->shortname),
'',
);

View file

@ -68,14 +68,11 @@ if ($course->id != $SITE->id || $userid != $USER->id) {
/// Now get the role assignments for this user.
$sql = "SELECT
ra.id, ra.userid, ra.contextid, ra.roleid, ra.component, ra.itemid,
c.path,
r.name AS rolename,
COALESCE(rn.name, r.name) AS localname
c.path
FROM
{role_assignments} ra
JOIN {context} c ON ra.contextid = c.id
JOIN {role} r ON ra.roleid = r.id
LEFT JOIN {role_names} rn ON rn.roleid = ra.roleid AND rn.contextid = ra.contextid
WHERE
ra.userid = ?
"./*AND ra.active = 1*/"
@ -83,6 +80,8 @@ $sql = "SELECT
contextlevel DESC, contextid ASC, r.sortorder ASC";
$roleassignments = $DB->get_records_sql($sql, array($user->id));
$allroles = role_fix_names(get_all_roles());
/// In order to display a nice tree of contexts, we need to get all the
/// ancestors of all the contexts in the query we just did.
$requiredcontexts = array();
@ -142,14 +141,14 @@ echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
if (!$roleassignments) {
echo '<p>', get_string('noroleassignments', 'role'), '</p>';
} else {
print_report_tree($systemcontext->id, $contexts, $systemcontext, $fullname);
print_report_tree($systemcontext->id, $contexts, $systemcontext, $fullname, $allroles);
}
/// End of page.
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
function print_report_tree($contextid, $contexts, $systemcontext, $fullname) {
function print_report_tree($contextid, $contexts, $systemcontext, $fullname, $allroles) {
global $CFG, $OUTPUT;
// Only compute lang strings, etc once.
@ -170,15 +169,13 @@ function print_report_tree($contextid, $contexts, $systemcontext, $fullname) {
// If there are any role assignments here, print them.
foreach ($contexts[$contextid]->roleassignments as $ra) {
$role = $allroles[$ra->roleid];
$value = $ra->contextid . ',' . $ra->roleid;
$inputid = 'unassign' . $value;
echo '<p>';
if ($ra->rolename == $ra->localname) {
echo strip_tags(format_string($ra->localname));
} else {
echo strip_tags(format_string($ra->localname . ' (' . $ra->rolename . ')'));
}
echo $role->localname;
if (has_capability('moodle/role:assign', $context)) {
$raurl = $assignurl . '?contextid=' . $ra->contextid . '&amp;roleid=' .
$ra->roleid . '&amp;removeselect[]=' . $ra->userid;
@ -210,7 +207,7 @@ function print_report_tree($contextid, $contexts, $systemcontext, $fullname) {
echo '<ul>';
foreach ($contexts[$contextid]->children as $childcontextid) {
echo '<li>';
print_report_tree($childcontextid, $contexts, $systemcontext, $fullname);
print_report_tree($childcontextid, $contexts, $systemcontext, $fullname, $allroles);
echo '</li>';
}
echo '</ul>';

View file

@ -54,9 +54,10 @@ if (!during_initial_install()) { //do not use during installation
// front page default role
$options = array(0=>new lang_string('none')); // roles to choose from
$defaultfrontpageroleid = 0;
foreach (get_all_roles() as $role) {
$roles = role_fix_names(get_all_roles(), null, ROLENAME_ORIGINALANDSHORT);
foreach ($roles as $role) {
if (empty($role->archetype) or $role->archetype === 'guest' or $role->archetype === 'frontpage' or $role->archetype === 'student') {
$options[$role->id] = strip_tags(format_string($role->name)) . ' ('. $role->shortname . ')';
$options[$role->id] = $role->localname;
if ($role->archetype === 'frontpage') {
$defaultfrontpageroleid = $role->id;
}

View file

@ -45,8 +45,9 @@ if ($hassiteconfig
$defaultuserid = null;
$defaultguestid = null;
foreach (get_all_roles() as $role) {
$rolename = strip_tags(format_string($role->name)) . ' ('. $role->shortname . ')';
$roles = role_fix_names(get_all_roles(), null, ROLENAME_ORIGINALANDSHORT);
foreach ($roles as $role) {
$rolename = $role->localname;
switch ($role->archetype) {
case 'manager':
$creatornewroles[$role->id] = $rolename;

View file

@ -38,7 +38,7 @@ $roleids = optional_param_array('roles', array('0'), PARAM_INTEGER);
// Clean the passed in list of role ids. If 'All' selected as an option, or
// if none were selected, do all roles.
$allroles = get_all_roles();
$allroles = role_fix_names(get_all_roles());
$cleanedroleids = array();
foreach ($roleids as $roleid) {
if ($roleid == 0) {
@ -73,7 +73,7 @@ foreach ($allcapabilities as $cap) {
// Prepare the list of roles to choose from
$rolechoices = array('0' => get_string('all'));
foreach ($allroles as $role) {
$rolechoices[$role->id] = $role->name;
$rolechoices[$role->id] = $role->localname;
}
if (count($cleanedroleids) == count($allroles)) {
// Select 'All', rather than each role individually.
@ -162,7 +162,7 @@ if ($capability) {
if (count($cleanedroleids) != count($allroles)) {
$rolenames = array();
foreach ($cleanedroleids as $roleid) {
$rolenames[] = $allroles[$roleid]->name;
$rolenames[] = $allroles[$roleid]->localname;
}
echo '<p>', get_string('forroles', 'tool_capability', implode(', ', $rolenames)), '</p>';
}
@ -207,7 +207,7 @@ function print_report_tree($contextid, $contexts, $allroles) {
foreach ($allroles as $role) {
if (isset($contexts[$contextid]->rolecapabilities[$role->id])) {
$permission = $contexts[$contextid]->rolecapabilities[$role->id];
echo '<tr class="r' . ($rowcounter % 2) . '"><th class="cell">', $role->name,
echo '<tr class="r' . ($rowcounter % 2) . '"><th class="cell">', $role->localname,
'</th><td class="cell">' . $strpermissions[$permission] . '</td></tr>';
$rowcounter++;
}

View file

@ -97,7 +97,7 @@ if (!$problems) {
$data = array();
foreach ($problems as $problem) {
$levelname = get_contextlevel_name($problem->contextlevel);
$rolename = format_string($roles[$problem->roleid]->name);
$rolename = role_get_name($roles[$problem->roleid]);
//TODO: show list of users if count low
$count = $problem->racount;
$edit = array();