From: tjhunt Date: Fri, 8 May 2009 07:47:50 +0000 (+0000) Subject: blocklib: MDL-19010 fix editing block config and block roles. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e03c0c1d49dad7f1d7ccaecee33dfde324f3027f;p=moodle.git blocklib: MDL-19010 fix editing block config and block roles. --- diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php index bedf540101..1d37a0dfa4 100755 --- a/admin/roles/tabs.php +++ b/admin/roles/tabs.php @@ -118,54 +118,39 @@ if ($currenttab != 'update') { break; case CONTEXT_BLOCK: - if ($blockinstance = $DB->get_record('block_instance_old', array('oldid'=>$context->instanceid))) { - if ($block = $DB->get_record('block', array('id'=>$blockinstance->blockid))) { - $blockname = print_context_name($context); - - - switch ($blockinstance->pagetype) { - case 'course-view': - if ($course = $DB->get_record('course', array('id'=>$blockinstance->pageid))) { - - require_login($course); - - $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc'); - $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); - $navigation = build_navigation($navlinks); - print_header("$straction: $blockname", $course->fullname, $navigation); - } - break; - - case 'blog-view': - $strblogs = get_string('blogs','blog'); - $navlinks[] = array('name' => $strblogs, - 'link' => $CFG->wwwroot.'/blog/index.php', - 'type' => 'misc'); - $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc'); - $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); - $navigation = build_navigation($navlinks); - print_header("$straction: $strblogs", $SITE->fullname, $navigation); - break; - - case 'tag-index': - $strtags = get_string('tags'); - $navlinks[] = array('name' => $strtags, - 'link' => $CFG->wwwroot.'/tag/index.php', - 'type' => 'misc'); - $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc'); - $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); - $navigation = build_navigation($navlinks); - print_header("$straction: $strtags", $SITE->fullname, $navigation); - break; - - default: - $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc'); - $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); - $navigation = build_navigation($navlinks); - print_header("$straction: $blockname", $SITE->fullname, $navigation); - break; - } + if ($blockinstance = $DB->get_record('block_instances', array('id' => $context->instanceid))) { + $blockname = print_context_name($context); + + $parentcontext = get_context_instance_by_id($blockinstance->contextid); + $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc'); + $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); + switch ($parentcontext->contextlevel) { + case CONTEXT_SYSTEM: + break; + + case CONTEXT_COURSECAT: + $PAGE->set_category_by_id($parentcontext->instanceid); + break; + + case CONTEXT_COURSE: + require_login($parentcontext->instanceid); + break; + + case CONTEXT_MODULE: + $cm = get_coursemodule_from_id('', $parentcontext->instanceid); + require_login($parentcontext->instanceid, false, $cm); + break; + + case CONTEXT_USER: + break; + + default: + throw new invalid_state_exception('Block context ' . $blockname . + ' has parent context with an improper contextlevel ' . $parentcontext->contextlevel); + + } + print_header("$straction: $blockname", $PAGE->course->fullname, build_navigation($navlinks)); } break; diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index a92534922a..72e4eec81b 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -460,7 +460,8 @@ class block_base { $movebuttons .= '' . ''.$this->str->assignroles.''; - if ($this->user_can_edit()) { + // TODO MDL-19010 fix and re-enable. + if (false && $this->user_can_edit()) { $movebuttons .= '' . ''.$title.''; } @@ -713,7 +714,7 @@ class block_base { function instance_config_save($data, $nolongerused = false) { global $DB; $DB->set_field('block_instances', 'configdata', base64_encode(serialize($data)), - array($field => $this->instance->id)); + array('id' => $this->instance->id)); } /** diff --git a/lib/accesslib.php b/lib/accesslib.php index 01afc631f7..dc2c239d6b 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3594,10 +3594,10 @@ function fetch_context_capabilities($context) { break; case CONTEXT_BLOCK: // block caps - $cb = $DB->get_record('block_instances', array('id'=>$context->instanceid)); + $bi = $DB->get_record('block_instances', array('id' => $context->instanceid)); $extra = ''; - $extracaps = block_method_result($cb->blockname, 'get_extra_capabilities'); + $extracaps = block_method_result($bi->blockname, 'get_extra_capabilities'); if ($extracaps) { list($extra, $params) = $DB->get_in_or_equal($extracaps, SQL_PARAMS_NAMED, 'cap0'); $extra = "OR name $extra"; @@ -3608,7 +3608,7 @@ function fetch_context_capabilities($context) { WHERE (contextlevel = ".CONTEXT_BLOCK." AND component = :component) $extra"; - $params['component'] = "block/$block->name"; + $params['component'] = 'block/' . $bi->blockname; break; default: diff --git a/lib/blocklib.php b/lib/blocklib.php index 4f6208e317..11e9225e09 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -384,6 +384,10 @@ class block_manager implements ArrayAccess { $blockinstance->configdata = ''; $blockinstance->id = $DB->insert_record('block_instances', $blockinstance); + if ($this->page->context->contextlevel == CONTEXT_COURSE) { + get_context_instance(CONTEXT_BLOCK, $blockinstance->id); + } + // If the new instance was created, allow it to do additional setup if($block = block_instance($blockname, $blockinstance)) { $block->instance_create(); @@ -872,29 +876,19 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori switch($blockaction) { case 'config': - $block = blocks_get_record($instance->blockid); - // Hacky hacky tricky stuff to get the original human readable block title, - // even if the block has configured its title to be something else. - // Create the object WITHOUT instance data. - $blockobject = block_instance($block->name); - if ($blockobject === false) { - break; - } - // First of all check to see if the block wants to be edited - if(!$blockobject->user_can_edit()) { + if(!$instance->user_can_edit()) { break; } // Now get the title and AFTER that load up the instance - $blocktitle = $blockobject->get_title(); - $blockobject->_load_instance($instance); + $blocktitle = $instance->get_title(); // Define the data we're going to silently include in the instance config form here, // so we can strip them from the submitted data BEFORE serializing it. $hiddendata = array( 'sesskey' => sesskey(), - 'instanceid' => $instance->id, + 'instanceid' => $instance->instance->id, 'blockaction' => 'config' ); @@ -906,32 +900,30 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori foreach($remove as $item) { unset($data->$item); } - if(!$blockobject->instance_config_save($data, $pinned)) { - print_error('cannotsaveblock'); - } - // And nothing more, continue with displaying the page - } - else { + $instance->instance_config_save($data); + redirect($page->url->out()); + + } else { // We need to show the config screen, so we highjack the display logic and then die $strheading = get_string('blockconfiga', 'moodle', $blocktitle); - $page->print_header(get_string('pageheaderconfigablock', 'moodle'), array($strheading => '')); + $nav = build_navigation($strheading, $page->cm); + print_header($strheading, $strheading, $nav); - echo '
'; /// Make CSS easier + echo '
'; /// Make CSS easier print_heading($strheading); echo '
'; echo '

'; - foreach($hiddendata as $name => $val) { - echo ''; - } + echo $page->url->hidden_params_out(array(), 0, $hiddendata); echo '

'; - $blockobject->instance_config_print(); + $instance->instance_config_print(); echo '
'; echo '
'; - $PAGE->set_pagetype('blocks-' . $block->name); + global $PAGE; + $PAGE->set_docs_path('blocks/' . $instance->name()); print_footer(); - die(); // Do not go on with the other page-related stuff + die; // Do not go on with the other page-related stuff } break; case 'toggle':