CMS::Drupal::Modules::MembershipEntity - Perl interface to Drupal MembershipEntity entities
version 0.96
use CMS::Drupal::Modules::MembershipEntity; my $ME = CMS::Drupal::Modules::MembershipEntity->new( { dbh => $dbh } ); my $href = $ME->fetch_memberships( 'all' ); # or: my $href = $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 ... }
Or, for a single Membership:
my $mem = $ME->fetch_memberships( 123 ); print $mem->type; send_newsletter( $mem->uid ) if $mem->active; # etc ...
This method returns either a hashref containing Membership objects indexed by mid, or a single Membership object (if it was called with a single mid).
When called with the argument 'all', 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 array containing mids, the hashref will contain an object for each mid in the array.
When called with a single mid, the method will return a single object (no hashref).
# Fetch a single Membership my $mem = $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( @list ); # Fetch all your Memberships my $hashref = $ME->fetch_memberships('all'); # Same thing but with a warning my $hashref = $ME->fetch_memberships();
IMPORTANT: If you have bad records in your Drupal database, the module will print a warning and skip the record. This happens when there are no Terms belonging to the Membership, or when the Term is missing a start date or end date. You should immediately normalize your data! This issue will also cause installation testing to fail if you have configured your environment to test against your real Drupal database.
This package provides easy access to Perl objects representing Membership Entity memberships and their terms. Rather than creating those objects directly, you should allow this module to do so.
For each Membership that you want, you can fetch a Membership object, which contains at least one Term object, so you have access to all the methods you can use on your Membership and its Terms.
For this reason the methods actually provided by the submodules are documented here.
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.
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 a hashref of Term objects, indexed by tid. Each Term can be accessed by the methods described in the Membership Terms section below.
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 $mem->mid . ' has already renewed' if $mem->has_renewal;
Methods are:
is_active()
is_expired()
is_cancelled()
is_pending()
has_renewal()
current_was_renewal()
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 ... }
You can directly access all the Term's attributes as follows:
$term->attr_name;
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.
print 'This is a live one' if $term->is_current; push @renewals, $term->tid if $term->was_renewal;
is_current()
is_future()
was_renewal()
CMS::Drupal::Modules::MembershipEntity::Membership
CMS::Drupal::Modules::MembershipEntity::Term
CMS::Drupal
Nick Tonkin <tonkin@cpan.org>
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.
To install CMS::Drupal::Modules::MembershipEntity, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CMS::Drupal::Modules::MembershipEntity
CPAN shell
perl -MCPAN -e shell install CMS::Drupal::Modules::MembershipEntity
For more information on module installation, please visit the detailed CPAN module installation guide.