vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Hook location help (https://vborg.vbsupport.ru/showthread.php?t=200452)

MoMan 01-02-2009 07:06 PM

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.

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:

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.

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
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.

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!


All times are GMT. The time now is 07:59 PM.

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.01069 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete