I'd like to pick up this thread again.
For me it's important that users are not only ADDED to a joomla usergroup, they should also be REMOVED from one group while processing a subscription plan. But without losing other groups they're already in. Same vice versa when the subscription expires.
Some examples:
no subscription plan
Users are members in groups SPECIAL and NON-MEMBER
subscription plan EXAMPLE_A
Users should be members in groups SPECIAL and EXAMPLE_A
subscription plan EXAMPLE_B
Users should be members in groups SPECIAL and EXAMPLE_B
subscription expires
Users are members in groups SPECIAL and NON-MEMBER again
With your setting it's only possible they are in NON-MEMBER and EXAMPLE_A (or EXAMPLE_B) the SAME time.
Currently in the backend (inside the subscription plan) I made a setup to add and remove the users to one of the so called EXAMPLE-groups, additionally I've changed some rows inside joomlagroups.php-plugin to remove the group ID 13 when a plan is activated and add it to the users when it expires.
Code:
function onMembershipActive($row) {
if ($row->user_id) {
$user = JFactory::getUser($row->user_id);
$currentGroups = $user->get('groups') ;
$plan = JTable::getInstance('Osmembership','Plan');
$plan->load($row->plan_id);
$params = new JRegistry($plan->params);
$groups = explode(',', $params->get('joomla_group_ids'));
$currentGroups = array_unique(array_merge($currentGroups, $groups)) ;
/* fix to remove group id 13 */
$id = array_search(13, $currentGroups);
unset($currentGroups[$id]);
$currentGroups = array_values($currentGroups);
$user->set('groups', $currentGroups);
$user->save(true);
}
}
Code:
function onMembershipExpire($row) {
if ($row->user_id) {
if (version_compare(JVERSION, '1.6.0', 'ge')) {
$user = & JFactory::getUser($row->user_id);
$currentGroups = $user->get('groups') ;
$plan = &JTable::getInstance('Osmembership','Plan');
$plan->load($row->plan_id);
$params = new JRegistry($plan->params);
$groups = explode(',', $params->get('joomla_expried_group_ids'));
$currentGroups = array_unique(array_diff($currentGroups, $groups)) ;
/* fix to add group id 13 */
$currentGroups[] = 13;
$user->set('groups', $currentGroups);
$user->save(true);
} else {
#Joomla 1.5, implement it later
}
}
}
Any other idea that is more clean?! Hope I'm not writing an absolutely mess?! :blink: :silly:
Thanks for your great support!!