Beispiel #1
0
function assignment_backup_one_mod($bf, $preferences, $assignment)
{
    global $CFG, $DB;
    if (is_numeric($assignment)) {
        $assignment = $DB->get_record('assignment', array('id' => $assignment));
    }
    $status = true;
    //Start mod
    fwrite($bf, start_tag("MOD", 3, true));
    //Print assignment data
    fwrite($bf, full_tag("ID", 4, false, $assignment->id));
    fwrite($bf, full_tag("MODTYPE", 4, false, "assignment"));
    fwrite($bf, full_tag("NAME", 4, false, $assignment->name));
    fwrite($bf, full_tag("DESCRIPTION", 4, false, $assignment->intro));
    fwrite($bf, full_tag("FORMAT", 4, false, $assignment->introformat));
    fwrite($bf, full_tag("RESUBMIT", 4, false, $assignment->resubmit));
    fwrite($bf, full_tag("PREVENTLATE", 4, false, $assignment->preventlate));
    fwrite($bf, full_tag("EMAILTEACHERS", 4, false, $assignment->emailteachers));
    fwrite($bf, full_tag("VAR1", 4, false, $assignment->var1));
    fwrite($bf, full_tag("VAR2", 4, false, $assignment->var2));
    fwrite($bf, full_tag("VAR3", 4, false, $assignment->var3));
    fwrite($bf, full_tag("VAR4", 4, false, $assignment->var4));
    fwrite($bf, full_tag("VAR5", 4, false, $assignment->var5));
    fwrite($bf, full_tag("ASSIGNMENTTYPE", 4, false, $assignment->assignmenttype));
    fwrite($bf, full_tag("MAXBYTES", 4, false, $assignment->maxbytes));
    fwrite($bf, full_tag("TIMEDUE", 4, false, $assignment->timedue));
    fwrite($bf, full_tag("TIMEAVAILABLE", 4, false, $assignment->timeavailable));
    fwrite($bf, full_tag("GRADE", 4, false, $assignment->grade));
    fwrite($bf, full_tag("TIMEMODIFIED", 4, false, $assignment->timemodified));
    $class = 'assignment_' . $assignment->assignmenttype;
    require_once $CFG->dirroot . '/mod/assignment/lib.php';
    require_once $CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
    call_user_func(array($class, 'backup_one_mod'), $bf, $preferences, $assignment);
    //if we've selected to backup users info, then execute backup_assignment_submisions and
    //backup_assignment_files_instance
    if (backup_userdata_selected($preferences, 'assignment', $assignment->id)) {
        $status = backup_assignment_submissions($bf, $preferences, $assignment);
        if ($status) {
            $status = backup_assignment_files_instance($bf, $preferences, $assignment->id);
        }
    }
    //End mod
    $status = fwrite($bf, end_tag("MOD", 3, true));
    return $status;
}
function assignment_backup_one_mod($bf, $preferences, $assignment)
{
    global $CFG;
    if ($assignment === 0) {
        //no active instances of assignment to be backed up - skip backup
        return false;
    }
    if (is_numeric($assignment)) {
        $assignment = get_record('assignment', 'id', $assignment);
    }
    if (empty($assignment->assignmenttype)) {
        // No assignment type will cause fatal error below in require_once so bail out now
        // Probably ended up here by restoring a course into
        // a moodle without this assignmenttype
        return false;
    }
    $status = true;
    //Start mod
    fwrite($bf, start_tag("MOD", 3, true));
    //Print assignment data
    fwrite($bf, full_tag("ID", 4, false, $assignment->id));
    fwrite($bf, full_tag("MODTYPE", 4, false, "assignment"));
    fwrite($bf, full_tag("NAME", 4, false, $assignment->name));
    fwrite($bf, full_tag("DESCRIPTION", 4, false, $assignment->description));
    fwrite($bf, full_tag("FORMAT", 4, false, $assignment->format));
    fwrite($bf, full_tag("RESUBMIT", 4, false, $assignment->resubmit));
    fwrite($bf, full_tag("PREVENTLATE", 4, false, $assignment->preventlate));
    fwrite($bf, full_tag("EMAILTEACHERS", 4, false, $assignment->emailteachers));
    fwrite($bf, full_tag("VAR1", 4, false, $assignment->var1));
    fwrite($bf, full_tag("VAR2", 4, false, $assignment->var2));
    fwrite($bf, full_tag("VAR3", 4, false, $assignment->var3));
    fwrite($bf, full_tag("VAR4", 4, false, $assignment->var4));
    fwrite($bf, full_tag("VAR5", 4, false, $assignment->var5));
    fwrite($bf, full_tag("ASSIGNMENTTYPE", 4, false, $assignment->assignmenttype));
    fwrite($bf, full_tag("MAXBYTES", 4, false, $assignment->maxbytes));
    fwrite($bf, full_tag("TIMEDUE", 4, false, $assignment->timedue));
    fwrite($bf, full_tag("TIMEAVAILABLE", 4, false, $assignment->timeavailable));
    fwrite($bf, full_tag("GRADE", 4, false, $assignment->grade));
    fwrite($bf, full_tag("TIMEMODIFIED", 4, false, $assignment->timemodified));
    $class = 'assignment_' . $assignment->assignmenttype;
    require_once $CFG->dirroot . '/mod/assignment/lib.php';
    require_once $CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
    call_user_func(array($class, 'backup_one_mod'), $bf, $preferences, $assignment);
    //if we've selected to backup users info, then execute backup_assignment_submisions and
    //backup_assignment_files_instance
    if (backup_userdata_selected($preferences, 'assignment', $assignment->id)) {
        $status = backup_assignment_submissions($bf, $preferences, $assignment);
        if ($status) {
            $status = backup_assignment_files_instance($bf, $preferences, $assignment->id);
        }
    }
    //End mod
    $status = fwrite($bf, end_tag("MOD", 3, true));
    return $status;
}