View Full Version : Hook location help
MoMan
01-02-2009, 07:06 PM
I'm using a feedback system (itrader) mod which gives all users on my site a feedback score based on successful item purchases, and I would like to include this score in the postbit. However, a certain few lines of code need to be executed in order to fetch the value of the feedback variable from the database.
Which hook location would I use to insert my code, given a separate feedback score needs to be retrieved for each postbit?
The variable which my code should populate is included in my postbit_legacy template.
Lynne
01-02-2009, 08:04 PM
I'd figure out the names of the columns you need and in which table they are in and see if you can use a plugin to do a join into and existing query for the post information. But, as I mentioned, you need the name of the column, the table, and the column to do userid join on.
MoMan
01-02-2009, 08:59 PM
Thanks for the reply!
Here's the query that I'd be running:
$itraders = $vbulletin->db->query_read("SELECT COUNT(" . ($vbulletin->options['itrader_ratestyle'] ? 'DISTINCT(userid)' : 'userid') . ") AS usercount, COUNT(*) AS usercountall, rating
FROM " . TABLE_PREFIX . "itrader
WHERE rateduserid = " . $userinfo['userid'] . "
GROUP BY rating
");
All we care about is the userid and the feedback rating, and that should be in _vbuser.
Lynne
01-02-2009, 11:31 PM
That would add one query per post. It's better to add a join to an existing query is what I'm saying.
MoMan
01-03-2009, 05:08 AM
Definitely- fifteen extra queries per page of a thread could be pretty hard on the server. Let me know if you can help me out with finding the one query to add my code to, and if you need any additional info. Thanks in advance!
Dismounted
01-03-2009, 05:26 AM
Look in showthread.php - look where it generates a query for users. ;)
MoMan
01-03-2009, 05:44 AM
Looks like that would be around ($hook = vBulletinHook::fetch_hook('showthread_query')) ? eval($hook) : false;
--------------- Added 1230969042 at 1230969042 ---------------
Update:
After placing that query after showthread_query, I get a DB error:
Database error in vBulletin 3.7.4:
Invalid SQL:
SELECT COUNT(DISTINCT(userid)) AS usercount, COUNT(*) AS usercountall, rating
FROM _vbitrader
WHERE rateduserid =
GROUP BY rating;
MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY rating' at line 4
Error Number : 1064
Request Date : Saturday, January 3rd 2009 @ 01:47:53 AM
Error Date : Saturday, January 3rd 2009 @ 01:47:54 AM
Classname : vB_Database
MySQL Version : 5.0.22
The exact code I'm running is:
// ###################### Generates iTrader Score Info #######################
// This is the first column's data, but also can be used to update a user's score
$userinfo['tradepos'] = 0;
$userinfo['tradeneu'] = 0;
$userinfo['tradeneg'] = 0;
$userinfo['tradeposall'] = 0;
$itraders = $vbulletin->db->query_read("SELECT COUNT(" . ($vbulletin->options['itrader_ratestyle'] ? 'DISTINCT(userid)' : 'userid') . ") AS usercount, COUNT(*) AS usercountall, rating
FROM " . TABLE_PREFIX . "itrader
WHERE rateduserid = " . $userinfo['userid'] . "
GROUP BY rating
");
while ($itrader = $vbulletin->db->fetch_array($itraders)) {
switch ($itrader['rating']) {
case 1:
$userinfo['tradepos'] = $itrader['usercount'];
$userinfo['tradeposall'] = $itrader['usercountall'];
break;
case 0:
$userinfo['tradeneu'] = $itrader['usercount'];
break;
case -1:
$userinfo['tradeneg'] = $itrader['usercount'];
break;
}
}
$dbupdate['itrader_total'] = $userinfo['tradescore'] = $userinfo['tradepos'] - $userinfo['tradeneg'];
$userinfo['tradescore'] = vb_number_format($userinfo['tradescore']);
$tradeall = $userinfo['tradepos'] + $userinfo['tradeneu'] + $userinfo['tradeneg'];
if($tradeall) {
@$userinfo['tradepcnt'] = (1 - ($userinfo['tradeneg'] / $tradeall) ) * 100;
$dbupdate['itrader_pcnt'] = round($userinfo['tradepcnt'],0);
$userinfo['tradepcnt'] = vb_number_format($userinfo['tradepcnt'],1);
} else {
$userinfo['tradepcnt'] = 0.0;
$dbupdate['itrader_pcnt'] = round($userinfo['tradepcnt'],0);
}
return;
// ################################################## ####################
I'd appreciate your help in sniffing out the problem, as my expertise in php doesn't got as far as I'd like it to.
Dismounted
01-03-2009, 09:31 AM
Look at the query right under that hook!!! You can use $hook_query_joins...
Lynne
01-03-2009, 03:24 PM
I don't think $userinfo is going to work on the showthread page. The variable you want to use there is $post. So, try changing that in your query and see if it works.
But, as Hanson pointed out, you can simply join into the existing $post query to grab your information there with a join to your itrader table.
MoMan
01-03-2009, 09:28 PM
Your mentioning $post got me to try using those in my postbit, and it turns out both $post[itrader_total] and pcnt are defined. So problem solved! Thanks for your help.
Lynne
01-03-2009, 10:15 PM
Excellent!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.