Subversion Repositories oidfminutesapp

[/] [trunk/] [lib/] [OIDFMinutes/] [Model/] [DB.pm] - Rev 4

Compare with Previous | Blame | View Log

package OIDFMinutes::Model::DB;

use strict;
use base 'Catalyst::Model::DBIC::Schema';

__PACKAGE__->config(
    schema_class => 'OIDFMinutes::Schema',
    connect_info => [
        'dbi:mysql:oidfminutes',
        'oidfminutes',
        'oidfminutes',
        { AutoCommit => 1 },
    ],
);

sub fetch_user_by_ident {
    my ($ident, $c) = @_;

    my $ident_rs = $c->model('DB::UserIdent')->search({
        ident => $ident,
    });

    my $user_rs = $ident_rs->search_related('user');

    return $user_rs->next();
}

sub fetch_team_by_urlname {
    my ($urlname, $c) = @_;

    my $team_rs = $c->model('DB::Team')->search({
        urlname => $urlname,
    });

    return $team_rs->next();
}

sub fetch_minutes_by_team_urlname_and_meeting_date {
    my ($team_urlname, $date, $c) = @_;

    return undef unless $date =~ /^\d\d\d\d-\d\d-\d\d$/;

    my $team = fetch_team_by_urlname($team_urlname, $c);

    if ($team) {
        my $teamid = $team->teamid;

        my $minutes_rs = $c->model('DB::Minutes')->search({
            teamid => $teamid,
            meeting_date => $date,
        });

        return $minutes_rs->next();
    }
    else {
        return undef;
    }
}

=head1 NAME

OIDFMinutes::Model::DB - Catalyst DBIC Schema Model
=head1 SYNOPSIS

See L<OIDFMinutes>

=head1 DESCRIPTION

L<Catalyst::Model::DBIC::Schema> Model using schema L<OIDFMinutes::Schema>

=head1 AUTHOR

Martin Atkins,,,

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;

Compare with Previous | Blame