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;
$movebuttons .= '<a class="icon roles" title="'. $this->str->assignroles .'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">' .
'<img src="'.$CFG->pixpath.'/i/roles.gif" alt="'.$this->str->assignroles.'" /></a>';
- if ($this->user_can_edit()) {
+ // TODO MDL-19010 fix and re-enable.
+ if (false && $this->user_can_edit()) {
$movebuttons .= '<a class="icon hide" title="'. $title .'" href="'.$script.'&blockaction=toggle">' .
'<img src="'. $CFG->pixpath.$icon .'" alt="'.$title.'" /></a>';
}
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));
}
/**
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";
WHERE (contextlevel = ".CONTEXT_BLOCK."
AND component = :component)
$extra";
- $params['component'] = "block/$block->name";
+ $params['component'] = 'block/' . $bi->blockname;
break;
default:
$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();
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'
);
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 '<div class="block-config" id="'.$block->name.'">'; /// Make CSS easier
+ echo '<div class="block-config" id="'.$instance->name().'">'; /// Make CSS easier
print_heading($strheading);
echo '<form method="post" name="block-config" action="'. $page->url->out(false) .'">';
echo '<p>';
- foreach($hiddendata as $name => $val) {
- echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
- }
+ echo $page->url->hidden_params_out(array(), 0, $hiddendata);
echo '</p>';
- $blockobject->instance_config_print();
+ $instance->instance_config_print();
echo '</form>';
echo '</div>';
- $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':