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

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2014, 02:08 PM
autoescala autoescala is offline
 
Join Date: Oct 2011
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query to alter displaygroupid for members of additional usergroup?

Hello to all,

Here is what I have. I have a usergroup called "VIP". When members use the VB subscription feature to donate to the site, they are made "Additional Members" of the Forum Supporter usergroup.

What I want is for these member's usernames to be green on the Who's Online List.

However, username markups only affect "Primary Members" of a usergroup. IF a particular member of the Forum Supporter usergroup happens to have enough snap to look in the User CP, they can choose to identify themselves with the Forum Supporter usergroup and then the markup works. The problem is, few even know about that feature, nor would they mess with it if I mentioned it.

I want to keep the users as Additional members of the Registered Users primary usergroup but I want to force their profile to identify them with VIP usergroup. The only way I can think to do this is to run a manual query on the "user" table. However, I cannot figure out the structure of the query and this site:

is pretty worthless in my opinion for someone trying to learn the basics. No, I am not a programmer.

Currently, for users that are VIP I have these conditions:

usergroupid = 2 (Registered User)
membergrouids = 13 (VIP)
displaygroupid = 2

and I want to change that for all Forum Supporters to the following:

usergroupid = 2 (Registered User)
membergrouids = 13 (VIP)
displaygroupid = 13

It is crucial that the query check to ensure that the usergroupid = 2 AND membergroupids = 13 before making the update to usergroupid because there are some other usergroups that might get selected and I don't want to mess with their displaygroupid.

I would really like to have this as a PHP script so that I can add it to the Scheduled Task manager to run once a day for new members of the Forum Supporter usergroup. It would be sweet if it could be done via the subscription creation, but there is no option for controlling the displaygroupid that I know of.

I would really appreciate anyone being able to help me out.

Best Regards
Reply With Quote
  #2  
Old 01-23-2014, 02:42 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think this might work (although I haven't tried it):

PHP Code:
$vbulletin->db->query_write("UPDATE " TABLE_PREFIX "user set displaygroupid=13
                                              WHERE usergroupid=2 AND FIND_IN_SET(13, membergroupids)"
); 

I think you could also set it when the subscription happens by editing the file includes/class_paid_subscription.php. Around line 397 (in version 4.2.2) is this code:
Code:
if (!empty($sub['membergroupids']))
{
	$membergroupids = array_merge(fetch_membergroupids_array($user, false), array_diff(fetch_membergroupids_array($sub, false), fetch_membergroupids_array($user, false)));
	if ($user['usergroupid'] == 2 AND in_array(13, $membergroupids))
	{
		$userdm->set('displaygroupid', 13);
	}
}

and I think if you add the part in red it might set the displaygroupid for you (again I haven't tested it). Also, I'm not sure what will happen when the subscription expires, there may be other code needed to remove it.


ETA: I guess the above could be done using a hook on location paidsub_build, but it would require a little more code since the $userdm has been destroyed at that point. But maybe someone can work out the code for that to avoid editing files.
Reply With Quote
2 благодарности(ей) от:
CoffeeLovesYou, TheLastSuperman
  #3  
Old 01-23-2014, 03:17 PM
autoescala autoescala is offline
 
Join Date: Oct 2011
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, but i copy/paste your code in Manual Queery field to execute and it says:

error 1064
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 '$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user set displaygroupid=' at line 1

I'm doing something wrong ? your code can't be used from the Admin Cpanel?

Best Regards and Thanks for your time
Reply With Quote
  #4  
Old 01-23-2014, 07:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, you said you wanted php code. If you just want the query it would be something like:
Code:
UPDATE user set displaygroupid=13 WHERE usergroupid=2 AND FIND_IN_SET(13, membergroupids)

...but if you have a table prefix, you'll have to add that before "user". (Try it first, if it doesn't work because of an unknown table, then you might need a prefix).
Reply With Quote
  #5  
Old 01-24-2014, 07:17 AM
autoescala autoescala is offline
 
Join Date: Oct 2011
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Well, you said you wanted php code. If you just want the query it would be something like:
Code:
UPDATE user set displaygroupid=13 WHERE usergroupid=2 AND FIND_IN_SET(13, membergroupids)

...but if you have a table prefix, you'll have to add that before "user". (Try it first, if it doesn't work because of an unknown table, then you might need a prefix).

IT WORKS!!! Thank you very much!
Reply With Quote
  #6  
Old 01-30-2014, 07:34 AM
autoescala autoescala is offline
 
Join Date: Oct 2011
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@kh99 your tip works as a charm. But how can I do to automatize this as a cron job?

I created the first php based on first answers, but If I load from a browser nothing happens, I thing. Its normal ?

Thanks in advance
Reply With Quote
  #7  
Old 01-30-2014, 09:31 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure what you mean exactly, about loading from a browser. But if you want it to run automatically, create a plugin using your code (or my code from post #2) and use hook location cron_script_cleanup_daily or cron_script_cleanup_hourly, depending on how often you want it to run.
Reply With Quote
  #8  
Old 02-03-2014, 12:58 PM
autoescala autoescala is offline
 
Join Date: Oct 2011
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I'm not sure what you mean exactly, about loading from a browser. But if you want it to run automatically, create a plugin using your code (or my code from post #2) and use hook location cron_script_cleanup_daily or cron_script_cleanup_hourly, depending on how often you want it to run.
thank you very much, very useful your answer, I'm able to apply your solution easily, and works fine!!!
Best Regards
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:48 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.05163 seconds
  • Memory Usage 2,249KB
  • 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
  • (3)bbcode_code
  • (1)bbcode_php
  • (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
  • (2)post_thanks_box_bit
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete