Page 1 of 1

Answer to custom profile field puts user in a group

Posted: Mon Aug 25, 2008 3:24 am
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.

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

Posted: Wed Aug 27, 2008 9:41 pm
by Anyasha
I shall try my luck with a bump.

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

Posted: Sat Aug 30, 2008 6:57 am
by BiggDawgg
This would interest me also .. does anyone know if this can be done?

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

Posted: Wed Dec 17, 2008 9:17 pm
by Anyasha
Has anything popped up yet?

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

Posted: Wed May 13, 2009 8:20 pm
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.

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

Posted: Thu May 14, 2009 3:48 pm
by wolx
Woah, this would be really great! I was just thinking on something like that..

Hope someone makes this :P

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

Posted: Thu May 14, 2009 4:16 pm
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

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

Posted: Sun Jun 07, 2009 11:25 pm
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

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

Posted: Mon Jun 08, 2009 7:12 pm
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.

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

Posted: Mon Jun 08, 2009 7:38 pm
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

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

Posted: Mon Jun 08, 2009 7:56 pm
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.

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

Posted: Mon Jun 08, 2009 8:05 pm
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!

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

Posted: Tue Jun 09, 2009 12:24 am
by mtrs

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

Posted: Tue Jun 09, 2009 12:35 am
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: :!: