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 11-30-2012, 02:55 AM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Creating Custom Promotions & validating profile fields

I new new to VB and have been trying to setup a support form.
My requirement:
For each purchase I give user a purchase code which she uses to gain access for the support forum for that respoective product only.

What I have dont so far?
->I have created usergroups for each product, where each product forum is accessible to that user group.
-> Added profile fields for users to enter purchase code against each product.

What I need to do and How can I do this?
-> Validate purchase code using my http API on Profile field saving.
-> Add additional usergroup to the user's groups if validation is successful.

The second one I believe could be done by creating some custom promotion to change the usergroup.
Please suggest if you've a better idea to how can I achieve this...
Reply With Quote
  #2  
Old 12-06-2012, 08:16 AM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, since more people could be visiting this thread. The solution is to create a plugin which changes the usergroup based on the profile field. Since CURL is allowed in the plugin one can validate it via and API call. I have partially succeeded in achieving this so will post the whole code once its complete.
cheers,
VT
Reply With Quote
  #3  
Old 12-07-2012, 12:52 PM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

have to Admit, very poor documentation to start coding on VB.

To VB guys here's a suggestion: Learn from WordPress on how CODEX should be built to help developers.
Reply With Quote
  #4  
Old 12-07-2012, 01:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I agree, it's difficult to get started. I haven't been around that long compared to some here, but I think the reason is that vbulletin wasn't originally designed to support code modifications. The hook system was added later, but it was just a matter of choosing some locations in the code where plugin code can be executed, and there really is no API so you have to read the code to figure out what to do.

Having said that - if you have specific questions you can ask and someone will probably be able to help.
Reply With Quote
  #5  
Old 12-07-2012, 01:16 PM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks KH99, was hoping someone to reply.
To begin with:
I want to know the hook which gets triggered when a user saves her custom profile field.

Lets say I created a profile field from adminCp as "A"
Now I want to run my code when "A" is saved/updated by the user.
Reply With Quote
  #6  
Old 12-07-2012, 01:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, well, there are two places it can be changed (the "settings" page and the profile), as well as registration, if you've set it to show up there. But I think you could handle any case by using hook userdata_presave. At that point you can check the value and set an error if it's invalid (or do anything else you want, of course). So basically something like this:

Code:
if ($this->setfields["fieldX"]) // field X has been set, new value in $this->userfield["fieldX"]
{
   if ($this->userfield["fieldX"] is bad)
   {
       $this->error('errorphrase');
   }
}

Of course you'd replace X with the id of your field, and errorphrase with the varname of an actual phrase (that you'd need to create). Also note that that plugin is executed inside a function, so if you need global variables you have to use "global". If you want to see what's going on, look at includes/class_dm_user.php, around line 1865, and maybe ajax.php, the 'saveuserfield' section that starts around line 814 to see how the datamanager is used to update profile fields.
Reply With Quote
  #7  
Old 12-07-2012, 05:10 PM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks a lot,

So I get most of my answers with this hook "userdata_presave" to validate my field via API & "userdata_postsave" to change the usergroup....

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

I more query, How do I set a secondary user group.
I can fetch all data of a user using
global $vbulletin;
get the existing membergroup ids as $vbulletin->userinfo['membergroupids']; now I want update the exisiting member ids.

I found this line in forums:
$userdata->set('membergroupids',$membergroupids);

is $userdata also a global var like $vbulletin? when I try updating the update field is stuck ... is there something Im doing wrong here..

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

That worked....

But now I am stuck at another issue, I used my code for the administrator and it worked, ,

$userdata->set('membergroupids',$membergroupids);

So, now the admin is has addition usergroup, but this did not work for the other sample user I tried...

even a simple error message on profile field update is not appearing for the user...
any clues?
Reply With Quote
  #8  
Old 12-12-2012, 11:50 AM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All Right,

Everything is complete now and I've tested that if the profile field is set then add additional member group to user and change its primary group.
But now,
when I make an api call to validate the data entered in the profile field the user get stuck on loading saving the profile field.....

So, I guessed that it might be because of the api call (which is pretty fast)...
But what I could not understand is even if I set other field the loading state of the profile field never ends even if it is not field "X" ....

need help..please..almost done..
Reply With Quote
  #9  
Old 12-12-2012, 12:25 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PS: can you give me a demo (PM me)? I dont understand all what you needed, I think I can help you.
I think you can run a query for the user if that user has set userfieldX
Reply With Quote
  #10  
Old 12-12-2012, 02:20 PM
vibethemes vibethemes is offline
 
Join Date: Nov 2012
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

great,
Below is my plugin code, what it does is as soon as user fills the profile field "X" , it validates it via an API call, if correct then changes the primary usergroup of the user to registered members from novice and adds a membergroup which gives user privelages to access the special forum:
PHP Code:
global $vbulletin,$userdata;
if (
$this->setfields["field7"]) 
{  
 
$json_results file_get_contents('some API URL'.$this->userfield["field7"].'.json');

$results=json_decode($json_resultstrue);
foreach(
$result as $res){
  
$itemid=$res->item_id;
  
$purchaser=$res->buyer;break;
}

if(
$purchaser == $this->userfield["field5"] && $item_id == 'CUSTOMID')
    if(!
in_array($vbulletin->userinfo['usergroupid'], array(2,6,7))){
       
$userdata->set('usergroupid',2);
       
$membergroupids $userdata->fetch_field('membergroupids');
       if (
$membergroupids)
               {
                    if(
strpos($membergroupids', 9,') == false)
                       
$membergroupids $membergroupids ", 9";
                   }
                   else{  
$membergroupids 9;  
                    }
           
$userdata->set('membergroupids'$membergroupids);
             }
    }else{
           
$this->error('Invalid Purchase Code !');
        }

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

Now the issue is:
Whether or not field7 is edited or not. User can not save profile changes as it gets stuck at loading state.
My inferences form this:
-> So it looks like the code is being executed for all the fields whereas it should execute only when field 7 is saved.
-> The wait for save never ends, I dont see an error or save.
but when I refersh the page the new value is saved and shown for field7.
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:46 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.04880 seconds
  • Memory Usage 2,268KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_code
  • (1)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