diff --git a/IFComp/lib/IFComp/Controller/Ballot.pm b/IFComp/lib/IFComp/Controller/Ballot.pm index 24a9fc60..7fa89706 100644 --- a/IFComp/lib/IFComp/Controller/Ballot.pm +++ b/IFComp/lib/IFComp/Controller/Ballot.pm @@ -36,7 +36,7 @@ sub root :Chained('/') :PathPart('ballot') :CaptureArgs(0) { return; } - my $order_by; + my @entries; if ( $c->req->params->{ shuffle } ) { $c->stash->{ is_shuffled } = 1; my $seed = ''; @@ -44,25 +44,26 @@ sub root :Chained('/') :PathPart('ballot') :CaptureArgs(0) { $seed = $c->user->get_object->id; $c->stash->{ is_personalized } = 1; } - $order_by = "rand($seed)"; + my $order_by = "rand($seed)"; + @entries = $current_comp->entries( + {}, + { + order_by => $order_by, + } + ); } else { - $order_by = 'title asc'; + @entries = sort { $a->sort_title cmp $b->sort_title } + $current_comp->entries(); } - $c->stash->{ entries_rs } = $current_comp->entries( - {}, - { - order_by => $order_by, - } - ); + $c->stash->{ entries } = \@entries; my $user_is_author = 0; if ( $c->user && $c->user->get_object->current_comp_entries ) { $user_is_author = 1; } $c->stash->{ user_is_author } = $user_is_author; - } sub index :Chained('root') :PathPart('') :Args(0) { diff --git a/IFComp/lib/IFComp/Schema/Result/Entry.pm b/IFComp/lib/IFComp/Schema/Result/Entry.pm index 190a12ce..fc817856 100644 --- a/IFComp/lib/IFComp/Schema/Result/Entry.pm +++ b/IFComp/lib/IFComp/Schema/Result/Entry.pm @@ -404,6 +404,14 @@ Readonly my @DEFAULT_INFORM_CONTENT => qw( index.html ); +has 'sort_title' => ( + is => 'ro', + isa => 'Maybe[Str]', + lazy_build => 1, + clearer => 'clear_sort_title', + predicate => 'has_sort_title', +); + has 'directory' => ( is => 'ro', isa => 'Path::Class::Dir', @@ -571,10 +579,21 @@ around update => sub { } } - return $self->$orig( @_ ); + if ( $self->is_column_changed( 'title' ) && $self->has_sort_title ) { + $self->clear_sort_title; + } + return $self->$orig( @_ ); }; +sub _build_sort_title { + my $self = shift; + my $title = $self->title; + # for right now, just remove initial articles + $title =~ s/^(?:the|a|an) //i; + return $title; +} + sub _build_directory_name { my $self = shift; diff --git a/IFComp/root/src/ballot/index.tt b/IFComp/root/src/ballot/index.tt index d811c3b8..32f2ada4 100644 --- a/IFComp/root/src/ballot/index.tt +++ b/IFComp/root/src/ballot/index.tt @@ -86,7 +86,7 @@

[% END %] -[% WHILE (entry = entries_rs.next) %] +[% FOR entry IN entries %] [% IF entry.is_qualified %]
[% INCLUDE _entry_title.tt include_permalink = 1 %] diff --git a/IFComp/root/src/ballot/vote.tt b/IFComp/root/src/ballot/vote.tt index 51084763..6c8254e5 100644 --- a/IFComp/root/src/ballot/vote.tt +++ b/IFComp/root/src/ballot/vote.tt @@ -49,7 +49,7 @@ We'd love to have you join us as a judge! It's as easy as logging in, creating a [% END %] -[% WHILE (entry = entries_rs.next) %] +[% FOR entry IN entries %] [% IF entry.is_qualified %]
[% entry.title | html %] by [% INCLUDE author_name.tt %]