Moodle  2.2.1
http://www.collinsharper.com
block_manager Class Reference
Inheritance diagram for block_manager:

Public Member Functions

 __construct ($page)
 Constructor ================================================================.
 get_regions ()
 Getter methods =============================================================.
 get_default_region ()
 get_addable_blocks ()
 is_block_present ($blockname)
 is_known_block_type ($blockname, $includeinvisible=false)
 is_known_region ($region)
 get_blocks_for_region ($region)
 get_content_for_region ($region, $output)
 region_has_content ($region, $output)
 get_installed_blocks ()
 add_region ($region)
 Setter methods =============================================================.
 add_regions ($regions)
 set_default_region ($defaultregion)
 add_fake_block ($bc, $region)
 add_pretend_block ($bc, $region)
 region_completely_docked ($region, $output)
 region_uses_dock ($regions, $output)
 load_blocks ($includeinvisible=null)
 Actions ====================================================================.
 add_block ($blockname, $region, $weight, $showinsubcontexts, $pagetypepattern=NULL, $subpagepattern=NULL)
 add_block_at_end_of_default_region ($blockname)
 add_blocks ($blocks, $pagetypepattern=NULL, $subpagepattern=NULL, $showinsubcontexts=false, $weight=0)
 reposition_block ($blockinstanceid, $newregion, $newweight)
 find_instance ($instanceid)
 create_all_block_instances ()
 edit_controls ($block)
 Process actions from the URL ===============================================.
 process_url_actions ()
 process_url_add ()
 process_url_delete ()
 process_url_show_hide ()
 process_url_edit ()
 process_url_move ()
 show_only_fake_blocks ($setting=true)

Data Fields

const MAX_WEIGHT = 10

Protected Member Functions

 get_move_target_url ($region, $weight)
 check_not_yet_loaded ()
 Inner workings =============================================================.
 check_is_loaded ()
 check_known_block_type ($blockname, $includeinvisible=false)
 check_region_is_known ($region)
 prepare_per_region_arrays ()
 create_block_instances ($birecords)
 create_block_contents ($instances, $output, $region)
 ensure_instances_exist ($region)
 ensure_content_created ($region, $output)

Protected Attributes

 $page
 $regions = array()
 $defaultregion = null
 $allblocks = null
 $addableblocks = null
 $birecordsbyregion = null
 $blockinstances = array()
 $visibleblockcontent = array()
 $extracontent = array()
 $movingblock = null
 $fakeblocksonly = false

Detailed Description

This class keeps track of the block that should appear on a moodle_page.

The page to work with as passed to the constructor.

Since:
Moodle 2.0

Definition at line 94 of file blocklib.php.


Constructor & Destructor Documentation

__construct ( page)

Constructor ================================================================.

Constructor.

Parameters:
object$pagethe moodle_page object object we are managing the blocks for, or a reasonable faxilimily. (See the comment at the top of this class and http://en.wikipedia.org/wiki/Duck_typing)

Definition at line 176 of file blocklib.php.


Member Function Documentation

add_block ( blockname,
region,
weight,
showinsubcontexts,
pagetypepattern = NULL,
subpagepattern = NULL 
)

Add a block to the current page, or related pages. The block is added to context $this->page->contextid. If $pagetypepattern $subpagepattern

Parameters:
string$blocknameThe type of block to add.
string$regionthe block region on this page to add the block to.
integer$weightdetermines the order where this block appears in the region.
boolean$showinsubcontextswhether this block appears in subcontexts, or just the current context.
string | null$pagetypepatternwhich page types this block should appear on. Defaults to just the current page type.
string | null$subpagepatternwhich subpage this block should appear on. NULL = any (the default), otherwise only the specified subpage.

Definition at line 634 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 665 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

add_blocks ( blocks,
pagetypepattern = NULL,
subpagepattern = NULL,
showinsubcontexts = false,
weight = 0 
)

Convenience method, calls add_block repeatedly for all the blocks in $blocks.

Parameters:
array$blocksarray with array keys the region names, and values an array of block names.
string$pagetypepatternoptional. Passed to
See also:
add_block()
Parameters:
string$subpagepatternoptional. Passed to
See also:
add_block()

Definition at line 716 of file blocklib.php.

Here is the call graph for this function:

add_fake_block ( bc,
region 
)

Add something that looks like a block, but which isn't an actual block_instance, to this page.

Parameters:
block_contents$bcthe content of the block-like thing.
string$regiona block region that exists on this page.

Definition at line 421 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

add_pretend_block ( bc,
region 
)

When the block_manager class was created, the add_fake_block() was called add_pretend_block, which is inconsisted with show_only_fake_blocks(). To fix this inconsistency, this method was renamed to add_fake_block. Please update your code.

Parameters:
block_contents$bcthe content of the block-like thing.
string$regiona block region that exists on this page.

Definition at line 441 of file blocklib.php.

Here is the call graph for this function:

add_region ( region)

Setter methods =============================================================.

Add a region to a page

Parameters:
string$regionadd a named region where blocks may appear on the current page. This is an internal name, like 'side-pre', not a string to display in the UI.

Definition at line 382 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

add_regions ( regions)

Add an array of regions

See also:
add_region()
Parameters:
array$regionsthis utility method calls add_region for each array element.

Definition at line 393 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

check_is_loaded ( ) [protected]

Check whether the page blocks have been loaded yet

Nearly identical to the above function check_not_yet_loaded() except different message

Returns:
void Throws coding exception if already loaded

Definition at line 826 of file blocklib.php.

Here is the caller graph for this function:

check_known_block_type ( blockname,
includeinvisible = false 
) [protected]

Check if a block type is known and usable

Parameters:
string$blocknameThe block type name to search for
bool$includeinvisibleInclude disabled block types in the initial pass
Returns:
void Coding Exception thrown if unknown or not enabled

Definition at line 839 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

check_not_yet_loaded ( ) [protected]

Inner workings =============================================================.

Check whether the page blocks have been loaded yet

Returns:
void Throws coding exception if already loaded

Definition at line 813 of file blocklib.php.

Here is the caller graph for this function:

check_region_is_known ( region) [protected]

Check if a region is known by its name

Parameters:
string$region
Returns:
void Coding Exception thrown if the region is not known

Definition at line 855 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Create all the block instances for all the blocks that were loaded by load_blocks. This is used, for example, to ensure that all blocks get a chance to initialise themselves via the block_base::specialize() method, before any output is done.

Definition at line 897 of file blocklib.php.

Here is the call graph for this function:

create_block_contents ( instances,
output,
region 
) [protected]

Return an array of content objects from a set of block instances

Parameters:
array$instancesAn array of block instances
renderer_baseThe renderer to use.
string$regionthe region name.
Returns:
array An array of block_content (and possibly block_move_target) objects.

Definition at line 911 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

create_block_instances ( birecords) [protected]

Create a set of new block instance from a record array

Parameters:
array$birecordsAn array of block instance records
Returns:
array An array of instantiated block_instance objects

Definition at line 881 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

edit_controls ( block)

Process actions from the URL ===============================================.

Get the appropriate list of editing icons for a block. This is used to set block_contents::$controls in block_base::get_contents_for_output().

Parameters:
$outputThe core_renderer to use when generating the output. (Need to get icon paths.)
Returns:
an array in the format for block_contents::$controls

Definition at line 998 of file blocklib.php.

Here is the call graph for this function:

ensure_content_created ( region,
output 
) [protected]

Ensure that there is some content within the given region

Parameters:
string$regionThe name of the region to check

Definition at line 971 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

ensure_instances_exist ( region) [protected]

Ensure block instances exist for a given region

Parameters:
string$regionCheck for bi's with the instance with this name

Definition at line 958 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

find_instance ( instanceid)

Find a given block by its instance id

Parameters:
integer$instanceid
Returns:
object

Definition at line 794 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

The list of block types that may be added to this page.

Returns:
array block name => record from block table.

Definition at line 212 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_blocks_for_region ( region)

Get an array of all blocks within a given region

Parameters:
string$regiona block region that exists on this page.
Returns:
array of block instances.

Definition at line 297 of file blocklib.php.

Here is the call graph for this function:

get_content_for_region ( region,
output 
)

Returns an array of block content objects that exist in a region

Parameters:
string$regiona block region that exists on this page.
Returns:
array of block block_contents objects for all the blocks in a region.

Definition at line 309 of file blocklib.php.

Here is the call graph for this function:

Get the region name of the region blocks are added to by default

Returns:
string the internal names of the region where new blocks are added by default, and where any blocks from an unrecognised region are shown. (Imagine that blocks were added with one theme selected, then you switched to a theme with different block positions.)

Definition at line 202 of file blocklib.php.

Here is the caller graph for this function:

Get an array of all of the installed blocks.

Returns:
array contents of the block table.

Definition at line 365 of file blocklib.php.

Here is the caller graph for this function:

get_move_target_url ( region,
weight 
) [protected]

Helper method used by get_content_for_region.

Parameters:
string$regionregion name
float$weightweight. May be fractional, since you may want to move a block between ones with weight 2 and 3, say ($weight would be 2.5).
Returns:
string URL for moving block $this->movingblock to this position.

Definition at line 322 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Getter methods =============================================================.

Get an array of all region names on this page where a block may appear

Returns:
array the internal names of the regions on this page where block may appear.

Definition at line 187 of file blocklib.php.

Here is the caller graph for this function:

is_block_present ( blockname)

Given a block name, find out of any of them are currently present in the page

Parameters:
string$blockname- the basic name of a block (eg "navigation")
Returns:
boolean - is there one of these blocks in the current page?

Definition at line 246 of file blocklib.php.

is_known_block_type ( blockname,
includeinvisible = false 
)

Find out if a block type is known by the system

Parameters:
string$blocknamethe name of the type of block.
boolean$includeinvisibleif false (default) only check 'visible' blocks, that is, blocks enabled by the admin.
Returns:
boolean true if this block in installed.

Definition at line 271 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

is_known_region ( region)

Find out if a region exists on a page

Parameters:
string$regiona region name
Returns:
boolean true if this region exists on this page.

Definition at line 287 of file blocklib.php.

Here is the caller graph for this function:

load_blocks ( includeinvisible = null)

Actions ====================================================================.

This method actually loads the blocks for our page from the database.

Parameters:
boolean | null$includeinvisiblenull (default) - load hidden blocks if $this->page->user_is_editing(); true - load hidden blocks. false - don't load hidden blocks.

Reimplemented in my_syspage_block_manager.

Definition at line 500 of file blocklib.php.

Here is the call graph for this function:

prepare_per_region_arrays ( ) [protected]

Returns an array of region names as keys and nested arrays for values

Returns:
array an array where the array keys are the region names, and the array values are empty arrays.

Definition at line 867 of file blocklib.php.

Here is the caller graph for this function:

Process any block actions that were specified in the URL.

Returns:
boolean true if anything was done. False if not.

Definition at line 1066 of file blocklib.php.

Here is the call graph for this function:

Handle adding a block.

Returns:
boolean true if anything was done. False if not.

Definition at line 1079 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Handle deleting a block.

Returns:
boolean true if anything was done. False if not.

Definition at line 1107 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Handle showing/processing the submission from the block editing form.

Returns:
boolean true if the form was submitted and the new config saved. Does not return if the editing form was displayed. False otherwise.

Definition at line 1166 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Handle showing/processing the submission from the block editing form.

Returns:
boolean true if the form was submitted and the new config saved. Does not return if the editing form was displayed. False otherwise.

Definition at line 1364 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Handle showing or hiding a block.

Returns:
boolean true if anything was done. False if not.

Definition at line 1133 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

region_completely_docked ( region,
output 
)

Checks to see whether all of the blocks within the given region are docked

See also:
region_uses_dock
Parameters:
string$region
Returns:
bool True if all of the blocks within that region are docked

Definition at line 453 of file blocklib.php.

Here is the call graph for this function:

region_has_content ( region,
output 
)

Determine whether a region contains anything. (Either any real blocks, or the add new block UI.)

(You may wonder why the $output parameter is required. Unfortunately, because of the way that blocks work, the only reliable way to find out if a block will be visible is to get the content for output, and to get the content, you need a renderer. Fortunately, this is not a performance problem, because we cache the output that is generated, and in almost every case where we call region_has_content, we are about to output the blocks anyway, so we are not doing wasted effort.)

Parameters:
string$regiona block region that exists on this page.
object$outputa core_renderer. normally the global $OUTPUT.
Returns:
boolean Whether there is anything in this region.

Definition at line 343 of file blocklib.php.

Here is the call graph for this function:

region_uses_dock ( regions,
output 
)

Checks to see whether any of the blocks within the given regions are docked

See also:
region_completely_docked
Parameters:
array | string$regionsarray of regions (or single region)
Returns:
bool True if any of the blocks within that region are docked

Definition at line 474 of file blocklib.php.

Here is the call graph for this function:

reposition_block ( blockinstanceid,
newregion,
newweight 
)

Move a block to a new position on this page.

If this block cannot appear on any other pages, then we change defaultposition/weight in the block_instances table. Otherwise we just set the position on this page.

Parameters:
$blockinstanceidthe block instance id.
$newregionthe new region name.
$newweightthe new weight.

Definition at line 737 of file blocklib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

set_default_region ( defaultregion)

Set the default region for new blocks on the page

Parameters:
string$defaultregionthe internal names of the region where new blocks should be added by default, and where any blocks from an unrecognised region are shown.

Definition at line 406 of file blocklib.php.

Here is the call graph for this function:

show_only_fake_blocks ( setting = true)

Turns the display of normal blocks either on or off.

Parameters:
bool$setting

Definition at line 1490 of file blocklib.php.


Field Documentation

$addableblocks = null [protected]

Definition at line 123 of file blocklib.php.

$allblocks = null [protected]

Definition at line 116 of file blocklib.php.

$birecordsbyregion = null [protected]

Definition at line 129 of file blocklib.php.

$blockinstances = array() [protected]

Definition at line 136 of file blocklib.php.

$defaultregion = null [protected]

Definition at line 113 of file blocklib.php.

$extracontent = array() [protected]

Definition at line 150 of file blocklib.php.

$fakeblocksonly = false [protected]

Show only fake blocks

Definition at line 166 of file blocklib.php.

$movingblock = null [protected]

Definition at line 161 of file blocklib.php.

$page [protected]

Definition at line 107 of file blocklib.php.

$regions = array() [protected]

Definition at line 110 of file blocklib.php.

$visibleblockcontent = array() [protected]

Definition at line 143 of file blocklib.php.

const MAX_WEIGHT = 10

The UI normally only shows block weights between -MAX_WEIGHT and MAX_WEIGHT, although other weights are valid.

Definition at line 99 of file blocklib.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations