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


PHP completion_info::wipe_session_cache方法代码示例

本文整理汇总了PHP中completion_info::wipe_session_cache方法的典型用法代码示例。如果您正苦于以下问题:PHP completion_info::wipe_session_cache方法的具体用法?PHP completion_info::wipe_session_cache怎么用?PHP completion_info::wipe_session_cache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在completion_info的用法示例。


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

示例1: test_is_available

 function test_is_available()
 {
     global $DB, $USER;
     $courseid = $this->make_course();
     // No conditions
     $cmid = $this->make_course_module($courseid);
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertTrue($ci->is_available($text, false, 0));
     $this->assertEqual('', $text);
     // Time (from)
     $time = time() + 100;
     $cmid = $this->make_course_module($courseid, array('availablefrom' => $time));
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertFalse($ci->is_available($text));
     $this->assert(new PatternExpectation('/' . preg_quote(userdate($time, get_string('strftimedate', 'langconfig'))) . '/'), $text);
     $time = time() - 100;
     $cmid = $this->make_course_module($courseid, array('availablefrom' => $time));
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertTrue($ci->is_available($text));
     $this->assertEqual('', $text);
     $this->assert(new PatternExpectation('/' . preg_quote(userdate($time, get_string('strftimedate', 'langconfig'))) . '/'), $ci->get_full_information());
     // Time (until)
     $cmid = $this->make_course_module($courseid, array('availableuntil' => time() - 100));
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual('', $text);
     // Completion
     $oldid = $cmid;
     $cmid = $this->make_course_module($courseid);
     $this->make_section($courseid, array($oldid, $cmid));
     $oldcm = $DB->get_record('course_modules', array('id' => $oldid));
     $oldcm->completion = COMPLETION_TRACKING_MANUAL;
     $DB->update_record('course_modules', $oldcm);
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $ci->add_completion_condition($oldid, COMPLETION_COMPLETE);
     $this->assertFalse($ci->is_available($text, false));
     $this->assertEqual(get_string('requires_completion_1', 'condition', 'xxx'), $text);
     $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
     $completion->update_state($oldcm, COMPLETION_COMPLETE);
     completion_info::wipe_session_cache();
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     $this->assertFalse($ci->is_available($text, false, $USER->id + 1));
     completion_info::wipe_session_cache();
     condition_info::wipe_session_cache();
     $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
     $completion->update_state($oldcm, COMPLETION_INCOMPLETE);
     $this->assertFalse($ci->is_available($text));
     $ci->wipe_conditions();
     $ci->add_completion_condition($oldid, COMPLETION_INCOMPLETE);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     $this->assertTrue($ci->is_available($text, false, $USER->id + 1));
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text, true));
     // Grade
     $ci->wipe_conditions();
     // Add a fake grade item
     $gradeitemid = $DB->insert_record('grade_items', (object) array('courseid' => $courseid, 'itemname' => 'frog'));
     // Add a condition on a value existing...
     $ci->add_grade_condition($gradeitemid, null, null, true);
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual(get_string('requires_grade_any', 'condition', 'frog'), $text);
     // Fake it existing
     $DB->insert_record('grade_grades', (object) array('itemid' => $gradeitemid, 'userid' => $USER->id, 'finalgrade' => 3.78));
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text, true));
     // Now require that user gets more than 3.78001
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 3.78001, null, true);
     condition_info::wipe_session_cache();
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual(get_string('requires_grade_min', 'condition', 'frog'), $text);
     // ...just on 3.78...
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 3.78, null, true);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     // ...less than 3.78
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, null, 3.78, true);
     condition_info::wipe_session_cache();
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual(get_string('requires_grade_max', 'condition', 'frog'), $text);
     // ...less than 3.78001
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, null, 3.78001, true);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     // ...in a range that includes it
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 3, 4, true);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     // ...in a range that doesn't include it
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 4, 5, true);
     condition_info::wipe_session_cache();
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:testconditionlib.php

示例2: test_section_is_available

    public function test_section_is_available() {
        global $DB, $USER;
        $courseid = $this->make_course();

        // Enrol user (needed for groups)
        $enrolplugin = enrol_get_plugin('manual');
        $course = $DB->get_record('course', array('id' => $courseid));
        $enrolplugin->add_instance($course);
        $enrolinstances = enrol_get_instances($courseid, false);
        foreach ($enrolinstances as $enrolinstance) {
            if ($enrolinstance->enrol === 'manual') {
                break;
            }
        }
        $enrolplugin->enrol_user($enrolinstance, $USER->id);

        // Module for conditions later
        $cmid = $this->make_course_module($courseid);

        // No conditions
        $sectionid = $this->make_section($courseid, array($cmid), 1);
        $ci = new condition_info_section((object)array('id' => $sectionid),
                CONDITION_MISSING_EVERYTHING);
        $this->assertTrue($ci->is_available($text, false, 0));
        $this->assertEquals('', $text);

        // Time (from)
        $time = time() + 100;
        $sectionid = $this->make_section($courseid, array(), 2, array('availablefrom' => $time));
        $ci = new condition_info_section((object)array('id' => $sectionid),
                CONDITION_MISSING_EVERYTHING);
        $this->assertFalse($ci->is_available($text));
        $timetext = userdate($time, get_string('strftimedate', 'langconfig'));
        $this->assertRegExp('~' . preg_quote($timetext) . '~', $text);

        $time=time()-100;
        $sectionid = $this->make_section($courseid, array(), 3, array('availablefrom' => $time));
        $ci = new condition_info_section((object)array('id' => $sectionid),
                CONDITION_MISSING_EVERYTHING);
        $this->assertTrue($ci->is_available($text));
        $this->assertEquals('', $text);
        $timetext = userdate($time, get_string('strftimedate', 'langconfig'));
        $this->assertRegExp('~' . preg_quote($timetext) . '~', $ci->get_full_information());

        // Time (until)
        $sectionid = $this->make_section($courseid, array(), 4, array('availableuntil' => time() - 100));
        $ci = new condition_info_section((object)array('id' => $sectionid),
            CONDITION_MISSING_EVERYTHING);
        $this->assertFalse($ci->is_available($text));
        $this->assertEquals('', $text);

        // Completion: first set up cm
        $sectionid = $this->make_section($courseid, array(), 5);
        $cm = $DB->get_record('course_modules', array('id' => $cmid));
        $cm->completion = COMPLETION_TRACKING_MANUAL;
        $DB->update_record('course_modules', $cm);

        // Completion: Reset modinfo after changing the options
        rebuild_course_cache($courseid);
        $reset = 'reset';
        get_fast_modinfo($reset);

        // Completion: Add condition
        $ci = new condition_info_section((object)array('id' => $sectionid),
                CONDITION_MISSING_EVERYTHING);
        $ci->add_completion_condition($cmid, COMPLETION_COMPLETE);
        condition_info_section::wipe_session_cache();

        // Completion: Check
        $this->assertFalse($ci->is_available($text, false));
        $this->assertEquals(get_string('requires_completion_1', 'condition', 'xxx'), $text);
        completion_info::wipe_session_cache();
        $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
        $completion->update_state($cm, COMPLETION_COMPLETE);
        completion_info::wipe_session_cache();
        condition_info_section::wipe_session_cache();
        $this->assertTrue($ci->is_available($text));
        $this->assertFalse($ci->is_available($text, false, $USER->id + 1));

        // Completion: Uncheck
        completion_info::wipe_session_cache();
        condition_info_section::wipe_session_cache();
        $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
        $completion->update_state($cm, COMPLETION_INCOMPLETE);
        $this->assertFalse($ci->is_available($text));

        // Completion: Incomplete condition
        $ci->wipe_conditions();
        $ci->add_completion_condition($cmid, COMPLETION_INCOMPLETE);
        condition_info_section::wipe_session_cache();
        $this->assertTrue($ci->is_available($text));
        $this->assertTrue($ci->is_available($text, false, $USER->id + 1));
        condition_info_section::wipe_session_cache();
        $this->assertTrue($ci->is_available($text, true));

        // Grade: Add a fake grade item
        $gradeitemid = $DB->insert_record('grade_items', (object)array(
            'courseid' => $courseid, 'itemname' => 'frog'));

        // Grade: Add a condition on a value existing
//.........这里部分代码省略.........
开发者ID:JP-Git,项目名称:moodle,代码行数:101,代码来源:conditionlib_test.php


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