class Xarcell_DataWriter_User extends XFCP_Xarcell_DataWriter_User
{
protected function _preSaveDefaults()
{
if ($this->get('dob_day') && $this->get('dob_month') && $this->get('dob_year'))
{
// Get age
$age = $this->getModelFromCache('XenForo_Model_UserProfile')->calculateAge(
$this->get('dob_year'), $this->get('dob_month'), $this->get('dob_day')
);
// Get mapped usergroup
$newUsergroup = $this->_getUsergroupByAge($age);
// Get existing secondary usergroups as an array
$secondaryUsergroups = explode(',', $this->get('secondary_group_ids'));
if($newUsergroup != null)
{
// if its not in the array...
if(!in_array($newUsergroup, $secondaryUsergroups))
{
// add it.
$secondaryUsergroups[] = $newUsergroup;
}
}
// Set the new list of secondary usergroups
$this->setSecondaryGroups($secondaryUsergroups);
}
parent::_preSaveDefaults();
}
protected function _getUsergroupByAge($age)
{
if($age > 12 && $age < 100)
{
return $age - 2;
}
}
}