Bug 12194: Add option 'Oblique title' in labels
[koha-ffzg.git] / C4 / Creators / Layout.pm
index d5c41ea..cf0b751 100644 (file)
@@ -10,7 +10,7 @@ use C4::Debug;
 use C4::Creators::PDF;
 
 BEGIN {
-    use version; our $VERSION = qv('1.0.0_1');
+    use version; our $VERSION = qv('3.07.00.049');
 }
 
 # FIXME: Consider this style parameter verification instead...
@@ -33,6 +33,7 @@ sub _check_params {
         'printing_type',
         'layout_name',
         'guidebox',
+        'oblique_title',
         'font',
         'font_size',
         'callnum_split',
@@ -40,6 +41,8 @@ sub _check_params {
         'format_string',
         'layout_xml',           # FIXME: all layouts should be stored in xml format to greatly simplify handling -chris_n
         'creator',
+        'units',
+        'start_label',
     );
     if (scalar(@_) >1) {
         my %given_params = @_;
@@ -59,24 +62,29 @@ sub _check_params {
     return $exit_code;
 }
 
+use constant PRESET_FIELDS => [qw(title author isbn issn itemtype barcode itemcallnumber)];
 sub new {
     my $invocant = shift;
     my $self = '';
     if (_check_params(@_) eq 1) {
-        return;
+        return -1;
     }
     my $type = ref($invocant) || $invocant;
     if (grep {$_ eq 'Labels'} @_) {
        $self = {
+            layout_xml      =>      '',
+            units           =>      'POINT',
+            start_label     =>      1,
             barcode_type    =>      'CODE39',
             printing_type   =>      'BAR',
             layout_name     =>      'DEFAULT',
             guidebox        =>      0,
+            oblique_title   =>      1,
             font            =>      'TR',
             font_size       =>      3,
             callnum_split   =>      0,
             text_justify    =>      'L',
-            format_string   =>      'title, author, isbn, issn, itemtype, barcode, callnumber',
+            format_string   =>      join(', ', @{ PRESET_FIELDS() }),
             @_,
         };
     }
@@ -95,13 +103,11 @@ sub retrieve {
     my %opts = @_;
     my $type = ref($invocant) || $invocant;
     my $query = "SELECT * FROM creator_layouts WHERE layout_id = ? AND creator = ?";
-    #warn "QUERY: $query\n";    #XXX Remove
-    #warn "PARAMS: layout_id=" . $opts{'layout_id'} . " creator=" . $opts{'creator'} . "\n";    #XXX Remove
     my $sth = C4::Context->dbh->prepare($query);
     $sth->execute($opts{'layout_id'}, $opts{'creator'});
     if ($sth->err) {
         warn sprintf('Database returned the following error: %s', $sth->errstr);
-        return;
+        return -1;
     }
     my $self = $sth->fetchrow_hashref;
     bless ($self, $type);
@@ -125,8 +131,8 @@ sub delete {
         push @params, $opts{'layout_id'}, $opts{'creator'};
     }
     if (scalar(@params) < 2) {   # If there is no layout id or creator type then we cannot delete it
-        warn sprintf('%s : Cannot delete layout as the profile id is invalid or non-existant.', $call_type) if !$params[0];
-        warn sprintf('%s : Cannot delete layout as the creator type is invalid or non-existant.', $call_type) if !$params[1];
+        warn sprintf('%s : Cannot delete layout as the profile id is invalid or non-existent.', $call_type) if !$params[0];
+        warn sprintf('%s : Cannot delete layout as the creator type is invalid or non-existent.', $call_type) if !$params[1];
         return -1;
     }
     my $query = "DELETE FROM creator_layouts WHERE layout_id = ? AND creator = ?";
@@ -136,7 +142,6 @@ sub delete {
         warn sprintf('Database returned the following error on attempted DELETE: %s', $sth->errstr);
         return -1;
     }
-    return; # return no error code on success
 }
 
 sub save {
@@ -157,7 +162,7 @@ sub save {
         $sth->execute(@params);
         if ($sth->err) {
             warn sprintf('Database returned the following error: %s', $sth->errstr);
-            return;
+            return -1;
         }
         return $self->{'layout_id'};
     }
@@ -179,7 +184,7 @@ sub save {
         $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(layout_id) FROM creator_layouts;");
         $sth1->execute();
@@ -192,19 +197,22 @@ sub save {
 sub get_attr {
     my $self = shift;
     if (_check_params(@_) eq 1) {
-        return;
+        return -1;
     }
     my ($attr) = @_;
     if (exists($self->{$attr})) {
         return $self->{$attr};
     }
+    else {
+        return -1;
+    }
     return;
 }
 
 sub set_attr {
     my $self = shift;
     if (_check_params(@_) eq 1) {
-        return;
+        return -1;
     }
     my %attrs = @_;
     foreach my $attrib (keys(%attrs)) {
@@ -219,7 +227,7 @@ sub get_text_wrap_cols {
     my $string = '';
     my $strwidth = 0;
     my $col_count = 0;
-    my $textlimit = $params{'label_width'} - ( 3 * $params{'left_text_margin'});
+    my $textlimit = $params{'label_width'} - (( 3 * $params{'left_text_margin'} ) || 13.5 );
 
     while ($strwidth < $textlimit) {
         $string .= '0';
@@ -261,7 +269,7 @@ This module provides methods for creating, retrieving, and otherwise manipulatin
             CODE39MOD10     = Code 3 of 9 with modulo 10 checksum
 
 =item .
-            COOP2OF5        = A varient of 2 of 5 barcode based on NEC's "Process 8000" code
+            COOP2OF5        = A variant of 2 of 5 barcode based on NEC's "Process 8000" code
 
 =item .
             INDUSTRIAL2OF5  = The standard 2 of 5 barcode (a binary level bar code developed by Identicon Corp. and Computer Identics Corp. in 1970)
@@ -387,7 +395,7 @@ R       = Right
 
 =head2 get_attr($attribute)
 
-    Invoking the I<get_attr> method will return the value of the requested attribute or undef on error.
+    Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors.
 
     example:
         C<my $value = $layout->get_attr($attribute);>