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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-23-2012, 05:54 AM
pureturk pureturk is offline
 
Join Date: Jun 2007
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Is this possible? (fieldX values in Thread Information)

I have a custom profile field where users must choose upon registration.
For example, lets say this profile field is called " favorite fruit"
and options are;
Apple
Melon
Grape
Banana

Now How do I get my "thread information" box to display users viewing forums as this;

There are currently 6 users browsing this thread.
Apple:1 Melon:2 Grape:0 Banana:3
Reply With Quote
  #2  
Old 08-23-2012, 05:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's one way you might be able to do it: You would need to turn on "Show Users Browsing Thread" in the adminCP options, then create a plugin using hook showthread_loggedinuser and code like this:
Code:
$viewing_users[] = $loggedin['userid'];

Then you need to do a query, in another plugin using hook showthread_complete:
Code:
$viewing_users[] = $vbulletin->userinfo['userid'];
$field = 'fieldX'; // change X to your actual field #
$results = $vbulletin->db->query_read_slave("SELECT $field, count(*) AS num FROM " .   TABLE_PREFIX . "userfield WHERE userid IN (" . implode(',', $viewing_users) . ") GROUP BY $field");
while ($row = $vbulletin->db->fetch_array($results))
{
    $fruit_viewing[$row[$field]] = $row['num'];
}

// If you don't want to actually display the "users browsing", you could uncomment this:
// $show['activeusers'] = false;

vB_Template::preRegister('SHOWTHREAD', array('fruit_viewing' => $fruit_viewing));

Then in showthread where you want it to appear, something like:
Code:
<vb:each from="fruit_viewing" key="fruit" value="num">
    {vb:raw fruit}: {vb:raw num} 
</vb:each>

BTW, I haven't actually tried this.
Reply With Quote
  #3  
Old 08-24-2012, 10:51 AM
pureturk pureturk is offline
 
Join Date: Jun 2007
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Let me try it and I ll get back to you in a bit

--------------- Added [DATE]1345809644[/DATE] at [TIME]1345809644[/TIME] ---------------

This is way too advanced for me.

I went to add new plugin and chose "showthread_loggedinuser and put;
$viewing_users[] = $loggedin['userid'];
in the PHP code
Saved it.

Then if I did all that right, I m not too sure what you mean by "Then you need to do a query, in another plugin using hook showthread_complete:"

Quote:
Originally Posted by kh99 View Post
Here's one way you might be able to do it: You would need to turn on "Show Users Browsing Thread" in the adminCP options, then create a plugin using hook showthread_loggedinuser and code like this:
Code:
$viewing_users[] = $loggedin['userid'];

Then you need to do a query, in another plugin using hook showthread_complete:
Code:
if (is_array($viewing_users) AND count($viewing_users))
{
   $field = 'fieldX'; // change X to your actual field #
   $results = $vbulletin->db->query_slave("SELECT $field, count(*) AS num FROM " .   TABLE_PREFIX . "userfield WHERE userid IN (" . implode(',', $viewing_users) . ") GROUP BY $field");
   while ($row = $vbulletin->db->fetch_array($results))
   {
       $fruit_viewing[$row[$field]] = $row['num'];
   }
}

// If you don't want to actually display the "users browsing", you could uncomment this:
// $show['activeusers'] = false;

Then in showthread where you want it to appear, something like:
Code:
<vb:each from="fruit_viewing" key="fruit" value="num">
    {vb:raw fruit}: {vb:raw num} 
</vb:each>

BTW, I haven't actually tried this.
Reply With Quote
  #4  
Old 08-24-2012, 11:27 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by pureturk View Post
Then if I did all that right, I m not too sure what you mean by "Then you need to do a query, in another plugin using hook showthread_complete:"
I was just talking about what the code is doing. You just have to create another plugin like you did for the first one. Make sure you check the "Yes" radio button to enable your plugins.
Reply With Quote
  #5  
Old 08-24-2012, 12:01 PM
pureturk pureturk is offline
 
Join Date: Jun 2007
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
<vb:each from="fruit_viewing" key="fruit" value="num">
    {vb:raw fruit}: {vb:raw num} 
</vb:each>
Do I change anything in this? Obviuosly i dont care about peoples favorite fruit lol
It didnt work..
Reply With Quote
  #6  
Old 08-24-2012, 12:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I was assuming you'd edit the variable names to something that made more sense.

I did forget one line: at the end of the second plugin, you need to register the variable to the template, like:
Code:
vB_Template::preRegister('SHOWTHREAD', array('fruit_viewing' => $fruit_viewing));
Reply With Quote
  #7  
Old 08-24-2012, 02:16 PM
pureturk pureturk is offline
 
Join Date: Jun 2007
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I created both hooks and added the line you provided at the end of second hook
changed the fieldX to Field 6 which is where the actual custom field is.

i edited the showthread template with the necessary code for the mod to show.

still no luck
Reply With Quote
  #8  
Old 08-24-2012, 06:28 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...did you remember to turn on "Show Users Browsing Thread"?

If it doesn't work I might have to see your exact code (which you can PM if you'd rather).
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 08:16 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10621 seconds
  • Memory Usage 2,234KB
  • 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
  • (8)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete