当前位置: 首页>>代码示例>>PHP>>正文


PHP question_delete_course函数代码示例

本文整理汇总了PHP中question_delete_course函数的典型用法代码示例。如果您正苦于以下问题:PHP question_delete_course函数的具体用法?PHP question_delete_course怎么用?PHP question_delete_course使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了question_delete_course函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: remove_course_contents


//.........这里部分代码省略.........
    $DB->delete_records_select('course_modules_completion', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
    // Remove course-module data that has not been removed in modules' _delete_instance callbacks.
    $cms = $DB->get_records('course_modules', array('course' => $course->id));
    $allmodulesbyid = array_flip($allmodules);
    foreach ($cms as $cm) {
        if (array_key_exists($cm->module, $allmodulesbyid)) {
            try {
                $DB->delete_records($allmodulesbyid[$cm->module], array('id' => $cm->instance));
            } catch (Exception $e) {
                // Ignore weird or missing table problems.
            }
        }
        context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
        $DB->delete_records('course_modules', array('id' => $cm->id));
    }
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess');
    }
    // Cleanup the rest of plugins. Deprecated since Moodle 3.2. TODO MDL-53297 remove in 3.6.
    $cleanuplugintypes = array('report', 'coursereport', 'format');
    $callbacks = get_plugins_with_function('delete_course', 'lib.php');
    foreach ($cleanuplugintypes as $type) {
        if (!empty($callbacks[$type])) {
            foreach ($callbacks[$type] as $pluginfunction) {
                debugging("Callback delete_course is deprecated. Function {$pluginfunction} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER);
                $pluginfunction($course->id, $showfeedback);
            }
            if ($showfeedback) {
                echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
            }
        }
    }
    // Delete questions and question categories.
    question_delete_course($course, $showfeedback);
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
    }
    // Make sure there are no subcontexts left - all valid blocks and modules should be already gone.
    $childcontexts = $coursecontext->get_child_contexts();
    // Returns all subcontexts since 2.2.
    foreach ($childcontexts as $childcontext) {
        $childcontext->delete();
    }
    unset($childcontexts);
    // Remove all roles and enrolments by default.
    if (empty($options['keep_roles_and_enrolments'])) {
        // This hack is used in restore when deleting contents of existing course.
        role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
        enrol_course_delete($course);
        if ($showfeedback) {
            echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
        }
    }
    // Delete any groups, removing members and grouping/course links first.
    if (empty($options['keep_groups_and_groupings'])) {
        groups_delete_groupings($course->id, $showfeedback);
        groups_delete_groups($course->id, $showfeedback);
    }
    // Filters be gone!
    filter_delete_all_for_context($coursecontext->id);
    // Notes, you shall not pass!
    note_delete_all($course->id);
    // Die comments!
    comment::delete_comments($coursecontext->id);
    // Ratings are history too.
    $delopt = new stdclass();
开发者ID:lucaboesch,项目名称:moodle,代码行数:67,代码来源:moodlelib.php

示例2: test_question_delete_course

 /**
  * This function tests the question_delete_course function.
  *
  * @param bool $feedback Whether to return feedback
  * @dataProvider provider_feedback
  */
 public function test_question_delete_course($feedback)
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
     // Test that the feedback works.
     if ($feedback) {
         $this->expectOutputRegex('|' . get_string('unusedcategorydeleted', 'question') . '|');
     }
     question_delete_course($course, $feedback);
     // Verify category deleted.
     $criteria = array('id' => $qcat->id);
     $this->assertEquals(0, $DB->count_records('question_categories', $criteria));
     // Verify questions deleted or moved.
     $criteria = array('category' => $qcat->id);
     $this->assertEquals(0, $DB->count_records('question', $criteria));
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:24,代码来源:questionlib_test.php

示例3: remove_course_contents


//.........这里部分代码省略.........
            if (function_exists($formatdelete)) {
                if ($showfeedback) {
                    echo $OUTPUT->notification($strdeleted . ' ' . $format);
                }
                $formatdelete($course->id);
            }
        }
    }
    // Remove all data from gradebook - this needs to be done before course modules
    // because while deleting this information, the system may need to reference
    // the course modules that own the grades.
    remove_course_grades($courseid, $showfeedback);
    remove_grade_letters($context, $showfeedback);
    // Remove all data from availability and completion tables that is associated
    // with course-modules belonging to this course. Note this is done even if the
    // features are not enabled now, in case they were enabled previously
    $DB->delete_records_select('course_modules_completion', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
    $DB->delete_records_select('course_modules_availability', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
    // Delete course blocks - they may depend on modules so delete them first
    blocks_delete_all_for_context($context->id);
    // Delete every instance of every module
    if ($allmods = $DB->get_records('modules')) {
        foreach ($allmods as $mod) {
            $modname = $mod->name;
            $modfile = $CFG->dirroot . '/mod/' . $modname . '/lib.php';
            $moddelete = $modname . '_delete_instance';
            // Delete everything connected to an instance
            $moddeletecourse = $modname . '_delete_course';
            // Delete other stray stuff (uncommon)
            $count = 0;
            if (file_exists($modfile)) {
                include_once $modfile;
                if (function_exists($moddelete)) {
                    if ($instances = $DB->get_records($modname, array('course' => $course->id))) {
                        foreach ($instances as $instance) {
                            if ($cm = get_coursemodule_from_instance($modname, $instance->id, $course->id)) {
                                /// Delete activity context questions and question categories
                                question_delete_activity($cm, $showfeedback);
                            }
                            if ($moddelete($instance->id)) {
                                $count++;
                            } else {
                                echo $OUTPUT->notification('Could not delete ' . $modname . ' instance ' . $instance->id . ' (' . format_string($instance->name) . ')');
                            }
                            if ($cm) {
                                // delete cm and its context in correct order
                                delete_context(CONTEXT_MODULE, $cm->id);
                                // some callbacks may try to fetch context, better delete first
                                $DB->delete_records('course_modules', array('id' => $cm->id));
                            }
                        }
                    }
                } else {
                    //note: we should probably delete these anyway
                    echo $OUTPUT->notification('Function ' . $moddelete . '() doesn\'t exist!');
                }
                if (function_exists($moddeletecourse)) {
                    $moddeletecourse($course, $showfeedback);
                }
            }
            if ($showfeedback) {
                echo $OUTPUT->notification($strdeleted . ' ' . $count . ' x ' . $modname);
            }
        }
    }
    // Delete any groups, removing members and grouping/course links first.
    groups_delete_groupings($course->id, $showfeedback);
    groups_delete_groups($course->id, $showfeedback);
    // Delete questions and question categories
    question_delete_course($course, $showfeedback);
    // Delete course tags
    coursetag_delete_course_tags($course->id, $showfeedback);
    // Delete legacy files (just in case some files are still left there after conversion to new file api)
    fulldelete($CFG->dataroot . '/' . $course->id);
    // cleanup course record - remove links to delted stuff
    $oldcourse = new stdClass();
    $oldcourse->id = $course->id;
    $oldcourse->summary = '';
    $oldcourse->modinfo = NULL;
    $oldcourse->legacyfiles = 0;
    $oldcourse->defaultgroupingid = 0;
    $oldcourse->enablecompletion = 0;
    $DB->update_record('course', $oldcourse);
    // Delete all related records in other tables that may have a courseid
    // This array stores the tables that need to be cleared, as
    // table_name => column_name that contains the course id.
    $tablestoclear = array('event' => 'courseid', 'log' => 'course', 'course_sections' => 'course', 'course_modules' => 'course', 'course_display' => 'course', 'backup_courses' => 'courseid', 'user_lastaccess' => 'courseid', 'backup_log' => 'courseid');
    foreach ($tablestoclear as $table => $col) {
        $DB->delete_records($table, array($col => $course->id));
    }
    // Delete all remaining stuff linked to context,
    // such as remaining roles, files, comments, etc.
    // Keep the context record for now.
    delete_context(CONTEXT_COURSE, $course->id, false);
    //trigger events
    $course->context = $context;
    // you can not access context in cron event later after course is deleted
    events_trigger('course_content_removed', $course);
    return true;
}
开发者ID:hitphp,项目名称:moodle,代码行数:101,代码来源:moodlelib.php

示例4: remove_course_contents


//.........这里部分代码省略.........
                                $result = false;
                            }
                            if ($cm) {
                                // delete cm and its context in correct order
                                delete_records('course_modules', 'id', $cm->id);
                                delete_context(CONTEXT_MODULE, $cm->id);
                            }
                        }
                    }
                } else {
                    notify('Function ' . $moddelete . '() doesn\'t exist!');
                    $result = false;
                }
                if (function_exists($moddeletecourse)) {
                    $moddeletecourse($course, $showfeedback);
                }
            }
            if ($showfeedback) {
                notify($strdeleted . ' ' . $count . ' x ' . $modname);
            }
        }
    } else {
        error('No modules are installed!');
    }
    /// Give local code a chance to delete its references to this course.
    require_once $CFG->libdir . '/locallib.php';
    notify_local_delete_course($courseid, $showfeedback);
    /// Delete course blocks
    if ($blocks = get_records_sql("SELECT *\n                                   FROM {$CFG->prefix}block_instance\n                                   WHERE pagetype = '" . PAGE_COURSE_VIEW . "'\n                                   AND pageid = {$course->id}")) {
        if (delete_records('block_instance', 'pagetype', PAGE_COURSE_VIEW, 'pageid', $course->id)) {
            if ($showfeedback) {
                notify($strdeleted . ' block_instance');
            }
            require_once $CFG->libdir . '/blocklib.php';
            foreach ($blocks as $block) {
                /// Delete any associated contexts for this block
                delete_context(CONTEXT_BLOCK, $block->id);
                // fix for MDL-7164
                // Get the block object and call instance_delete()
                if (!($record = blocks_get_record($block->blockid))) {
                    $result = false;
                    continue;
                }
                if (!($obj = block_instance($record->name, $block))) {
                    $result = false;
                    continue;
                }
                // Return value ignored, in core mods this does not do anything, but just in case
                // third party blocks might have stuff to clean up
                // we execute this anyway
                $obj->instance_delete();
            }
        } else {
            $result = false;
        }
    }
    /// Delete any groups, removing members and grouping/course links first.
    require_once $CFG->dirroot . '/group/lib.php';
    groups_delete_groupings($courseid, $showfeedback);
    groups_delete_groups($courseid, $showfeedback);
    /// Delete all related records in other tables that may have a courseid
    /// This array stores the tables that need to be cleared, as
    /// table_name => column_name that contains the course id.
    $tablestoclear = array('event' => 'courseid', 'log' => 'course', 'course_sections' => 'course', 'course_modules' => 'course', 'backup_courses' => 'courseid', 'user_lastaccess' => 'courseid', 'backup_log' => 'courseid');
    foreach ($tablestoclear as $table => $col) {
        if (delete_records($table, $col, $course->id)) {
            if ($showfeedback) {
                notify($strdeleted . ' ' . $table);
            }
        } else {
            $result = false;
        }
    }
    /// Clean up metacourse stuff
    if ($course->metacourse) {
        delete_records("course_meta", "parent_course", $course->id);
        sync_metacourse($course->id);
        // have to do it here so the enrolments get nuked. sync_metacourses won't find it without the id.
        if ($showfeedback) {
            notify("{$strdeleted} course_meta");
        }
    } else {
        if ($parents = get_records("course_meta", "child_course", $course->id)) {
            foreach ($parents as $parent) {
                remove_from_metacourse($parent->parent_course, $parent->child_course);
                // this will do the unenrolments as well.
            }
            if ($showfeedback) {
                notify("{$strdeleted} course_meta");
            }
        }
    }
    /// Delete questions and question categories
    question_delete_course($course, $showfeedback);
    /// Remove all data from gradebook
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    remove_course_grades($courseid, $showfeedback);
    remove_grade_letters($context, $showfeedback);
    return $result;
}
开发者ID:nadavkav,项目名称:rtlMoodle,代码行数:101,代码来源:moodlelib.php

示例5: quiz_upgrade


//.........这里部分代码省略.........
                    }
                }
            }
        }
        // Remove duplicate entries from quiz_multichoice
        if ($dups = get_records_sql("\n                SELECT question, answers, count(*) as num\n                FROM {$CFG->prefix}quiz_multichoice\n                GROUP BY question, answers\n                HAVING count(*) > 1")) {
            foreach ($dups as $dup) {
                $ids = get_records_sql("\n                    SELECT id, id\n                    FROM {$CFG->prefix}quiz_multichoice\n                    WHERE question = '{$dup->question}'\n                    AND answers = '{$dup->answers}'");
                $skip = true;
                foreach ($ids as $id) {
                    if ($skip) {
                        $skip = false;
                    } else {
                        $success = $success && delete_records('quiz_multichoice', 'id', $id->id);
                    }
                }
            }
        }
    }
    if ($success && $oldversion < 2005060300) {
        //Search all the orphan categories (those whose course doesn't exist)
        //and process them, deleting or moving them to site course - Bug 2459
        //Set debug to false
        $olddebug = $db->debug;
        $db->debug = false;
        //Iterate over all the quiz_categories records to get their course id
        if ($courses = get_records_sql("SELECT DISTINCT course as id, course\n                                         FROM {$CFG->prefix}quiz_categories")) {
            //Iterate over courses
            foreach ($courses as $course) {
                //If the course doesn't exist, orphan category found!
                //Process it with question_delete_course(). It will do all the hard work.
                if (!record_exists('course', 'id', $course->id)) {
                    require_once "{$CFG->libdir}/questionlib.php";
                    $success = $success && question_delete_course($course);
                }
            }
        }
        //Reset rebug to its original state
        $db->debug = $olddebug;
    }
    if ($success && $oldversion < 2005062600) {
        $success = $success && modify_database('', "\n            CREATE TABLE `prefix_quiz_essay` (\n                `id` int(10) unsigned NOT NULL auto_increment,\n                `question` int(10) unsigned NOT NULL default '0',\n                `answer` varchar(255) NOT NULL default '',\n                PRIMARY KEY  (`id`),\n                KEY `question` (`question`)\n           ) TYPE=MyISAM COMMENT='Options for essay questions'");
        $success = $success && modify_database('', "\n            CREATE TABLE `prefix_quiz_essay_states` (\n              `id` int(10) unsigned NOT NULL auto_increment,\n              `stateid` int(10) unsigned NOT NULL default '0',\n              `graded` tinyint(4) unsigned NOT NULL default '0',\n              `fraction` varchar(10) NOT NULL default '0.0',\n              `response` text NOT NULL,\n              PRIMARY KEY  (`id`)\n            ) TYPE=MyISAM COMMENT='essay question type specific state information'");
    }
    if ($success && $oldversion < 2005070202) {
        // add new unique id to prepare the way for lesson module to have its own attempts table
        $success = $success && table_column('quiz_attempts', '', 'uniqueid', 'integer', '10', 'unsigned', '0', 'not null', 'id');
        // initially we can use the id as the unique id because no other modules use attempts yet.
        $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET uniqueid = id", false);
        // we set $CFG->attemptuniqueid to the next available id
        $record = get_record_sql("SELECT max(id)+1 AS nextid FROM {$CFG->prefix}quiz_attempts");
        $success = $success && set_config('attemptuniqueid', empty($record->nextid) ? 1 : $record->nextid);
    }
    if ($success && $oldversion < 2006020801) {
        // add new field to store time delay between the first and second quiz attempt
        $success = $success && table_column('quiz', '', 'delay1', 'integer', '10', 'unsigned', '0', 'not null', 'popup');
        // add new field to store time delay between the second and any additional quizes
        $success = $success && table_column('quiz', '', 'delay2', 'integer', '10', 'unsigned', '0', 'not null', 'delay1');
    }
    if ($success && $oldversion < 2006021101) {
        // set defaultgrade field properly (probably not necessary, but better make sure)
        $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false);
        $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '7'", false);
    }
    if ($success && $oldversion < 2006021103) {
        // add new field to store the question-level shuffleanswers option
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:67,代码来源:mysql.php

示例6: remove_course_contents


//.........这里部分代码省略.........
    // Remove all data from availability and completion tables that is associated
    // with course-modules belonging to this course. Note this is done even if the
    // features are not enabled now, in case they were enabled previously.
    $DB->delete_records_select('course_modules_completion', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
    $DB->delete_records_select('course_modules_availability', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
    // Remove course-module data.
    $cms = $DB->get_records('course_modules', array('course' => $course->id));
    foreach ($cms as $cm) {
        if ($module = $DB->get_record('modules', array('id' => $cm->module))) {
            try {
                $DB->delete_records($module->name, array('id' => $cm->instance));
            } catch (Exception $e) {
                // Ignore weird or missing table problems
            }
        }
        context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
        $DB->delete_records('course_modules', array('id' => $cm->id));
    }
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess');
    }
    // Cleanup the rest of plugins
    $cleanuplugintypes = array('report', 'coursereport', 'format');
    foreach ($cleanuplugintypes as $type) {
        $plugins = get_plugin_list_with_function($type, 'delete_course', 'lib.php');
        foreach ($plugins as $plugin => $pluginfunction) {
            $pluginfunction($course->id, $showfeedback);
        }
        if ($showfeedback) {
            echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
        }
    }
    // Delete questions and question categories
    question_delete_course($course, $showfeedback);
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
    }
    // Make sure there are no subcontexts left - all valid blocks and modules should be already gone
    $childcontexts = $coursecontext->get_child_contexts();
    // returns all subcontexts since 2.2
    foreach ($childcontexts as $childcontext) {
        $childcontext->delete();
    }
    unset($childcontexts);
    // Remove all roles and enrolments by default
    if (empty($options['keep_roles_and_enrolments'])) {
        // this hack is used in restore when deleting contents of existing course
        role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
        enrol_course_delete($course);
        if ($showfeedback) {
            echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
        }
    }
    // Delete any groups, removing members and grouping/course links first.
    if (empty($options['keep_groups_and_groupings'])) {
        groups_delete_groupings($course->id, $showfeedback);
        groups_delete_groups($course->id, $showfeedback);
    }
    // filters be gone!
    filter_delete_all_for_context($coursecontext->id);
    // die comments!
    comment::delete_comments($coursecontext->id);
    // ratings are history too
    $delopt = new stdclass();
    $delopt->contextid = $coursecontext->id;
    $rm = new rating_manager();
开发者ID:nmicha,项目名称:moodle,代码行数:67,代码来源:moodlelib.php

示例7: remove_course_contents


//.........这里部分代码省略.........
                }
                $formatdelete($course->id);
            }
        }
    }
    /// Delete every instance of every module
    if ($allmods = $DB->get_records('modules')) {
        foreach ($allmods as $mod) {
            $modname = $mod->name;
            $modfile = $CFG->dirroot . '/mod/' . $modname . '/lib.php';
            $moddelete = $modname . '_delete_instance';
            // Delete everything connected to an instance
            $moddeletecourse = $modname . '_delete_course';
            // Delete other stray stuff (uncommon)
            $count = 0;
            if (file_exists($modfile)) {
                include_once $modfile;
                if (function_exists($moddelete)) {
                    if ($instances = $DB->get_records($modname, array('course' => $course->id))) {
                        foreach ($instances as $instance) {
                            if ($cm = get_coursemodule_from_instance($modname, $instance->id, $course->id)) {
                                /// Delete activity context questions and question categories
                                question_delete_activity($cm, $showfeedback);
                            }
                            if ($moddelete($instance->id)) {
                                $count++;
                            } else {
                                echo $OUTPUT->notification('Could not delete ' . $modname . ' instance ' . $instance->id . ' (' . format_string($instance->name) . ')');
                                $result = false;
                            }
                            if ($cm) {
                                // delete cm and its context in correct order
                                $DB->delete_records('course_modules', array('id' => $cm->id));
                                delete_context(CONTEXT_MODULE, $cm->id);
                            }
                        }
                    }
                } else {
                    echo $OUTPUT->notification('Function ' . $moddelete . '() doesn\'t exist!');
                    $result = false;
                }
                if (function_exists($moddeletecourse)) {
                    $moddeletecourse($course, $showfeedback);
                }
            }
            if ($showfeedback) {
                echo $OUTPUT->notification($strdeleted . ' ' . $count . ' x ' . $modname);
            }
        }
    } else {
        print_error('nomodules', 'debug');
    }
    /// Delete course blocks
    blocks_delete_all_for_context($context->id);
    /// Delete any groups, removing members and grouping/course links first.
    require_once $CFG->dirroot . '/group/lib.php';
    groups_delete_groupings($courseid, $showfeedback);
    groups_delete_groups($courseid, $showfeedback);
    /// Delete all related records in other tables that may have a courseid
    /// This array stores the tables that need to be cleared, as
    /// table_name => column_name that contains the course id.
    $tablestoclear = array('event' => 'courseid', 'log' => 'course', 'course_sections' => 'course', 'course_modules' => 'course', 'backup_courses' => 'courseid', 'user_lastaccess' => 'courseid', 'backup_log' => 'courseid');
    foreach ($tablestoclear as $table => $col) {
        if ($DB->delete_records($table, array($col => $course->id))) {
            if ($showfeedback) {
                echo $OUTPUT->notification($strdeleted . ' ' . $table);
            }
        } else {
            $result = false;
        }
    }
    /// Clean up metacourse stuff
    if ($course->metacourse) {
        $DB->delete_records("course_meta", array("parent_course" => $course->id));
        sync_metacourse($course->id);
        // have to do it here so the enrolments get nuked. sync_metacourses won't find it without the id.
        if ($showfeedback) {
            echo $OUTPUT->notification("{$strdeleted} course_meta");
        }
    } else {
        if ($parents = $DB->get_records("course_meta", array("child_course" => $course->id))) {
            foreach ($parents as $parent) {
                remove_from_metacourse($parent->parent_course, $parent->child_course);
                // this will do the unenrolments as well.
            }
            if ($showfeedback) {
                echo $OUTPUT->notification("{$strdeleted} course_meta");
            }
        }
    }
    /// Delete questions and question categories
    question_delete_course($course, $showfeedback);
    /// Remove all data from gradebook
    remove_course_grades($courseid, $showfeedback);
    remove_grade_letters($context, $showfeedback);
    /// Delete course tags
    require_once $CFG->dirroot . '/tag/coursetagslib.php';
    coursetag_delete_course_tags($course->id, $showfeedback);
    return $result;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:moodlelib.php

示例8: quiz_upgrade


//.........这里部分代码省略.........
                    } else {
                        $success = $success && delete_records('quiz_shortanswer', 'id', $id->id);
                    }
                }
            }
        }
        // Remove duplicate entries from quiz_multichoice
        if ($dups = get_records_sql("\n                SELECT question, answers, count(*) as num\n                FROM {$CFG->prefix}quiz_multichoice\n                GROUP BY question, answers\n                HAVING count(*) > 1")) {
            foreach ($dups as $dup) {
                $ids = get_records_sql("\n                    SELECT id, id\n                    FROM {$CFG->prefix}quiz_multichoice\n                    WHERE question = '{$dup->question}'\n                    AND answers = '{$dup->answers}'");
                $skip = true;
                foreach ($ids as $id) {
                    if ($skip) {
                        $skip = false;
                    } else {
                        $success = $success && delete_records('quiz_multichoice', 'id', $id->id);
                    }
                }
            }
        }
        //Search all the orphan categories (those whose course doesn't exist)
        //and process them, deleting or moving them to site course - Bug 2459
        //Set debug to false
        $olddebug = $db->debug;
        $db->debug = false;
        //Iterate over all the quiz_categories records to get their course id
        if ($courses = get_records_sql("SELECT DISTINCT course as id, course\n                                         FROM {$CFG->prefix}quiz_categories")) {
            //Iterate over courses
            foreach ($courses as $course) {
                //If the course doesn't exist, orphan category found!
                //Process it with question_delete_course(). It will do all the hard work.
                if (!record_exists('course', 'id', $course->id)) {
                    require_once "{$CFG->libdir}/questionlib.php";
                    $success = $success && question_delete_course($course);
                }
            }
        }
        //Reset rebug to its original state
        $db->debug = $olddebug;
    }
    if ($success && $oldversion < 2005060301) {
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz_rqp_type RENAME TO ' . $CFG->prefix . 'quiz_rqp_types');
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz_rqp_type_id_seq RENAME TO ' . $CFG->prefix . 'rqp_types_id_seq');
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz_rqp_types ALTER COLUMN id SET DEFAULT nextval(\'' . $CFG->prefix . 'quiz_rqp_types_id_seq\')');
        $success = $success && execute_sql('DROP INDEX ' . $CFG->prefix . 'quiz_rqp_type_name_uk');
        $success = $success && execute_sql('CREATE UNIQUE INDEX ' . $CFG->prefix . 'quiz_rqp_types_name_uk ON ' . $CFG->prefix . 'quiz_rqp_types (name);');
    }
    if ($success && $oldversion < 2005060302) {
        // Mass cleanup of bad postgres upgrade scripts
        $success = $success && execute_sql('CREATE UNIQUE INDEX ' . $CFG->prefix . 'quiz_newest_states_attempt_idx ON ' . $CFG->prefix . 'quiz_newest_states (attemptid, questionid)', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_attemptonlast_datasets DROP CONSTRAINT ' . $CFG->prefix . 'quiz_category_userid_unique', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_attemptonlast_datasets ADD CONSTRAINT ' . $CFG->prefix . 'quiz_attemptonlast_datasets_category_userid UNIQUE (category, userid)', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_question_instances DROP CONSTRAINT ' . $CFG->prefix . 'quiz_question_grades_pkey', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_question_instances ADD CONSTRAINT ' . $CFG->prefix . 'quiz_question_instances_pkey PRIMARY KEY (id)', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_question_versions DROP CONSTRAINT ' . $CFG->prefix . 'quiz_question_version_pkey', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_question_versions ADD CONSTRAINT ' . $CFG->prefix . 'quiz_question_versions_pkey PRIMARY KEY (id)', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_states DROP CONSTRAINT ' . $CFG->prefix . 'quiz_responses_pkey', false);
        $success = $success && execute_sql('ALTER TABLE ONLY ' . $CFG->prefix . 'quiz_states ADD CONSTRAINT ' . $CFG->prefix . 'quiz_states_pkey PRIMARY KEY (id)', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz ALTER decimalpoints SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz ALTER optionflags SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz ALTER penaltyscheme SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz ALTER popup SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz ALTER questionsperpage SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz ALTER review SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz_answers ALTER answer SET NOT NULL', false);
        $success = $success && execute_sql('ALTER TABLE ' . $CFG->prefix . 'quiz_attempts ALTER layout SET NOT NULL', false);
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:67,代码来源:postgres7.php

示例9: remove_course_contents


//.........这里部分代码省略.........
            foreach ($blocks as $block) {
                /// Delete any associated contexts for this block
                // Block instances are rarely created. Since the block instance is gone from the above delete
                // statement, calling delete_context() will generate a warning as get_context_instance could
                // no longer create the context as the block is already gone.
                if (record_exists('context', 'contextlevel', CONTEXT_BLOCK, 'instanceid', $block->id)) {
                    delete_context(CONTEXT_BLOCK, $block->id);
                }
                // fix for MDL-7164
                // Get the block object and call instance_delete()
                if (!($record = blocks_get_record($block->blockid))) {
                    $result = false;
                    continue;
                }
                if (!($obj = block_instance($record->name, $block))) {
                    $result = false;
                    continue;
                }
                // Return value ignored, in core mods this does not do anything, but just in case
                // third party blocks might have stuff to clean up
                // we execute this anyway
                $obj->instance_delete();
            }
        } else {
            $result = false;
        }
    }
    /// Delete any groups, removing members and grouping/course links first.
    //TODO: If groups or groupings are to be shared between courses, think again!
    if ($groupids = groups_get_groups($course->id)) {
        foreach ($groupids as $groupid) {
            if (groups_remove_all_members($groupid)) {
                if ($showfeedback) {
                    notify($strdeleted . ' groups_members');
                }
            } else {
                $result = false;
            }
            /// Delete any associated context for this group ??
            delete_context(CONTEXT_GROUP, $groupid);
            if (groups_delete_group($groupid)) {
                if ($showfeedback) {
                    notify($strdeleted . ' groups');
                }
            } else {
                $result = false;
            }
        }
    }
    /// Delete any groupings.
    $result = groups_delete_all_groupings($course->id);
    if ($result && $showfeedback) {
        notify($strdeleted . ' groupings');
    }
    /// Delete all related records in other tables that may have a courseid
    /// This array stores the tables that need to be cleared, as
    /// table_name => column_name that contains the course id.
    $tablestoclear = array('event' => 'courseid', 'log' => 'course', 'course_sections' => 'course', 'course_modules' => 'course', 'grade_category' => 'courseid', 'grade_exceptions' => 'courseid', 'grade_item' => 'courseid', 'grade_letter' => 'courseid', 'grade_preferences' => 'courseid', 'backup_courses' => 'courseid', 'backup_log' => 'courseid');
    foreach ($tablestoclear as $table => $col) {
        if (delete_records($table, $col, $course->id)) {
            if ($showfeedback) {
                notify($strdeleted . ' ' . $table);
            }
        } else {
            $result = false;
        }
    }
    /// Clean up metacourse stuff
    if ($course->metacourse) {
        delete_records("course_meta", "parent_course", $course->id);
        sync_metacourse($course->id);
        // have to do it here so the enrolments get nuked. sync_metacourses won't find it without the id.
        if ($showfeedback) {
            notify("{$strdeleted} course_meta");
        }
    } else {
        if ($parents = get_records("course_meta", "child_course", $course->id)) {
            foreach ($parents as $parent) {
                remove_from_metacourse($parent->parent_course, $parent->child_course);
                // this will do the unenrolments as well.
            }
            if ($showfeedback) {
                notify("{$strdeleted} course_meta");
            }
        }
    }
    /// Delete questions and question categories
    include_once $CFG->libdir . '/questionlib.php';
    question_delete_course($course, $showfeedback);
    /// Delete all roles and overiddes in the course context (but keep the course context)
    if ($courseid != SITEID) {
        delete_context(CONTEXT_COURSE, $course->id);
    }
    // fix for MDL-9016
    // clear the cache because the course context is deleted, and
    // we don't want to write assignment, overrides and context_rel table
    // with this old context id!
    get_context_instance('clearcache');
    return $result;
}
开发者ID:veritech,项目名称:pare-project,代码行数:101,代码来源:moodlelib.php


注:本文中的question_delete_course函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。