]> Frank Brehm's Git Trees - books.git/commitdiff
Weiter mit Umlagern der Module
authorFrank Brehm <frank@brehm-online.com>
Tue, 16 Feb 2010 23:02:48 +0000 (23:02 +0000)
committerFrank Brehm <frank@brehm-online.com>
Tue, 16 Feb 2010 23:02:48 +0000 (23:02 +0000)
13 files changed:
frbr_books.yml
lib/FrBr/Books.pm
lib/FrBr/Books/Controller/Autor.pm
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Controller/Root.pm
lib/FrBr/Books/Controller/Serie.pm
lib/FrBr/Books/Plugin/Author.pm [new file with mode: 0644]
lib/FrBr/Books/Plugin/BookAdd.pm [new file with mode: 0644]
lib/FrBr/Books/Plugin/ConfigLoader.pm
lib/FrBr/Books/Plugin/Serie.pm
lib/FrBr/Books/Plugin/User.pm
lib/FrBr/Books/Util/Author.pm [deleted file]
lib/FrBr/Books/Util/Book.pm

index 892a803ab37290437ac7f74ecb3d2b665c0e668e..199bb6e03cf52423a2313d94309a7ae822345d13 100644 (file)
@@ -12,7 +12,10 @@ log_level:      info
 colored_log:    0
 #
 # Standard-Listenlaenge
-default_list_length:    20
+default_list_length: 20
+#
+# Maximallänge von Autor und Buchtitel in Listen
+max_length_title:    40
 #
 # Anzahl der angezeigten zugeordneten Bücher in einer anderen Liste
 default_count_books_in_other_list: 5
index 983e1e071a4efea657128bb3ea3086821039d833..36dec1eb1196173b8ee1d0a19fe2029f8b8c4952 100644 (file)
@@ -38,6 +38,8 @@ use Catalyst qw/
     Session::Store::DBIC
     Session::State::Cookie
 
+    +FrBr::Books::Plugin::Author
+    +FrBr::Books::Plugin::BookAdd
     +FrBr::Books::Plugin::Ort
     +FrBr::Books::Plugin::Serie
     +FrBr::Books::Plugin::User
@@ -104,6 +106,7 @@ __PACKAGE__->config(
         },
     },
     'default_view'  => 'TtDefault',
+    'max_length_title'  => 40,
     'View::TtDefault' => {
         'CATALYST_VAR' => 'Catalyst',
         'INCLUDE_PATH' => [
index dc420b2e2219c22d43f03184087aee4daaa78e38..59dc3f4b46a2b1ad31d70513e5c697fbb69a1dcb 100644 (file)
@@ -8,7 +8,6 @@ use warnings;
 use base 'Catalyst::Controller';
 
 use FrBr::Common;
-use FrBr::Books::Util::Author;
 
 =head1 NAME
 
@@ -125,7 +124,7 @@ sub list : Local {
         $c->session->{'autor_list_page'} = $page;
     }
 
-    my ( $liste, $anzahl )  = get_author_list( $c, 'get_books' => 1, 'page' => $page );
+    my ( $liste, $anzahl )  = $c->b_get_author_list( 'get_books' => 1, 'page' => $page );
     $c->log->debug( get_output_string( $K, "Erhaltene Liste der Autoren: ", $liste ) ) if $c->stash->{'debug_level'} >= 2;
     my $max_page = 1;
     if ( $anzahl ) {
@@ -239,7 +238,7 @@ sub form_view : Path('view') {
         return 1;
     }
 
-    my $aliste = get_author_list( $c, 'autor_id' => $aid, 'get_books' => 1, );
+    my $aliste = $c->b_get_author_list( 'autor_id' => $aid, 'get_books' => 1, );
     $c->log->debug( get_output_string( $K, "Erhaltene Autorenliste: ", $aliste ) ) if $c->stash->{'debug_level'} >= 2;
 
     unless ( $aliste and scalar( @$aliste ) ) {
@@ -259,7 +258,7 @@ sub form_view : Path('view') {
 
 #-------------------------------------------------------
 
-=head2 delete_autor( )
+=head2 delete_autor_form( )
 
 Loescht einen vorhandenen Autor.
 
@@ -295,7 +294,7 @@ sub delete_autor_form : Path('delete') {
     $c->session->{'delete_autor_id'} = $aid;
 
     # Angaben zum Autor aus der Datenbank holen
-    my $aliste = get_author_list( $c, 'autor_id' => $aid );
+    my $aliste = $c->b_get_author_list( 'autor_id' => $aid );
 
     unless ( $aliste and scalar( @$aliste ) ) {
         $c->stash->{'template'} = 'error.tt2';
@@ -324,7 +323,7 @@ sub delete_autor_form : Path('delete') {
 
     if ( $c->request->params->{'really_delete_author'} and $c->request->params->{'really_delete_author'} eq 'yes' and $c->request->params->{'do_delete'} ) {
         eval {
-            delete_autor( $c, $aid );
+            $c->b_delete_autor( $aid );
         };
         if ( $@ ) {
             $c->stash->{'error_message'} = $@;
@@ -382,7 +381,7 @@ sub form_edit : Path('edit') {
     }
 
     # Angaben zum Autor aus der Datenbank holen
-    my $aliste = get_author_list( $c, 'autor_id' => $aid );
+    my $aliste = $c->b_get_author_list( 'autor_id' => $aid );
 
     unless ( $aliste and scalar( @$aliste ) ) {
         $c->stash->{'template'} = 'error.tt2';
@@ -437,7 +436,7 @@ sub save_author : Private {
        $c->log->debug( get_output_string( $K, "Sichere Autor: ", $c->stash->{'autor_edit'} ) ) if $c->stash->{'debug_level'} >= 2;
     my $autor_id = undef;
     eval {
-        $autor_id = save_autor( $c, $c->stash->{'autor_edit'} );
+        $autor_id = $c->b_save_autor( $c->stash->{'autor_edit'} );
     };
     if ( $@ ) {
         $c->stash->{'error_message'} = $@;
index ea9d380974937cb3becc75d12c8b3db2bb3ef241..7dc248eb87ec02ae911e45bb246020ea247c3a5c 100644 (file)
@@ -8,7 +8,6 @@ use warnings;
 use base 'Catalyst::Controller';
 
 use FrBr::Common;
-use FrBr::Books::Util::Author;
 use FrBr::Books::Util::Book;
 use FrBr::Books::Util::Bindungsart;
 use FrBr::Books::Util::Category;
@@ -1266,7 +1265,7 @@ sub prepare_data_structures : Private {
     my $K = ( caller(0) )[3] . "(): ";
 
     # Autoren zusammensammeln
-    my $autor_list_complete = get_author_list($c);
+    my $autor_list_complete = $c->b_get_author_list();
     $c->log->debug( get_output_string( $K . "Autoren gesamt: ", $autor_list_complete ) );
 
     $c->stash->{'autor_list'} = {};
index 5ebe27b65aaa68c4abe2e469bacb4255ec6891d6..731747becfc72f47c7187290f6883483fce3d6e9 100644 (file)
@@ -127,19 +127,6 @@ sub auto : Private {
         $c->stash->{'is_test_environment'} = 1;
     }
 
-#    $storage->sql_maker->quote_char( [qw/` `/] );
-#    $storage->sql_maker->name_sep('.');
-#
-#    my $SQL = "SET NAMES 'utf8'";
-#    warn $SQL . ";\n" if $storage->debug();
-#
-#    $storage->dbh_do(
-#        sub {
-#            my ( $storage_a, $dbh ) = @_;
-#            $dbh->do($SQL);
-#        }
-#    );
-
     $c->session->{'last_run'} = localtime();
 
     # Letzten und aktuellen Pfad behalten
@@ -223,6 +210,9 @@ sub auto : Private {
     # Listenlaenge festlegen
     $c->stash->{'list_length'} = $c->session->{'list_length'} || $c->config->{'default_list_length'} || 20;
 
+    # Maximallänge von Autor und Buchtitel in Listen festlegen
+    $c->stash->{'max_length_title'} = $c->session->{'max_length_title'} || $c->config->{'max_length_title'} || 40;
+
     # Anzahl der angezeigten zugeordneten Bücher in einer anderen Liste
     $c->stash->{'books_in_other_list'} = $c->session->{'books_in_other_list'} || $c->config->{'default_count_books_in_other_list'} || 10;
 
index 17f21ef253f239e92c290051bf247c399591ff7b..eb47664bf4b983d786934ec8fba1742e1b5cf4f4 100644 (file)
@@ -431,7 +431,7 @@ sub prepare_data_structures : Private {
     my $K = ( caller(0) )[3] . "(): ";
 
     # Liste aller Bücher zusammensammeln
-    my $buchliste = get_booklist( $c, { 'sort_criteria' => [ 'title', 'autoren' ], } );
+    my $buchliste = get_booklist( $c, { 'short_author' => 1, 'sort_criteria' => [ 'title', 'autoren' ], } );
 
     $c->stash->{'book_list'} = {};
     $c->stash->{'book_array_sorted'} = [];
@@ -439,8 +439,9 @@ sub prepare_data_structures : Private {
     for my $book ( @$buchliste ) {
 
         my $buch_id = $book->{'id'};
-        my $title = $book->{'title'};
-        $title .= " (" . join( ", ", @{ $book->{'autoren'} } ) . ")" if ( $book->{'autoren'} and scalar(@{ $book->{'autoren'} }) );
+        #my $title = $book->{'title'};
+        #$title .= " (" . join( ", ", @{ $book->{'autoren'} } ) . ")" if ( $book->{'autoren'} and scalar(@{ $book->{'autoren'} }) );
+        my $title = $c->b_complete_book_title( $book );
 
         $c->stash->{'book_list'}{$buch_id} = $title;
         push @{ $c->stash->{'book_array_sorted'} }, $buch_id;
diff --git a/lib/FrBr/Books/Plugin/Author.pm b/lib/FrBr/Books/Plugin/Author.pm
new file mode 100644 (file)
index 0000000..e945ff4
--- /dev/null
@@ -0,0 +1,505 @@
+package FrBr::Books::Plugin::Author;
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use FrBr::Common;
+use FrBr::Books::Util::Locks;
+
+our $VERSION = '0.2';
+{
+    my ($rev) = '$Revision$' =~ /(\d+)/;
+    $VERSION = sprintf( $VERSION . ".%d", $rev );
+}
+
+=head1 NAME
+
+FrBr::Books::Plugin::Author - Modul fuer Funktionen rund um Autoren
+
+=head1 METHODS
+
+=cut
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_get_author_list( $params )
+
+Sammelt alle Autoren zusammen.
+
+Folgende benannte Parameter koennen ueber $params uebergeben werden:
+
+=over 4
+
+=item B<get_books>
+
+Boolscher Parameter, der aussagt, dass auch die Buecher des Autors / der Autoren
+mit zuammengesammelt werden sollen.
+
+=item B<autor_id>: Die ID eines konkreten Autors
+
+=item B<page>
+
+Integer: Zeigt an, welche Seite von Verlagen dargestellt werden soll.
+
+Wenn nicht angegeben, werden alle Verlage zurückgegeben.
+
+=item B<list_length>
+
+Listenlänge einer Seite (wenn seitenweise gewünscht wird).
+
+=back
+
+Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen Suchkriterien entsprechen, sowie im Listenkontext die Anzahl der Autoren, die den uebergebenen Suchkriterien entsprechen.
+
+Die zurueckgegebene Array-Ref hat folgenden Aufbau:
+
+       $res = [
+               {
+                       'id'          => 1,
+                       'name'        => 'J.R.R. Tolkien',
+                       'titel'       => undef,
+                       'vorname'     => 'J.R.R.',
+                       'mittelname'  => undef,
+                       'nachname'    => 'Tolkien',
+                       'name_suffix' => undef,
+                       'descr'       => 'Bla Blub',
+                       'about'       => 'Der Autor wurde ...',
+                       'books'       => [
+                               {
+                                       'id'             => 22,
+                                       'title'          => 'Der Herr der Ringe',
+                                       'title_original' => 'The Lord Of The Rings',
+                                       'untertitel'     => 'Triligie',
+                                       'isbn'           => '123-45-678-908',
+                               },
+                               {
+                                       'id'             => 34,
+                                       'title'          => 'Silmarillion',
+                                       ...
+                               },
+                               ...
+                       ],
+               },
+               {
+                       'id'    => 2,
+                       ...
+               },
+                       ...
+       ];
+
+Die Liste ist nach den Nachnamen, Vornamen, Mittelnamen und Namens-Suffixen alphabetisch sortiert.
+
+=cut
+
+sub b_get_author_list {
+
+    my $c = shift;
+    my $K = ( caller(0) )[3] . "(): ";
+
+    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+    my $params = {};
+    if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
+        $params = $_[0];
+    }
+    else {
+        %$params = @_;
+    }
+    $c->log->debug(  get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
+
+    my $list = [];
+       my $anzahl_autoren = 0;
+
+       my $page = to_int( $params->{'page'} ) ? to_int( $params->{'page'} ) : undef;
+       my $rows = to_int( $params->{'list_length'} ) ? to_int( $params->{'list_length'} ) : undef;
+    unless ( defined $rows ) {
+           $rows = $c->stash->{'list_length'} || 20 if defined $page;
+    }
+
+    my $search_params = undef;
+       if ( $params->{'autor_id'} ) {
+               $search_params = {
+                       'me.id' => $params->{'autor_id'},
+               };
+       }
+
+       $anzahl_autoren = $c->model('Schema::Autoren')->count( $search_params );
+    $c->log->debug(  get_output_string( $K, "Anzahl gefundene Autoren: ", $anzahl_autoren ) ) if $c->stash->{'debug_level'} >= 2;
+
+    my $other_params = {};
+    $other_params->{'order_by'} = [ 'nachname', 'vorname', 'mittelname', 'name_suffix' ];
+    $other_params->{'select'} = [
+        'id',
+        'titel',
+        'vorname',
+        'mittelname',
+        'nachname',
+        'name_suffix',
+        'autor_descr',
+               'about',
+    ];
+    $other_params->{'as'} = [
+        'id',
+        'titel',
+        'vorname',
+        'mittelname',
+        'nachname',
+        'name_suffix',
+        'autor_descr',
+               'about',
+    ];
+       if ( $page ) {
+               $other_params->{'rows'} = $rows;
+               $other_params->{'page'} = $page;
+       }
+       for my $autor_rs ( $c->model('Schema::Autoren')->search( $search_params, $other_params )->all() ) {
+               my $autor = {};
+               $autor->{'id'}          = $autor_rs->id();
+               $autor->{'titel'}       = $autor_rs->titel();
+               $autor->{'vorname'}     = $autor_rs->vorname();
+               $autor->{'mittelname'}  = $autor_rs->mittelname();
+               $autor->{'nachname'}    = $autor_rs->nachname();
+               $autor->{'name_suffix'} = $autor_rs->name_suffix();
+               $autor->{'descr'}       = $autor_rs->autor_descr();
+               $autor->{'about'}       = $autor_rs->about();
+               $autor->{'books'}       = [];
+               my @N;
+               push @N, $autor->{'titel'} if $autor->{'titel'};
+               push @N, $autor->{'vorname'} if $autor->{'vorname'};
+               push @N, $autor->{'mittelname'} if $autor->{'mittelname'};
+               push @N, $autor->{'nachname'};
+               push @N, $autor->{'name_suffix'} if $autor->{'name_suffix'};
+               $autor->{'name'}  = join( " ", @N );
+               push @$list, $autor;
+       }
+
+    if ( $params->{'get_books'} ) {
+        for my $autor ( @$list ) {
+            my $aid = $autor->{'id'};
+            $search_params = { 'autor_id' => $autor->{'id'} };
+            $other_params = {};
+            $other_params->{'order_by'} = [ 'buch.title', 'buch.untertitel' ];
+            $other_params->{'join'}     = [ 'buch' ];
+            $other_params->{'select'}   = [
+                'me.id',
+                'me.ord_num',
+                'buch.id',
+                'buch.title',
+                'buch.title_original',
+                'buch.untertitel',
+                'buch.isbn',
+            ];
+            $other_params->{'as'}   = [
+                'id',
+                'ord_num_book_author',
+                'buch_id',
+                'title',
+                'title_original',
+                'untertitel',
+                'isbn',
+            ];
+            $c->log->debug(  get_output_string( $K, "Suchparameter: ", $search_params ) ) if $c->stash->{'debug_level'} >= 2;
+            $c->log->debug(  get_output_string( $K, "Andere Parameter: ", $other_params ) ) if $c->stash->{'debug_level'} >= 2;
+            my $uhu = $c->model('Schema');
+            #$c->log->debug(  get_output_string( $K, "Datenquelle: ", $uhu ) ) if $c->stash->{'debug_level'} >= 2;
+            #for my $ref ( $c->model('Schema::Autor2buch')->search( $search_params, $other_params )->all() ) {
+            for my $ref ( $c->model('Schema')->resultset('Autor2buch')->search( $search_params, $other_params )->all() ) {
+
+                my $buch = {};
+
+                $buch->{'id'}             = $ref->get_column('buch_id');
+                $buch->{'title'}          = $ref->get_column('title');
+                $buch->{'title_original'} = $ref->get_column('title_original');
+                $buch->{'untertitel'}     = $ref->get_column('untertitel');
+                $buch->{'isbn'}           = $ref->get_column('isbn');
+
+                push @{ $autor->{'books'} }, $buch;
+
+            }
+        }
+    }
+
+    return ( wantarray ? ( $list, $anzahl_autoren ) : $list );
+}
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_save_autor( $autor )
+
+=cut
+
+sub b_save_autor {
+
+       my $c     = shift;
+       my $autor = shift;
+       my $K = ( caller(0) )[3] . "(): ";
+
+       $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+    my $storage = $c->model('Schema')->storage;
+       $c->stash->{'storage'}{'save_autor_result'} = '';
+
+       my $search_params = {};
+       my $row = {};
+
+    my $tmp = $autor->{'titel'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'titel'} = $tmp eq '' ? undef : $tmp;
+
+    $tmp = $autor->{'vorname'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'vorname'} = $tmp eq '' ? undef : $tmp;
+       $search_params->{'vorname'} = $tmp if $tmp ne '';
+
+    $tmp = $autor->{'mittelname'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'mittelname'} = $tmp eq '' ? undef : $tmp;
+       $search_params->{'mittelname'} = $tmp if $tmp ne '';
+
+    $tmp = $autor->{'nachname'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'nachname'} = $tmp;
+       $search_params->{'nachname'} = $tmp;
+
+    $tmp = $autor->{'name_suffix'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'name_suffix'} = $tmp eq '' ? undef : $tmp;
+       $search_params->{'name_suffix'} = $tmp if $tmp ne '';
+
+    $tmp = $autor->{'descr'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'autor_descr'} = $tmp;
+
+    $tmp = $autor->{'about'};
+    $tmp = '' unless defined $tmp;
+    $tmp =~ s/^\s+//;
+    $tmp =~ s/\s+$//;
+       $row->{'about'} = $tmp eq '' ? undef : $tmp;
+
+       my $saved_aid = $c->b_get_autor_id( $search_params );
+       
+    # Zuerst einmal Test im nichgelocktem Zustand ...
+    if ( $autor->{'id'} ) {
+        if ( $saved_aid and ( $saved_aid != $autor->{'id'} ) ) {
+            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den übergebenen Angaben.';
+            $c->log->info( $K . "Es existiert bereits ein Autor mit den übergebenen Angaben." );
+            return undef;
+        }
+    }
+    else {
+        if ( $saved_aid ) {
+            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den uebergebenen Angaben.';
+            $c->log->info( $K . "Es existiert bereits ein Autor mit den uebergebenen Angaben." );
+            return undef;
+        }
+    }
+
+    # Sperren der Autoren-Tabelle
+    lock_tables( $c, 'write' => [ 'autoren', 'autoren', 'as', 'me' ] );
+
+       $saved_aid = $c->b_get_autor_id( $search_params );
+       
+    # Und jetzt Test im gelocktem Zustand ...
+    if ( $autor->{'id'} ) {
+        if ( $saved_aid and ( $saved_aid != $autor->{'id'} ) ) {
+            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den übergebenen Angaben.';
+            $c->log->info( $K . "Es existiert bereits ein Autor mit den übergebenen Angaben." );
+            unlock_tables($c);
+            return undef;
+        }
+    }
+    else {
+        if ( $saved_aid ) {
+            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den uebergebenen Angaben.';
+            $c->log->info( $K . "Es existiert bereits ein Autor mit den uebergebenen Angaben." );
+            unlock_tables($c);
+            return undef;
+        }
+    }
+
+    my $new_id = undef;
+
+       eval {
+               if ( $autor->{'id'} ) {
+                       $new_id = $autor->{'id'};
+                       my $count = $c->model('Schema::Autoren')->count( { 'id' => $autor->{'id'} } );
+                       if ( $count ) {
+                               $c->model('Schema::Autoren')->search( { 'id' => $autor->{'id'} } )->update( $row );
+                       }
+                       else {
+                               $row->{'id'} = $new_id;
+                               $c->model('Schema::Autoren')->create($row);
+                       }
+               }
+               else {
+                       $c->model('Schema::Autoren')->create($row);
+               $new_id = $storage->last_insert_id();
+               }
+       };
+       if ( $@ ) {
+               $c->stash->{'save_autor_result'} = $@;
+               $c->log->info( $K . $@ );
+               unlock_tables($c);
+               return undef;
+       }
+
+    unlock_tables($c);
+    $c->stash->{'save_autor_result'} = 'OK';
+    return $new_id;
+
+}
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_get_autor_id( 'nachname' => 'Wolf', 'vorname' => 'Friedrich' )
+
+=cut
+
+sub b_get_autor_id {
+
+    my $c = shift;
+    my $K = ( caller(0) )[3] . "(): ";
+
+    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 3;
+
+    my $params = {};
+    if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
+        $params = $_[0];
+    }
+    else {
+        %$params = @_;
+    }
+    $c->log->debug(  get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
+
+    my $storage = $c->model('Schema')->storage;
+    #$c->log->debug(  get_output_string( $K, "Storage: ", $storage ) ) if $c->stash->{'debug_level'} >= 4;
+
+    my $name = $params->{'nachname'};
+    $name = $params->{'mittelname'} . " " . $name if defined $params->{'mittelname'};
+    $name = $params->{'vorname'} . " " . $name if defined $params->{'vorname'};
+    $name .= " " . $params->{'name_suffix'} if defined $params->{'name_suffix'};
+
+    my $select_func = sub {
+
+        my ( $storage, $dbh, $name ) = @_;
+        my $sql = <<ENDE;
+SELECT `me`.`id`
+  FROM `autoren` AS `me`
+ WHERE CONCAT(
+           IFNULL( `me`.`vorname`, '' ),    IF( ISNULL(`me`.`vorname`), '', ' ' ),
+           IFNULL( `me`.`mittelname`, '' ), IF( ISNULL(`me`.`mittelname`), '', ' ' ),
+           `me`.`nachname`,
+           IF( ISNULL( `me`.`name_suffix` ), '', ' ' ), IFNULL( `me`.`name_suffix`, '' )
+       ) = ?
+ENDE
+
+        if ( $storage->debug() ) {
+            my $text = $sql;
+            $text =~ s/\s+$//;
+            $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $name ) ) . "\n";
+            warn $text;
+        }
+
+        my $sth = $dbh->prepare($sql);
+        $sth->execute( $name );
+
+        return $sth->fetchall_arrayref();
+    };
+
+    my $id = undef;
+    for my $autor_rs ( $storage->dbh_do( $select_func, $name ) ) {
+        $id = $autor_rs->[0][0];
+    }
+
+       $c->log->debug( $K . get_output_string( "Ermittelte Autor-Id: ", ( defined $id ? $id : '<keine>' ) ) ) if $c->stash->{'debug_level'} >= 2;
+    return $id;
+
+}
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_delete_autor( $autor_id )
+
+Loescht den Autor mit der uebergebenen Autor-Id
+
+=cut
+
+sub b_delete_autor {
+
+    my $c        = shift;
+    my $autor_id = shift;
+    my $K        = ( caller(0) )[3] . "(): ";
+
+    $c->log->debug( $K . "aufgerufen fuer Autor-Id " . ( defined $autor_id ? $autor_id : '<undef>' ) . "." ) if $c->stash->{'debug_level'} > 2;
+
+    return undef unless $autor_id and to_int($autor_id);
+    $autor_id = to_int($autor_id);
+
+    my $schema =  $c->model('Schema')->{'schema'};
+
+#      # Sperren der Autoren- und der Buecher-Tabelle
+#      lock_tables( $c, 'write' => [ 'autoren', 'autoren', 'as', 'me', ], 'read' => [ 'autor2buch', 'autor2buch', 'as', 'me', ] );
+
+       # Raus, wenn der Autor noch Buecher hat ...
+       if ( $c->model('Schema::Autor2buch')->count( { 'autor_id' => $autor_id, } ) ) {
+               my $msg = 'Es existieren noch Buecher dieses Autors.';
+#              unlock_tables($c);
+               die $msg . "\n";
+       }
+
+       # Das eigentliche Löschen
+    my $coderef = sub {
+        $c->model('Schema::Autoren')->search( { 'id' => $autor_id } )->delete();
+    };
+
+    my $rs;
+    eval {
+        $rs = $schema->txn_do($coderef);
+    };
+
+    if ($@) {                             # Transaction failed
+               my $msg = $@ =~ /Rollback failed/i ? "Rollback nicht erfolgreich!" : $@;
+#              unlock_tables($c);
+               die $msg . "\n";
+               return undef;
+    }
+#    unlock_tables($c);
+       return 1;
+
+}
+
+#-----------------------------------------------------------------------------------
+
+=head1 AUTHOR
+
+Frank Brehm
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
+
+__END__
+
+# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
diff --git a/lib/FrBr/Books/Plugin/BookAdd.pm b/lib/FrBr/Books/Plugin/BookAdd.pm
new file mode 100644 (file)
index 0000000..e7888c8
--- /dev/null
@@ -0,0 +1,97 @@
+package FrBr::Books::Plugin::BookAdd;
+
+# $Id$
+# $URL$
+
+use Carp qw/croak/;
+use FrBr::Common;
+
+our $VERSION = '0.1';
+{
+    my ($rev) = '$Revision$' =~ /(\d+)/;
+    $VERSION = sprintf( $VERSION . ".%d", $rev );
+}
+
+#---------------------------------------------------------------------------
+
+=head2 $c->b_complete_book_title( $book )
+
+Gibt einen kompletten Buchtitel (mit Autoren) zurück,
+wobei die Maximallänge von Buchtitel und Autoren berücksichtigt wird.
+
+Übergeben wird eine Hash-Ref, die folgenden Aufbau haben muss:
+
+    $book = {
+        'autoren' => [
+            'Bill Napier',
+            'John Doe',
+        ],
+        'title' => 'Der 77. Grad',
+        'untertitel' => undef,
+    };
+
+Die Rückggabe erfolgt als String der Form:
+
+    $title = 'Der 77. Grad (Bill Napier, John Doe)';
+
+=cut
+
+sub b_complete_book_title {
+
+    my $c = shift;
+    my $book = shift;
+    my $K = ( caller(0) )[3] . "(): ";
+
+    $c->log->debug( get_output_string( $K, "aufgerufen." ) );
+
+    unless ( $book and ref($book) and ( ref($book) eq 'HASH' ) ) {
+        carp( sprintf( "%sKein Buch übergeben!", $K ) );
+        return undef;
+    }
+
+    my $res = '';
+    my $max = $c->stash->{'max_length_title'} || $c->session->{'max_length_title'} || $c->config->{'max_length_title'} || 40;
+    $max = 10 if $max < 10;
+
+    # Buchtitel stutzen
+    $res = defined $book->{'title'} ? $book->{'title'} : '';
+    $res =~ s/^\s+//;
+    $res =~ s/\s+$//;
+    if ( length($res) > $max ) {
+        $res = substr( $res, 0, ( $max - 3 ) ) . "...";
+    }
+
+    # Autor stutzen
+    my $authors = '';
+    if ( $book->{'autoren'} and scalar( @{ $book->{'autoren'} } ) ) {
+
+        # Runde 1 - volle Autoren
+        $authors = join( ", ", @{ $book->{'autoren'} } );
+
+        # Runde 2 - Autoren einzeln stutzen
+        if ( length($authors) > $max ) {
+            $authors = join( ", ", map { substr( $_, 0, ( $max - 3 ) ) . "..." } @{ $book->{'autoren'} } );
+        }
+
+        # Runde 3 - Autoren insgesamt stutzen
+        if ( length($authors) > $max ) {
+            $authors = substr( $authors, 0, ( $max - 3 ) ) . "...";
+        }
+
+        $res .= " (" . $authors . ")" if $authors;
+
+    }
+
+    return $res;
+
+}
+
+#---------------------------------------------------------------------------
+
+1;
+
+#---------------------------------------------------------------------------
+
+__END__
+
+# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
index 714e70e91fc2a59382a2e1ec5f9e795b50a0bf26..a7600b83c41a7736eb67f6210b8afdef1756ee73 100644 (file)
@@ -6,7 +6,7 @@ package FrBr::Books::Plugin::ConfigLoader;
 use base "Catalyst::Plugin::ConfigLoader";
 use FrBr::Common;
 
-our $VERSION = '0.03';
+our $VERSION = '0.3';
 {
     my ($rev) = '$Revision$' =~ /(\d+)/;
     $VERSION = sprintf( $VERSION . ".%d", $rev );
index af5064f6c5022d2dc1e1f949d80bdb4297cd3ad7..a688879deb27bc90fbe040264d25a115410ddf96 100644 (file)
@@ -15,10 +15,6 @@ our $VERSION = '0.2';
     $VERSION = sprintf( $VERSION . ".%d", $rev );
 }
 
-#        &get_serienliste
-#        &save_serie
-#        &delete_serie
-
 =head1 NAME
 
 FrBr::Books::Plugin::Serie - Modul fuer Funktionen rund um Buchserien
index a5742d2a989e47beb0dc13236e3686ba37adf6c4..d7c8aef2f53fb65e3aae3792ddaa57bb7fea0188 100644 (file)
@@ -52,9 +52,15 @@ sub b_save_user_prefs {
     # Filter für Buchliste speichern
     $prefs->{'booklist_filter'} = $c->session->{'booklist_filter'} if $c->session->{'booklist_filter'};
 
+
+    # Maximallänge von Autor und Buchtitel in Listen festlegen
+    $prefs->{'max_length_title'} = $c->session->{'max_length_title'} if $c->session->{'max_length_title'};
+
     # Anzahl der angezeigten zugeordneten Bücher in einer anderen Liste
     $prefs->{'books_in_other_list'} = $c->stash->{'books_in_other_list'};
 
+    $c->log->debug( get_output_string( $K, "Speicher Nutzereinstellungenin Datenbank: ", $prefs ) );
+
     my $dump = Dump($prefs);
     $c->model('Schema::UserAdd')->search( { 'user_id' => $user_id } )->update( { 'prefs' => $dump } ) ;
 
@@ -94,6 +100,7 @@ sub b_restore_user_prefs {
         $c->log->warn( $k . "Fehler beim Restore der Nutzereinstellungen: " . $@ );
         return; 
     }
+    $c->log->debug( get_output_string( $K, "Aus der Datenbank erhaltene Nutzereinstellungen: ", $prefs ) );
     return unless $prefs;
 
     if ( $prefs->{'list_length'} ) {
@@ -115,6 +122,12 @@ sub b_restore_user_prefs {
 
     }
 
+    # Maximallänge von Autor und Buchtitel in Listen festlegen
+    if ( $prefs->{'max_length_title'} ) {
+        $c->session->{'max_length_title'} = $prefs->{'max_length_title'};
+        $c->stash->{'max_length_title'} = $prefs->{'max_length_title'};
+    }
+
     # Sortierkriterien der Buchliste
     $c->session->{'book_order_criteria'} = $prefs->{'book_order_criteria'} if $prefs->{'book_order_criteria'};
 
diff --git a/lib/FrBr/Books/Util/Author.pm b/lib/FrBr/Books/Util/Author.pm
deleted file mode 100644 (file)
index 5ba8d81..0000000
+++ /dev/null
@@ -1,522 +0,0 @@
-package FrBr::Books::Util::Author;
-
-# $Id$
-# $URL$
-
-use strict;
-use warnings;
-
-use FrBr::Common;
-use FrBr::Books::Util::Locks;
-
-# Export-Deklarationen
-
-BEGIN {
-
-    use Exporter();
-    our ( $VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
-
-    # set the version for version checking
-    $VERSION = 0.1;
-    my ($rev) = '$Revision$' =~ /(\d+)/;
-    $VERSION = sprintf( $VERSION . ".%d", $rev );
-
-    @ISA    = qw(Exporter);
-    @EXPORT = qw(
-        &get_author_list
-        &get_autor_id
-        &save_autor
-               &delete_autor
-    );
-
-    #%EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
-
-    # your exported package globals go here,
-    # as well as any optionally exported functions
-    #@EXPORT_OK   = qw($Var1 %Hashit &func3);
-} ## end BEGIN
-
-our @EXPORT_OK;
-
-=head1 NAME
-
-FrBr::Books::Util::Author - Modul fuer Funktionen rund um Autoren
-
-=head1 METHODS
-
-=cut
-
-#-----------------------------------------------------------------------------------
-
-=head2 get_author_list( $c, $params )
-
-Sammelt alle Autoren zusammen.
-
-Folgende benannte Parameter koennen ueber $params uebergeben werden:
-
-=over 4
-
-=item B<get_books>
-
-Boolscher Parameter, der aussagt, dass auch die Buecher des Autors / der Autoren
-mit zuammengesammelt werden sollen.
-
-=item B<autor_id>: Die ID eines konkreten Autors
-
-=item B<page>
-
-Integer: Zeigt an, welche Seite von Verlagen dargestellt werden soll.
-
-Wenn nicht angegeben, werden alle Verlage zurückgegeben.
-
-=back
-
-Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen Suchkriterien entsprechen, sowie im Listenkontext die Anzahl der Autoren, die den uebergebenen Suchkriterien entsprechen.
-
-Die zurueckgegebene Array-Ref hat folgenden Aufbau:
-
-       $res = [
-               {
-                       'id'          => 1,
-                       'name'        => 'J.R.R. Tolkien',
-                       'titel'       => undef,
-                       'vorname'     => 'J.R.R.',
-                       'mittelname'  => undef,
-                       'nachname'    => 'Tolkien',
-                       'name_suffix' => undef,
-                       'descr'       => 'Bla Blub',
-                       'about'       => 'Der Autor wurde ...',
-                       'books'       => [
-                               {
-                                       'id'             => 22,
-                                       'title'          => 'Der Herr der Ringe',
-                                       'title_original' => 'The Lord Of The Rings',
-                                       'untertitel'     => 'Triligie',
-                                       'isbn'           => '123-45-678-908',
-                               },
-                               {
-                                       'id'             => 34,
-                                       'title'          => 'Silmarillion',
-                                       ...
-                               },
-                               ...
-                       ],
-               },
-               {
-                       'id'    => 2,
-                       ...
-               },
-                       ...
-       ];
-
-Die Liste ist nach den Nachnamen, Vornamen, Mittelnamen und Namens-Suffixen alphabetisch sortiert.
-
-=cut
-
-sub get_author_list {
-
-    my $c = shift;
-    my $K = ( caller(0) )[3] . "(): ";
-
-    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
-
-    my $params = {};
-    if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
-        $params = $_[0];
-    }
-    else {
-        %$params = @_;
-    }
-    $c->log->debug(  get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
-
-    my $list = [];
-       my $anzahl_autoren = 0;
-
-       my $page = to_int( $params->{'page'} ) ? to_int( $params->{'page'} ) : undef;
-       my $rows = undef;
-       $rows = $c->stash->{'list_length'} || 20 if defined $page;
-
-    my $search_params = undef;
-       if ( $params->{'autor_id'} ) {
-               $search_params = {
-                       'me.id' => $params->{'autor_id'},
-               };
-       }
-
-       $anzahl_autoren = $c->model('Schema::Autoren')->count( $search_params );
-    $c->log->debug(  get_output_string( $K, "Anzahl gefundene Autoren: ", $anzahl_autoren ) ) if $c->stash->{'debug_level'} >= 2;
-
-    my $other_params = {};
-    $other_params->{'order_by'} = [ 'nachname', 'vorname', 'mittelname', 'name_suffix' ];
-    $other_params->{'select'} = [
-        'id',
-        'titel',
-        'vorname',
-        'mittelname',
-        'nachname',
-        'name_suffix',
-        'autor_descr',
-               'about',
-    ];
-    $other_params->{'as'} = [
-        'id',
-        'titel',
-        'vorname',
-        'mittelname',
-        'nachname',
-        'name_suffix',
-        'autor_descr',
-               'about',
-    ];
-       if ( $page ) {
-               $other_params->{'rows'} = $rows;
-               $other_params->{'page'} = $page;
-       }
-       for my $autor_rs ( $c->model('Schema::Autoren')->search( $search_params, $other_params )->all() ) {
-               my $autor = {};
-               $autor->{'id'}          = $autor_rs->id();
-               $autor->{'titel'}       = $autor_rs->titel();
-               $autor->{'vorname'}     = $autor_rs->vorname();
-               $autor->{'mittelname'}  = $autor_rs->mittelname();
-               $autor->{'nachname'}    = $autor_rs->nachname();
-               $autor->{'name_suffix'} = $autor_rs->name_suffix();
-               $autor->{'descr'}       = $autor_rs->autor_descr();
-               $autor->{'about'}       = $autor_rs->about();
-               $autor->{'books'}       = [];
-               my @N;
-               push @N, $autor->{'titel'} if $autor->{'titel'};
-               push @N, $autor->{'vorname'} if $autor->{'vorname'};
-               push @N, $autor->{'mittelname'} if $autor->{'mittelname'};
-               push @N, $autor->{'nachname'};
-               push @N, $autor->{'name_suffix'} if $autor->{'name_suffix'};
-               $autor->{'name'}  = join( " ", @N );
-               push @$list, $autor;
-       }
-
-    if ( $params->{'get_books'} ) {
-        for my $autor ( @$list ) {
-            my $aid = $autor->{'id'};
-            $search_params = { 'autor_id' => $autor->{'id'} };
-            $other_params = {};
-            $other_params->{'order_by'} = [ 'buch.title', 'buch.untertitel' ];
-            $other_params->{'join'}     = [ 'buch' ];
-            $other_params->{'select'}   = [
-                'me.id',
-                'me.ord_num',
-                'buch.id',
-                'buch.title',
-                'buch.title_original',
-                'buch.untertitel',
-                'buch.isbn',
-            ];
-            $other_params->{'as'}   = [
-                'id',
-                'ord_num_book_author',
-                'buch_id',
-                'title',
-                'title_original',
-                'untertitel',
-                'isbn',
-            ];
-            $c->log->debug(  get_output_string( $K, "Suchparameter: ", $search_params ) ) if $c->stash->{'debug_level'} >= 2;
-            $c->log->debug(  get_output_string( $K, "Andere Parameter: ", $other_params ) ) if $c->stash->{'debug_level'} >= 2;
-            my $uhu = $c->model('Schema');
-            #$c->log->debug(  get_output_string( $K, "Datenquelle: ", $uhu ) ) if $c->stash->{'debug_level'} >= 2;
-            #for my $ref ( $c->model('Schema::Autor2buch')->search( $search_params, $other_params )->all() ) {
-            for my $ref ( $c->model('Schema')->resultset('Autor2buch')->search( $search_params, $other_params )->all() ) {
-
-                my $buch = {};
-
-                $buch->{'id'}             = $ref->get_column('buch_id');
-                $buch->{'title'}          = $ref->get_column('title');
-                $buch->{'title_original'} = $ref->get_column('title_original');
-                $buch->{'untertitel'}     = $ref->get_column('untertitel');
-                $buch->{'isbn'}           = $ref->get_column('isbn');
-
-                push @{ $autor->{'books'} }, $buch;
-
-            }
-        }
-    }
-
-    return ( wantarray ? ( $list, $anzahl_autoren ) : $list );
-}
-
-#-----------------------------------------------------------------------------------
-
-=head2 save_autor( $c, $autor )
-
-=cut
-
-sub save_autor {
-
-       my $c     = shift;
-       my $autor = shift;
-       my $K = ( caller(0) )[3] . "(): ";
-
-       $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
-
-       my $storage = $c->stash->{'storage'};
-       $c->stash->{'storage'}{'save_autor_result'} = '';
-
-       my $search_params = {};
-       my $row = {};
-
-    my $tmp = $autor->{'titel'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'titel'} = $tmp eq '' ? undef : $tmp;
-
-    $tmp = $autor->{'vorname'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'vorname'} = $tmp eq '' ? undef : $tmp;
-       $search_params->{'vorname'} = $tmp if $tmp ne '';
-
-    $tmp = $autor->{'mittelname'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'mittelname'} = $tmp eq '' ? undef : $tmp;
-       $search_params->{'mittelname'} = $tmp if $tmp ne '';
-
-    $tmp = $autor->{'nachname'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'nachname'} = $tmp;
-       $search_params->{'nachname'} = $tmp;
-
-    $tmp = $autor->{'name_suffix'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'name_suffix'} = $tmp eq '' ? undef : $tmp;
-       $search_params->{'name_suffix'} = $tmp if $tmp ne '';
-
-    $tmp = $autor->{'descr'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'autor_descr'} = $tmp;
-
-    $tmp = $autor->{'about'};
-    $tmp = '' unless defined $tmp;
-    $tmp =~ s/^\s+//;
-    $tmp =~ s/\s+$//;
-       $row->{'about'} = $tmp eq '' ? undef : $tmp;
-
-       my $saved_aid = get_autor_id( $c, $search_params );
-       
-    # Zuerst einmal Test im nichgelocktem Zustand ...
-    if ( $autor->{'id'} ) {
-        if ( $saved_aid and ( $saved_aid != $autor->{'id'} ) ) {
-            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den übergebenen Angaben.';
-            $c->log->info( $K . "Es existiert bereits ein Autor mit den übergebenen Angaben." );
-            return undef;
-        }
-    }
-    else {
-        if ( $saved_aid ) {
-            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den uebergebenen Angaben.';
-            $c->log->info( $K . "Es existiert bereits ein Autor mit den uebergebenen Angaben." );
-            return undef;
-        }
-    }
-
-    # Sperren der Autoren-Tabelle
-    lock_tables( $c, 'write' => [ 'autoren', 'autoren', 'as', 'me' ] );
-
-       $saved_aid = get_autor_id( $c, $search_params );
-       
-    # Und jetzt Test im gelocktem Zustand ...
-    if ( $autor->{'id'} ) {
-        if ( $saved_aid and ( $saved_aid != $autor->{'id'} ) ) {
-            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den übergebenen Angaben.';
-            $c->log->info( $K . "Es existiert bereits ein Autor mit den übergebenen Angaben." );
-            unlock_tables($c);
-            return undef;
-        }
-    }
-    else {
-        if ( $saved_aid ) {
-            $c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den uebergebenen Angaben.';
-            $c->log->info( $K . "Es existiert bereits ein Autor mit den uebergebenen Angaben." );
-            unlock_tables($c);
-            return undef;
-        }
-    }
-
-    my $new_id = undef;
-
-       eval {
-               if ( $autor->{'id'} ) {
-                       $new_id = $autor->{'id'};
-                       my $count = $c->model('Schema::Autoren')->count( { 'id' => $autor->{'id'} } );
-                       if ( $count ) {
-                               $c->model('Schema::Autoren')->search( { 'id' => $autor->{'id'} } )->update( $row );
-                       }
-                       else {
-                               $row->{'id'} = $new_id;
-                               $c->model('Schema::Autoren')->create($row);
-                       }
-               }
-               else {
-                       $c->model('Schema::Autoren')->create($row);
-               $new_id = $storage->last_insert_id();
-               }
-       };
-       if ( $@ ) {
-               $c->stash->{'save_autor_result'} = $@;
-               $c->log->info( $K . $@ );
-               unlock_tables($c);
-               return undef;
-       }
-
-    unlock_tables($c);
-    $c->stash->{'storage'}{'save_autor_result'} = 'OK';
-    return $new_id;
-
-}
-
-#-----------------------------------------------------------------------------------
-
-=head2 get_autor_id( $c, 'nachname' => 'Wolf', 'vorname' => 'Friedrich' )
-
-=cut
-
-sub get_autor_id {
-
-    my $c = shift;
-    my $K = ( caller(0) )[3] . "(): ";
-
-    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 3;
-
-    my $params = {};
-    if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
-        $params = $_[0];
-    }
-    else {
-        %$params = @_;
-    }
-    $c->log->debug(  get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
-
-    my $storage = $c->stash->{'storage'};
-    #$c->log->debug(  get_output_string( $K, "Storage: ", $storage ) ) if $c->stash->{'debug_level'} >= 4;
-
-    my $name = $params->{'nachname'};
-    $name = $params->{'mittelname'} . " " . $name if defined $params->{'mittelname'};
-    $name = $params->{'vorname'} . " " . $name if defined $params->{'vorname'};
-    $name .= " " . $params->{'name_suffix'} if defined $params->{'name_suffix'};
-
-    my $select_func = sub {
-
-        my ( $storage, $dbh, $name ) = @_;
-        my $sql = <<ENDE;
-SELECT `me`.`id`
-  FROM `autoren` AS `me`
- WHERE CONCAT(
-           IFNULL( `me`.`vorname`, '' ),    IF( ISNULL(`me`.`vorname`), '', ' ' ),
-           IFNULL( `me`.`mittelname`, '' ), IF( ISNULL(`me`.`mittelname`), '', ' ' ),
-           `me`.`nachname`,
-           IF( ISNULL( `me`.`name_suffix` ), '', ' ' ), IFNULL( `me`.`name_suffix`, '' )
-       ) = ?
-ENDE
-
-        if ( $storage->debug() ) {
-            my $text = $sql;
-            $text =~ s/\s+$//;
-            $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $name ) ) . "\n";
-            warn $text;
-        }
-
-        my $sth = $dbh->prepare($sql);
-        $sth->execute( $name );
-
-        return $sth->fetchall_arrayref();
-    };
-
-    my $id = undef;
-    for my $autor_rs ( $storage->dbh_do( $select_func, $name ) ) {
-        $id = $autor_rs->[0][0];
-    }
-
-       $c->log->debug( $K . get_output_string( "Ermittelte Autor-Id: ", ( defined $id ? $id : '<keine>' ) ) ) if $c->stash->{'debug_level'} >= 2;
-    return $id;
-
-}
-
-#-----------------------------------------------------------------------------------
-
-=head2 delete_autor( $c, $autor_id )
-
-Loescht den Autor mit der uebergebenen Autor-Id
-
-=cut
-
-sub delete_autor {
-
-    my $c        = shift;
-    my $autor_id = shift;
-    my $K        = ( caller(0) )[3] . "(): ";
-
-    $c->log->debug( $K . "aufgerufen fuer Autor-Id " . ( defined $autor_id ? $autor_id : '<undef>' ) . "." ) if $c->stash->{'debug_level'} > 2;
-
-    return undef unless $autor_id and to_int($autor_id);
-    $autor_id = to_int($autor_id);
-
-    my $schema =  $c->model('Schema')->{'schema'};
-
-#      # Sperren der Autoren- und der Buecher-Tabelle
-#      lock_tables( $c, 'write' => [ 'autoren', 'autoren', 'as', 'me', ], 'read' => [ 'autor2buch', 'autor2buch', 'as', 'me', ] );
-
-       # Raus, wenn der Autor noch Buecher hat ...
-       if ( $c->model('Schema::Autor2buch')->count( { 'autor_id' => $autor_id, } ) ) {
-               my $msg = 'Es existieren noch Buecher dieses Autors.';
-#              unlock_tables($c);
-               die $msg . "\n";
-       }
-
-       # Das eigentliche Löschen
-    my $coderef = sub {
-        $c->model('Schema::Autoren')->search( { 'id' => $autor_id } )->delete();
-    };
-
-    my $rs;
-    eval {
-        $rs = $schema->txn_do($coderef);
-    };
-
-    if ($@) {                             # Transaction failed
-               my $msg = $@ =~ /Rollback failed/i ? "Rollback nicht erfolgreich!" : $@;
-#              unlock_tables($c);
-               die $msg . "\n";
-               return undef;
-    }
-#    unlock_tables($c);
-       return 1;
-
-}
-
-#-----------------------------------------------------------------------------------
-
-=head1 AUTHOR
-
-Frank Brehm
-
-=head1 LICENSE
-
-This library is free software, you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-1;
-
-__END__
-
-# vim: noai : ts=4 fenc=utf-8 filetype=perl :
index 049b41d74ac0d8779062d9ad1512123dd3228041..d09f68d9bf42111a67bb27908f02a8829ee6227f 100644 (file)
@@ -74,6 +74,8 @@ Wenn nicht übergeben, werden alle Buecher des Resultsets zurueckgegeben.
 
 Ist standardmaessig 20. Wird nicht beruecksichtigt, wenn I<page> nicht mit uebergeben wurde.
 
+=item I<short_author>: bool - Autor in Kurzfassung
+
 =item I<filter>: eine optionale Hash-Ref mit folgenden Filterkriterien:
 
 
@@ -154,6 +156,8 @@ sub get_booklist {
 
     my $storage = $c->stash->{'storage'};
 
+    my $short_author = $params->{'short_author'} ? 1 : undef;
+
     # Such- und Sortierparameter zusammensammeln
     my $b_search_params = {};
     my $order = undef;
@@ -459,9 +463,24 @@ sub get_booklist {
         my $bid = $ref->get_column('buch_id');
         my $aid = $ref->get_column('autor_id');
         my @N;
-        push @N, $ref->get_column('titel') if $ref->get_column('titel');
-        push @N, $ref->get_column('vorname') if $ref->get_column('vorname');
-        push @N, $ref->get_column('mittelname') if $ref->get_column('mittelname');
+        if ( $short_author ) {
+            my $n;
+            if ( $ref->get_column('vorname') ) {
+                $n = substr( $ref->get_column('vorname'), 0, 1 );
+                $n .= ".";
+                push @N, $n;
+            }
+            if ( $ref->get_column('mittelname') ) {
+                $n = substr( $ref->get_column('mittelname'), 0, 1 );
+                $n .= ".";
+                push @N, $n;
+            }
+        }
+        else {
+            push @N, $ref->get_column('titel') if $ref->get_column('titel');
+            push @N, $ref->get_column('vorname') if $ref->get_column('vorname');
+            push @N, $ref->get_column('mittelname') if $ref->get_column('mittelname');
+        }
         push @N, $ref->get_column('nachname');
         push @N, $ref->get_column('name_suffix') if $ref->get_column('name_suffix');
         my $autor = join( " ", @N );