Answer to custom profile field puts user in a group

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Scam Warning
Locked
Anyasha
Registered User
Posts: 704
Joined: Mon Aug 07, 2006 4:02 am
Name: Anyasha

Answer to custom profile field puts user in a group

Post by Anyasha »

Upon registration, I'd like a user to enter a group corresponding with an answer to a certain dropdown custom profile field. Let's say I have a question called "favorite color". The user selects "red" from the dropdown and is therefor placed in the group "red" when his registration is complete.

I know about the Auto Group mod, so perhaps this is an "addon" but I'm not entirely sure.
Kiss me, I'm Polish!
Anyasha
Registered User
Posts: 704
Joined: Mon Aug 07, 2006 4:02 am
Name: Anyasha

Re: Answer to custom profile field puts user in a group

Post by Anyasha »

I shall try my luck with a bump.
Kiss me, I'm Polish!
User avatar
BiggDawgg
Registered User
Posts: 356
Joined: Tue Oct 19, 2004 8:46 am
Location: USA, Illinois
Contact:

Re: Answer to custom profile field puts user in a group

Post by BiggDawgg »

This would interest me also .. does anyone know if this can be done?
Anyasha
Registered User
Posts: 704
Joined: Mon Aug 07, 2006 4:02 am
Name: Anyasha

Re: Answer to custom profile field puts user in a group

Post by Anyasha »

Has anything popped up yet?
Kiss me, I'm Polish!
Anyasha
Registered User
Posts: 704
Joined: Mon Aug 07, 2006 4:02 am
Name: Anyasha

Re: Answer to custom profile field puts user in a group

Post by Anyasha »

I hope I'm not breaking any rules by bumping this ancient topic rather than creating a new one. Just wondering if anyone has spotted or started anything of the like.
Kiss me, I'm Polish!
wolx
Registered User
Posts: 135
Joined: Thu Aug 02, 2007 12:16 pm

Re: Answer to custom profile field puts user in a group

Post by wolx »

Woah, this would be really great! I was just thinking on something like that..

Hope someone makes this :P
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Answer to custom profile field puts user in a group

Post by mtrs »

Instead of adding a user to a group at registration, based on custom profile field value, it can be easier adding users to a group at first login.

Open
includes/functions.php
Find

Code: Select all

// The following assigns all _common_ variables that may be used at any point in a template.         
Add before

Code: Select all

    //Begin: Add user to a group based on cpf
    if ($user->data['user_lastvisit'] == 0 && $user->data['user_id'] != ANONYMOUS && !$user->data['is_bot'])
    {
		$user->get_profile_fields($user->data['user_id']);
		$user_fields = $user->profile_fields;
		$gender = 0;
		//we check if gender cpf created and have a value
		//$gender = 1, means female, $gender = 2 means female
		if (isset($user_fields['pf_gender']))
		{
			$gender = $user_fields['pf_gender'];
		} 

		if ($gender == 1)
		{
			$group_id = 1440;//male group_id - change it to actual id value
		}
		else if ($gender == 2)
		{
			$group_id = 11111;//female group_id - change it to actual id value
		}
		if (in_array($gender, array(1, 2)))
		{
			$user_id_ary = array($user->data['user_id']);
			$group_make_default = 0;

			if (!function_exists('group_user_add'))
			{
				include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
			}
			if(!group_memberships($group_id, $user->data['user_id'],true))
			{
				group_user_add($group_id, $user_id_ary, false, false, $group_make_default, 0, 0, false);    
			}
		}
    }
    //End: Add user to a group based on cpf  
I didn't test it, you should check first and test with cpf values and actual group_ids
I abandoned all of my mods.
sounique15
Registered User
Posts: 22
Joined: Fri Oct 26, 2007 4:05 pm

Re: Answer to custom profile field puts user in a group

Post by sounique15 »

mtrs wrote:Instead of adding a user to a group at registration, based on custom profile field value, it can be easier adding users to a group at first login.

Open
includes/functions.php
Find

Code: Select all

// The following assigns all _common_ variables that may be used at any point in a template.         
Add before

Code: Select all

    //Begin: Add user to a group based on cpf
    if ($user->data['user_lastvisit'] == 0 && $user->data['user_id'] != ANONYMOUS && !$user->data['is_bot'])
    {
		$user->get_profile_fields($user->data['user_id']);
		$user_fields = $user->profile_fields;
		$gender = 0;
		//we check if gender cpf created and have a value
		//$gender = 1, means female, $gender = 2 means female
		if (isset($user_fields['pf_gender']))
		{
			$gender = $user_fields['pf_gender'];
		} 

		if ($gender == 1)
		{
			$group_id = 1440;//male group_id - change it to actual id value
		}
		else if ($gender == 2)
		{
			$group_id = 11111;//female group_id - change it to actual id value
		}
		if (in_array($gender, array(1, 2)))
		{
			$user_id_ary = array($user->data['user_id']);
			$group_make_default = 0;

			if (!function_exists('group_user_add'))
			{
				include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
			}
			if(!group_memberships($group_id, $user->data['user_id'],true))
			{
				group_user_add($group_id, $user_id_ary, false, false, $group_make_default, 0, 0, false);    
			}
		}
    }
    //End: Add user to a group based on cpf  
I didn't test it, you should check first and test with cpf values and actual group_ids

Using this code would it be necessary to make the custom profile field "viewable" in the user control panel?
And thanks for the code, but is it possible to elaborate a little on where some of the data comes from like where would I find the group id, user id, and the value of the answer in the custom profile field?

Sorry if these are dumb questions! :oops:

P.S.- Would it be too much trouble if I asked you to customize the code based on what I need? I can't offer anything but I would definitely appreciate it!! :D
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Answer to custom profile field puts user in a group

Post by mtrs »

I am working on a different type of mod now: Groups on registration,
it will list OPEN groups in dropdown box on registration, then user may or must select another group in addititon to one of default (REGISTERED or REGISTERED_COPPA) groups.
The code is working, but, testing, ACP control option features and packaging will take time.
I abandoned all of my mods.
sounique15
Registered User
Posts: 22
Joined: Fri Oct 26, 2007 4:05 pm

Re: Answer to custom profile field puts user in a group

Post by sounique15 »

mtrs wrote:I am working on a different type of mod now: Groups on registration,
it will list OPEN groups in dropdown box on registration, then user may or must select another group in addititon to one of default (REGISTERED or REGISTERED_COPPA) groups.
The code is working, but, testing, ACP control option features and packaging will take time.

I'm a little confused on what your mod will do so maybe you can clarify it for me. Correct me if I'm wrong but what I understand it to do is that there will be two boxes one with a default group in it and the other with a "sub-group"?

Either way that sounds great would love to know when it is done or at least in beta!! In the meantime I'm going to try to figure out the code you gave and see if I can make do with that!!

Once again thanks and good luck with your mod!! :D
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Answer to custom profile field puts user in a group

Post by mtrs »

Mod will list "OPEN to register" user groups in a dropdown box on registration screen. So, users can join on registration.
At the end, user will be member of default group and a second group selected on registration.
The selection can be compulsory, second group can be default, will be configurable at ACP.
I abandoned all of my mods.
sounique15
Registered User
Posts: 22
Joined: Fri Oct 26, 2007 4:05 pm

Re: Answer to custom profile field puts user in a group

Post by sounique15 »

mtrs wrote:Mod will list "OPEN to register" user groups in a dropdown box on registration screen. So, users can join on registration.
At the end, user will be member of default group and a second group selected on registration.
The selection can be compulsory, second group can be default, will be configurable at ACP.
Ok I get it now that makes sense. Thanks for the clarification!! Once again good luck and I can't wait until it's done!
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Answer to custom profile field puts user in a group

Post by mtrs »

I abandoned all of my mods.
sounique15
Registered User
Posts: 22
Joined: Fri Oct 26, 2007 4:05 pm

Re: Answer to custom profile field puts user in a group

Post by sounique15 »

mtrs wrote:I made a mod for this request: http://www.phpbb.com/community/viewtopi ... &t=1639285
You are AWESOME!! Thanks sooooo much!! :D :mrgreen: :D :mrgreen: :!:
Locked

Return to “[3.0.x] MOD Requests”

cron