function opigno_lms_init in Opigno LMS 7
Implements hook_init().cd .drush
File
- ./
opigno_lms.profile, line 26 - Enables modules and site configuration for a standard site installation. Provides a default API for Apps and modules to use. This will simplify the user experience.
Code
function opigno_lms_init() {
// We need to store the default roles so other modules can use them easily.
// Using this in hook_install() does not work, as the feature is not completely
// done installing at that point (or so it seems - it doesn't make any sense).
// Check the roles are found and set. If not, get them now.
// Make sure we find at least one of them. If not, don't store anything and wait
// for the next page load.
$og_roles = variable_get('opigno_lms_default_og_roles', array());
if (empty($og_roles)) {
module_load_include('install', 'opigno_lms');
// Get the role IDs to set them as variables.
// If not a single role is found, then we still haven't finished installing the roles.
// In that case, don't store the variable so we re-run this logic on the next page load.
$found = FALSE;
foreach (array(
OPIGNO_LMS_COURSE_ADMIN_ROLE => 'manager',
OPIGNO_LMS_COURSE_COACH_ROLE => 'coach',
OPIGNO_LMS_COURSE_TEACHER_ROLE => 'teacher',
OPIGNO_LMS_COURSE_STUDENT_ROLE => 'student',
OPIGNO_LMS_COURSE_MODERATOR_ROLE => 'forum moderator',
) as $role_key => $role_name) {
$rid = _opigno_lms_install_get_role_by_name($role_name, OPIGNO_COURSE_BUNDLE);
if (!empty($rid)) {
$og_roles[$role_key] = $rid;
$found = TRUE;
}
}
if ($found) {
variable_set('opigno_lms_default_og_roles', $og_roles);
variable_set('og_group_manager_default_rids_node_course', array(
$og_roles[OPIGNO_LMS_COURSE_ADMIN_ROLE],
));
$rid = _opigno_lms_install_get_role_by_name('manager', 'class');
if (!empty($rid)) {
variable_set('og_group_manager_default_rids_node_class', array(
$rid,
));
}
}
}
$platform_roles = variable_get('opigno_lms_default_platform_roles', array());
if (empty($platform_roles)) {
module_load_include('install', 'opigno_lms');
// Get the role IDs to set them as variables.
// If not a single role is found, then we still haven't finished installing the roles.
// In that case, don't store the variable so we re-run this logic on the next page load.
$found = FALSE;
foreach (array(
OPIGNO_LMS_STUDENT_MANAGER_ROLE => 'student manager',
OPIGNO_LMS_ADMIN_ROLE => 'administrator',
OPIGNO_LMS_FORUM_ADMINISTRATOR_ROLE => 'forum administrator',
) as $role_key => $role_name) {
$role = user_role_load_by_name($role_name);
if (!empty($role->rid)) {
$platform_roles[$role_key] = $role->rid;
$found = TRUE;
}
}
if ($found) {
variable_set('opigno_lms_default_platform_roles', $platform_roles);
}
}
}