Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2009, 07:06 PM
MoMan MoMan is offline
 
Join Date: Oct 2005
Location: USA
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Hook location help

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.
Reply With Quote
  #2  
Old 01-02-2009, 08:04 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 01-02-2009, 08:59 PM
MoMan MoMan is offline
 
Join Date: Oct 2005
Location: USA
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the reply!

Here's the query that I'd be running:

Code:
$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.
Reply With Quote
  #4  
Old 01-02-2009, 11:31 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That would add one query per post. It's better to add a join to an existing query is what I'm saying.
Reply With Quote
  #5  
Old 01-03-2009, 05:08 AM
MoMan MoMan is offline
 
Join Date: Oct 2005
Location: USA
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #6  
Old 01-03-2009, 05:26 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Look in showthread.php - look where it generates a query for users.
Reply With Quote
  #7  
Old 01-03-2009, 05:44 AM
MoMan MoMan is offline
 
Join Date: Oct 2005
Location: USA
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looks like that would be around
PHP Code:
($hook vBulletinHook::fetch_hook('showthread_query')) ? eval($hook) : false
--------------- Added [DATE]1230969042[/DATE] at [TIME]1230969042[/TIME] ---------------

Update:

After placing that query after showthread_query, I get a DB error:

Code:
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:

PHP Code:
// ###################### 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'] = (- ($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.
Reply With Quote
  #8  
Old 01-03-2009, 09:31 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Look at the query right under that hook!!! You can use $hook_query_joins...
Reply With Quote
  #9  
Old 01-03-2009, 03:24 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #10  
Old 01-03-2009, 09:28 PM
MoMan MoMan is offline
 
Join Date: Oct 2005
Location: USA
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:12 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03973 seconds
  • Memory Usage 2,279KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete