From: Simon Cozens Date: Thu, 5 Feb 2004 17:44:27 +0000 (+0000) Subject: This gives us row ordering by column. X-Git-Tag: 2.10~315 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=7232f39368bec26e484089f9f81ab6b6dc94e9eb;p=maypole.git This gives us row ordering by column. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@47 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Apache/MVC/Model/CDBI.pm b/lib/Apache/MVC/Model/CDBI.pm index 854118e..2d2aa2b 100644 --- a/lib/Apache/MVC/Model/CDBI.pm +++ b/lib/Apache/MVC/Model/CDBI.pm @@ -4,6 +4,7 @@ use Lingua::EN::Inflect::Number qw(to_PL); use Class::DBI::AsForm; use Class::DBI::FromCGI; use Class::DBI::AbstractSearch; +use Class::DBI::Plugin::RetrieveAll; use Class::DBI::Pager; use CGI::Untaint; use strict; @@ -83,11 +84,19 @@ sub search :Exported { sub list :Exported { my ($self, $r) = @_; + my %ok_columns = map {$_ => 1} $self->columns; if ( my $rows = $r->config->{rows_per_page}) { $self = $self->pager($rows, $r->query->{page}); $r->{template_args}{pager} = $self; } - $r->objects([ $self->retrieve_all ]); + my $order; + if ($order = $r->query->{order} and $ok_columns{$order}) { + $r->objects([ $self->retrieve_all_sorted_by( $order. + ($r->query->{o2} eq "desc" && " DESC") + )]); + } else { + $r->objects([ $self->retrieve_all ]); + } } 1; diff --git a/templates/factory/list b/templates/factory/list index 2a15964..f1290ef 100644 --- a/templates/factory/list +++ b/templates/factory/list @@ -16,7 +16,15 @@ [% FOR col = classmetadata.columns.list; NEXT IF col == "id"; - ""; classmetadata.colnames.$col; ""; + ""; + ''; + classmetadata.colnames.$col; + ''; + ""; END %] diff --git a/templates/factory/pager b/templates/factory/pager index 9053098..9defa40 100644 --- a/templates/factory/pager +++ b/templates/factory/pager @@ -8,7 +8,7 @@ IF pager AND pager.first_page != pager.last_page; IF num == pager.current_page; "["; num; "] "; ELSE; - ''; + ''; "["; num; "]"; ' '; END;