]> git.mjollnir.org Git - moodle.git/commitdiff
blocklib: MDL-19010 and now you can delete blocks too!
authortjhunt <tjhunt>
Fri, 8 May 2009 06:34:40 +0000 (06:34 +0000)
committertjhunt <tjhunt>
Fri, 8 May 2009 06:34:40 +0000 (06:34 +0000)
blocks/moodleblock.class.php
course/rest.php
lang/en_utf8/error.php
lib/blocklib.php

index 41b8d6b482e9051c1d13a4af13673c1e62ac14bf..a92534922aebb9bdf16e4c180cc94c0c37330f6c 100644 (file)
@@ -455,7 +455,7 @@ class block_base {
         }
 
         $page = $this->page;
-        $script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey()));
+        $script = $page->url->out(false, array('instanceid' => $this->instance->id, 'sesskey' => sesskey()));
 
         $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>';
index 5e803eb1f1ce7c3fa2203ad3cfe80a689c3ee020..94541198098b7bab939455d4bfbdeab6980d1172 100644 (file)
@@ -29,12 +29,13 @@ $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
 $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
 
 if (!empty($instanceid)) {
-    $blockinstance = blocks_find_instance($instanceid, $pageblocks);
-    if (!$blockinstance || $blockinstance->pageid != $course->id
-                        || $blockinstance->pagetype != 'course-view') {
-        error_log('AJAX commands.php: Bad block ID '.$instanceid);
-        die;
-    }
+    throw new moodle_exception('ajax blocks editing currently broken. MDL-19010');
+//    $blockinstance = blocks_find_instance($instanceid, $pageblocks);
+//    if (!$blockinstance || $blockinstance->pageid != $course->id
+//                        || $blockinstance->pagetype != 'course-view') {
+//        error_log('AJAX commands.php: Bad block ID '.$instanceid);
+//        die;
+//    }
 }
 
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
index aae3df3732108ae74ccc1751283e14601ff62779..cc63f07081f34044d5cc864bde0e15be548f852e 100644 (file)
@@ -6,6 +6,7 @@ $string['adminprimarynoedit'] = 'The primary admin cannot be edited by others';
 $string['authnotexisting'] = 'The autorization plugin doesn\'t exist';
 $string['authorizeerror'] = 'Authorize error';
 $string['blockdoesnotexist'] = 'This block does not exist';
+$string['blockdoesnotexistonpage'] = 'This block (id=$a->instanceid) does not exist on this page ($a->url).';
 $string['blockcannotinistantiate'] = 'Problem in instantiating block object';
 $string['blockcannotread'] = 'Could not read data for blockid= $a ';
 $string['blockcannotconfig'] = 'This block does not support global configuration';
index 7df64a96ab78ef5403897cc73f7cdd21b12e5a4a..4f6208e317f735b81a33a24ff0ef79b742607cc6 100644 (file)
@@ -45,6 +45,15 @@ define('BLOCKS_PINNED_BOTH',2);
 
 require_once($CFG->libdir.'/pagelib.php');
 
+class block_not_on_page_exception extends moodle_exception {
+    public function __construct($instanceid, $page) {
+        $a = new stdClass;
+        $a->instanceid = $instanceid;
+        $a->url = $page->url;
+        parent::__construct('blockdoesnotexistonpage', '', $page->url, $a);
+    }
+}
+
 /**
  * This class keeps track of the block that should appear on a moodle_page.
  * The page to work with as passed to the constructor.
@@ -398,6 +407,23 @@ class block_manager implements ArrayAccess {
         }
     }
 
+    /**
+     * 
+     * @param integer $instanceid
+     * @return unknown_type
+     */
+    public function find_instance($instanceid) {
+        foreach ($this->regions as $region => $notused) {
+            $this->ensure_instances_exist($region);
+            foreach($this->blockinstances[$region] as $instance) {
+                if ($instance->instance->id == $instanceid) {
+                    return $instance;
+                }
+            }
+        }
+        throw new block_not_on_page_exception($instanceid, $this->page);
+    }
+
 /// Inner workings =============================================================
 
     /**
@@ -681,7 +707,9 @@ function blocks_name_allowed_in_format($name, $pageformat) {
  * @param $skipblockstables for internal use only. Makes @see blocks_delete_all_for_context() more efficient.
  */
 function blocks_delete_instance($instance, $nolongerused = false, $skipblockstables = false) {
-    if ($block = block_instance($block->blockname, $instance)) {
+    global $DB;
+
+    if ($block = block_instance($instance->blockname, $instance)) {
         $block->instance_delete();
     }
     delete_context(CONTEXT_BLOCK, $instance->id);
@@ -822,22 +850,10 @@ function blocks_find_block($blockid, $blocksarray) {
     return false;
 }
 
-function blocks_find_instance($instanceid, $blocksarray) {
-    foreach($blocksarray as $subarray) {
-        foreach($subarray as $instance) {
-            if($instance->id == $instanceid) {
-                return $instance;
-            }
-        }
-    }
-    return false;
-}
-
 // Simple entry point for anyone that wants to use blocks
 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
-    // TODO deprecate.
-    blocks_execute_url_action($page, $blockmanager,($pinned==BLOCKS_PINNED_TRUE));
     $page->blocks->load_blocks();
+    blocks_execute_url_action($page, $page->blocks);
     return $page->blocks;
 }
 
@@ -933,7 +949,7 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori
             if(empty($instance))  {
                 print_error('invalidblockinstance', '', '', $blockaction);
             }
-            blocks_delete_instance($instance, $pinned);
+            blocks_delete_instance($instance->instance, $pinned);
         break;
         case 'moveup':
             if(empty($instance))  {
@@ -1080,10 +1096,8 @@ function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
 
     if (!empty($blockid)) {
         blocks_execute_action($PAGE, $blockmanager, strtolower($blockaction), $blockid, $pinned);
-
-    }
-    else if (!empty($instanceid)) {
-        $instance = blocks_find_instance($instanceid, $blockmanager);
+    } else if (!empty($instanceid)) {
+        $instance = $blockmanager->find_instance($instanceid);
         blocks_execute_action($PAGE, $blockmanager, strtolower($blockaction), $instance, $pinned);
     }
 }