use strict;
use warnings;
-use POSIX qw(ceil);
+use POSIX qw( ceil );
use autouse 'Data::Dumper' => qw(Dumper);
use C4::Context;
-use C4::Debug;
-use C4::Creators::Profile 1.000000;
-use C4::Creators::Lib 1.000000 qw(get_unit_values);
+use C4::Creators::Profile;
+use C4::Creators::Lib qw( get_unit_values );
-BEGIN {
- use version; our $VERSION = qv('1.0.0_1');
-}
sub _check_params {
shift if $_[0] =~ m/::/; # this seems a bit hackish
my $invocant = shift;
my $type = ref($invocant) || $invocant;
if (_check_params(@_) eq 1) {
- return;
+ return -1;
}
my $self = {
profile_id => 0,
$sth->execute($opts{'template_id'}, $opts{'creator'});
if ($sth->err) {
warn sprintf('Database returned the following error: %s', $sth->errstr);
- return;
+ return -1;
}
my $self = $sth->fetchrow_hashref;
$self = _conv_points($self) if (($opts{convert} && $opts{convert} == 1) || $opts{profile_id});
push @query_params, $opts{'template_id'}, $opts{'creator'};
}
if (scalar(@query_params) < 2) { # If there is no template id or creator type then we cannot delete it
- warn sprintf('%s : Cannot delete template as the template id is invalid or non-existant.', $call_type) if !$query_params[0];
- warn sprintf('%s : Cannot delete template as the creator type is invalid or non-existant.', $call_type) if !$query_params[1];
- return;
+ warn sprintf('%s : Cannot delete template as the template id is invalid or non-existent.', $call_type) if !$query_params[0];
+ warn sprintf('%s : Cannot delete template as the creator type is invalid or non-existent.', $call_type) if !$query_params[1];
+ return -1;
}
- my $query = "DELETE FROM " . $opts{'table_name'} . " WHERE template_id = ? AND creator = ?";
+ my $query = "DELETE FROM creator_templates WHERE template_id = ? AND creator = ?";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute(@query_params);
$self->{'template_stat'} = 0;
foreach my $key (keys %{$self}) {
next if ($key eq 'template_id') || ($key eq 'template_stat') || ($key eq 'creator');
push (@params, $self->{$key});
- $query .= "$key=?, ";
+ $query .= "`$key`=?, ";
}
$query = substr($query, 0, (length($query)-2));
push (@params, $self->{'template_id'}, $self->{'creator'});
$sth->execute(@params);
if ($sth->err) {
warn sprintf('Database returned the following error: %s', $sth->errstr);
- return;
+ return -1;
}
$self->{'template_stat'} = 1;
return $self->{'template_id'};
foreach my $key (keys %{$self}) {
next if $key eq 'template_stat';
push (@params, $self->{$key});
- $query .= "$key, ";
+ $query .= "`$key`, ";
}
$query = substr($query, 0, (length($query)-2));
$query .= ") VALUES (";
$sth->execute(@params);
if ($sth->err) {
warn sprintf('Database returned the following error: %s', $sth->errstr);
- return;
+ return -1;
}
my $sth1 = C4::Context->dbh->prepare("SELECT MAX(template_id) FROM " . $opts{'table_name'} . ";");
$sth1->execute();
sub get_attr {
my $self = shift;
if (_check_params(@_) eq 1) {
- return;
+ return -1;
}
my ($attr) = @_;
if (exists($self->{$attr})) {
return $self->{$attr};
}
- return;
+ else {
+ return -1;
+ }
}
sub set_attr {
my $self = shift;
if (_check_params(@_) eq 1) {
- return;
+ return -1;
}
my %attrs = @_;
foreach my $attrib (keys(%attrs)) {
my $template = C4::Labels::Template->new(profile_id => 1, page_width => 8.5, page_height => 11.0, units => 'INCH'); # Creates and returns a new template object using
the supplied values to override the defaults
- B<NOTE:> This template is I<not> written to the database untill save() is invoked. You have been warned!
+ B<NOTE:> This template is I<not> written to the database until save() is invoked. You have been warned!
=head2 retrieve(template_id => $template_id)
=head2 save()
Invoking the I<save> method attempts to insert the template into the database if the template is new and update the existing template record if
- the template exists. The method returns the new record template_id upon success and undef upon failure (This avoids template_ids conflicting with a
+ the template exists. The method returns the new record template_id upon success and -1 upon failure (This avoids template_ids conflicting with a
record template_id of 1). Errors are logged to the Apache log.
example:
=head2 get_attr($attribute)
- Invoking the I<get_attr> method will return the value of the requested attribute or undef on errors.
+ Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors.
example:
C<my $value = $template->get_attr($attribute);>
This file is part of Koha.
-Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later version.
+Koha is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+Koha is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
-Fifth Floor, Boston, MA 02110-1301 USA.
+You should have received a copy of the GNU General Public License
+along with Koha; if not, see <http://www.gnu.org/licenses>.
=head1 DISCLAIMER OF WARRANTY