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 | |
---|
1 | package Vote::DB::Ballot; |
---|
2 | |
---|
3 | # $Id$ |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | use base 'Vote::DB::common'; |
---|
8 | use Vote::DB::Poll; |
---|
9 | |
---|
10 | =head1 NAME |
---|
11 | |
---|
12 | Vote::Model::Vote - Catalyst Model |
---|
13 | |
---|
14 | =head1 DESCRIPTION |
---|
15 | |
---|
16 | Catalyst Model. |
---|
17 | |
---|
18 | =cut |
---|
19 | |
---|
20 | sub 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 | |
---|
30 | sub ballotid { $_[0]->{id} } |
---|
31 | |
---|
32 | sub poll { |
---|
33 | my ($self) = @_; |
---|
34 | Vote::DB::Poll->new($self->{dbstring}, $self->info->{poll}); |
---|
35 | } |
---|
36 | |
---|
37 | sub 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 | |
---|
50 | sub 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 | |
---|
60 | sub 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 | |
---|
76 | Thauvin Olivier |
---|
77 | |
---|
78 | =head1 LICENSE |
---|
79 | |
---|
80 | This library is free software, you can redistribute it and/or modify |
---|
81 | it under the same terms as Perl itself or CeCILL. |
---|
82 | |
---|
83 | =cut |
---|
84 | |
---|
85 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.