Forums | Mahara Community

Support /
Access Items in $SIDEBLOCK


anonymous profile picture
Account deleted
Posts: 34

21 July 2009, 15:07

How do you acces individual parts of the $SIDEBLOCK array?  Ex: in the sideblock, if you have a new message it says '1 New Message' in the sidebar.

I want to take those individual fields and place them where ever I want.  The only thing is I don't know how to access the Friends Request and the New Message.  

I want to place those two fields in the header section and I don't know how to call only those two parts from the $SIDEBLOCK array.  Any help would be great!

anonymous profile picture
Account deleted
Posts: 117

21 July 2009, 15:28

The friend request, I'm not sure about.  Haven't messed with it yet.  But, to display unread messages in the header, open lib/web.php and make the following change:

Find (should be around line #366):

    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    if ($USER->is_logged_in()) {
        $smarty->assign('MAINNAV', main_nav());
    }
    else {
        $smarty->assign('sitedefaultlang', get_string('sitedefault', 'admin') . ' (' .
                        get_string_from_language(get_config('lang'), 'thislanguage') . ')');
        $smarty->assign('LANGUAGES', get_languages());
    }

and right under (or right before):

$smarty->assign('MAINNAV', main_nav());

add:

$smarty->assign('UNREAD_MESSAGES', count_records('notification_internal_activity', 'usr', $USER->get('id'), 'read', 0));
$pendingfriends = count_records('usr_friend_request', 'owner', $USER->get('id'));
$pendingfriendsmessage = $pendingfriends == 1 ? get_string('pendingfriend') : get_string('pendingfriends');
$smarty->assign('PENDINGFRIENDS', $pendingfriends);
$smarty->assign('PENDINGFRIENDS_MESSAGE', $pendingfriendsmessage);

and then in your header template, you can use the $UNREAD_MESSAGES variable anywhere you want to display the number of unread messages, $PENDINGFRIENDS to display the number of pending friends, and $PENDINGFRIENDS_MESSAGE to display "pending friend" or "pending friends" depending on the number of pending friends.

That should work. I know the unread messages part works. The pending friends part should work fine, too.

anonymous profile picture
Account deleted
Posts: 117

21 July 2009, 15:31

(Ignore this. I just updated the message above.)

anonymous profile picture
Account deleted
Posts: 34

21 July 2009, 20:39

I haven't implemented the code yet. However, looking over Stephen's code, it looks as though this may work.  I'll post again after I try this out.  Thanks Stephen!!
anonymous profile picture
Account deleted
Posts: 1643

21 July 2009, 16:43

Hi - the sideblocks are fully built in that array, which means you wouldn't be able to get the information out of $SIDEBLOCKS directly. Doing what Stephen suggests is probably how I'd do it Smile
anonymous profile picture
Account deleted
Posts: 34

22 July 2009, 9:06

This worked out well!!  Thanks again Stephen!!  I modified your code slightly.

$numofunreadmsgs = count_records('notification_internal_activity', 'usr', $USER->get('id'), 'read', 0);
$unreadmsgs = $numofunreadmsgs == 1 ? get_string('unreadmessage') : get_string('unreadmessages');
$smarty->assign('NUM_OF_UNREAD_MESSAGES', $numofunreadmsgs);
$smarty->assign('UNREAD_MESSAGES', $unreadmsgs);
$pendingfriends = count_records('usr_friend_request', 'owner', $USER->get('id'));
$pendingfriendsmessage = $pendingfriends == 1 ? get_string('pendingfriend') : get_string('pendingfriends');
$smarty->assign('PENDINGFRIENDS', $pendingfriends);
$smarty->assign('PENDINGFRIENDS_MESSAGE', $pendingfriendsmessage); 

6 results