NAME

CMS::Drupal::Modules::MembershipEntity

VERSION

version 0.092

SYNOPSIS

use CMS::Drupal::Modules::MembershipEntity;

my $ME = CMS::Drupal::Modules::MembershipEntity->new( dbh => $dbh );

my $hashref = $ME->fetch_memberships;
# or:
my $hashref = $ME->fetch_memberships([ 123, 456, 789 ]);
# or:
my $hashref = $ME->fetch_memberships([ 123 ]);
# or:
my $hashref = $ME->fetch_memberships( \@list );

foreach my $mid ( sort keys %{$hashref} ) {
  my $mem = $hashref->{ $mid };
  
  print $mem->{'type'};
  &send_newsletter( $mem->{'uid'} ) if $mem->active;
  
  # etc ...
}

USAGE

This package returns a hashref containing one element for each Membership that was requested. The hashref is indexed by mid and the element is a Membership object, which contains at least one Term object, so you have access to all the methods you can use on your Membership.

For this reason the methods actually provided by the submodules are documented here.

METHODS

fetch_memberships

This method returns a hashref containing Membership objects indexed by mid.

When called with no arguments, the hashref contains all Memberships in the Drupal database, which might be too much for your memory if you have lots of them.

When called with an arrayref containing mids, the hashref will contain an object for each mid in the arrayref.

# Fetch a single Membership
my $hashref = $ME->fetch_memberships([ 1234 ]); 

# Fetch a set of Memberships
my $hashref = $ME->fetch_memberships([ 1234, 5678 ]);

# Fetch a set of Memberships using a list you prepared elsewhere
my $hashref = $ME->fetch_memberships( $array_ref );

# Fetch all your Memberships
my $hashref = $ME->fetch_memberships;

Memberships

This module uses CMS::Drupal::Modules::MembershipEntity::Membership so you don't have to. The methods described below are actually in the latter module.

my $hashref = $ME->fetch_memberships([ 1234 ]);
my $mem = $hashref->{'1234'};

Attributes

You can directly access all the Membership's attributes as follows:

$mem->{ attr_name }

Where attr_name is one of:

mid           
member_id
type
uid
status
created
changed

There is also another attribute `terms`, which contains an hashref of Term objects, indexed by tid. Each Term can be accessed by the methods described in the Membership Terms section below.

is_active

Returns true if the Membership status is active, else returns false.

say "User $mem->{'uid'} is in good standing" if $mem->is_active;

has_renewal

Returns true if the Membership has at least one Term for which is_future returns true.

say "User $mem->{'uid'} has already renewed" if $mem->has_renewal;

Membership Terms

This module uses CMS::Drupal::Modules::MembershipEntity::Term so you don't have to. The methods described below are actually in the latter module.

while ( my ($tid, $term) = each %{$mem->{'terms'}} ) {
 # do something ...
}

Attributes

You can directly access all the Term's attributes as follows:

$term->{ attr_name }

Where attr_name is one of:

tid
mid
status
term
modifiers
start
end

There is also another attribute, `array_position`, which is used to determine if the Term is a renewal, etc.

is_active

Returns true if the Term status is active, else returns false. (Note that 'active' does not necessarily mean 'current', see below.)

say "$term->{'tid'} is active" if $term->is_active;

is_current

Returns true if the Term is current, meaning that the datetime now falls between the start and end of the Term. (Note that the Term may be 'current' but not 'active', eg 'pending'.)

say "This is a live one" if $term->is_current;

is_future

Returns true if the `start` of the Term is in the future compared to now.

say "$mem->{'uid'} has a prepaid renewal" if $term->is_future;

was_renewal

Returns true if the Term was a renewal when it was created (as determined simply by the fact that there was an earlier one).

say "$mem->{'uid'} is a repeat customer" if $term->was_renewal;

SEE ALSO

CMS::Drupal::Modules::MembershipEntity::Membership

CMS::Drupal::Modules::MembershipEntity::Membership

CMS::Drupal