blocklib: MDL-19010 once again you can add blocks, at least on the coures page.
authortjhunt <tjhunt>
Fri, 8 May 2009 03:30:58 +0000 (03:30 +0000)
committertjhunt <tjhunt>
Fri, 8 May 2009 03:30:58 +0000 (03:30 +0000)
lib/blocklib.php
lib/weblib.php

index a2d3876a81eacee9278a6d3e7f4aee355903cd90..7df64a96ab78ef5403897cc73f7cdd21b12e5a4a 100644 (file)
@@ -1051,7 +1051,7 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori
             }
 
             $region = $page->blocks->get_default_region();
-            $weight = $DB->get_field_sql("SELECT MAX(weight) FROM {block_instances} 
+            $weight = $DB->get_field_sql("SELECT MAX(defaultweight) FROM {block_instances} 
                     WHERE contextid = ? AND defaultregion = ?", array($page->context->id, $region));
             $pagetypepattern = $page->pagetype;
             if (strpos($pagetypepattern, 'course-view') === 0) {
@@ -1295,21 +1295,18 @@ function blocks_print_adminblock($page, $blockmanager) {
         $strblocks = '<div class="title"><h2>';
         $strblocks .= get_string('blocks');
         $strblocks .= '</h2></div>';
+
         $stradd    = get_string('add');
         foreach ($missingblocks as $blockid) {
             $block = blocks_get_record($blockid);
             $blockobject = block_instance($block->name);
-            if ($blockobject === false) {
-                continue;
-            }
-            if(!$blockobject->user_can_addto($page)) {
-                continue;
+            if ($blockobject !== false && $blockobject->user_can_addto($page)) {
+                $menu[$block->id] = $blockobject->get_title();
             }
-            $menu[$block->id] = $blockobject->get_title();
         }
-        asort($menu);
+        asort($menu, SORT_LOCALE_STRING);
 
-        $target = $page->url->out(array('sesskey' => sesskey(), 'blockaction' => 'add'));
+        $target = $page->url->out(false, array('sesskey' => sesskey(), 'blockaction' => 'add'));
         $content = popup_form($target.'&amp;blockid=', $menu, 'add_block', '', $stradd .'...', '', '', true);
         print_side_block($strblocks, $content, NULL, NULL, NULL, array('class' => 'block_adminblock'));
     }
index cc08fa943ff32b4637a3f5ed688123996c620248..2c67564d7f1e553010c5ec6deea79be64d687c71 100644 (file)
@@ -373,18 +373,21 @@ class moodle_url {
     /**
      * Output url
      *
-     * @param boolean $noquerystring whether to output page params as a query string in the url.
+     * @param boolean $omitquerystring whether to output page params as a query string in the url.
      * @param array $overrideparams params to add to the output url, these override existing ones with the same name.
      * @return string url
      */
-    public function out($noquerystring = false, $overrideparams = array()) {
+    public function out($omitquerystring = false, $overrideparams = array()) {
         $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): '';
         $uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':'';
         $uri .= $this->host ? $this->host : '';
         $uri .= $this->port ? ':'.$this->port : '';
         $uri .= $this->path ? $this->path : '';
-        if (!$noquerystring) {
-            $uri .= (count($this->params)||count($overrideparams)) ? '?'.$this->get_query_string($overrideparams) : '';
+        if (!$omitquerystring) {
+            $querystring = $this->get_query_string($overrideparams);
+            if ($querystring) {
+                $uri .= '?' . $querystring;
+            }
         }
         $uri .= $this->fragment ? '#'.$this->fragment : '';
         return $uri;