Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
411 views
in Plugins by

I was working on a customized version of the on-site-notifications plugin: https://github.com/q2apro/q2apro-on-site-notifications to make it work with several eventlog tables.

While doing this i introduced a separate table as a collector for the event count, which makes the page load much faster than before (before the layer module calculated on each page load the new events). Now only one number is read.

I dont have time to implement this for the single eventlog now, but here is the way to go:

1. Create new table qa_notifycount:

$tablename3 = qa_db_add_table_prefix('notifycount');

if(!in_array($tablename3, $tableslc)) 

{

// db-table per installation: 'CREATE TABLE IF NOT EXISTS ^notifycount (

// we use only one central one for all installations

qa_db_query_sub(

'CREATE TABLE IF NOT EXISTS qa_notifycount (

userid int(10) unsigned NOT NULL UNIQUE,

notifycount int(10) unsigned DEFAULT 0,

PRIMARY KEY (userid)

) ENGINE=MyISAM'

);

}


2. Introduce two new functions in qa-plugin.php:

function q2apro_notifycount_increase($userid)

{

// central qa_notifycount table

qa_db_query_sub('

INSERT INTO qa_notifycount (userid, notifycount) VALUES(#, 1) 

ON DUPLICATE KEY UPDATE userid = #, notifycount = (notifycount+1)

',

$userid, $userid

);

}

function q2apro_notifycount_nill($userid)

{

// central qa_notifycount table

qa_db_query_sub('

INSERT INTO qa_notifycount (userid, notifycount) VALUES(#, 0) 

ON DUPLICATE KEY UPDATE userid = #, notifycount = 0

',

$userid, $userid

);

}

3. In q2apro-history-check.php add before `exit()`:

q2apro_notifycount_nill($userid);

4. Add to q2apro-onsitenotifications-event.php (after each INSERT INTO query) the lines: 

// increate notifycount for user

q2apro_notifycount_increase($uid);

ffdf

5. Add to q2apro-onsitenotifications-layer.php at top of function doctype():

// central qa_notifycount table

$eventcount = qa_db_read_one_value(qa_db_query_sub('

SELECT notifycount FROM qa_notifycount

WHERE userid = #

',

$userid

  ), true);

// q2apro notification tooltip

if(!empty($eventcount))

{

// ...

Done. Hope that helps. And yes, would be nice is someone is implementing it for the official plugin.

Please log in or register to answer this question.

...