From: skodak Date: Sat, 23 Sep 2006 12:51:00 +0000 (+0000) Subject: role sortorder column now has unique index; new function get_all_roles() that returns... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ece4945bd26f22da6c1c33719c7e536adc9dd443;p=moodle.git role sortorder column now has unique index; new function get_all_roles() that returns all roles with correct sort --- diff --git a/admin/roles/allowassign.php b/admin/roles/allowassign.php index a2c046c286..61626faa94 100755 --- a/admin/roles/allowassign.php +++ b/admin/roles/allowassign.php @@ -22,7 +22,7 @@ /// get all roles - $roles = get_records('role'); + $roles = get_all_roles(); if ($grant = data_submitted()) { diff --git a/admin/roles/allowoverride.php b/admin/roles/allowoverride.php index b76f48e24c..3db7cb9ccc 100755 --- a/admin/roles/allowoverride.php +++ b/admin/roles/allowoverride.php @@ -20,7 +20,7 @@ /// get all roles - $roles = get_records('role'); + $roles = get_all_roles(); if ($grant = data_submitted()) { diff --git a/admin/roles/manage.php b/admin/roles/manage.php index 9e017cd003..a1a4f0a3ad 100755 --- a/admin/roles/manage.php +++ b/admin/roles/manage.php @@ -24,7 +24,7 @@ $errors = array(); $newrole = false; - $roles = get_records('role', '', '', 'sortorder ASC, id ASC'); + $roles = get_all_roles(); $rolescount = count($roles); /// fix sort order if needed @@ -211,31 +211,9 @@ $role = $roles[$roleid]; if ($role->sortorder > 0) { $above = $roles[$rolesort[$role->sortorder - 1]]; - $r = new object(); - $r->id = $role->id; - $r->sortorder = $above->sortorder; - if (!update_record('role', $r)) { - $errors[] = "Can not update role with ID $r->id!"; - } - - $r->id = $above->id; - $r->sortorder = $role->sortorder; - if (!update_record('role', $r)) { - $errors[] = "Can not update role with ID $r->id!"; - } - - if (count($errors)) { - $msg = '

'; - foreach ($errors as $e) { - $msg .= $e.'
'; - } - $msg .= '

'; - admin_externalpage_print_header($adminroot); - notify($msg); - print_continue('manage.php'); - admin_externalpage_print_footer($adminroot); - die; + if (!switch_roles($role, $above)) { + error("Cannot move role with ID $roleid"); } } } @@ -248,31 +226,9 @@ $role = $roles[$roleid]; if ($role->sortorder + 1 < $rolescount) { $bellow = $roles[$rolesort[$role->sortorder + 1]]; - $r = new object(); - - $r->id = $role->id; - $r->sortorder = $bellow->sortorder; - if (!update_record('role', $r)) { - $errors[] = "Can not update role with ID $r->id!"; - } - - $r->id = $bellow->id; - $r->sortorder = $role->sortorder; - if (!update_record('role', $r)) { - $errors[] = "Can not update role with ID $r->id!"; - } - if (count($errors)) { - $msg = '

'; - foreach ($errors as $e) { - $msg .= $e.'
'; - } - $msg .= '

'; - admin_externalpage_print_header($adminroot); - notify($msg); - print_continue('manage.php'); - admin_externalpage_print_footer($adminroot); - die; + if (!switch_roles($role, $bellow)) { + error("Cannot move role with ID $roleid"); } } } @@ -403,4 +359,43 @@ } admin_externalpage_print_footer($adminroot); + die; + + +/// ================ some internal functions ====================//// + +function switch_roles($first, $second) { + $status = true; + //first find temorary sortorder number + $tempsort = count_records('role') + 3; + while (get_record('role','sortorder', $tempsort)) { + $tempsort += 3; + } + + $r1 = new object(); + $r1->id = $first->id; + $r1->sortorder = $tempsort; + $r2 = new object(); + $r2->id = $second->id; + $r2->sortorder = $first->sortorder; + + if (!update_record('role', $r1)) { + debugging("Can not update role with ID $r1->id!"); + $status = false; + } + + if (!update_record('role', $r2)) { + debugging("Can not update role with ID $r2->id!"); + $status = false; + } + + $r1->sortorder = $second->sortorder; + if (!update_record('role', $r1)) { + debugging("Can not update role with ID $r1->id!"); + $status = false; + } + + return $status; +} + ?> diff --git a/course/groups-edit.html b/course/groups-edit.html index 9c0f3bef32..05620d4443 100755 --- a/course/groups-edit.html +++ b/course/groups-edit.html @@ -1,7 +1,7 @@