MDL-22054 improving blocks management UI and removing debug message because the block...
authorPetr Skoda <skodak@moodle.org>
Sun, 11 Apr 2010 12:08:40 +0000 (12:08 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 11 Apr 2010 12:08:40 +0000 (12:08 +0000)
admin/blocks.php
lib/blocklib.php

index d878e49..13e5a1c 100644 (file)
 
 /// Get and sort the existing blocks
 
 
 /// Get and sort the existing blocks
 
-    if (!$blocks = $DB->get_records('block')) {
+    if (!$blocks = $DB->get_records('block', array(), 'name ASC')) {
         print_error('noblocks', 'error');  // Should never happen
     }
 
     $incompatible = array();
 
         print_error('noblocks', 'error');  // Should never happen
     }
 
     $incompatible = array();
 
-    foreach ($blocks as $block) {
-        if (($blockobject = block_instance($block->name)) === false) {
-            // Failed to load
-            continue;
-        }
-        $blockbyname[$blockobject->get_title()] = $block->id;
-        $blockobjects[$block->id] = $blockobject;
-    }
-
-    if(empty($blockbyname)) {
-        print_error('failtoloadblocks', 'error');
-    }
-
-    ksort($blockbyname);
-
 /// Print the table of all blocks
 
     $table = new flexible_table('admin-blocks-compatible');
 /// Print the table of all blocks
 
     $table = new flexible_table('admin-blocks-compatible');
     $table->set_attribute('class', 'compatibleblockstable blockstable generaltable');
     $table->setup();
 
     $table->set_attribute('class', 'compatibleblockstable blockstable generaltable');
     $table->setup();
 
-    foreach ($blockbyname as $blockname => $blockid) {
-
-        $blockobject = $blockobjects[$blockid];
-        $block       = $blocks[$blockid];
+    foreach ($blocks as $blockid=>$block) {
+        $blockname = $block->name;
 
 
+        if (!file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) {
+            $blockobject  = false;
+            $strblockname = '<span class="notifyproblem">'.$blockname.' ('.get_string('missingfromdisk').')</span>';
+        } else {
+            if (!$blockobject  = block_instance($block->name)) {
+                $incompatible[] = $block;
+                continue;
+            }
+            $strblockname = get_string('pluginname', 'block_'.$blockname);
+        }
+        
         $delete = '<a href="blocks.php?delete='.$blockid.'&amp;sesskey='.sesskey().'">'.$strdelete.'</a>';
 
         $settings = ''; // By default, no configuration
         $delete = '<a href="blocks.php?delete='.$blockid.'&amp;sesskey='.sesskey().'">'.$strdelete.'</a>';
 
         $settings = ''; // By default, no configuration
-        if ($blockobject->has_config()) {
+        if ($blockobject and $blockobject->has_config()) {
             if (file_exists($CFG->dirroot.'/blocks/'.$block->name.'/settings.php')) {
                 $settings = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=blocksetting'.$block->name.'">'.$strsettings.'</a>';
             } else {
             if (file_exists($CFG->dirroot.'/blocks/'.$block->name.'/settings.php')) {
                 $settings = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=blocksetting'.$block->name.'">'.$strsettings.'</a>';
             } else {
         }
         $class = ''; // Nothing fancy, by default
 
         }
         $class = ''; // Nothing fancy, by default
 
-        if ($blocks[$blockid]->visible) {
+        if (!$blockobject) {
+            // ignore
+            $visible = '';
+        } else if ($blocks[$blockid]->visible) {
             $visible = '<a href="blocks.php?hide='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strhide.'">'.
                        '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon" alt="'.$strhide.'" /></a>';
         } else {
             $visible = '<a href="blocks.php?hide='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strhide.'">'.
                        '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon" alt="'.$strhide.'" /></a>';
         } else {
             $class = ' class="dimmed_text"'; // Leading space required!
         }
 
             $class = ' class="dimmed_text"'; // Leading space required!
         }
 
+
+        if ($blockobject) {
+            $blockobject->get_version();
+        }
         $table->add_data(array(
         $table->add_data(array(
-            '<span'.$class.'>'.$blockobject->get_title().'</span>',
+            '<span'.$class.'>'.$strblockname.'</span>',
             $blocklist,
             $blocklist,
-            '<span'.$class.'>'.$blockobject->get_version().'</span>',
+            '<span'.$class.'>'.$block->version.'</span>',
             $visible,
             $delete,
             $settings
             $visible,
             $delete,
             $settings
 
     $table->print_html();
 
 
     $table->print_html();
 
-    if(!empty($incompatible)) {
+    if (!empty($incompatible)) {
         echo $OUTPUT->heading(get_string('incompatibleblocks', 'blockstable', 'admin'));
 
         $table = new flexible_table('admin-blocks-incompatible');
         echo $OUTPUT->heading(get_string('incompatibleblocks', 'blockstable', 'admin'));
 
         $table = new flexible_table('admin-blocks-incompatible');
index 1977027..41a1498 100644 (file)
@@ -1369,7 +1369,7 @@ function block_load_class($blockname) {
         require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
         include_once($blockpath);
     }else{
         require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
         include_once($blockpath);
     }else{
-        debugging("$blockname code does not exist in $blockpath", DEBUG_DEVELOPER);
+        //debugging("$blockname code does not exist in $blockpath", DEBUG_DEVELOPER);
         return false;
     }
 
         return false;
     }