Use AEC to control modules

(0 votes, average 0 out of 5)

Use these recipes to the AEC (Account Expiration Control) component to control which modules appear.

  • display a module only if user has a valid subscription to a specified AEC plan
  • display a module only if a user does not have a valid subscription to a specified AEC plan

Don’t forget to customise the module IDs that you are returning, to match the IDs of your own modules.

Display a module only if user has a valid subscription to a specified AEC plan:

The first part of the recipe retrieves the user’s subscription from AEC, and gets the plan id from that. You can then return module ids based on which plan the user is on, if any.

if ($user->id) {
  $plan = null;
  require_once( JPATH_SITE . "/components/com_acctexp/acctexp.class.php" );
  $metaUser = new metaUser( $user->id );
  if ($metaUser->hasSubscription) {
    $sub = $metaUser->focusSubscription;
    if ($sub and !$sub->is_expired()) {
      $plan = $sub->plan;
    }
  }
  if ($plan == AAA) return BBB;
  if ($plan == CCC) return DDD;
 // add more lines as appropriate...
  // Replace AAA and CCC with the plan ids to check for,
  // and BBB and DDD with the modules to use for people
  // in those plans
}

Display a module only if user DOES NOT have a valid subscription to a specified AEC plan:

plan = null;
if ($user->id) {
  require_once( JPATH_SITE . "/components/com_acctexp/acctexp.class.php" );
  $metaUser = new metaUser( $user->id );
  if ($metaUser->hasSubscription) {
    $sub = $metaUser->focusSubscription;
    if ($sub and !$sub->is_expired()) {
      $plan = $sub->plan;
    }
  }
}
// replace XXX with the module id to use if the user has no valid plan subscriptions
// (optional)
if ($plan == null) return XXX;
// replace ZZZ with the module id to return if the plan id is NOT YYY (replace YYY
// with a plan id number). (optional)
if ($plan != YYY) return ZZZ;