Patch to allow a center position for Moodle blocks

Patch to allow a center position for Moodle blocks

by Alfredo Artiles -
Number of replies: 19
Hi all, this is my first post in the Moodle Comunity, but i have a couple of years modifiying Moodle for EATCO Research Group at Córdoba's University.
This is a very simple patch to allow a center position for Moodle blocks

IMPORTANT: this patch is done for version 1.7 dev looking forward to be included in the next release. Make a backup of your current files before overwrite them or just merge this 3 files.

With this pacth the blocks can be moved to the center column over the sections area.  Using the same arrow icons on edit mode, if you move left a block that is currently at the right position then it will move to the center position
Center Blocks
Installation:
    1/Upgrade your Moodle installation to 1.7 dev or later
    2/Merge the files listed in the patch

CVS path for this contrib is: moodle.cvs.sourceforge.net/moodle/contrib/center_blocks_position_patch/

NOTE: All changes are comented in the form: //aartiles: comment
Files changes:

 - /index.php
/// aartiles: Added a center blocks position
    if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) {
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER);
    }

 - /lib/blocklib.php
 //aartiles: New block position BLOCK_POS_CENTER
define('BLOCK_POS_CENTER', 'c');

 - /lib/pagelib.php
    //aartiles: Added new block position BLOCK_POS_CENTER
    function blocks_get_positions() {
        return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT, BLOCK_POS_CENTER);
    }

    //aartiles: Changes done for complain with a center blocks position
    function blocks_move_position(&$instance, $move) {
        if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
            return BLOCK_POS_CENTER;
        } else if($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_RIGHT) {
            return BLOCK_POS_RIGHT;
        } else if ($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_LEFT) {
            return BLOCK_POS_LEFT;
        } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
            return BLOCK_POS_CENTER;
        }
        return $instance->position;
    }
   
Hope this helps some bady.
Alfredo
 
Average of ratings: -
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by N Hansen -
Alfredo-This looks useful. I have two questions. Does it work with blocks on module pages? Can one only position the block at the top of the center, or is there an option to put it at the bottom below any other content?
In reply to N Hansen

Re: Patch to allow a center position for Moodle blocks

by Alfredo Artiles -
Well, you are right, now it is only working at the index page, at course pages the blocks disapears when moved left or right because we have to do the same i did at index.php on each course format format.php.

We must add this code at format.php for each course format under middle-column td definition:

/// Start main column
    echo '<td id="middle-column">';

/// aartiles: Added a center blocks position
    if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) {
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER);
    }
///...
  
    print_heading_block(get_string('weeklyoutline'), 'outline');

I only want to show that it is very easy to add this feature and a lot of people will love it.

About the second question, for now it only can position at the top of content, but i think it is quite easy to support other positions since this part have been programmed to be very flexible by Jon Papaioannou

In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by Art Lader -
Would love to see this become standard. Is it in the Moodle Tracker - http://tracker.moodle.org/secure/Dashboard.jspa ?

-- Art
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by N Hansen -
What about module pages? Some module pages support blocks.
In reply to N Hansen

Re: Patch to allow a center position for Moodle blocks

by Alfredo Artiles -
What do you mean with module pages? Can you tell me which one?
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by N Hansen -
Some modules allow you to include blocks on their pages, for example, the quiz module. There is a setting that has to be turned on in the site administration to allow this though. But if it is turned on, you will see at the top of the quiz page on the right a button that says "Turn block editing on."
In reply to N Hansen

Re: Patch to allow a center position for Moodle blocks

by Alfredo Artiles -
As I see, the module pages manages the blocks independently, its pages inherits from page_generic_activity class, and this class have defined only one position BLOCK_POS_LEFT. So the blocks can only be placed at left position.
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by Anil Sharma -
I wish this was available for 1.9 and as a standard. We have production sites where we want the moodle blocks in the center now. Has there been any further development on this ?
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks in 1.9

by Ger Tielemans -

I like this extra block option!!

Testing for 1.9:

  • The My Page handles it also differently: how to implement it here?
    (patching /my/index.php and /my/pagelib.php seems to be enough smile)
  • If Ajax is switched on, you cannot move the blocks to the center with the cross-hair for the course overview pages. (Frontpage does not support Ajax for the blocks, so no problem there.) 
In reply to Ger Tielemans

Re: Patch to allow a center position for Moodle blocks in 1.9

by Birgit May -
Has there been any development in moving the blocks in the middle also up and down?
In reply to Birgit May

Re: Patch to allow a center position for Moodle blocks in 1.9

by Ger Tielemans -
We use this now for several months in 1.9.x in combination with pinned blocks. Especially on the My Moodle page.
After a change, you must correct the settings in the table block_pinned:
the column position (l c r)
and more important: the column weight (here are the clashes)
In reply to Ger Tielemans

Re: Patch to allow a center position for Moodle blocks in 1.9

by Carol Booth -
This looks exactly what I need. I want to display news items from one course on a wall mounted display. Having only done a small amount with php, I am struggling to follow what I need to do. Is there a kind soul out there who would like to summarise the above for the less able?
Many thanks
Carol
In reply to Ger Tielemans

Odp: Re: Patch to allow a center position for Moodle blocks in 1.9

by Marcin Stanowski -

Hi, I use 1.9.9 version and applied the aartiles patch, do not know why but it does not affect the My Moodle.

You say it is possible to patch My Moodle. How did you do that?

 

Regards,

 

Marcin

In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by Jez Blake -
Hi
I am very new to this but have installed the files for this patch. It works fine and the block (HTML block with image) moves to the middle. My problem is that it then causes a number of other areas to stop working - specifically 'site news' and 'user accounts'. Both of these areas just return a blank page. I have changed the files back and now it works fine again.

All I want to do is put an image on the top, middle of the landing page and it is giving me real problems.

Moodle is fantastic though and I am enjoying working with it.
Thanks.
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by John Skelton -
I'm having a problem using this with sticky blocks. When I move blocks with sticky blocks into the centre they disappear on the sticky blocks view but are visible in the course.

My problem is I can't move them out from the centre now, any ideas?
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by sarah ryder -
Has anyone had a problem with the show/hide functionality not working for the blocks that appear in the center?
In reply to Alfredo Artiles

Re: Patch to allow a center position for Moodle blocks

by Barbara Lawrence -
I've installed the 1.9.8 version of the patch (http://tracker.moodle.org/browse/MDL-21023). However I've found that some blocks are visible in the centre column only while editing is turned on, but when it is turned off they disappear. I've tried various blocks at random: the blog menu, calendar, course categories, global search, messages, and section links blocks are good guys and stay put, but blog tags, Latest news, and mentees blocks disappear. It happens on the front page and course pages.
Has anyone else experienced this?

I'm using (Windows, Apache 2.2.14, php 5.2.9, postgreSQL 8.2)
In reply to Barbara Lawrence

Re: Patch to allow a center position for Moodle blocks

by Barbara Lawrence -
I'm sorry, I have just realised that those blocks which were not appearing in the centre show the same behaviour in the left and right columns. I think it is probably correct, because these blocks do not have any content.