本文整理汇总了PHP中context_helper::get_preload_record_columns方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::get_preload_record_columns方法的具体用法?PHP context_helper::get_preload_record_columns怎么用?PHP context_helper::get_preload_record_columns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context_helper
的用法示例。
在下文中一共展示了context_helper::get_preload_record_columns方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_string
$title = get_string('reportformissingqtypes', 'report_questioninstances');
} else if ($requestedqtype == '_all_') {
$sqlqtypetest = '';
$params = array();
$title = get_string('reportforallqtypes', 'report_questioninstances');
} else {
$sqlqtypetest = 'WHERE qtype = ?';
$params = array($requestedqtype);
$title = get_string('reportforqtype', 'report_questioninstances',
question_bank::get_qtype($requestedqtype)->local_name());
}
// Get the question counts, and all the context information, for each
// context. That is, rows of these results can be used as $context objects.
$ctxpreload = context_helper::get_preload_record_columns_sql('con');
$ctxgroupby = implode(',', array_keys(context_helper::get_preload_record_columns('con')));
$counts = $DB->get_records_sql("
SELECT qc.contextid, count(1) as numquestions, sum(hidden) as numhidden, $ctxpreload
FROM {question} q
JOIN {question_categories} qc ON q.category = qc.id
JOIN {context} con ON con.id = qc.contextid
$sqlqtypetest
GROUP BY qc.contextid, $ctxgroupby
ORDER BY numquestions DESC, numhidden ASC, con.contextlevel ASC, con.id ASC", $params);
// Print the report heading.
echo $OUTPUT->heading($title);
// Initialise the table.
$table = new html_table();
$table->head = array(
示例2: test_everything_in_accesslib
//.........这里部分代码省略.........
$this->assertEquals($countcats, 1);
$this->assertEquals($countcourses, 6);
$this->assertEquals($countblocks, 1);
$context = context_course::instance($testcourses[2]);
$children = $context->get_child_contexts();
$this->assertEquals(count($children), 7); // depends on number of default blocks
$context = context_module::instance($testpages[3]);
$children = $context->get_child_contexts();
$this->assertEquals(count($children), 1);
$context = context_block::instance($testblocks[1]);
$children = $context->get_child_contexts();
$this->assertEquals(count($children), 0);
unset($children);
unset($countcats);
unset($countcourses);
unset($countblocks);
// ======= context_helper::reset_caches() ============================
context_helper::reset_caches();
$this->assertEquals(context_inspection::test_context_cache_size(), 0);
context_course::instance($SITE->id);
$this->assertEquals(context_inspection::test_context_cache_size(), 1);
// ======= context preloading ========================================
context_helper::reset_caches();
$sql = "SELECT ".context_helper::get_preload_record_columns_sql('c')."
FROM {context} c
WHERE c.contextlevel <> ".CONTEXT_SYSTEM;
$records = $DB->get_records_sql($sql);
$firstrecord = reset($records);
$columns = context_helper::get_preload_record_columns('c');
$firstrecord = (array)$firstrecord;
$this->assertSame(array_keys($firstrecord), array_values($columns));
context_helper::reset_caches();
foreach ($records as $record) {
context_helper::preload_from_record($record);
$this->assertEquals($record, new stdClass());
}
$this->assertEquals(context_inspection::test_context_cache_size(), count($records));
unset($records);
unset($columns);
context_helper::reset_caches();
context_helper::preload_course($SITE->id);
$this->assertEquals(7, context_inspection::test_context_cache_size()); // depends on number of default blocks
// ====== assign_capability(), unassign_capability() ====================
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertFalse($rc);
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext->id);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertEquals($rc->permission, CAP_ALLOW);
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext->id);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertEquals($rc->permission, CAP_ALLOW);
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext, true);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
示例3: test_everything_in_accesslib
//.........这里部分代码省略.........
$countcats++;
}
if ($child->contextlevel == CONTEXT_COURSE) {
$countcourses++;
}
if ($child->contextlevel == CONTEXT_BLOCK) {
$countblocks++;
}
}
$this->assertEqual(count($children), 8);
$this->assertEqual($countcats, 1);
$this->assertEqual($countcourses, 6);
$this->assertEqual($countblocks, 1);
$context = context_course::instance($testcourses[2]);
$children = $context->get_child_contexts();
$this->assertEqual(count($children), 3);
$context = context_module::instance($testpages[3]);
$children = $context->get_child_contexts();
$this->assertEqual(count($children), 1);
$context = context_block::instance($testblocks[1]);
$children = $context->get_child_contexts();
$this->assertEqual(count($children), 0);
unset($children);
unset($countcats);
unset($countcourses);
unset($countblocks);
// ======= context_helper::reset_caches() ============================
context_helper::reset_caches();
$this->assertEqual(context_inspection::test_context_cache_size(), 0);
context_course::instance($SITE->id);
$this->assertEqual(context_inspection::test_context_cache_size(), 1);
// ======= context preloading ========================================
context_helper::reset_caches();
$sql = "SELECT " . context_helper::get_preload_record_columns_sql('c') . "\n FROM {context} c\n WHERE c.contextlevel <> " . CONTEXT_SYSTEM;
$records = $DB->get_records_sql($sql);
$firstrecord = reset($records);
$columns = context_helper::get_preload_record_columns('c');
$firstrecord = (array) $firstrecord;
$this->assertIdentical(array_keys($firstrecord), array_values($columns));
context_helper::reset_caches();
foreach ($records as $record) {
context_helper::preload_from_record($record);
$this->assertIdentical($record, new stdClass());
}
$this->assertEqual(context_inspection::test_context_cache_size(), count($records));
unset($records);
unset($columns);
context_helper::reset_caches();
context_helper::preload_course($SITE->id);
$this->assertEqual(context_inspection::test_context_cache_size(), 4);
// ====== assign_capability(), unassign_capability() ====================
$rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
$this->assertFalse($rc);
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext->id);
$rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
$this->assertEqual($rc->permission, CAP_ALLOW);
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext->id);
$rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
$this->assertEqual($rc->permission, CAP_ALLOW);
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext, true);
$rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
$this->assertEqual($rc->permission, CAP_PREVENT);
assign_capability('moodle/site:accessallgroups', CAP_INHERIT, $allroles['teacher'], $frontpagecontext);
$rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
$this->assertFalse($rc);
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext);