Пример #1
0
function question_insert_c_and_q_ids_for_module($backup_unique_code, $course, $modulename, $instances)
{
    global $CFG, $DB;
    $status = true;
    // using 'dummykeyname' in sql because otherwise $DB->get_records_sql_menu returns an error
    // if two key names are the same.
    $cmcontexts = array();
    if (!empty($instances)) {
        list($usql, $params) = $DB->get_in_or_equal(array_keys($instances));
        $params[] = $modulename;
        $params[] = $course;
        $cmcontexts = $DB->get_records_sql_menu("SELECT c.id, c.id AS dummykeyname FROM {modules} m,\n                                                        {course_modules} cm, {context} c\n                               WHERE cm.instance {$usql} AND m.name = ? AND m.id = cm.module AND cm.id = c.instanceid\n                                    AND c.contextlevel = " . CONTEXT_MODULE . " AND cm.course = ?", $params);
    }
    if ($cmcontexts) {
        list($usql, $params) = $DB->get_in_or_equal(array_keys($cmcontexts));
        $status = $status && $DB->execute("INSERT INTO {backup_ids} (backup_code, table_name, old_id, info)\n                                               SELECT '{$backup_unique_code}', 'question_categories', qc.id, '{$modulename}'\n                                                 FROM {question_categories} qc\n                                                WHERE qc.contextid {$usql}", $params);
    }
    $status = $status && question_insert_q_ids($backup_unique_code, $modulename);
    return $status;
}
Пример #2
0
function question_insert_c_and_q_ids_for_module($backup_unique_code, $course, $modulename, $instances)
{
    global $CFG;
    $status = true;
    // using 'dummykeyname' in sql because otherwise get_records_sql_menu returns an error
    // if two key names are the same.
    $cmcontexts = array();
    if (!empty($instances)) {
        $cmcontexts = get_records_sql_menu("SELECT c.id, c.id AS dummykeyname FROM {$CFG->prefix}modules m,\n                                                        {$CFG->prefix}course_modules cm,\n                                                        {$CFG->prefix}context c\n                               WHERE m.name = '{$modulename}' AND m.id = cm.module AND cm.id = c.instanceid\n                                    AND c.contextlevel = " . CONTEXT_MODULE . " AND cm.course = {$course}\n                                    AND cm.instance IN (" . implode(',', array_keys($instances)) . ")");
    }
    if ($cmcontexts) {
        $status = $status && execute_sql("INSERT INTO {$CFG->prefix}backup_ids\n                                       (backup_code, table_name, old_id, info)\n                                   SELECT '{$backup_unique_code}', 'question_categories', qc.id, '{$modulename}'\n                                   FROM {$CFG->prefix}question_categories qc\n                                   WHERE qc.contextid IN (" . join(array_keys($cmcontexts), ', ') . ")", false);
    }
    $status = $status && question_insert_q_ids($backup_unique_code, $modulename);
    return $status;
}