unreaded private messages on external page [solved]
Posted by Terradon
unreaded private messages on external page [solved] October 28, 2010 05:53PM |
Registered: 15 years ago Posts: 160 |
Hi,
our phorum is up and running perfectly.
because this phorum is also a replacement for our pm-system,
i would like to show on other pages of our website,
the amount of unreaded private messages of the user.
i can't find the used query for this, as it is used in phorums' private messages page?
Edited 1 time(s). Last edit at 10/29/2010 12:38PM by Terradon.
our phorum is up and running perfectly.
because this phorum is also a replacement for our pm-system,
i would like to show on other pages of our website,
the amount of unreaded private messages of the user.
i can't find the used query for this, as it is used in phorums' private messages page?
Edited 1 time(s). Last edit at 10/29/2010 12:38PM by Terradon.
October 28, 2010 06:21PM |
Admin Registered: 20 years ago Posts: 8,532 |
The function from the db layer is:
For performance reasons, this one does not contain the message count. It only checks if there are new messages available. For friendly retrieval of the new message count, I would like to implement a counter in the user data that holds the active new message count, so no query is needed for doing the counting and checking anymore. That will be a Phorum 5.3 feature though, so for now you'll have to go with this query function.
If you want the total message count, then you'll have to take this function as the basis for writing your own function. It shouldn't be really hard to modify the function to retrieve a total new message count.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
function phorum_db_pm_checknew($user_id = NULL)
For performance reasons, this one does not contain the message count. It only checks if there are new messages available. For friendly retrieval of the new message count, I would like to implement a counter in the user data that holds the active new message count, so no query is needed for doing the counting and checking anymore. That will be a Phorum 5.3 feature though, so for now you'll have to go with this query function.
If you want the total message count, then you'll have to take this function as the basis for writing your own function. It shouldn't be really hard to modify the function to retrieve a total new message count.
Maurice Makaay
Phorum Development Team



Re: unreaded private messages on external page October 28, 2010 06:38PM |
Registered: 15 years ago Posts: 160 |
thanks,
in my opinion a user only needs an indication IF he/she has new messages,
how many isn't relevant. a waste of resources.
but from what i have seen, i just cannot use a simple standalone query in my websites' mainmenu?
in the database i see a bunch of codes in the field meta, from which i cant get a marker for newmessages?
i will try to go on anyway:)
in my opinion a user only needs an indication IF he/she has new messages,
how many isn't relevant. a waste of resources.
but from what i have seen, i just cannot use a simple standalone query in my websites' mainmenu?
in the database i see a bunch of codes in the field meta, from which i cant get a marker for newmessages?
i will try to go on anyway:)
Re: unreaded private messages on external page October 28, 2010 06:44PM |
Registered: 15 years ago Posts: 160 |
mm...
found this in phorum__pm_messages, rule 6000+ :)
there is no field read_flag in table phorum__pm_messages,
it is packed inside a bunch of other values in the field meta
i really do not understand how to retrieve this value??
For now i just am thinking of:
when visitor logs in on the site, i have to retrieve his phorum userid.
and to use the mentioned function, i have to include something of phorum to get it working?
maybe i haven't explained it clearly, but i wanted to check for new mesages, while the visitor is on my site, but not in the phorum pages.
Edited 4 time(s). Last edit at 10/28/2010 06:55PM by Terradon.
found this in phorum__pm_messages, rule 6000+ :)
Language: PHP// {{{ Function: phorum_db_pm_checknew() /** * Check if the user has any new private messages. This is useful in case * you only want to know whether the user has new messages or not and when * you are not interested in the exact amount of new messages. * * @param mixed $user_id * The user to check for or NULL to use the active Phorum user (default). * * @return boolean * TRUE in case there are new messages, FALSE otherwise. */ function phorum_db_pm_checknew($user_id = NULL) { $PHORUM = $GLOBALS[';PHORUM';]; if ($user_id === NULL) $user_id = $PHORUM[';user';][';user_id';]; settype($user_id, ';int';); $new = phorum_db_interact( DB_RETURN_VALUE, "SELECT user_id FROM {$PHORUM[';pm_xref_table';]} WHERE user_id = $user_id AND read_flag = 0 LIMIT 1" ); return (bool)$new; } // }}}
there is no field read_flag in table phorum__pm_messages,
it is packed inside a bunch of other values in the field meta
i really do not understand how to retrieve this value??
For now i just am thinking of:
when visitor logs in on the site, i have to retrieve his phorum userid.
and to use the mentioned function, i have to include something of phorum to get it working?
maybe i haven't explained it clearly, but i wanted to check for new mesages, while the visitor is on my site, but not in the phorum pages.
Edited 4 time(s). Last edit at 10/28/2010 06:55PM by Terradon.
October 28, 2010 07:13PM |
Admin Registered: 20 years ago Posts: 8,532 |
The query does not check the pm messages table, but the related xref table. The xref table is where the read flag is implemented. The flag is not in the message itself, because the message is shared between all that receive the message (and optionally the sender when keeping a copy in the outbox.)
If you want to use the function phorum_db_pm_checknew(), you will have to include common.php, which will load the database settings and the db layer library. It is not needed as such, since you can also program the query in a stand-along piece of code using your favorite MySQL access method from your own code.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
If you want to use the function phorum_db_pm_checknew(), you will have to include common.php, which will load the database settings and the db layer library. It is not needed as such, since you can also program the query in a stand-along piece of code using your favorite MySQL access method from your own code.
Maurice Makaay
Phorum Development Team



Re: unreaded private messages on external page October 28, 2010 07:20PM |
Registered: 15 years ago Posts: 160 |
October 28, 2010 07:35PM |
Admin Registered: 20 years ago Posts: 8,532 |
If you only want to know whether there are new messages or not, then add the limit = 1 too. That will save the database the work of providing a full record count.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Re: unreaded private messages on external page October 29, 2010 07:59AM |
Registered: 15 years ago Posts: 160 |
For archiving purpose, this is what works for us:
remember, as stated before, i personally think that the amount of unreaded private messages is of no use for an user, it is about notifying your users that they just have unreaded messages! More info is a waste of resources, which is important, because you will probably use this on every page of your website (a mark in your menu?).
Everybody: enjoy this perfect Phorum!
Edited 2 time(s). Last edit at 10/29/2010 08:03AM by Terradon.
remember, as stated before, i personally think that the amount of unreaded private messages is of no use for an user, it is about notifying your users that they just have unreaded messages! More info is a waste of resources, which is important, because you will probably use this on every page of your website (a mark in your menu?).
Language: PHPfunction get_phorum_id($your_username) { // get phorum-userid based on your websites user session-variable // for use anywhere in your site // assuming $your_username is a safe variable // database connection must exist for using this function // example use: $i_phorum_userid = get_phorum_id($_SESSION[';nick';]); $q = "SELECT user_id FROM phorum__users WHERE username = ';".$your_username."'; LIMIT 1"; $exec = mysql_query($q); // error check if(!$exec) { // failed query => use your own error handling return false; } else { $a_result = mysql_fetch_assoc($exec); $i_phorum_userid = $a_result[';user_id';]; return $i_phorum_userid; } } function unread_pm($i_phorum_userid) { /* get status of unreaded private messages anywhere in your website for use anywhere in your site assuming $i_phorum_userid is a safe variable database connection must exist for using this function example use: $b_unread_pm = unread_pm($i_phorum_userid); // return true or false if($b_unread_pm) { //show somehow they have unreaded pm';s :) } */ $q = "SELECT COUNT(*) AS i FROM phorum__pm_xref WHERE user_id = ';".$i_phorum_userid."'; AND read_flag = ';0'; LIMIT 1"; $exec = mysql_query($q); // error check if(!$exec) { // failed query => use your own error handling return false; } else { $a_result = mysql_fetch_assoc($exec); if($a_result[';i';] == 1) return true; else return false; } }
Everybody: enjoy this perfect Phorum!
Edited 2 time(s). Last edit at 10/29/2010 08:03AM by Terradon.
Sorry, only registered users may post in this forum.