]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Apache/MVC/Model/CDBI.pm
This adds basic searching. Want to change it to AbstractSearch, though.
[maypole.git] / lib / Apache / MVC / Model / CDBI.pm
index 695e1cbd7dec1fe0e6e6f9ed33863113df0b2c90..88c1d5282769240dcf338316d64b8465dfb37045 100644 (file)
@@ -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;