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


PHP course_integrity_check函数代码示例

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


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

示例1: test_course_integrity_check

 public function test_course_integrity_check()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course(array('numsections' => 1), array('createsections' => true));
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), array('section' => 0));
     $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id), array('section' => 0));
     $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id), array('section' => 0));
     $correctseq = join(',', array($forum->cmid, $page->cmid, $quiz->cmid));
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($correctseq, $section0->sequence);
     $this->assertEmpty($section1->sequence);
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section0->id, $cms[$page->cmid]->section);
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     $this->assertEmpty(course_integrity_check($course->id));
     // Now let's make manual change in DB and let course_integrity_check() fix it:
     // 1. Module appears twice in one section.
     $DB->update_record('course_sections', array('id' => $section0->id, 'sequence' => $section0->sequence . ',' . $page->cmid));
     $this->assertEquals(array('Failed integrity check for course [' . $course->id . ']. Sequence for course section [' . $section0->id . '] is "' . $section0->sequence . ',' . $page->cmid . '", must be "' . $section0->sequence . '"'), course_integrity_check($course->id));
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($correctseq, $section0->sequence);
     $this->assertEmpty($section1->sequence);
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section0->id, $cms[$page->cmid]->section);
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     // 2. Module appears in two sections (last section wins).
     $DB->update_record('course_sections', array('id' => $section1->id, 'sequence' => '' . $page->cmid));
     // First message about double mentioning in sequence, second message about wrong section field for $page.
     $this->assertEquals(array('Failed integrity check for course [' . $course->id . ']. Course module [' . $page->cmid . '] must be removed from sequence of section [' . $section0->id . '] because it is also present in sequence of section [' . $section1->id . ']', 'Failed integrity check for course [' . $course->id . ']. Course module [' . $page->cmid . '] points to section [' . $section0->id . '] instead of [' . $section1->id . ']'), course_integrity_check($course->id));
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($forum->cmid . ',' . $quiz->cmid, $section0->sequence);
     $this->assertEquals('' . $page->cmid, $section1->sequence);
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section1->id, $cms[$page->cmid]->section);
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     // 3. Module id is not present in course_section.sequence (integrity check with $fullcheck = false).
     $DB->update_record('course_sections', array('id' => $section1->id, 'sequence' => ''));
     $this->assertEmpty(course_integrity_check($course->id));
     // Not an error!
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($forum->cmid . ',' . $quiz->cmid, $section0->sequence);
     $this->assertEmpty($section1->sequence);
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section1->id, $cms[$page->cmid]->section);
     // Not changed.
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     // 4. Module id is not present in course_section.sequence (integrity check with $fullcheck = true).
     $this->assertEquals(array('Failed integrity check for course [' . $course->id . ']. Course module [' . $page->cmid . '] is missing from sequence of section [' . $section1->id . ']'), course_integrity_check($course->id, null, null, true));
     // Error!
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($forum->cmid . ',' . $quiz->cmid, $section0->sequence);
     $this->assertEquals('' . $page->cmid, $section1->sequence);
     // Yay, module added to section.
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section1->id, $cms[$page->cmid]->section);
     // Not changed.
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     // 5. Module id is not present in course_section.sequence and it's section is invalid (integrity check with $fullcheck = true).
     $DB->update_record('course_modules', array('id' => $page->cmid, 'section' => 8765));
     $DB->update_record('course_sections', array('id' => $section1->id, 'sequence' => ''));
     $this->assertEquals(array('Failed integrity check for course [' . $course->id . ']. Course module [' . $page->cmid . '] is missing from sequence of section [' . $section0->id . ']', 'Failed integrity check for course [' . $course->id . ']. Course module [' . $page->cmid . '] points to section [8765] instead of [' . $section0->id . ']'), course_integrity_check($course->id, null, null, true));
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($forum->cmid . ',' . $quiz->cmid . ',' . $page->cmid, $section0->sequence);
     // Module added to section.
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section0->id, $cms[$page->cmid]->section);
     // Section changed to section0.
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     // 6. Module is deleted from course_modules but not deleted in sequence (integrity check with $fullcheck = true).
     $DB->delete_records('course_modules', array('id' => $page->cmid));
     $this->assertEquals(array('Failed integrity check for course [' . $course->id . ']. Course module [' . $page->cmid . '] does not exist but is present in the sequence of section [' . $section0->id . ']'), course_integrity_check($course->id, null, null, true));
     $section0 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 0));
     $section1 = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1));
     $cms = $DB->get_records('course_modules', array('course' => $course->id), 'id', 'id,section');
     $this->assertEquals($forum->cmid . ',' . $quiz->cmid, $section0->sequence);
     $this->assertEmpty($section1->sequence);
     $this->assertEquals($section0->id, $cms[$forum->cmid]->section);
     $this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
     $this->assertEquals(2, count($cms));
 }
开发者ID:uniedpa,项目名称:moodle,代码行数:93,代码来源:courselib_test.php

示例2: get_array_of_activities

/**
 * For a given course, returns an array of course activity objects
 * Each item in the array contains he following properties:
 */
function get_array_of_activities($courseid)
{
    //  cm - course module id
    //  mod - name of the module (eg forum)
    //  section - the number of the section (eg week or topic)
    //  name - the name of the instance
    //  visible - is the instance visible or not
    //  groupingid - grouping id
    //  groupmembersonly - is this instance visible to group members only
    //  extra - contains extra string to include in any link
    global $CFG, $DB;
    if (!empty($CFG->enableavailability)) {
        require_once $CFG->libdir . '/conditionlib.php';
    }
    $course = $DB->get_record('course', array('id' => $courseid));
    if (empty($course)) {
        throw new moodle_exception('courseidnotfound');
    }
    $mod = array();
    $rawmods = get_course_mods($courseid);
    if (empty($rawmods)) {
        return $mod;
        // always return array
    }
    if ($sections = $DB->get_records('course_sections', array('course' => $courseid), 'section ASC', 'id,section,sequence')) {
        // First check and correct obvious mismatches between course_sections.sequence and course_modules.section.
        if ($errormessages = course_integrity_check($courseid, $rawmods, $sections)) {
            debugging(join('<br>', $errormessages));
            $rawmods = get_course_mods($courseid);
            $sections = $DB->get_records('course_sections', array('course' => $courseid), 'section ASC', 'id,section,sequence');
        }
        // Build array of activities.
        foreach ($sections as $section) {
            if (!empty($section->sequence)) {
                $sequence = explode(",", $section->sequence);
                foreach ($sequence as $seq) {
                    if (empty($rawmods[$seq])) {
                        continue;
                    }
                    $mod[$seq] = new stdClass();
                    $mod[$seq]->id = $rawmods[$seq]->instance;
                    $mod[$seq]->cm = $rawmods[$seq]->id;
                    $mod[$seq]->mod = $rawmods[$seq]->modname;
                    // Oh dear. Inconsistent names left here for backward compatibility.
                    $mod[$seq]->section = $section->section;
                    $mod[$seq]->sectionid = $rawmods[$seq]->section;
                    $mod[$seq]->module = $rawmods[$seq]->module;
                    $mod[$seq]->added = $rawmods[$seq]->added;
                    $mod[$seq]->score = $rawmods[$seq]->score;
                    $mod[$seq]->idnumber = $rawmods[$seq]->idnumber;
                    $mod[$seq]->visible = $rawmods[$seq]->visible;
                    $mod[$seq]->visibleold = $rawmods[$seq]->visibleold;
                    $mod[$seq]->groupmode = $rawmods[$seq]->groupmode;
                    $mod[$seq]->groupingid = $rawmods[$seq]->groupingid;
                    $mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly;
                    $mod[$seq]->indent = $rawmods[$seq]->indent;
                    $mod[$seq]->completion = $rawmods[$seq]->completion;
                    $mod[$seq]->extra = "";
                    $mod[$seq]->completiongradeitemnumber = $rawmods[$seq]->completiongradeitemnumber;
                    $mod[$seq]->completionview = $rawmods[$seq]->completionview;
                    $mod[$seq]->completionexpected = $rawmods[$seq]->completionexpected;
                    $mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom;
                    $mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil;
                    $mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
                    $mod[$seq]->showdescription = $rawmods[$seq]->showdescription;
                    if (!empty($CFG->enableavailability)) {
                        condition_info::fill_availability_conditions($rawmods[$seq]);
                        $mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion;
                        $mod[$seq]->conditionsgrade = $rawmods[$seq]->conditionsgrade;
                        $mod[$seq]->conditionsfield = $rawmods[$seq]->conditionsfield;
                    }
                    $modname = $mod[$seq]->mod;
                    $functionname = $modname . "_get_coursemodule_info";
                    if (!file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) {
                        continue;
                    }
                    include_once "{$CFG->dirroot}/mod/{$modname}/lib.php";
                    if ($hasfunction = function_exists($functionname)) {
                        if ($info = $functionname($rawmods[$seq])) {
                            if (!empty($info->icon)) {
                                $mod[$seq]->icon = $info->icon;
                            }
                            if (!empty($info->iconcomponent)) {
                                $mod[$seq]->iconcomponent = $info->iconcomponent;
                            }
                            if (!empty($info->name)) {
                                $mod[$seq]->name = $info->name;
                            }
                            if ($info instanceof cached_cm_info) {
                                // When using cached_cm_info you can include three new fields
                                // that aren't available for legacy code
                                if (!empty($info->content)) {
                                    $mod[$seq]->content = $info->content;
                                }
                                if (!empty($info->extraclasses)) {
                                    $mod[$seq]->extraclasses = $info->extraclasses;
//.........这里部分代码省略.........
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:101,代码来源:lib.php

示例3: array

    $where = '';
    $params = array();
} else {
    list($sql, $params) = $DB->get_in_or_equal($courseslist, SQL_PARAMS_NAMED, 'id');
    $where = 'WHERE id ' . $sql;
}
$coursescount = $DB->get_field_sql('SELECT count(id) FROM {course} ' . $where, $params);
if (!$coursescount) {
    cli_error('No courses found');
}
echo "Checking {$coursescount} courses...\n\n";
require_once $CFG->dirroot . '/course/lib.php';
$problems = array();
$courses = $DB->get_fieldset_sql('SELECT id FROM {course} ' . $where, $params);
foreach ($courses as $courseid) {
    $errors = course_integrity_check($courseid, null, null, true, empty($options['fix']));
    if ($errors) {
        if (!empty($options['fix'])) {
            // Reset the course cache to make sure cache is recalculated next time the course is viewed.
            rebuild_course_cache($courseid, true);
        }
        foreach ($errors as $error) {
            cli_problem($error);
        }
        $problems[] = $courseid;
    } else {
        echo "Course [{$courseid}] is OK\n";
    }
}
if (!count($problems)) {
    echo "\n...All courses are OK\n";
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:fix_course_sequence.php


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