]> git.mjollnir.org Git - moodle.git/commitdiff
blocklib: MDL-19010 fix editing block config and block roles.
authortjhunt <tjhunt>
Fri, 8 May 2009 07:47:50 +0000 (07:47 +0000)
committertjhunt <tjhunt>
Fri, 8 May 2009 07:47:50 +0000 (07:47 +0000)
admin/roles/tabs.php
blocks/moodleblock.class.php
lib/accesslib.php
lib/blocklib.php

index bedf540101071aa2552901fa6de2b580c8763488..1d37a0dfa4c27ea44680be3f1d5f44d69c1b5554 100755 (executable)
@@ -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;
 
index a92534922aebb9bdf16e4c180cc94c0c37330f6c..72e4eec81b9b7c62ebf50e4c9432a6b0df7e0725 100644 (file)
@@ -460,7 +460,8 @@ class block_base {
         $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.'&amp;blockaction=toggle">' .
                             '<img src="'. $CFG->pixpath.$icon .'" alt="'.$title.'" /></a>';
         }
@@ -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));
     }
 
     /**
index 01afc631f7210e048f722f69b8febe83ce674da1..dc2c239d6b3782fa6504fec408303bcc5b89dd07 100755 (executable)
@@ -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:
index 4f6208e317f735b81a33a24ff0ef79b742607cc6..11e9225e097fda2afc315d4bb4bedf0a29458e24 100644 (file)
@@ -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 '<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':