本文整理汇总了PHP中condition_info::wipe_conditions方法的典型用法代码示例。如果您正苦于以下问题:PHP condition_info::wipe_conditions方法的具体用法?PHP condition_info::wipe_conditions怎么用?PHP condition_info::wipe_conditions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类condition_info
的用法示例。
在下文中一共展示了condition_info::wipe_conditions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_cm_from_form
/**
* Utility function called by modedit.php; updates the
* course_modules_availability table based on the module form data.
*
* @param object $cm Course-module with as much data as necessary, min id
* @param object $fromform
* @param bool $wipefirst Defaults to true
*/
public static function update_cm_from_form($cm, $fromform, $wipefirst = true)
{
$ci = new condition_info($cm, CONDITION_MISSING_EVERYTHING, false);
if ($wipefirst) {
$ci->wipe_conditions();
}
foreach ($fromform->conditiongradegroup as $record) {
if ($record['conditiongradeitemid']) {
$ci->add_grade_condition($record['conditiongradeitemid'], $record['conditiongrademin'], $record['conditiongrademax']);
}
}
if (isset($fromform->conditioncompletiongroup)) {
foreach ($fromform->conditioncompletiongroup as $record) {
if ($record['conditionsourcecmid']) {
$ci->add_completion_condition($record['conditionsourcecmid'], $record['conditionrequiredcompletion']);
}
}
}
}
示例2: array
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();
//.........这里部分代码省略.........