From: Simon Cozens Date: Thu, 25 Mar 2004 12:23:25 +0000 (+0000) Subject: Some more fixes to sorting and viewing. X-Git-Tag: 2.10~271 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=fac297853fb5fe79a5e6ad4190ee5e3e3d1e289d;p=maypole.git Some more fixes to sorting and viewing. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@91 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index 6671d09..052ebc9 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -59,7 +59,7 @@ sub delete :Exported { $_->SUPER::delete for @{ $r->objects || [] }; $r->objects([ $self->retrieve_all ]); $r->{template} = "list"; - $self->list; + $self->list($r); } sub stringify_column { @@ -88,9 +88,13 @@ sub search :Exported { my %values = map { $_ => {$oper, $params{$_} } } grep { $params{$_} and $fields{$_} } keys %params; - $self = $self->do_pager($r); - $r->objects([ %values ? $self->search_where(%values) : $self->retrieve_all ]); $r->template("list"); + if (!%values) { return $self->list($r) } + $self = $self->do_pager($r); + my $order = $self->order($r); + $r->objects([ $self->search_where(\%values), + ($order ? { order => $order } : ()) + ]); $r->{template_args}{search} = 1; } @@ -101,15 +105,22 @@ sub do_pager { } else { return $self } } -sub list :Exported { +sub order { my ($self, $r) = @_; - my %ok_columns = map {$_ => 1} $self->columns; - $self = $self->do_pager($r); my $order; + my %ok_columns = map {$_ => 1} $self->columns; if ($order = $r->query->{order} and $ok_columns{$order}) { - $r->objects([ $self->retrieve_all_sorted_by( $order. - ($r->query->{o2} eq "desc" && " DESC") - )]); + $order .= ($r->query->{o2} eq "desc" && " DESC") + } + $order; +} + +sub list :Exported { + my ($self, $r) = @_; + $self = $self->do_pager($r); + my $order = $self->order($r); + if ($order) { + $r->objects([ $self->retrieve_all_sorted_by( $order )]); } else { $r->objects([ $self->retrieve_all ]); }