From: Simon Cozens <simon@simon-cozens.org>
Date: Sat, 31 Jan 2004 15:48:36 +0000 (+0000)
Subject: This adds basic searching. Want to change it to AbstractSearch, though.
X-Git-Tag: 2.10~330
X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=7afc363f8b7cd7b710d4ee4199976165363bcfab;p=maypole.git

This adds basic searching. Want to change it to AbstractSearch, though.


git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@32 48953598-375a-da11-a14b-00016c27c3ee
---

diff --git a/lib/Apache/MVC/Model/CDBI.pm b/lib/Apache/MVC/Model/CDBI.pm
index 695e1cb..88c1d52 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 CGI::Untaint;
+use strict;
 
 sub description { "A poorly defined class" }
 
@@ -37,7 +38,7 @@ sub do_edit :Exported {
     if (my %errors = $obj->cgi_update_errors) {
         # Set it up as it was:
         warn "There were errors: ".Dumper(\%errors)."\n";
-        $r->{template_args}{cgi_params} = \%params;
+        $r->{template_args}{cgi_params} = $r->{params};
         $r->{template_args}{errors} = \%errors;
         $r->{template} = "edit";
     } else {
@@ -59,4 +60,15 @@ sub adopt {
     $child->columns( Stringify => qw/ name / );
 }
 
+sub search :Exported {
+    my ($self, $r) = @_;
+    my %fields = map {$_ => 1 } $self->columns;
+    my %values = map { $_ => $params{$_} }
+                 grep { $params{$_} and $fields{$_} } keys %{$r->{params}};
+    $r->objects([ %values ? $self->search_like(%values) : $self->retrieve_all ]);
+    $r->template("list");
+    $r->{template_args}{search} = 1;
+}
+
+
 1;
diff --git a/templates/factory/list b/templates/factory/list
index efd3a95..d52d3e8 100644
--- a/templates/factory/list
+++ b/templates/factory/list
@@ -2,7 +2,11 @@
 
 [% INCLUDE header %]
 
+[% IF search %]
+<h2> Search results </h2>
+[% ELSE %]
 <h2> Listing of all [% classmetadata.plural %]</h2>
+[% END %]
 
 [% INCLUDE navbar %]
 <DIV class="search"> [% INCLUDE search_form %] </DIV>