public function copyMdlRoleObjectContextLevels(GcrMdlRole $mdl_role) { $this->deleteTableValues('role_context_levels'); foreach ($mdl_role->getContextLevels() as $mdl_role_context_level) { $params = array('roleid' => $this->obj->id, 'contextlevel' => $mdl_role_context_level->contextlevel); $this->app->insertIntoMdlTable('role_context_levels', $params); } }
public function resetMdlRoles() { $this->start_time = time(); $this->operation_description = 'mdl_roles set to template values on Moodle: <' . $this->app_description . '>'; $template_eschool = GcrEschoolTable::getPrimaryTemplate(); foreach ($this->app_array as $eschool) { if ($eschool->isPrimaryTemplate()) { continue; } $roles_copied = ''; $start_app_ts = time(); $template_mdl_roles = $template_eschool->selectFromMdlTable('role'); // First, make sure that every role on the template exists or is created // on the moodle. This must be done first because otherwise foreign // key references to new roles will reference a non-existing record. foreach ($template_mdl_roles as $template_mdl_role_obj) { $mdl_role_obj = $eschool->selectFromMdlTable('role', 'shortname', $template_mdl_role_obj->shortname, true); if (!$mdl_role_obj) { $sql = 'select max(sortorder) as max_sortorder from ' . $eschool->getShortName() . '.mdl_role'; $max_sortorder = $eschool->gcQuery($sql, array(), true); $params = array('name' => $template_mdl_role_obj->name, 'shortname' => $template_mdl_role_obj->shortname, 'description' => $template_mdl_role_obj->description, 'sortorder' => $max_sortorder->max_sortorder + 1, 'archetype' => $template_mdl_role_obj->archetype); $mdl_role_obj = $eschool->insertIntoMdlTable('role', $params); $roles_copied .= $mdl_role_obj->shortname . ';'; } } // Now, we copy all table data foreach ($template_mdl_roles as $template_mdl_role_obj) { $mdl_role_obj = $eschool->selectFromMdlTable('role', 'shortname', $template_mdl_role_obj->shortname, true); $mdl_role = new GcrMdlRole($mdl_role_obj, $eschool); $template_mdl_role = new GcrMdlRole($template_mdl_role_obj, $template_eschool); $mdl_role->copyMdlRoleObjectValues($template_mdl_role); } $seconds = time() - $start_app_ts; $result_text = false; if ($roles_copied != '') { $result_text = ' Roles: ' . $roles_copied . ' were copied from template in ' . $seconds . ' seconds.'; } $this->updateLogFile($eschool, true, $seconds, $result_text); } }