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
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
},
},
'default_view' => 'TtDefault',
+ 'max_length_title' => 40,
'View::TtDefault' => {
'CATALYST_VAR' => 'Catalyst',
'INCLUDE_PATH' => [
use base 'Catalyst::Controller';
use FrBr::Common;
-use FrBr::Books::Util::Author;
=head1 NAME
$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 ) {
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 ) ) {
#-------------------------------------------------------
-=head2 delete_autor( )
+=head2 delete_autor_form( )
Loescht einen vorhandenen Autor.
$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';
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'} = $@;
}
# 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';
$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'} = $@;
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;
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'} = {};
$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
# 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;
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'} = [];
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;
--- /dev/null
+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 :
--- /dev/null
+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 :
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 );
$VERSION = sprintf( $VERSION . ".%d", $rev );
}
-# &get_serienliste
-# &save_serie
-# &delete_serie
-
=head1 NAME
FrBr::Books::Plugin::Serie - Modul fuer Funktionen rund um Buchserien
# 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 } ) ;
$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'} ) {
}
+ # 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'};
+++ /dev/null
-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 :
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:
my $storage = $c->stash->{'storage'};
+ my $short_author = $params->{'short_author'} ? 1 : undef;
+
# Such- und Sortierparameter zusammensammeln
my $b_search_params = {};
my $order = undef;
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 );