% if ($sort eq 'review') { % } else {

<% ucfirst $sort %>s starting with '<% $first_letter %>'

% } % if (keys %reviews) { % foreach my $header (sort {lc $a cmp lc $b} keys %reviews) { % }
% if ($sort eq 'film') { % } else { % } <% $header %>
    % foreach my $review (sort $sort_sub @{ $reviews{$header} }) {
  • Review % if ($sort eq 'film') { by <% $review->{username} %> % } else { of <% $review->{title} %> (<% $review->{year} %>) % } on <% $review->{last_updated} %> % if($review->{score}){ % if($review->{score} >= 9){ (<% $review->{score} %>) % } else { (<% $review->{score} %>) % } % } % }
 
% } else {

No reviews

% } <%args> $display_set => 'eng' $first_letter => 'a' $sort => 'film' <%init> my $db = HKMDB::Database->new; my $sql = qq[ SELECT mr.id, m.title_$display_set, m.id, mr.username, mr.last_updated, m.year_made, mr.score FROM movies AS m, movie_reviews AS mr ]; #if ($sort eq 'film') #{ # $sql .= 'WHERE LCASE(m.title_eng) REGEXP ?'; #} #elsif ($sort eq 'reviewer') if ($sort eq 'reviewer') { $sql .= 'WHERE LCASE(mr.username) REGEXP ?'; } if ($sort eq 'review') { $sql .= 'WHERE mr.username REGEXP ? '; } my @bind; push @bind, "^$first_letter"; $sql .= ' AND m.id = mr.movie_id'; if ($display_set ne 'big5') { $sql .= ' AND mr.language_id = ?'; my $sql = 'SELECT id FROM written_languages WHERE language = ?'; my $lang_id = $db->select_one_row( sql => $sql, bind => $display_set ); push @bind, $lang_id; } my $sort_sub; if ($sort eq 'film') { $sort_sub = sub { lc $a->{username} cmp $b->{username} || $b->{last_updated} cmp $a->{last_updated} }; } if ($sort eq 'reviewer') { $sort_sub = sub { $a->{title} cmp $b->{title} }; } if ($sort eq 'review') { $sort_sub = sub { $a->{title} cmp $b->{title} }; } my %reviews; foreach my $row ( $db->select_rows( sql => $sql, bind => \@bind ) ) { # What's our primary key to sort on? my $index = $sort eq 'film' ? "$row->[1] ($row->[5])" : $row->[3]; push @{ $reviews{$index} }, { review_id => $row->[0], title => $row->[1], movie_id => $row->[2], username => $row->[3], last_updated => $row->[4], year => $row->[5], score => $row->[6], }; }