Notifications on external page using session + $notifications['unread_count']

Discuss general development subjects that are not specific to a particular version like the versioning control system we use or other infrastructure.
User avatar
extricate
Registered User
Posts: 8
Joined: Mon Dec 30, 2013 4:33 pm

Notifications on external page using session + $notifications['unread_count']

Post by extricate » Tue Mar 31, 2015 10:49 am

Hello fellow phpBB users,

This little thing has been bugging me for a couple of days. I sincerely love phpBB 3.1 new notifications system, and I really want to figure out a means to display the amount of unread notifications on my websites community page (outside of the forums).

I use the regular session integration and other features, such as using the $user->data['username'] for welcoming messages, and displaying if they have any unread mails with $user->data['user_unread_privmsg']. This all works absolutely perfectly (yay for phpBB as CMS, absolutely brilliant).

However, I haven't been able to find the name (if it actually is there), for unread notifications. I've tried a huge amount of variations on $user->data['user_notifications_unread_count']. I know user_notify exists, but I doubt this is the one I'm looking for - since it's been there since before 3.1 so I thought it might be used for something different entirely. Although I've also tried variations on that. Right now I'm down to about 87 different variations I've tried.

I'm really hoping somebody here knows how to show the amount of unread notifications using the above format.

Hope you guys can help me out!
Last edited by extricate on Tue Mar 31, 2015 3:01 pm, edited 1 time in total.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1731
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Notifications on external page using session + $user->data['notify']

Post by DavidIQ » Tue Mar 31, 2015 12:48 pm

It's actually a little more complex than that. The code you're wanting will look something like this:

Code: Select all

	$phpbb_notifications = $phpbb_container->get('notification_manager');

	$notifications = $phpbb_notifications->load_notifications(array(
			'all_unread'	=> true,
		));

	$template->assign_vars(array('NOTIFICATIONS_COUNT'			=> ($notifications !== false) ? $notifications['unread_count'] : 0,));
Image

User avatar
extricate
Registered User
Posts: 8
Joined: Mon Dec 30, 2013 4:33 pm

Re: Notifications on external page using session + $user->data['notify']

Post by extricate » Tue Mar 31, 2015 12:53 pm

Ah yea, I expected that much. I'll try to play with your code - I did notice the notification manager bit in the phpbb functions and tried to play with that but sadly my knowledge of PHP is lacking.

Thanks!

User avatar
extricate
Registered User
Posts: 8
Joined: Mon Dec 30, 2013 4:33 pm

Re: Notifications on external page using session + $user->data['notify']

Post by extricate » Tue Mar 31, 2015 1:07 pm

Okay, I managed it to return a 0, however it doesn't return the actual amount of unread notifications. My code looks as following now:

Code: Select all

$phpbb_notifications = $phpbb_container->get('notification_manager');
$notifications = $phpbb_notifications->load_notifications(array(
         'all_unread'   => true,
      ));

   $template->assign_vars(array('NOTIFICATIONS_COUNT'         => ($notifications !== false) ? $notifications['unread_count'] : 0,));
Up in the header, and...

Code: Select all

<span>. $notifications['unread_count'] .  ' notifications.</a></span> 
... to return the actual value

What am I missing?

Any help is much appreciated!

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1731
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Notifications on external page using session + $user->data['notify']

Post by DavidIQ » Tue Mar 31, 2015 2:17 pm

Change all_unread to count_unread. Everything else should stay the same.
Image

User avatar
extricate
Registered User
Posts: 8
Joined: Mon Dec 30, 2013 4:33 pm

Re: Notifications on external page using session + $user->data['notify']

Post by extricate » Tue Mar 31, 2015 2:22 pm

Thanks for your reply, I've tried the change but sadly:

Code: Select all

$phpbb_notifications = $phpbb_container->get('notification_manager');
   $notifications = $phpbb_notifications->load_notifications(array(
         'count_unread'   => true,
      ));

   $template->assign_vars(array('NOTIFICATIONS_COUNT'         => ($notifications !== false) ? $notifications['unread_count'] : 0,));
and ...

Code: Select all

Je hebt ' . $notifications['unread_count'] .  ' notificaties.
... still only returns a 0, even though I still have 2 unread notifications.

Edit: posted wrong code here, corrected code still doesn't work.

User avatar
RMcGirr83
Registered User
Posts: 357
Joined: Fri Mar 09, 2007 1:51 am
Contact:

Re: Notifications on external page using session + $user->data['notify']

Post by RMcGirr83 » Tue Mar 31, 2015 2:44 pm

<span>{NOTIFICATIONS_COUNT} notifications.</span>

:?:
Do not hire Christian Bullock he won't finish the job and will keep your money

User avatar
extricate
Registered User
Posts: 8
Joined: Mon Dec 30, 2013 4:33 pm

Re: Notifications on external page using session + $user->data['notify']

Post by extricate » Tue Mar 31, 2015 2:48 pm

RMcGirr83 wrote:<span>{NOTIFICATIONS_COUNT} notifications.</span>

:?:
Thanks for your input.

Sadly, I have yet to figure out a way to make hooks work on an external page.

Perhaps it's easier for you to understand what I'm trying to do when actually watching the page I'm trying to get it to work on: http://www.veiligheidscommunity.nl/

I'm trying to convert phpBB to be a CMS to run my entire website. Trying to understand basic concepts like this one is quite mandatory for me to succeed, and trying to understand the new notification system is only one step in that process... and a tough one at that, heh.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1731
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Notifications on external page using session + $user->data['notify']

Post by DavidIQ » Tue Mar 31, 2015 2:58 pm

Thought this would have been a quick answer but since it wasn't I have to now let you know that the proper location for this type of discussion is here.

Thanks.
Image

User avatar
extricate
Registered User
Posts: 8
Joined: Mon Dec 30, 2013 4:33 pm

Re: Notifications on external page using session + $user->data['notify']

Post by extricate » Tue Mar 31, 2015 2:59 pm

Ah, I thought considering I'm not writing an extension, I thought this would've been the appropriate location.

Thanks for referring me. Could you mayhaps be so kind as to move the actual thread?

Post Reply