]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11143, adding a new setting "defaultfrontpageroleid" where you choose a role...
authortoyomoyo <toyomoyo>
Wed, 26 Sep 2007 07:12:38 +0000 (07:12 +0000)
committertoyomoyo <toyomoyo>
Wed, 26 Sep 2007 07:12:38 +0000 (07:12 +0000)
admin/settings/frontpage.php
lib/accesslib.php

index 1393208acfeab3175401b7f0861bdbee6edbcf42..6522632f7d2849355ea328222d36b6dd125086d1 100644 (file)
@@ -40,6 +40,17 @@ $ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('f
 
 $ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&amp;wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
 
+// front page default role
+$temp = new admin_settingpage('frontpagedefaultrole', get_string('frontpagedefaultrole', 'admin'), 'moodle/site:config', false, get_context_instance(CONTEXT_SYSTEM));
+$roleoptions = array(0=>'N/A'); // roles to choose from
+if ($roles = get_records('role')) {
+    foreach ($roles as $role) {
+        $roleoptions[$role->id] = $role->name;
+    }
+}
+$temp->add(new admin_setting_configselect('defaultfrontpageroleid', get_string('frontpagedefaultrole', 'admin'), '', '', $roleoptions));
+$ADMIN->add('frontpage', $temp);
+
 $ADMIN->add('frontpage', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
 
 ?>
\ No newline at end of file
index 1818e0d0f4c2b3bb87c58ab58fa348862332e7ef..fe151c74c21aea0a3c5467bbcdfe6bd504a3697b 100755 (executable)
@@ -242,6 +242,46 @@ function get_role_access($roleid, $accessdata=NULL) {
     return $accessdata;
 }
 
+/**
+ * Gets the accessdata for role "sitewide" 
+ * (system down to course)
+ *
+ * @return array
+ */
+function get_default_frontpage_role_access($roleid, $accessdata=NULL) {
+
+    global $CFG;
+    
+    $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
+    $base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id;
+    //
+    // Overrides for the role in any contexts related to the course
+    //
+    $sql = "SELECT ctx.path,
+                   rc.capability, rc.permission
+            FROM {$CFG->prefix}context ctx
+            JOIN {$CFG->prefix}role_capabilities rc
+              ON rc.contextid=ctx.id
+            WHERE rc.roleid = {$roleid}
+                  AND (ctx.id = ".SYSCONTEXTID." OR ctx.path LIKE '$base/%')
+            ORDER BY ctx.depth, ctx.path";             
+            
+    if ($rs = get_recordset_sql($sql)) {
+        if ($rs->RecordCount()) {
+            while ($rd = rs_fetch_next_record($rs)) {
+                $k = "{$rd->path}:{$roleid}";
+                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
+            }
+            unset($rd);
+        }
+        rs_close($rs);
+    }
+
+    return $accessdata;
+}
+
+
 /**
  * Get the id for the not-logged-in role - or set it up if needed
  * @return bool
@@ -1514,7 +1554,19 @@ function load_user_accessdata($userid) {
     }
     $accessdata['dr'] = $CFG->defaultuserroleid;
 
-    $ACCESS[$userid] = $accessdata;
+    //
+    // provide "default frontpage role"
+    //
+    if ($CFG->defaultfrontpageroleid) {
+        $base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id;
+        $accessdata = get_default_frontpage_role_access($CFG->defaultfrongpageroleid, $accessdata);
+        if (!isset($accessdata['ra'][$base])) {
+            $accessdata['ra'][$base] = array($CFG->defaultfrongpageroleid);
+        } else {
+            array_push($accessdata['ra'][$base], $CFG->defaultfrongpageroleid);
+        }
+    }
+    $ACCESS[$userid] = $accessdata;  
     return true;
 }
 
@@ -1553,8 +1605,23 @@ function load_all_capabilities() {
         }
         $accessdata['dr'] = $CFG->defaultuserroleid;
 
-        $USER->access = $accessdata;
+        $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
 
+        //
+        // provide "default frontpage role"
+        //
+        
+        if ($CFG->defaultfrontpageroleid) {
+            $base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id;
+            $accessdata = get_default_frontpage_role_access($CFG->defaultfrontpageroleid, $accessdata);
+            if (!isset($accessdata['ra'][$base])) {
+                $accessdata['ra'][$base] = array($CFG->defaultfrontpageroleid);
+            } else {
+                array_push($accessdata['ra'][$base], $CFG->defaultfrontpageroleid);
+            }
+        } 
+        $USER->access = $accessdata;
+    
     } else {
         if ($roleid = get_notloggedin_roleid()) {
             $USER->access = get_role_access($roleid);