blocks editing ui: MDL-19398 showing and hiding blocks now works.

This commit is contained in:
tjhunt
2009-07-15 07:41:25 +00:00
parent 4a3b462021
commit ae42ff6fee
4 changed files with 75 additions and 13 deletions
+8 -4
View File
@@ -355,9 +355,12 @@ class block_base {
if (!$this->hide_header()) {
$bc->title = $this->title;
}
$bc->content = $this->formatted_contents($output);
if (!empty($this->content->footer)) {
$bc->footer = $this->content->footer;
if ($this->instance->visible) {
$bc->content = $this->formatted_contents($output);
if (!empty($this->content->footer)) {
$bc->footer = $this->content->footer;
}
}
if ($this->page->user_is_editing()) {
@@ -368,7 +371,8 @@ class block_base {
return null;
}
if (empty($CFG->allowuserblockhiding)) {
if (empty($CFG->allowuserblockhiding) ||
(empty($bc->content) && empty($bc->footer))) {
$bc->collapsible = block_contents::NOT_HIDEABLE;
} else if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) {
$bc->collapsible = block_contents::HIDDEN;
+1
View File
@@ -820,6 +820,7 @@ $string['hideadvancedsettings'] = 'Hide advanced settings';
$string['hidepicture'] = 'Hide picture';
$string['hidesection'] = 'Hide section $a';
$string['hidesettings'] = 'Hide settings';
$string['hideshowblocks'] = 'Hide or show blocks';
$string['hidetopicfromothers'] = 'Hide topic from others';
$string['hideweekfromothers'] = 'Hide week from others';
$string['hits'] = 'Hits';
+64 -7
View File
@@ -354,9 +354,12 @@ class block_manager {
/**
* This method actually loads the blocks for our page from the database.
*
* @param bool|null $includeinvisible
* @param boolean|null $includeinvisible
* null (default) - load hidden blocks if $this->page->user_is_editing();
* true - load hidden blocks.
* false - don't load hidden blocks.
*/
public function load_blocks($includeinvisible = NULL) {
public function load_blocks($includeinvisible = null) {
global $DB, $CFG;
if (!is_null($this->birecordsbyregion)) {
// Already done.
@@ -383,9 +386,9 @@ class block_manager {
$includeinvisible = $this->page->user_is_editing();
}
if ($includeinvisible) {
$visiblecheck = 'AND (bp.visible = 1 OR bp.visible IS NULL)';
} else {
$visiblecheck = '';
} else {
$visiblecheck = 'AND (bp.visible = 1 OR bp.visible IS NULL)';
}
$context = $this->page->context;
@@ -418,6 +421,8 @@ class block_manager {
bi.showinsubcontexts,
bi.pagetypepattern,
bi.subpagepattern,
bi.defaultregion,
bi.defaultweight,
COALESCE(bp.visible, 1) AS visible,
COALESCE(bp.region, bi.defaultregion) AS region,
COALESCE(bp.weight, bi.defaultweight) AS weight,
@@ -863,10 +868,10 @@ function block_edit_controls($block, $page) {
if ($block->user_can_edit() && $page->user_can_edit_blocks()) {
// Show/hide icon.
if ($block->instance->visible) {
$controls[] = array('url' => $actionurl . '&action=hide',
$controls[] = array('url' => $actionurl . '&bui_hideid=' . $block->instance->id,
'icon' => 't/hide', 'caption' => get_string('hide'));
} else {
$controls[] = array('url' => $actionurl . '&action=show',
$controls[] = array('url' => $actionurl . '&bui_showid=' . $block->instance->id,
'icon' => 't/show', 'caption' => get_string('show'));
}
@@ -970,7 +975,29 @@ function block_process_url_delete($page) {
* @return boolean true if anything was done. False if not.
*/
function block_process_url_show_hide($page) {
// TODO MDL-19398
if ($blockid = optional_param('bui_hideid', null, PARAM_INTEGER)) {
$newvisibility = 0;
} else if ($blockid = optional_param('bui_showid', null, PARAM_INTEGER)) {
$newvisibility = 1;
} else {
return false;
}
confirm_sesskey();
$block = $page->blocks->find_instance($blockid);
if (!$block->user_can_edit() || !$page->user_can_edit_blocks()) {
throw new moodle_exception('nopermissions', '', $page->url->out(), get_string('hideshowblocks'));
}
blocks_set_visibility($block->instance, $page, $newvisibility);
// If the page URL was a guses, it will contain the bui_... param, so we must make sure it is not there.
$page->ensure_param_not_in_url('bui_hideid');
$page->ensure_param_not_in_url('bui_showid');
return true;
}
///**
@@ -1099,6 +1126,36 @@ function blocks_delete_all_for_context($contextid) {
$DB->delete_records('block_positions', array('contextid' => $contextid));
}
/**
* Set a block to be visible or hidden on a particular page.
*
* @param object $instance a row from the block_instances, preferably LEFT JOINed with the
* block_positions table as return by block_manager.
* @param moodle_page $page the back to set the visibility with respect to.
* @param integer $newvisibility 1 for visible, 0 for hidden.
*/
function blocks_set_visibility($instance, $page, $newvisibility) {
global $DB;
if (!empty($instance->blockpositionid)) {
// Already have local information on this page.
$DB->set_field('block_positions', 'visible', $newvisibility, array('id' => $instance->blockpositionid));
return;
}
// Create a new block_positions record.
$bp = new stdClass;
$bp->blockinstanceid = $instance->id;
$bp->contextid = $page->context->id;
$bp->pagetype = $page->pagetype;
if ($page->subpage) {
$bp->subpage = $page->subpage;
}
$bp->visible = $newvisibility;
$bp->region = $instance->defaultregion;
$bp->weight = $instance->defaultweight;
$DB->insert_record('block_positions', $bp);
}
/**
* @deprecated since 2.0
* Delete all the blocks from a particular page.
+2 -2
View File
@@ -1932,7 +1932,7 @@ class moodle_core_renderer extends moodle_renderer_base {
echo '<table id="layout-table"><tr>';
foreach ($lt as $column) {
if ($column == 'left' && $this->page->blocks->region_has_content(BLOCK_POS_LEFT)) {
echo '<td id="left-column" style="width: ' . $preferredwidthright . 'px; vertical-align: top;">';
echo '<td id="left-column" class="block-region" style="width: ' . $preferredwidthright . 'px; vertical-align: top;">';
echo $this->container_start();
echo $this->blocks_for_region(BLOCK_POS_LEFT);
echo $this->container_end();
@@ -1947,7 +1947,7 @@ class moodle_core_renderer extends moodle_renderer_base {
echo '</td>';
} else if ($column == 'right' && $this->page->blocks->region_has_content(BLOCK_POS_RIGHT)) {
echo '<td id="right-column" style="width: ' . $preferredwidthright . 'px; vertical-align: top;">';
echo '<td id="right-column" class="block-region" style="width: ' . $preferredwidthright . 'px; vertical-align: top;">';
echo $this->container_start();
echo $this->blocks_for_region(BLOCK_POS_RIGHT);
echo $this->container_end();