get number of unread private messages
Permalink
Hi there, I'm a bit puzzled over this one...
I can get the total number of messages in someones mailbox by using:
but I'd really like to know how to display how many of those are unread or
if you get my drift... I'd be really grateful if you could point me in the right direction
Cheers
Rob
I can get the total number of messages in someones mailbox by using:
$ui = UserInfo::getByID($loggedInUser->getUserID()); $inbox = UserPrivateMessageMailbox::get($ui, UserPrivateMessageMailbox::MBTYPE_INBOX); $totalMessages = $inbox->getTotalMessages(); echo $totalMessages;
but I'd really like to know how to display how many of those are unread or
$msg->getMessageStatus() // where status is 'New'
if you get my drift... I'd be really grateful if you could point me in the right direction
Cheers
Rob
Can anyone point me in the right direction with this? Thanks
It doesn't look like this is a built in function, so you would have to override the core /src/User/PrivateMessageList class to add a filterByStatus function.
this sounds complicated... I thought there might be a way to look at the total of messages in the inbox and then 'count' how many were 'unread'...
how would I go about adding a filterByStatus function?
Thanks Hutman (again)
how would I go about adding a filterByStatus function?
Thanks Hutman (again)
You might be able to do that too, just do something like this
$ui = UserInfo::getByID($loggedInUser->getUserID()); $inbox = UserPrivateMessageMailbox::get($ui, UserPrivateMessageMailbox::MBTYPE_INBOX); $messageList = $inbox->getMessageList(); $unreadMessages = 0; if(count($messageList) > 0){ foreach($messageList as $message){ if($message->getMessageStatus() === 'New' || $message->getMessageStatus() === 'Unread'){ $unreadMessages++; } } }
Couldn't get it to work, so instead, went straight into the database...
Thanks for your help again Hutman :)
$UserID=$loggedInUser->getUserID(); //echo $UserID; $countnew = mysql_query("SELECT COUNT(*) FROM UserPrivateMessagesTo WHERE msgIsUnread = 1 AND uID = '$UserID'"); $unreadMessages = mysql_result($countnew,0); echo $unreadMessages;
Thanks for your help again Hutman :)