예제 #1
0
function quiz_check_backup_mods($course, $user_data = false, $backup_unique_code, $instances = null)
{
    //Deletes data from mdl_backup_ids (categories section)
    delete_category_ids($backup_unique_code);
    //Create date into mdl_backup_ids (categories section)
    insert_category_ids($course, $backup_unique_code, $instances);
    if (!empty($instances) && is_array($instances) && count($instances)) {
        $info = array();
        foreach ($instances as $id => $instance) {
            $info += quiz_check_backup_mods_instances($instance, $backup_unique_code);
        }
        return $info;
    }
    //First the course data
    $info[0][0] = get_string("modulenameplural", "quiz");
    if ($ids = quiz_ids($course)) {
        $info[0][1] = count($ids);
    } else {
        $info[0][1] = 0;
    }
    //Categories
    $info[1][0] = get_string("categories", "quiz");
    if ($ids = question_category_ids_by_backup($backup_unique_code)) {
        $info[1][1] = count($ids);
    } else {
        $info[1][1] = 0;
    }
    //Questions
    $info[2][0] = get_string("questions", "quiz");
    if ($ids = question_ids_by_backup($backup_unique_code)) {
        $info[2][1] = count($ids);
    } else {
        $info[2][1] = 0;
    }
    //Now, if requested, the user_data
    if ($user_data) {
        //Grades
        $info[3][0] = get_string("grades");
        if ($ids = quiz_grade_ids_by_course($course)) {
            $info[3][1] = count($ids);
        } else {
            $info[3][1] = 0;
        }
    }
    return $info;
}
예제 #2
0
function question_insert_site_file_names($course, $backup_unique_code)
{
    global $QTYPES, $CFG;
    $status = true;
    $questionids = question_ids_by_backup($backup_unique_code);
    $urls = array();
    if ($questionids) {
        foreach ($questionids as $question_bk) {
            $question = get_record('question', 'id', $question_bk->old_id);
            $QTYPES[$question->qtype]->get_question_options($question);
            $urls = array_merge_recursive($urls, $QTYPES[$question->qtype]->find_file_links($question, SITEID));
        }
    }
    ksort($urls);
    foreach (array_keys($urls) as $url) {
        if (file_exists($CFG->dataroot . '/' . SITEID . '/' . $url)) {
            $inserturl = new object();
            $inserturl->backup_code = $backup_unique_code;
            $inserturl->file_type = 'site';
            $url = clean_param($url, PARAM_PATH);
            $inserturl->path = addslashes($url);
            $status = $status && insert_record('backup_files', $inserturl);
        } else {
            notify(get_string('linkedfiledoesntexist', 'question', $url));
        }
    }
    return $status;
}
예제 #3
0
function quiz_check_backup_mods($course, $user_data = false, $backup_unique_code, $instances = null)
{
    //this function selects all the questions / categories to be backed up.
    quiz_insert_category_and_question_ids($course, $backup_unique_code, $instances);
    if ($course != SITEID) {
        question_insert_site_file_names($course, $backup_unique_code);
    }
    if (!empty($instances) && is_array($instances) && count($instances)) {
        $info = array();
        foreach ($instances as $id => $instance) {
            $info += quiz_check_backup_mods_instances($instance, $backup_unique_code);
        }
        return $info;
    }
    //First the course data
    $info[0][0] = get_string("modulenameplural", "quiz");
    if ($ids = quiz_ids($course)) {
        $info[0][1] = count($ids);
    } else {
        $info[0][1] = 0;
    }
    //Categories
    $info[1][0] = get_string("categories", "quiz");
    if ($ids = question_category_ids_by_backup($backup_unique_code)) {
        $info[1][1] = count($ids);
    } else {
        $info[1][1] = 0;
    }
    //Questions
    $info[2][0] = get_string("questions", "quiz");
    if ($ids = question_ids_by_backup($backup_unique_code)) {
        $info[2][1] = count($ids);
    } else {
        $info[2][1] = 0;
    }
    //Now, if requested, the user_data
    if ($user_data) {
        //Grades
        $info[3][0] = get_string("grades");
        if ($ids = quiz_grade_ids_by_course($course)) {
            $info[3][1] = count($ids);
        } else {
            $info[3][1] = 0;
        }
    }
    return $info;
}