NAME

CMS::Drupal::Modules::MembershipEntity - Perl interface to Drupal MembershipEntity entities

VERSION

version 0.094

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 ...
 }

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;

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.

Memberships

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

my $hashref = $ME->fetch_memberships([ 1234 ]);
my $mem = $hashref->{'1234'};
# now you have a Membership object

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.

Membership methods

Once you have the Membership object, you can call some methods on it:

print "User $mem->{'uid'} is in good standing" if $mem->is_active;
print "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 where they are documented compeletely.

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.

Membership Term methods

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

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

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

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

SEE ALSO

AUTHOR

Nick Tonkin <tonkin@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Nick Tonkin.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.