Skip to content

Commit 76a9978

Browse files
committed
Refactoring: Collect stray SQL stuff #16: Act::Talk
1 parent 8d17fc6 commit 76a9978

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

lib/Act/Data.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,23 @@ sub fetch_orders ($order_id) {
475475
}
476476

477477

478+
# ----------------------------------------------------------------------
479+
# From Act::Talk
480+
# Another two subroutines which don't pass a conference because they
481+
# refer to talks, which are associated with a conference.
482+
sub delete_talk_attendance ($talk_id) {
483+
sql('DELETE FROM user_talks WHERE talk_id=?', $talk_id);
484+
}
485+
486+
sub talk_stars ($talk_id) {
487+
my $sth = sql('SELECT COUNT(*) FROM user_talks'
488+
. ' WHERE talk_id=?', $talk_id);
489+
my ($count) = $sth->fetchrow_array();
490+
$sth->finish;
491+
return $count || 0;
492+
}
493+
494+
478495
# ----------------------------------------------------------------------
479496
# Fetch the database handler
480497
sub dbh {
@@ -743,6 +760,15 @@ which is mapped to C<'t'> or C<'f'>.
743760
Returns an array reference holding hash references for each of the
744761
orders.
745762
763+
=head3 Act::Data::delete_talk_attendance ($talk_id)
764+
765+
Removes information about a talk's attendance (before deleting the
766+
talk itself).
767+
768+
=head3 $count = Act::Data::talk_stars($talk_id)
769+
770+
Returns the number of stars for a talk given by its ID.
771+
746772
=head1 CAVEATS
747773
748774
The Act test suite doesn't exercise all of these functions. This is bad.

lib/Act/Talk.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package Act::Talk;
22
use Act::Config;
3+
use Act::Data;
34
use Act::Object;
45
use base qw( Act::Object );
56

@@ -32,18 +33,15 @@ our %sql_opts = ( 'order by' => 'talk_id' );
3233
sub delete {
3334
my ($self, %args) = @_;
3435

35-
sql('DELETE FROM user_talks WHERE talk_id=?', $self->talk_id);
36+
Act::Data::delete_talk_attendance($self->talk_id);
3637

3738
$self->SUPER::delete(%args);
3839
$Request{dbh}->commit;
3940
}
4041

4142
sub stars {
4243
my ($self, %args) = @_;
43-
my $sth = sql('SELECT COUNT(*) FROM user_talks WHERE talk_id=?', $self->talk_id);
44-
my ($count) = $sth->fetchrow_array();
45-
$sth->finish;
46-
return $count || 0;
44+
return Act::Data::talk_stars($self->talk_id);
4745
}
4846

4947
=head1 NAME

0 commit comments

Comments
 (0)