]> git.mjollnir.org Git - moodle.git/commitdiff
merged from MOODLE_19_STABLE: moving two functions from admin/roles/manage.php (switc...
authormjollnir_ <mjollnir_>
Tue, 18 Dec 2007 20:51:07 +0000 (20:51 +0000)
committermjollnir_ <mjollnir_>
Tue, 18 Dec 2007 20:51:07 +0000 (20:51 +0000)
admin/roles/manage.php
lib/accesslib.php

index 2c5f6675ec3e3737013fe916a95d80c87e5680c5..6e955ac8285d3750c51104a7fa39b32776dcfdf4 100755 (executable)
     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;
-}
-
-// duplicates all the base definitions of a role
-function role_cap_duplicate($sourcerole, $targetrole) {
-    global $CFG;
-    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
-    $caps = get_records_sql("SELECT * FROM {$CFG->prefix}role_capabilities
-                             WHERE roleid = $sourcerole->id
-                             AND contextid = $systemcontext->id");
-    // adding capabilities
-    foreach ($caps as $cap) {
-        unset($cap->id);
-        $cap->roleid = $targetrole;
-        insert_record('role_capabilities', $cap);
-    }
-}
 ?>
index f03f43b04dc558bffd19f975a2ec4208f668e123..2a1dcc25a2a24641a7a4b71a62c7ca2323fc6fb8 100755 (executable)
@@ -4984,4 +4984,67 @@ function is_contextpath_dirty($pathcontexts, $dirty) {
     return false;
 }
 
-?>
+/**
+ * 
+ * switch role order (used in admin/roles/manage.php)
+ *
+ * @param int $first id of role to move down
+ * @param int $second id of role to move up
+ *
+ * @return bool success or failure
+ */
+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;
+}
+
+/**
+ * duplicates all the base definitions of a role
+ *
+ * @param int $sourcerole id of role to copy from
+ * @param int $targetrole id of role to copy to
+ *
+ * @return void
+ */
+function role_cap_duplicate($sourcerole, $targetrole) {
+    global $CFG;
+    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+    $caps = get_records_sql("SELECT * FROM {$CFG->prefix}role_capabilities
+                             WHERE roleid = $sourcerole->id
+                             AND contextid = $systemcontext->id");
+    // adding capabilities
+    foreach ($caps as $cap) {
+        unset($cap->id);
+        $cap->roleid = $targetrole;
+        insert_record('role_capabilities', $cap);
+    }
+}?>