source: trunk/lib/Vote/DB/Ballot.pm @ 160

Last change on this file since 160 was 160, checked in by nanardon, 15 years ago
  • use an OO interface for each type of object
  • Property svn:keywords set to Id Rev
File size: 1.4 KB
Line 
1package Vote::DB::Ballot;
2
3# $Id$
4
5use strict;
6use warnings;
7use base 'Vote::DB::common';
8use Vote::DB::Poll;
9
10=head1 NAME
11
12Vote::Model::Vote - Catalyst Model
13
14=head1 DESCRIPTION
15
16Catalyst Model.
17
18=cut
19
20sub new {
21    my ($class, $dbstring, $id) = @_;
22   
23    bless {
24        id => $id,
25        dbstring => $dbstring,
26        db => Vote::DB::common::_newdb($dbstring),
27    }, $class;
28}
29
30sub ballotid { $_[0]->{id} }
31
32sub poll {
33    my ($self) = @_;
34    Vote::DB::Poll->new($self->{dbstring}, $self->info->{poll});
35}
36
37sub info {
38    my ($self) = @_;
39
40    my $sth = $self->db->prepare_cached(
41        q{ select * from ballot where id = ? }
42    );
43
44    $sth->execute($self->ballotid);
45    my $res = $sth->fetchrow_hashref;
46    $sth->finish;
47    $res
48}
49
50sub mark_invalid {
51    my ($self, $invalid) = @_;
52
53    my $sth = $self->db->prepare_cached(
54        q{update ballot set invalid = ? where id = ?}
55    );
56
57    $sth->execute($invalid ? 't' : 'f', $self->ballotid);
58}
59
60sub items {
61    my ($self) = @_;
62
63    my $sth = $self->db->prepare_cached(
64        q{select *, value as v from ballot_item where id = ?}
65    );
66    $sth->execute($self->ballotid);
67    my @ids;
68    while (my $res = $sth->fetchrow_hashref) {
69        push(@ids, $res);
70    }
71    \@ids
72}
73
74=head1 AUTHOR
75
76Thauvin Olivier
77
78=head1 LICENSE
79
80This library is free software, you can redistribute it and/or modify
81it under the same terms as Perl itself or CeCILL.
82
83=cut
84
851;
Note: See TracBrowser for help on using the repository browser.