本文整理汇总了PHP中upgrade_availability_item函数的典型用法代码示例。如果您正苦于以下问题:PHP upgrade_availability_item函数的具体用法?PHP upgrade_availability_item怎么用?PHP upgrade_availability_item使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了upgrade_availability_item函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_upgrade_availability_item
/**
* Tests the upgrade of an individual course-module or section from the
* old to new availability system. (This test does not use the database
* so it can run any time.)
*/
public function test_upgrade_availability_item()
{
global $CFG;
$this->resetAfterTest();
// This function is in the other upgradelib.
require_once $CFG->libdir . '/db/upgradelib.php';
// Groupmembersonly (or nothing). Show option on but ignored.
$CFG->enablegroupmembersonly = 0;
$this->assertNull(upgrade_availability_item(1, 0, 0, 0, 1, array(), array()));
$CFG->enablegroupmembersonly = 1;
$this->assertNull(upgrade_availability_item(0, 0, 0, 0, 1, array(), array()));
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"group"}]}', upgrade_availability_item(1, 0, 0, 0, 1, array(), array()));
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"grouping","id":4}]}', upgrade_availability_item(1, 4, 0, 0, 1, array(), array()));
// Dates (with show/hide options - until date always hides).
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"date","d":">=","t":996}]}', upgrade_availability_item(0, 0, 996, 0, 1, array(), array()));
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"date","d":">=","t":997}]}', upgrade_availability_item(0, 0, 997, 0, 0, array(), array()));
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"date","d":"<","t":998}]}', upgrade_availability_item(0, 0, 0, 998, 1, array(), array()));
$this->assertEquals('{"op":"&","showc":[true,false],"c":[' . '{"type":"date","d":">=","t":995},{"type":"date","d":"<","t":999}]}', upgrade_availability_item(0, 0, 995, 999, 1, array(), array()));
// Grade (show option works as normal).
$availrec = (object) array('sourcecmid' => null, 'requiredcompletion' => null, 'gradeitemid' => 13, 'grademin' => null, 'grademax' => null);
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"grade","id":13}]}', upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
$availrec->grademin = 4.1;
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"grade","id":13,"min":4.10000}]}', upgrade_availability_item(0, 0, 0, 0, 0, array($availrec), array()));
$availrec->grademax = 9.9;
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"grade","id":13,"min":4.10000,"max":9.90000}]}', upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
$availrec->grademin = null;
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"grade","id":13,"max":9.90000}]}', upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
// Completion (show option normal).
$availrec->grademax = null;
$availrec->gradeitemid = null;
$availrec->sourcecmid = 666;
$availrec->requiredcompletion = 1;
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"completion","cm":666,"e":1}]}', upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"completion","cm":666,"e":1}]}', upgrade_availability_item(0, 0, 0, 0, 0, array($availrec), array()));
// Profile conditions (custom/standard field, values/not, show option normal).
$fieldrec = (object) array('userfield' => 'email', 'operator' => 'isempty', 'value' => '', 'shortname' => null);
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"profile","op":"isempty","sf":"email"}]}', upgrade_availability_item(0, 0, 0, 0, 1, array(), array($fieldrec)));
$fieldrec->value = '@';
$fieldrec->operator = 'contains';
$this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"profile","op":"contains","sf":"email","v":"@"}]}', upgrade_availability_item(0, 0, 0, 0, 1, array(), array($fieldrec)));
$fieldrec->operator = 'isnotempty';
$fieldrec->userfield = null;
$fieldrec->shortname = 'frogtype';
$this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"profile","op":"isnotempty","cf":"frogtype"}]}', upgrade_availability_item(0, 0, 0, 0, 0, array(), array($fieldrec)));
// Everything at once.
$this->assertEquals('{"op":"&","showc":[false,true,false,true,true,true],' . '"c":[{"type":"grouping","id":13},' . '{"type":"date","d":">=","t":990},' . '{"type":"date","d":"<","t":991},' . '{"type":"grade","id":665,"min":70.00000},' . '{"type":"completion","cm":42,"e":2},' . '{"type":"profile","op":"isempty","sf":"email"}]}', upgrade_availability_item(1, 13, 990, 991, 1, array((object) array('sourcecmid' => null, 'gradeitemid' => 665, 'grademin' => 70), (object) array('sourcecmid' => 42, 'gradeitemid' => null, 'requiredcompletion' => 2)), array((object) array('userfield' => 'email', 'shortname' => null, 'operator' => 'isempty'))));
}
示例2: xmldb_main_upgrade
//.........这里部分代码省略.........
// (Performance: On the OU system, these took ~0.3 seconds, with about
// 20,000 results out of about 400,000 total rows in those tables.)
$cmcount = $DB->count_records_sql("\n SELECT COUNT(1)\n FROM {course_modules} cm\n WHERE cm.availablefrom != 0 OR\n cm.availableuntil != 0 OR\n EXISTS (SELECT 1 FROM {course_modules_availability} WHERE coursemoduleid = cm.id) OR\n EXISTS (SELECT 1 FROM {course_modules_avail_fields} WHERE coursemoduleid = cm.id)");
$sectcount = $DB->count_records_sql("\n SELECT COUNT(1)\n FROM {course_sections} cs\n WHERE cs.groupingid != 0 OR\n cs.availablefrom != 0 OR\n cs.availableuntil != 0 OR\n EXISTS (SELECT 1 FROM {course_sections_availability} WHERE coursesectionid = cs.id) OR\n EXISTS (SELECT 1 FROM {course_sections_avail_fields} WHERE coursesectionid = cs.id)");
if ($cmcount + $sectcount > 0) {
// Show progress bar and start db transaction.
$transaction = $DB->start_delegated_transaction();
$pbar = new progress_bar('availupdate', 500, true);
// Loop through all course-modules.
// (Performance: On the OU system, the query took <1 second for ~20k
// results; updating all those entries took ~3 minutes.)
$done = 0;
$lastupdate = 0;
$rs = $DB->get_recordset_sql("\n SELECT cm.id, cm.availablefrom, cm.availableuntil, cm.showavailability,\n COUNT(DISTINCT cma.id) AS availcount,\n COUNT(DISTINCT cmf.id) AS fieldcount\n FROM {course_modules} cm\n LEFT JOIN {course_modules_availability} cma ON cma.coursemoduleid = cm.id\n LEFT JOIN {course_modules_avail_fields} cmf ON cmf.coursemoduleid = cm.id\n WHERE cm.availablefrom != 0 OR\n cm.availableuntil != 0 OR\n cma.id IS NOT NULL OR\n cmf.id IS NOT NULL\n GROUP BY cm.id, cm.availablefrom, cm.availableuntil, cm.showavailability");
foreach ($rs as $rec) {
// Update progress initially and then once per second.
if (time() != $lastupdate) {
$lastupdate = time();
$pbar->update($done, $cmcount + $sectcount, "Updating activity availability settings ({$done}/{$cmcount})");
}
// Get supporting records - only if there are any (to reduce the
// number of queries where just date/group is used).
if ($rec->availcount) {
$availrecs = $DB->get_records('course_modules_availability', array('coursemoduleid' => $rec->id));
} else {
$availrecs = array();
}
if ($rec->fieldcount) {
$fieldrecs = $DB->get_records_sql("\n SELECT cmaf.userfield, cmaf.operator, cmaf.value, uif.shortname\n FROM {course_modules_avail_fields} cmaf\n LEFT JOIN {user_info_field} uif ON uif.id = cmaf.customfieldid\n WHERE cmaf.coursemoduleid = ?", array($rec->id));
} else {
$fieldrecs = array();
}
// Update item.
$availability = upgrade_availability_item(0, 0, $rec->availablefrom, $rec->availableuntil, $rec->showavailability, $availrecs, $fieldrecs);
if ($availability) {
$DB->set_field('course_modules', 'availability', $availability, array('id' => $rec->id));
}
// Update progress.
$done++;
}
$rs->close();
// Loop through all course-sections.
// (Performance: On the OU system, this took <1 second for, er, 150 results.)
$done = 0;
$rs = $DB->get_recordset_sql("\n SELECT cs.id, cs.groupingid, cs.availablefrom,\n cs.availableuntil, cs.showavailability,\n COUNT(DISTINCT csa.id) AS availcount,\n COUNT(DISTINCT csf.id) AS fieldcount\n FROM {course_sections} cs\n LEFT JOIN {course_sections_availability} csa ON csa.coursesectionid = cs.id\n LEFT JOIN {course_sections_avail_fields} csf ON csf.coursesectionid = cs.id\n WHERE cs.groupingid != 0 OR\n cs.availablefrom != 0 OR\n cs.availableuntil != 0 OR\n csa.id IS NOT NULL OR\n csf.id IS NOT NULL\n GROUP BY cs.id, cs.groupingid, cs.availablefrom,\n cs.availableuntil, cs.showavailability");
foreach ($rs as $rec) {
// Update progress once per second.
if (time() != $lastupdate) {
$lastupdate = time();
$pbar->update($done + $cmcount, $cmcount + $sectcount, "Updating section availability settings ({$done}/{$sectcount})");
}
// Get supporting records - only if there are any (to reduce the
// number of queries where just date/group is used).
if ($rec->availcount) {
$availrecs = $DB->get_records('course_sections_availability', array('coursesectionid' => $rec->id));
} else {
$availrecs = array();
}
if ($rec->fieldcount) {
$fieldrecs = $DB->get_records_sql("\n SELECT csaf.userfield, csaf.operator, csaf.value, uif.shortname\n FROM {course_sections_avail_fields} csaf\n LEFT JOIN {user_info_field} uif ON uif.id = csaf.customfieldid\n WHERE csaf.coursesectionid = ?", array($rec->id));
} else {
$fieldrecs = array();
}
// Update item.
$availability = upgrade_availability_item($rec->groupingid ? 1 : 0, $rec->groupingid, $rec->availablefrom, $rec->availableuntil, $rec->showavailability, $availrecs, $fieldrecs);
if ($availability) {