IF THEN Statement in Public Function

Grizzly Adam

Active member
I have two statements that I want to combine into one depending on the user who owns the album. If the album owner id is 1351, I want to call the second snippet of code. Can anyone help?

Code:
    public function getBreadCrumbs(array $user, $album = array())
    {
        $breadCrumbs = array();

        $breadCrumbs['user_'.$user['user_id']] = array(
            'href' => XenForo_Link::buildPublicLink('full:useralbums/list', $user),
            'value' => new XenForo_Phrase('xfr_useralbums_xs_albums', array('name' => $user['username'])),
        );

        if (!empty($album))
        {
            $breadCrumbs[$album['album_id']] = array(
                'href' => XenForo_Link::buildPublicLink('full:useralbums/view', $album),
                'value' => XenForo_Helper_String::censorString($album['title'])
            );
        }

        return $breadCrumbs;
    }

Code:
public function getGalleryCrumbs(array $user, $album = array())
    {
   

        if (!empty($album))
        {
            $breadCrumbs[$album['album_id']] = array(
                'href' => XenForo_Link::buildPublicLink('full:useralbums/view', $album),
                'value' => XenForo_Helper_String::censorString($album['title'])
            );
        }

        return $galleryCrumbs;
    }
 
Grizzly, there really isn't enough information to help. Do you want id 1351 to run both breadCrumbs and galleryCrumbs?

Anyway, this is one control structure to call a method in an if / else - but more may be needed to get it to work, such as a global variable.

Code:
if ( $user['user_id'] == '1351' ) {
     getGalleryCrumbs();
} else {
     getBreadCrumbs();
}

Of course, one could go ternary:

http://davidwalsh.name/php-shorthand-if-else-ternary-operators

And of course - this might totally fail because the calls can't be made in this manner but need self::getGalleryCrumbs() etc etc .
 
Back
Top Bottom