- $self = shift; # check to see if this is a method call
- $call_type = 'C4::Labels::Layout->delete';
- $query_param = $self->{'layout_id'};
- }
- else {
- %opts = @_;
- $call_type = 'C4::Labels::Layout::delete';
- $query_param = $opts{'layout_id'};
- }
- if ($query_param eq '') { # If there is no layout id then we cannot delete it
- syslog("LOG_ERR", "%s : Cannot delete layout as the layout id is invalid or non-existant.", $call_type);
- return 1;
- }
- my $query = "DELETE FROM labels_layouts WHERE layout_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($query_param);
- if ($sth->err) {
- syslog("LOG_ERR", "%s : Database returned the following error: %s", $call_type, $sth->errstr);
- return 1;
- }
- return 0;
-}
-
-=head2 $layout->save()
-
- Invoking the I<save> method attempts to insert the layout into the database if the layout is new and
- update the existing layout record if the layout exists. The method returns the new record id upon
- success and -1 upon failure (This avoids conflicting with a record id of 1). Errors are logged to the syslog.
-
- example:
- my $exitstat = $layout->save(); # to save the record behind the $layout object
-
-=cut
-
-sub save {
- my $self = shift;
- if ($self->{'layout_id'}) { # if we have an id, the record exists and needs UPDATE
- my @params;
- my $query = "UPDATE labels_layouts SET ";
- foreach my $key (keys %{$self}) {
- next if $key eq 'layout_id';
- push (@params, $self->{$key});
- $query .= "$key=?, ";
- }
- $query = substr($query, 0, (length($query)-2));
- $query .= " WHERE layout_id=?;";
- push (@params, $self->{'layout_id'});
- my $sth = C4::Context->dbh->prepare($query);
- #local $sth->{TraceLevel} = "3"; # enable DBI trace and set level; outputs to STDERR
- $sth->execute(@params);
- if ($sth->err) {
- syslog("LOG_ERR", "C4::Labels::Layout : Database returned the following error: %s", $sth->errstr);
- return -1;
- }
- return $self->{'layout_id'};
- }
- else { # otherwise create a new record
- my @params;
- my $query = "INSERT INTO labels_layouts (";
- foreach my $key (keys %{$self}) {
- push (@params, $self->{$key});
- $query .= "$key, ";
- }
- $query = substr($query, 0, (length($query)-2));
- $query .= ") VALUES (";
- for (my $i=1; $i<=(scalar keys %$self); $i++) {
- $query .= "?,";
- }
- $query = substr($query, 0, (length($query)-1));
- $query .= ");";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute(@params);
- if ($sth->err) {
- syslog("LOG_ERR", "C4::Labels::Layout : Database returned the following error: %s", $sth->errstr);
- return -1;
- }
- my $sth1 = C4::Context->dbh->prepare("SELECT MAX(layout_id) FROM labels_layouts;");
- $sth1->execute();
- my $id = $sth1->fetchrow_array;
- return $id;
- }
-}
-
-=head2 $layout->get_attr("attr")
-
- Invoking the I<get_attr> method will return the value of the requested attribute or 1 on errors.
-
- example:
- my $value = $layout->get_attr("attr");
-
-=cut
-
-sub get_attr {
- my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my ($attr) = @_;
- if (exists($self->{$attr})) {
- return $self->{$attr};