NAME

Gantry::Utils::CRUDHelp - helper routines for CRUD plugins

SYNOPSIS

use Gantry::Utils::CRUDHelp;

DESCRIPTION

Exports helper functions useful when writing CRUD plugins.

FUNCTIONS

clean_params

Pass a hash of form parameters and the fields list from a Gantry::Plugins::AutoCRUD style form method. Any field with key is whose value is not boolean is examined in the params hash. If its value is false, that value is changed to undef. This keeps the ORM from trying to insert a blank string into a date and integer fields which is fatal, at least for DBIx::Class inserting into Postgres.

clean_dates

Pass a hash of form parameters and the fields list from a Gantry::Plugins::AutoCRUD style form method. Any field with key is whose value is date is examined in the params hash. If its value is false, that value is changed to undef. This keeps the ORM from trying to insert a blank string into a date field which is fatal, at least for Class::DBI inserting into Postgres.

form_profile

Pass in the fields list from a Gantry::Plugins::AutoCRUD style _form method. Returns a hash reference suitable for passing to the check method of Data::FormValidator.

write_file( <form field name>, <file archive> );

write_file provides the code to collect a file from the form and write it to disk. This is to be called in the edit_post_action or add_post_action callback.

usage

sub edit_post_action {
   my( $self, $row ) = @_;
   
   my %params = $self->get_param_hash;
       
   if ( defined %params{'myfile'} ) {
   
       my $u = $self->write_file( 'myfile', '/home/html/images' );
       $row->update( $u );
   }   
}

recommend database fields

<file field>   varchar  -- /path to file>/11677952634.59186549016706.jpg
<file field>_ident  varchar -- 11677952634.59186549016706.jpg ( unique )
<file field>_suffix varchar -- .txt
<file field>_mime   varchar -- text/html
<file field>_name   varchar -- originalfilename.txt
<file field>_size   int     -- 2323

returns

will produce a hash ref

{
   '<file field>'  => '/home/archive/11677952634.59186549016706.jpg',
   '<file field>_ident'  => '11677952634.59186549016706.jpg',
   '<file field>_suffix' => '.txt',
   '<file field>_mime'   => 'text/html',
   '<file field>_name'   => 'originalfilename.txt',
   '<file field>_size'   => '2323',
}

SEE ALSO

Gantry::Plugins::AutoCRUD (for simpler situations)
Gantry::Plugins::CRUD (for slightly more complex situations)

AUTHOR

Phil Crow <philcrow2000@yahoo.com>

COPYRIGHT

Copyright (c) 2005, Phil Crow.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.