1. geri1104
  2. Support
  3. Tuesday, February 09 2016, 03:56 PM
Hi,
is this possible:
I want a user to be added to a usergroup based on his age.
for exampe:
if age > 40 than add to usergroup "old"

thx
admin Accepted Answer
Admin
Hi,
sorry this is not possible.

This is something that you need to manage with some Cron process, because the age value is not static (i.e. today I have 39 years old, tomorrow 40)

With our APIs you can build a simple plugin that check this, but this check come only when user Register or Update his profile (docs with example plugin at http://docs.easy-profile.com/index.php/article/triggers)
- Download, Install and Enable Skeleton Plugin
- remove samples functions: triggerFieldAvatarUpdate, triggerProfileUpdate
- add function like this:
public function triggerProfileUpdate($user,&$data,$changed,$isNew)
{
$aliasOfFieldBirthday='dob'; // replace with your Alias of Birthday field
$groupToAdd=10; // replace with ID of usergroup

$birthDate=JHtml::_('date', $data[$aliasOfFieldBirthday], 'm/d/Y','UTC');
$birthDate = explode("/", $birthDate);
$age = ( date( "md" , date( "U", mktime( 0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2] ) ) ) > date( "md" ) ? ((date( "Y" )-$birthDate[2])-1 ) : ( date( "Y" )-$birthDate[2] ) );

if ( $age > 40 ) JsnHelper::addUserToGroup( $user , $groupToAdd );
}


NOTE: This code is not tested and not supported, this is only for example purpose.
  1. more than a month ago
  2. Support
  3. # 1
geri1104 Accepted Answer
Ok, i will try this solution.

thank you very much for the fast answer!
  1. more than a month ago
  2. Support
  3. # 2
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.