Example #1
0
function backup_forum_ratings($bf, $preferences, $post)
{
    global $CFG;
    $status = true;
    $forum_ratings = get_records("forum_ratings", "post", $post, "id");
    //If there are ratings
    if ($forum_ratings) {
        //Write start tag
        $status = fwrite($bf, start_tag("RATINGS", 8, true));
        //Iterate over each rating
        foreach ($forum_ratings as $for_rat) {
            //Start rating
            $status = fwrite($bf, start_tag("RATING", 9, true));
            //Print forum_rating contents
            fwrite($bf, full_tag("GUID", 4, false, get_backup_guid('forum_ratings', 'id', $for_rat->id)));
            fwrite($bf, full_tag("ID", 10, false, $for_rat->id));
            fwrite($bf, full_tag("USERID", 10, false, $for_rat->userid));
            fwrite($bf, full_tag("TIME", 10, false, $for_rat->time));
            fwrite($bf, full_tag("POST_RATING", 10, false, $for_rat->rating));
            //End rating
            $status = fwrite($bf, end_tag("RATING", 9, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag("RATINGS", 8, true));
    }
    return $status;
}
Example #2
0
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 isset($preferences->mods[$moduletype]->backup) 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));
            //check to see if this module has a guid
            if ($guid = get_backup_guid($moduletype, 'id', $course_module->instance)) {
                fwrite($bf, full_tag("GUID", 6, false, $guid));
            }
            //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;
}