本文整理汇总了PHP中blocks_get_by_page函数的典型用法代码示例。如果您正苦于以下问题:PHP blocks_get_by_page函数的具体用法?PHP blocks_get_by_page怎么用?PHP blocks_get_by_page使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了blocks_get_by_page函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: backup_course_blocks
function backup_course_blocks($bf, $preferences)
{
global $CFG;
$status = true;
// Read all of the block table
$blocks = blocks_get_record();
$pages = array();
$pages[] = page_create_object(PAGE_COURSE_VIEW, $preferences->backup_course);
if (!empty($CFG->showblocksonmodpages)) {
// get course structure
$course = get_record('course', 'id', $preferences->backup_course);
$modinfo =& get_fast_modinfo($course);
foreach ($preferences->mods as $module) {
if (!$module->backup) {
continue;
}
if (empty($modinfo->instances[$module->name])) {
continue;
}
$pagetypes = page_import_types('mod/' . $module->name . '/');
if (empty($pagetypes)) {
continue;
}
foreach ($pagetypes as $pagetype) {
foreach ($modinfo->instances[$module->name] as $cm) {
if (!empty($module->instances[$cm->instance]->backup)) {
$pages[] = page_create_object($pagetype, $cm->instance);
}
}
}
}
}
//Blocks open tag
fwrite($bf, start_tag('BLOCKS', 2, true));
foreach ($pages as $page) {
if ($instances = blocks_get_by_page($page)) {
//Iterate over every block
foreach ($instances as $position) {
foreach ($position as $instance) {
//If we somehow have a block with an invalid id, skip it
if (empty($blocks[$instance->blockid]->name)) {
continue;
}
$blockname = $blocks[$instance->blockid]->name;
if (!($blockobj = block_instance($blockname, $instance))) {
// Invalid block
continue;
}
// encode absolute links in block config
$instance->configdata = $blockobj->get_backup_encoded_config();
//Begin Block
fwrite($bf, start_tag('BLOCK', 3, true));
fwrite($bf, full_tag('ID', 4, false, $instance->id));
fwrite($bf, full_tag('NAME', 4, false, $blockname));
fwrite($bf, full_tag('PAGEID', 4, false, $instance->pageid));
fwrite($bf, full_tag('PAGETYPE', 4, false, $instance->pagetype));
fwrite($bf, full_tag('POSITION', 4, false, $instance->position));
fwrite($bf, full_tag('WEIGHT', 4, false, $instance->weight));
fwrite($bf, full_tag('VISIBLE', 4, false, $instance->visible));
fwrite($bf, full_tag('CONFIGDATA', 4, false, $instance->configdata));
// Write instance data if needed
if ($blockobj->backuprestore_instancedata_used()) {
fwrite($bf, start_tag('INSTANCEDATA', 4, true));
$status = $blockobj->instance_backup($bf, $preferences);
fwrite($bf, end_tag('INSTANCEDATA', 4, true));
}
$context = get_context_instance(CONTEXT_BLOCK, $instance->id);
write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 4);
//End Block
fwrite($bf, end_tag('BLOCK', 3, true));
}
}
}
}
//Blocks close tag
$status = fwrite($bf, end_tag('BLOCKS', 2, true));
return $status;
}
示例2: blocks_get_by_page_pinned
/**
* Similar to blocks_get_by_page(), except that, the array returned includes
* pinned blocks as well. Pinned blocks are always appended before normal
* block instances.
*/
function blocks_get_by_page_pinned($page)
{
$pinned = blocks_get_pinned($page);
$user = blocks_get_by_page($page);
$weights = array();
foreach ($pinned as $pos => $arr) {
$weights[$pos] = count($arr);
}
foreach ($user as $pos => $blocks) {
if (!array_key_exists($pos, $pinned)) {
$pinned[$pos] = array();
}
if (!array_key_exists($pos, $weights)) {
$weights[$pos] = 0;
}
foreach ($blocks as $block) {
$pinned[$pos][$weights[$pos]] = $block;
$weights[$pos]++;
}
}
return $pinned;
}
示例3: page_map_class
}
// initialise default blocks on admin and site page if needed
if (empty($CFG->adminblocks_initialised)) {
require_once "{$CFG->dirroot}/{$CFG->admin}/pagelib.php";
require_once $CFG->libdir . '/blocklib.php';
page_map_class(PAGE_ADMIN, 'page_admin');
$page = page_create_object(PAGE_ADMIN, 0);
// there must be some id number
blocks_repopulate_page($page);
//add admin_tree block to site if not already present
if ($admintree = get_record('block', 'name', 'admin_tree')) {
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
$pageblocks = blocks_get_by_page($page);
blocks_execute_action($page, $pageblocks, 'add', (int) $admintree->id, false, false);
if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
$pageblocks = blocks_get_by_page($page);
// Needs to be re-got, since has just changed
blocks_execute_action($page, $pageblocks, 'moveleft', $admintreeinstance, false, false);
}
}
set_config('adminblocks_initialised', 1);
}
/// Define the unique site ID code if it isn't already set. This getter does that as a side-effect.
get_site_identifier();
/// Check if the guest user exists. If not, create one.
if (!record_exists("user", "username", "guest")) {
if (!($guest = create_guest_record())) {
notify("Could not create guest user record !!!");
}
}
/// Set up the admin user
示例4: bounded_number
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
// Display the blocks and allow blocklib to handle any block action requested
$pageblocks = blocks_get_by_page($PAGE);
if ($editing) {
if (!empty($blockaction) && confirm_sesskey()) {
if (!empty($blockid)) {
blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
} else {
if (!empty($instanceid)) {
$instance = blocks_find_instance($instanceid, $pageblocks);
blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
}
}
// This re-query could be eliminated by judicious programming in blocks_execute_action(),
// but I'm not sure if it's worth the complexity increase...
$pageblocks = blocks_get_by_page($PAGE);
}
$missingblocks = blocks_get_missing($PAGE, $pageblocks);
}
if (!empty($tagid)) {
$taginstance = get_record('tag', 'id', $tagid);
} elseif (!empty($tag)) {
$taginstance = tag_id($tag);
}
/// navigations
/// site blogs - sitefullname -> blogs -> (?tag)
/// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
/// group blogs - sitefullname -> course fullname ->group ->(?tag)
/// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
$blogstring = get_string('blogs', 'blog');
$tagstring = get_string('tag');
示例5: page_map_class
}
}
// initialise default blocks on admin and site page if needed
if (empty($CFG->adminblocks_initialised)) {
require_once "{$CFG->dirroot}/{$CFG->admin}/pagelib.php";
require_once $CFG->libdir . '/blocklib.php';
page_map_class(PAGE_ADMIN, 'page_admin');
$page = page_create_object(PAGE_ADMIN, 0);
// there must be some id number
blocks_repopulate_page($page);
//add admin_tree block to site if not already present
if ($admintree = get_record('block', 'name', 'admin_tree')) {
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
blocks_execute_action($page, blocks_get_by_page($page), 'add', (int) $admintree->id, false, false);
if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
}
}
set_config('adminblocks_initialised', 1);
}
/// Define the unique site ID code if it isn't already
if (empty($CFG->siteidentifier)) {
// Unique site identification code
set_config('siteidentifier', random_string(32) . $_SERVER['HTTP_HOST']);
}
/// Check if the guest user exists. If not, create one.
if (!record_exists("user", "username", "guest")) {
if (!($guest = create_guest_record())) {
notify("Could not create guest user record !!!");
}
}
示例6: backup_course_blocks
function backup_course_blocks($bf, $preferences)
{
global $CFG;
$status = true;
// Read all of the block table
$blocks = blocks_get_record();
$pages = array();
$pages[] = page_create_object(PAGE_COURSE_VIEW, $preferences->backup_course);
// Let's see if we have to backup blocks from modules
$modulerecords = get_records_sql('SELECT name, id FROM ' . $CFG->prefix . 'modules');
foreach ($preferences->mods as $module) {
if (!$module->backup) {
continue;
}
$cmods = get_records_select('course_modules', 'course = ' . $preferences->backup_course . ' AND module = ' . $modulerecords[$module->name]->id);
if (empty($cmods)) {
continue;
}
$pagetypes = page_import_types('mod/' . $module->name . '/');
if (empty($pagetypes)) {
continue;
}
foreach ($pagetypes as $pagetype) {
foreach ($cmods as $cmod) {
$pages[] = page_create_object($pagetype, $cmod->instance);
}
}
}
//Blocks open tag
fwrite($bf, start_tag('BLOCKS', 2, true));
while ($page = array_pop($pages)) {
if ($instances = blocks_get_by_page($page)) {
//Iterate over every block
foreach ($instances as $position) {
foreach ($position as $instance) {
//If we somehow have a block with an invalid id, skip it
if (empty($blocks[$instance->blockid]->name)) {
continue;
}
//Begin Block
fwrite($bf, start_tag('BLOCK', 3, true));
fwrite($bf, full_tag('ID', 4, false, $instance->id));
fwrite($bf, full_tag('NAME', 4, false, $blocks[$instance->blockid]->name));
fwrite($bf, full_tag('PAGEID', 4, false, $instance->pageid));
fwrite($bf, full_tag('PAGETYPE', 4, false, $instance->pagetype));
fwrite($bf, full_tag('POSITION', 4, false, $instance->position));
fwrite($bf, full_tag('WEIGHT', 4, false, $instance->weight));
fwrite($bf, full_tag('VISIBLE', 4, false, $instance->visible));
fwrite($bf, full_tag('CONFIGDATA', 4, false, $instance->configdata));
$context = get_context_instance(CONTEXT_BLOCK, $instance->id);
write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 4);
//End Block
fwrite($bf, end_tag('BLOCK', 3, true));
}
}
}
}
//Blocks close tag
$status = fwrite($bf, end_tag('BLOCKS', 2, true));
return $status;
}
示例7: blocks_remove_inappropriate
/**
* Actually delete from the database any blocks that are currently on this page,
* but which should not be there according to blocks_name_allowed_in_format.
*
* @todo Write/Fix this function. Currently returns immediatly
* @param $course
*/
function blocks_remove_inappropriate($course)
{
// TODO
return;
$blockmanager = blocks_get_by_page($page);
if (empty($blockmanager)) {
return;
}
if (($pageformat = $page->pagetype) == NULL) {
return;
}
foreach ($blockmanager as $region) {
foreach ($region as $instance) {
$block = blocks_get_record($instance->blockid);
if (!blocks_name_allowed_in_format($block->name, $pageformat)) {
blocks_delete_instance($instance->instance);
}
}
}
}