Conditionally override block

A place for users and developers of the Xataface to discuss and receive support.

Conditionally override block

Postby Gershy » Tue Jan 29, 2013 2:03 pm

Hi everyone!

The users of my application have an authority level. All levels ought to be able to view a table called "Applications" but for some levels I would like to override the main column block to display different information within the same table tab.

The behaviour I'm looking for is comparable to delegating to a superclass, however this isn't feasible as the table delegate class has no superclass. Here's what I mean:

Code: Select all
function block__main_column() {
    $user = Dataface_AuthenticationTool::getInstance()->getLoggedInUser();
    $authority = $user->val('Authority');

    if ($authority == 'Overridden Behaviour') {
        //Perform custom main_column decoration here
    } else if ($authority == 'Normal Behaviour') {
        parent::block__main_column();
    }
}

Considering that the "parent::block__main_column();" call cannot be performed (due to lack of a superclass), how ought I go about imitating the above mechanism?

Thanks in advance!
-Gersh
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Conditionally override block

Postby shannah » Tue Jan 29, 2013 2:17 pm

If you return a PEAR_Error from the block method, then it will ignore your block and use the default.

e.g.
Code: Select all
function block__myblock(){
    if ( /*some condition*/ ){
        echo "My block content";
    } else {
        return PEAR::raiseError("Just use the default block");
    }
}
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Conditionally override block

Postby Gershy » Tue Jan 29, 2013 2:33 pm

Terrific. I would have never guessed that. Thanks for the quick response!

-Gershy
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Conditionally override block

Postby Gershy » Thu Jan 31, 2013 5:34 pm

Also I presume that if I want to conditionally APPEND the default behaviour (as opposed to just overriding it) I ought to use write a block__after_main_column method in the delegate class, correct?...
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Conditionally override block

Postby shannah » Mon Feb 04, 2013 9:37 am

Yes. I can't think of an easy way to "append" to a block, rather than override it. You would have to look for a different block. In many cases there are after_xxx blocks that accompany the xxx block.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved