Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/category/db/install.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 
00030 function xmldb_enrol_category_install() {
00031     global $CFG, $DB;
00032 
00033     if (!$DB->record_exists_select('role_assignments', "contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array(CONTEXT_COURSECAT))) {
00034         // fresh install or nobody used category enrol
00035         return;
00036     }
00037 
00038     // existing sites need a way to keep category role enrols, but we do not want to encourage that on new sites
00039 
00040     // extremely ugly hack, the sync depends on the capabilities so we unfortunately force update of caps here
00041     // note: this is not officially supported and should not be copied elsewhere! :-(
00042     update_capabilities('enrol_category');
00043     $syscontext = get_context_instance(CONTEXT_SYSTEM);
00044     $archetypes = array('student', 'teacher', 'editingteacher');
00045     $enableplugin = false;
00046     foreach ($archetypes as $archetype) {
00047         $roles = get_archetype_roles($archetype);
00048         foreach ($roles as $role) {
00049             if (!$DB->record_exists_select('role_assignments', "roleid = ? AND contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array($role->id, CONTEXT_COURSECAT))) {
00050                 continue;
00051             }
00052             assign_capability('enrol/category:synchronised', CAP_ALLOW, $role->id, $syscontext->id, true);
00053             $levels = get_role_contextlevels($role->id);
00054             $levels[] = CONTEXT_COURSECAT;
00055             set_role_contextlevels($role->id, $levels);
00056             $enableplugin = true;
00057         }
00058     }
00059 
00060     if (!$enableplugin) {
00061         return;
00062     }
00063 
00064     // enable this plugin
00065     $enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
00066     $enabledplugins[] = 'category';
00067     $enabledplugins = array_unique($enabledplugins);
00068     set_config('enrol_plugins_enabled', implode(',', $enabledplugins));
00069 
00070     // brute force course resync, this may take a while
00071     require_once("$CFG->dirroot/enrol/category/locallib.php");
00072     enrol_category_sync_full();
00073 }
 All Data Structures Namespaces Files Functions Variables Enumerations