function backup_course_modules($bf, $preferences, $section) { global $CFG; $status = true; $first_record = true; //Now print the mods in section //Extracts mod id from sequence $tok = strtok($section->sequence, ","); while ($tok) { //Get module's type $moduletype = get_module_type($preferences->backup_course, $tok); //Check if we've selected to backup that type if ($moduletype and $preferences->mods[$moduletype]->backup) { $selected = true; } else { $selected = false; } if ($selected) { $context = get_context_instance(CONTEXT_MODULE, $tok); //Gets course_module data from db $course_module = get_records("course_modules", "id", $tok); //If it's the first, pring MODS tag if ($first_record) { fwrite($bf, start_tag("MODS", 4, true)); $first_record = false; } // if we're doing selected instances, check that too. if (is_array($preferences->mods[$moduletype]->instances) && count($preferences->mods[$moduletype]->instances) && (!array_key_exists($course_module[$tok]->instance, $preferences->mods[$moduletype]->instances) || empty($preferences->mods[$moduletype]->instances[$course_module[$tok]->instance]->backup))) { $tok = strtok(","); continue; } // find all role values that has an override in this context $roles = get_records('role_capabilities', 'contextid', $context->id); //Print mod info from course_modules fwrite($bf, start_tag("MOD", 5, true)); //Save neccesary info to backup_ids fwrite($bf, full_tag("ID", 6, false, $tok)); fwrite($bf, full_tag("TYPE", 6, false, $moduletype)); fwrite($bf, full_tag("INSTANCE", 6, false, $course_module[$tok]->instance)); fwrite($bf, full_tag("ADDED", 6, false, $course_module[$tok]->added)); fwrite($bf, full_tag("SCORE", 6, false, $course_module[$tok]->score)); fwrite($bf, full_tag("INDENT", 6, false, $course_module[$tok]->indent)); fwrite($bf, full_tag("VISIBLE", 6, false, $course_module[$tok]->visible)); fwrite($bf, full_tag("GROUPMODE", 6, false, $course_module[$tok]->groupmode)); // get all the role_capabilities overrides in this mod write_role_overrides_xml($bf, $context, 6); /// write role_assign code here write_role_assignments_xml($bf, $preferences, $context, 6); /// write role_assign code here fwrite($bf, end_tag("MOD", 5, true)); } //check for next $tok = strtok(","); } //Si ha habido modulos, final de MODS if (!$first_record) { $status = fwrite($bf, end_tag("MODS", 4, true)); } return $status; }
function backup_course_modules($bf, $preferences, $section) { global $CFG; $status = true; $first_record = true; //Now print the mods in section //Extracts mod id from sequence $tok = strtok($section->sequence, ","); while ($tok) { //Get module's type $moduletype = get_module_type($preferences->backup_course, $tok); //Check if we've selected to backup that type if ($moduletype and $preferences->mods[$moduletype]->backup) { $selected = true; } else { $selected = false; } if ($selected) { $context = get_context_instance(CONTEXT_MODULE, $tok); //Gets course_module data from db - verify activity exists and is enabled! $sql = "SELECT cm.*\n FROM {$CFG->prefix}course_modules cm\n JOIN {$CFG->prefix}modules m ON m.id = cm.module\n JOIN {$CFG->prefix}{$moduletype} a ON a.id = cm.instance\n WHERE m.visible = 1 AND cm.id = {$tok}"; if (!($course_module = get_record_sql($sql))) { // cm exists but activity instance missing - probably caused by double clicking $tok = strtok(","); continue; } //If it's the first, pring MODS tag if ($first_record) { fwrite($bf, start_tag("MODS", 4, true)); $first_record = false; } // if we're doing selected instances, check that too. if (is_array($preferences->mods[$moduletype]->instances) && count($preferences->mods[$moduletype]->instances) && (!array_key_exists($course_module->instance, $preferences->mods[$moduletype]->instances) || empty($preferences->mods[$moduletype]->instances[$course_module->instance]->backup))) { $tok = strtok(","); continue; } // find all role values that has an override in this context $roles = get_records('role_capabilities', 'contextid', $context->id); //Print mod info from course_modules fwrite($bf, start_tag("MOD", 5, true)); //Save neccesary info to backup_ids fwrite($bf, full_tag("ID", 6, false, $tok)); fwrite($bf, full_tag("TYPE", 6, false, $moduletype)); fwrite($bf, full_tag("INSTANCE", 6, false, $course_module->instance)); fwrite($bf, full_tag("ADDED", 6, false, $course_module->added)); fwrite($bf, full_tag("SCORE", 6, false, $course_module->score)); fwrite($bf, full_tag("INDENT", 6, false, $course_module->indent)); fwrite($bf, full_tag("VISIBLE", 6, false, $course_module->visible)); fwrite($bf, full_tag("GROUPMODE", 6, false, $course_module->groupmode)); fwrite($bf, full_tag("GROUPINGID", 6, false, $course_module->groupingid)); fwrite($bf, full_tag("GROUPMEMBERSONLY", 6, false, $course_module->groupmembersonly)); fwrite($bf, full_tag("IDNUMBER", 6, false, $course_module->idnumber)); // get all the role_capabilities overrides in this mod write_role_overrides_xml($bf, $context, 6); /// write role_assign code here write_role_assignments_xml($bf, $preferences, $context, 6); /// write role_assign code here fwrite($bf, end_tag("MOD", 5, true)); } //check for next $tok = strtok(","); } //Si ha habido modulos, final de MODS if (!$first_record) { $status = fwrite($bf, end_tag("MODS", 4, true)); } return $status; }
function backup_course_modules($bf, $preferences, $section) { global $CFG, $DB; $status = true; $first_record = true; $course = $DB->get_record('course', array('id' => $preferences->backup_course)); if (!$course) { return false; } //Now print the mods in section //Extracts mod id from sequence $tok = strtok($section->sequence, ","); while ($tok) { //Get module's type $moduletype = get_module_type($preferences->backup_course, $tok); //Check if we've selected to backup that type if ($moduletype and $preferences->mods[$moduletype]->backup) { $selected = true; } else { $selected = false; } if ($selected) { $context = get_context_instance(CONTEXT_MODULE, $tok); //Gets course_module data from db - verify activity exists and is enabled! $sql = "SELECT cm.*\n FROM {course_modules} cm\n JOIN {modules} m ON m.id = cm.module\n JOIN {" . $moduletype . "} a ON a.id = cm.instance\n WHERE m.visible = 1 AND cm.id = {$tok}"; if (!($course_module = $DB->get_record_sql($sql))) { // cm exists but activity instance missing - probably caused by double clicking $tok = strtok(","); continue; } //If it's the first, pring MODS tag if ($first_record) { fwrite($bf, start_tag("MODS", 4, true)); $first_record = false; } // if we're doing selected instances, check that too. if (is_array($preferences->mods[$moduletype]->instances) && count($preferences->mods[$moduletype]->instances) && (!array_key_exists($course_module->instance, $preferences->mods[$moduletype]->instances) || empty($preferences->mods[$moduletype]->instances[$course_module->instance]->backup))) { $tok = strtok(","); continue; } // find all role values that has an override in this context $roles = $DB->get_records('role_capabilities', array('contextid' => $context->id)); //Print mod info from course_modules fwrite($bf, start_tag("MOD", 5, true)); //Save neccesary info to backup_ids fwrite($bf, full_tag("ID", 6, false, $tok)); fwrite($bf, full_tag("TYPE", 6, false, $moduletype)); fwrite($bf, full_tag("INSTANCE", 6, false, $course_module->instance)); fwrite($bf, full_tag("ADDED", 6, false, $course_module->added)); fwrite($bf, full_tag("SCORE", 6, false, $course_module->score)); fwrite($bf, full_tag("INDENT", 6, false, $course_module->indent)); fwrite($bf, full_tag("VISIBLE", 6, false, $course_module->visible)); fwrite($bf, full_tag("GROUPMODE", 6, false, $course_module->groupmode)); fwrite($bf, full_tag("GROUPINGID", 6, false, $course_module->groupingid)); fwrite($bf, full_tag("GROUPMEMBERSONLY", 6, false, $course_module->groupmembersonly)); fwrite($bf, full_tag("IDNUMBER", 6, false, $course_module->idnumber)); fwrite($bf, full_tag("COMPLETION", 6, false, $course_module->completion)); fwrite($bf, full_tag("COMPLETIONGRADEITEMNUMBER", 6, false, $course_module->completiongradeitemnumber)); fwrite($bf, full_tag("COMPLETIONVIEW", 6, false, $course_module->completionview)); fwrite($bf, full_tag("COMPLETIONEXPECTED", 6, false, $course_module->completionexpected)); fwrite($bf, full_tag("AVAILABLEFROM", 6, false, $course_module->availablefrom)); fwrite($bf, full_tag("AVAILABLEUNTIL", 6, false, $course_module->availableuntil)); fwrite($bf, full_tag("SHOWAVAILABILITY", 6, false, $course_module->showavailability)); // Write role assigns, overrides, etc. write_per_context_data($bf, $preferences, $context, 6); // write completion data if enabled and user data enabled require_once $CFG->libdir . '/completionlib.php'; $completion = new completion_info($course); if ($completion->is_enabled($course_module) && backup_userdata_selected($preferences, $moduletype, $course_module->instance)) { fwrite($bf, start_tag("COMPLETIONDATA", 6, true)); // Get all completion records for this module and loop $data = $DB->get_records('course_modules_completion', array('coursemoduleid' => $course_module->id)); $data = $data ? $data : array(); foreach ($data as $completion) { // Write completion record fwrite($bf, start_tag("COMPLETION", 7, true)); fwrite($bf, full_tag("USERID", 8, false, $completion->userid)); fwrite($bf, full_tag("COMPLETIONSTATE", 8, false, $completion->completionstate)); fwrite($bf, full_tag("VIEWED", 8, false, $completion->viewed)); fwrite($bf, full_tag("TIMEMODIFIED", 8, false, $completion->timemodified)); fwrite($bf, end_tag("COMPLETION", 7, true)); } fwrite($bf, end_tag("COMPLETIONDATA", 6, true)); } // Write availability data if enabled require_once $CFG->libdir . '/conditionlib.php'; if (!empty($CFG->enableavailability)) { fwrite($bf, start_tag("AVAILABILITYDATA", 6, true)); // Get all availability restrictions for this activity $data = $DB->get_records('course_modules_availability', array('coursemoduleid' => $course_module->id)); $data = $data ? $data : array(); foreach ($data as $availability) { // Write availability record fwrite($bf, start_tag("AVAILABILITY", 7, true)); fwrite($bf, full_tag("SOURCECMID", 8, false, $availability->sourcecmid)); fwrite($bf, full_tag("REQUIREDCOMPLETION", 8, false, $availability->requiredcompletion)); fwrite($bf, full_tag("GRADEITEMID", 8, false, $availability->gradeitemid)); fwrite($bf, full_tag("GRADEMIN", 8, false, $availability->grademin)); fwrite($bf, full_tag("GRADEMAX", 8, false, $availability->grademax)); fwrite($bf, end_tag("AVAILABILITY", 7, true)); } fwrite($bf, end_tag("AVAILABILITYDATA", 6, true)); } fwrite($bf, end_tag("MOD", 5, true)); } //check for next $tok = strtok(","); } //Si ha habido modulos, final de MODS if (!$first_record) { $status = fwrite($bf, end_tag("MODS", 4, true)); } return $status; }