CGI::Ex::Recipes::Add - Implements the creation of a new recipe!


CGI-Ex-Recipes documentation Contained in the CGI-Ex-Recipes distribution.

Index


Code Index:

NAME

Top

CGI::Ex::Recipes::Add - Implements the creation of a new recipe!

VERSION

Top

Version 0.02

SYNOPSIS

Top

Perhaps a little code snippet.

    sub skip { 0 }
    sub name_step { 'edit' }
    ...




METHODS

Top

See the general documentations for these methods in CGI::Ex::App

skip

name_step

Returns edit in order the edit.tthtml template to be used

finalize

The real work is done here. First checks for abs record in the recipes table with the same title and if found adds an error to the template. Otherwise inserts the new record. See the code foreach details.

AUTHOR

Top

Красимир Беров, <k.berov at gmail.com>

BUGS

Top

Not known

SUPPORT

Top

    perldoc CGI::Ex::Recipes

COPYRIGHT & LICENSE

Top


CGI-Ex-Recipes documentation Contained in the CGI-Ex-Recipes distribution.

package CGI::Ex::Recipes::Add;
use utf8;
use warnings;
use strict;
use base qw(CGI::Ex::Recipes);
our $VERSION = sprintf "%d.%03d", q$Revision 0.001$ =~ /(\d+)/g;


sub skip { 0 }
sub name_step { 'edit' }


sub finalize {
    my $self = shift;
    my $form = $self->form;

    my $s = "SELECT COUNT(*) FROM recipes WHERE title = ?";
    my ($count) = $self->dbh->selectrow_array($s, {}, $form->{'title'});
    if ($count) {
        $self->add_errors(title => 'A recipe by this title already exists');
        return 0;
    }

    $s = "INSERT INTO recipes (pid, is_category, title, problem, analysis, solution, sortorder, tstamp, date_added)
                    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
    my $tstamp = $self->now;
    $self->dbh->prepare($s)->execute(
                           $form->{'pid'},
                           $form->{'is_category'}||0,
                           $form->{'title'},
                           $form->{'problem'},
                           $form->{'analysis'},
                           $form->{'solution'},
                           $form->{'sortorder'},
                           $tstamp,
                           $tstamp,);
    $self->add_to_form(success => "Recipe added to the database");
    return 1;
}

1; # End of CGI::Ex::Recipes::Add

__END__