Skip to content

Commit

Permalink
Refactoring: Collect stray SQL stuff #16: Act::Talk
Browse files Browse the repository at this point in the history
  • Loading branch information
HaraldJoerg committed Jul 5, 2019
1 parent 8d17fc6 commit 76a9978
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
26 changes: 26 additions & 0 deletions lib/Act/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,23 @@ sub fetch_orders ($order_id) {
}


# ----------------------------------------------------------------------
# From Act::Talk
# Another two subroutines which don't pass a conference because they
# refer to talks, which are associated with a conference.
sub delete_talk_attendance ($talk_id) {
sql('DELETE FROM user_talks WHERE talk_id=?', $talk_id);
}

sub talk_stars ($talk_id) {
my $sth = sql('SELECT COUNT(*) FROM user_talks'
. ' WHERE talk_id=?', $talk_id);
my ($count) = $sth->fetchrow_array();
$sth->finish;
return $count || 0;
}


# ----------------------------------------------------------------------
# Fetch the database handler
sub dbh {
Expand Down Expand Up @@ -743,6 +760,15 @@ which is mapped to C<'t'> or C<'f'>.
Returns an array reference holding hash references for each of the
orders.
=head3 Act::Data::delete_talk_attendance ($talk_id)
Removes information about a talk's attendance (before deleting the
talk itself).
=head3 $count = Act::Data::talk_stars($talk_id)
Returns the number of stars for a talk given by its ID.
=head1 CAVEATS
The Act test suite doesn't exercise all of these functions. This is bad.
Expand Down
8 changes: 3 additions & 5 deletions lib/Act/Talk.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Act::Talk;
use Act::Config;
use Act::Data;
use Act::Object;
use base qw( Act::Object );

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

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

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

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

=head1 NAME
Expand Down

0 comments on commit 76a9978

Please sign in to comment.