Skip to content

Commit

Permalink
Refactoring: Collect stray SQL stuff #17: Act::User forgotten things
Browse files Browse the repository at this point in the history
Two more queries were "forgotten" in the first run.
  • Loading branch information
HaraldJoerg committed Jul 5, 2019
1 parent 76a9978 commit e1b1c86
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
30 changes: 29 additions & 1 deletion lib/Act/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ sub remove_right ($conference,$user_id,$right_id) {
$dbh->commit;
}

# ----------------------------------------------------------------------
# From Act::User
sub user_rights ($conference,$user_id) {
my $sth = sql(
'SELECT right_id FROM rights WHERE conf_id=? AND user_id=?',
$conference, $user_id
);
my @rights = map { $_->[0] } @{ $sth->fetchall_arrayref };
$sth->finish;
return \@rights;
}

# ----------------------------------------------------------------------
# From Act::Handler::User::Search
Expand Down Expand Up @@ -360,7 +371,14 @@ sub tshirt_size ($user_id) {


# ----------------------------------------------------------------------
# From Act::User::update
# From Act::User
sub bio ($user_id) {
my $sth = sql('SELECT lang, bio FROM bios WHERE user_id=?',$user_id);
my %bio = map { @$_ } @{$sth->fetchall_arrayref()};
$sth->finish;
return \%bio;
}

sub update_bio ($user_id,$bio) {
my @sql =
(
Expand Down Expand Up @@ -645,6 +663,11 @@ id C<$user_id> for the conference C<$conference>.
Removes the right C<$right_id> (a string) from the user with numerical
user id C<$user_id> for the conference C<$conference>.
=head3 Act::Data::user_rights ($conference, $user_id)
Returns an array reference to the rights of a C<user_id> for a
C<$conference>.
=head3 $ref = Act::Data::countries($conference)
Returns a reference to an array of ISO country codes from where users
Expand Down Expand Up @@ -716,6 +739,11 @@ of conference.
B<Note:> This routine needs to be checked closely. It breaks the
segregation of duties between the provider and the organizers.
=head3 Act::Data::bio($user_id)
Returns the biographies for C<$user_id> as a hash reference with
languages as keys.
=head3 Act::Data::update_bio($user_id,$bio)
Updates a user's biography, or biographies. C<$bio> is a reference to
Expand Down
18 changes: 3 additions & 15 deletions lib/Act/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,8 @@ sub rights {
return $self->{rights} if exists $self->{rights};

# get the user's rights
$self->{rights} = {};

my $sth = sql(
'SELECT right_id FROM rights WHERE conf_id=? AND user_id=?',
$Request{conference}, $self->user_id
);
$self->{rights}{$_->[0]}++ for @{ $sth->fetchall_arrayref };
$sth->finish;

my $rights = Act::Data::user_rights($Request{conference},$self->user_id);
$self->{rights}{$_->[0]}++ for @$rights;
return $self->{rights};
}

Expand Down Expand Up @@ -105,12 +98,7 @@ sub bio {
return $self->{bio} if exists $self->{bio};

# fill the cache if necessary
my $sth = sql("SELECT lang, bio FROM bios WHERE user_id=?", $self->user_id );
$self->{bio} = {};
while( my $bio = $sth->fetchrow_arrayref() ) {
$self->{bio}{$bio->[0]} = $bio->[1];
}
$sth->finish();
$self->{bio} = Act::Data::bio($self->user_id);
return $self->{bio};
}

Expand Down

0 comments on commit e1b1c86

Please sign in to comment.