function blocks_print_group(&$page, &$pageblocks, $position) { global $COURSE, $CFG, $USER; $isediting = $page->user_is_editing(); if (empty($pageblocks[$position])) { $groupblocks = array(); $maxweight = 0; } else { $groupblocks = $pageblocks[$position]; $maxweight = max(array_keys($groupblocks)); } if (!empty($CFG->ajaxcapable) && $CFG->ajaxcapable && !empty($COURSE->javascriptportal) && $isediting) { $COURSE->javascriptportal->currentblocksection = $position; $COURSE->javascriptportal->block_add($position . 'inst0', FALSE); } foreach ($groupblocks as $instance) { if (!empty($instance->pinned)) { $maxweight--; } } foreach ($groupblocks as $instance) { // $instance may have ->rec and ->obj // cached from when we walked $pageblocks // in blocks_have_content() if (empty($instance->rec)) { if (empty($instance->blockid)) { continue; // Can't do anything } $block = blocks_get_record($instance->blockid); } else { $block = $instance->rec; } if (empty($block)) { // Block doesn't exist! We should delete this instance! continue; } if (empty($block->visible)) { // Disabled by the admin continue; } if (empty($instance->obj)) { if (!($obj = block_instance($block->name, $instance))) { // Invalid block continue; } } else { $obj = $instance->obj; } $editalways = $page->edit_always(); if ($isediting && empty($instance->pinned) || !empty($editalways)) { $options = 0; // The block can be moved up if it's NOT the first one in its position. If it is, we look at the OR clause: // the first block might still be able to move up if the page says so (i.e., it will change position) $options |= BLOCK_MOVE_UP * ($instance->weight != 0 || $page->blocks_move_position($instance, BLOCK_MOVE_UP) != $instance->position); // Same thing for downward movement $options |= BLOCK_MOVE_DOWN * ($instance->weight != $maxweight || $page->blocks_move_position($instance, BLOCK_MOVE_DOWN) != $instance->position); // For left and right movements, it's up to the page to tell us whether they are allowed $options |= BLOCK_MOVE_RIGHT * ($page->blocks_move_position($instance, BLOCK_MOVE_RIGHT) != $instance->position); $options |= BLOCK_MOVE_LEFT * ($page->blocks_move_position($instance, BLOCK_MOVE_LEFT) != $instance->position); // Finally, the block can be configured if the block class either allows multiple instances, or if it specifically // allows instance configuration (multiple instances override that one). It doesn't have anything to do with what the // administrator has allowed for this block in the site admin options. $options |= BLOCK_CONFIGURE * ($obj->instance_allow_multiple() || $obj->instance_allow_config()); $obj->_add_edit_controls($options); } if (!$instance->visible && empty($COURSE->javascriptportal)) { if ($isediting) { $obj->_print_shadow(); } } else { global $COURSE; if (!empty($COURSE->javascriptportal)) { $COURSE->javascriptportal->currentblocksection = $position; } $obj->_print_block(); } if (!empty($COURSE->javascriptportal) && (empty($instance->pinned) || !$instance->pinned)) { $COURSE->javascriptportal->block_add('inst' . $instance->id, !$instance->visible); } } // End foreach // Check if // we are on the default position/side AND // we're editing the page AND // ( // we have the capability to manage blocks OR // we are in myMoodle page AND have the capibility to manage myMoodle blocks // ) // for constant PAGE_MY_MOODLE include_once $CFG->dirroot . '/my/pagelib.php'; $coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id); $myownblogpage = isset($page->filtertype) && isset($page->filterselect) && $page->type == 'blog-view' && $page->filtertype == 'user' && $page->filterselect == $USER->id; $managecourseblocks = has_capability('moodle/site:manageblocks', $coursecontext); $editmymoodle = $page->type == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', $coursecontext); if ($page->blocks_default_position() == $position && $page->user_is_editing() && ($managecourseblocks || $editmymoodle || $myownblogpage || defined('ADMIN_STICKYBLOCKS'))) { print_side_block(NULL, NULL, NULL, NULL, NULL, array('id' => BLOCK_POS_RIGHT . 'inst0', 'class' => 'tempblockhandler')); blocks_print_adminblock($page, $pageblocks); } else { if ($page->user_is_editing() && ($managecourseblocks || $editmymoodle || $myownblogpage || defined('ADMIN_STICKYBLOCKS'))) { print_side_block(NULL, NULL, NULL, NULL, NULL, array('id' => BLOCK_POS_LEFT . 'inst0', 'class' => 'tempblockhandler')); } } }
function blocks_print_group($page, $blockmanager, $region) { global $COURSE, $CFG, $USER; $isediting = $page->user_is_editing(); $groupblocks = $blockmanager->get_blocks_for_region($region); foreach ($groupblocks as $instance) { if ($isediting && empty($instance->pinned)) { $options = 0; // The block can be moved up if it's NOT the first one in its position. If it is, we look at the OR clause: // the first block might still be able to move up if the page says so (i.e., it will change position) // TODO $options |= BLOCK_MOVE_UP * ($instance->weight != 0 || ($page->blocks_move_position($instance, BLOCK_MOVE_UP) != $instance->position)); // Same thing for downward movement // TODO $options |= BLOCK_MOVE_DOWN * ($instance->weight != $maxweight || ($page->blocks_move_position($instance, BLOCK_MOVE_DOWN) != $instance->position)); // For left and right movements, it's up to the page to tell us whether they are allowed // TODO $options |= BLOCK_MOVE_RIGHT * ($page->blocks_move_position($instance, BLOCK_MOVE_RIGHT) != $instance->position); // TODO $options |= BLOCK_MOVE_LEFT * ($page->blocks_move_position($instance, BLOCK_MOVE_LEFT ) != $instance->position); // Finally, the block can be configured if the block class either allows multiple instances, or if it specifically // allows instance configuration (multiple instances override that one). It doesn't have anything to do with what the // administrator has allowed for this block in the site admin options. $options |= BLOCK_CONFIGURE * ($instance->instance_allow_multiple() || $instance->instance_allow_config()); $instance->_add_edit_controls($options); } if (false && !$instance->visible && empty($COURSE->javascriptportal)) { if ($isediting) { $instance->_print_shadow(); } } else { global $COURSE; if (!empty($COURSE->javascriptportal)) { $COURSE->javascriptportal->currentblocksection = $region; } $instance->_print_block(); } if (!empty($COURSE->javascriptportal) && (empty($instance->pinned) || !$instance->pinned)) { $COURSE->javascriptportal->block_add('inst' . $instance->id, !$instance->visible); } } // End foreach if ($page->blocks->get_default_region() == $region && $page->user_is_editing() && $page->user_can_edit_blocks()) { blocks_print_adminblock($page, $blockmanager); } }