Skip to content

Instantly share code, notes, and snippets.

@delonnewman
Created October 6, 2008 22:08
Show Gist options
  • Save delonnewman/15154 to your computer and use it in GitHub Desktop.
Save delonnewman/15154 to your computer and use it in GitHub Desktop.
package Domestic::Member;
use Moose;
use Moose::Util::TypeConstraints;
use DateTime ();
use Domestic::DB;
subtype 'Date'
=> as 'DateTime'
=> where { $_->isa('DateTime') };
coerce 'DateTime'
=> from 'Str'
=> via {
/(\d\d\d\d)-(\d\d)-(\d\d)/;
DateTime->new( year => $1, month => $2, day => $3 );
};
has 'id' => ( is => 'rw', isa => 'Int' );
has 'name' => ( is => 'rw', isa => 'Maybe[Str]' );
has 'params' => ( is => 'rw', isa => 'Maybe[Str]' );
has 'email' => ( is => 'rw', isa => 'Maybe[Str]' );
has 'status' => ( is => 'rw', isa => 'Maybe[Int]' );
has 'portrait' => ( is => 'rw', isa => 'Maybe[Str]' );
has 'background' => ( is => 'rw', isa => 'Maybe[Str]' );
has 'experation_date' => ( is => 'rw', isa => 'DateTime',
coerce => 1, default => sub { DateTime->now()->add( days => 15 ) } );
# Private variables
has 'table' => ( isa => 'Str', default => 'jos_members_provider' );
has 'connection' => ( isa => 'Object' );
sub BUILDER {
my $self = shift;
$self->connection =
Domestic::DB->new( 'domestic_development', 'localhost', 'root',
'n3wman' );
}
sub find {
my $q = shift;
my $options = shift;
return _find_first($options) if $q eq 'first';
return _find_all($options) if $q eq 'all';
# FIXME: This could be generalized
my $query = <<QUERY;
SELECT
jos_pd_members_provider.id,
CONCAT(name, ' ', lastname) AS name,
params,
email,
status,
portrait,
background,
notificationDate AS experation_date
FROM jos_pd_members_provider, jos_users
WHERE
jos_pd_members_provider.uid = jos_users.id
AND jos_pd_members_provider.id = ?;
QUERY
my ( $id, $name, $params, $email, $status, $portrait, $background, $experation_date ) =
Domestic::DB->new( 'domestic_development', 'localhost', 'root',
'n3wman' )->get_row( $query, [$q] );
return Domestic::Member->new(
id => $id,
name => $name,
params => $params,
email => $email,
status => $status,
portrait => $portrait,
background => $background,
experation_date => $experation_date
);
}
sub _find_first {
}
sub _find_all {
}
sub find_by_query {
}
sub find_expired {
}
sub find_active {
}
sub find_inactive {
}
sub find_pending {
}
sub send_mail_to {
}
sub set_active {
}
sub is_active {
}
sub set_pending {
}
sub is_pending {
}
sub set_inactive {
}
sub is_inactive {
}
sub set_expired {
}
sub is_expired {
}
sub is_past_experation {
my $self = shift;
my $cmp = DateTime->compare(DateTime->now(), $self->experationDate);
return 1 if $cmp == 1;
return 0;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment