X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FApache%2FMVC%2FModel%2FCDBI.pm;h=d842d5f16730788f52efb256d88bbbf83057fa63;hb=727e28be9837a49a27e024e5ee68c33da59039e0;hp=695e1cbd7dec1fe0e6e6f9ed33863113df0b2c90;hpb=d635ca733a7199c4f9893e8d5a50e96a1295f092;p=maypole.git diff --git a/lib/Apache/MVC/Model/CDBI.pm b/lib/Apache/MVC/Model/CDBI.pm index 695e1cb..d842d5f 100644 --- a/lib/Apache/MVC/Model/CDBI.pm +++ b/lib/Apache/MVC/Model/CDBI.pm @@ -3,16 +3,9 @@ use base qw(Apache::MVC::Model::Base Class::DBI); use Lingua::EN::Inflect::Number qw(to_PL); use Class::DBI::AsForm; use Class::DBI::FromCGI; +use Class::DBI::AbstractSearch; use CGI::Untaint; - -sub description { "A poorly defined class" } - -sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns } - -sub get_objects { - my ($self, $r) = @_; - return $self->retrieve(shift @{$r->{args}}); -} +use strict; sub related { my ($self, $r) = @_; @@ -37,7 +30,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 +52,30 @@ sub adopt { $child->columns( Stringify => qw/ name / ); } +sub search :Exported { + return shift->SUPER::search(@_) if caller eq "Class::DBI"; # oops + my ($self, $r) = @_; + my %fields = map {$_ => 1 } $self->columns; + my $oper = "like"; # For now + use Carp; Carp::confess("Urgh") unless ref $r; + my %params = %{$r->{params}}; + my %values = map { $_ => {$oper, $params{$_} } } + grep { $params{$_} and $fields{$_} } keys %params; + + $r->objects([ %values ? $self->search_where(%values) : $self->retrieve_all ]); + $r->template("list"); + $r->{template_args}{search} = 1; +} + 1; + +=head1 NAME + +Apache::MVC::Model::CDBI - Model class based on Class::DBI + +=head1 DESCRIPTION + +This is a master model class which uses C to do all the hard +work of fetching rows and representing them as objects; instead, it +concentrates on the actions that can be performed in the URL: +C, C and C.