From: Frank Brehm Date: Thu, 27 Mar 2008 17:19:58 +0000 (+0000) Subject: Ändern Buchserie dazu X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=1a884b6c4ca3212ccef5984e28d4e61adbd4a53d;p=books.git Ändern Buchserie dazu --- diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index aff8712..3469735 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -11,6 +11,7 @@ use FrBr::Common; use FrBr::Books::Util::Author; use FrBr::Books::Util::Book; use FrBr::Books::Util::Category; +use FrBr::Books::Util::Serie; use FrBr::Books::Util::Verlag; =head1 NAME @@ -196,6 +197,21 @@ sub bookdata_session2stash : Private { } $c->log->debug( get_output_string( $K . "Kategorien, die fehlen: ", $c->stash->{'kategorie_list_no'} ) ); + my %Serien; + + $c->stash->{'serienliste_book'} = []; + for my $serien_id ( @{$c->session->{'book_data_edit'}{'serien'}} ) { + push @{$c->stash->{'serienliste_book'}}, $serien_id; + $Serien{$serien_id} = 1; + } + $c->log->debug( get_output_string( $K . "Serien des Buches: ", $c->stash->{'serienliste_book'} ) ); + + $c->stash->{'serienliste_no'} = []; + for my $serien_id ( @{$c->stash->{'serien_ids'}} ) { + push @{$c->stash->{'serienliste_no'}}, $serien_id unless $Serien{$serien_id}; + } + $c->log->debug( get_output_string( $K . "Serien, die fehlen: ", $c->stash->{'serienliste_no'} ) ); + $c->stash->{'book_edit'}{'title'} = $c->session->{'book_data_edit'}{'title'}; $c->stash->{'book_edit'}{'untertitel'} = $c->session->{'book_data_edit'}{'untertitel'}; $c->stash->{'book_edit'}{'original_title'} = $c->session->{'book_data_edit'}{'original_title'}; @@ -376,6 +392,48 @@ sub bookdata_cgi2session : Private { } } + # Kategorien + $c->session->{'book_data_edit'}{'serien'} = [] unless $c->session->{'book_data_edit'}{'serien'}; + + my %Buchserie; + $i = 1; + for my $serien_id ( @{$c->session->{'book_data_edit'}{'serien'}} ) { + $Buchserie{$serien_id} = $i; + $i++; + } + + if ( $c->request->params->{'wird_serie'} ) { + if ( $c->request->params->{'buchserie_not'} ) { + my $serien = ref($c->request->params->{'buchserie_not'}) eq 'ARRAY' ? $c->request->params->{'buchserie_not'} : [$c->request->params->{'buchserie_not'}]; + $c->log->debug( get_output_string( $K . "Fuege Buchserie hinzu: ", $serien ) ); + for my $serien_id ( @$serien ) { + next unless $serien_id; + unless ( $Buchserie{$serien_id} ) { + push @{$c->session->{'book_data_edit'}{'serien'}}, $serien_id; + $Buchserie{$serien_id} = scalar( @{$c->session->{'book_data_edit'}{'serien'}} ); + } + } + } + } + elsif ( $c->request->params->{'entf_serie'} ) { + if ( $c->request->params->{'serie_book'} ) { + my $serien = ref($c->request->params->{'serie_book'}) eq 'ARRAY' ? $c->request->params->{'serie_book'} : [$c->request->params->{'serie_book'}]; + $c->log->debug( get_output_string( $K . "Loesche Serien: ", $serien ) ); + for my $serien_id ( @$serien ) { + next unless $serien_id; + $i = $Buchserie{$serien_id}; + next unless $i; + splice( @{$c->session->{'book_data_edit'}{'serien'}}, $i - 1, 1 ); + $i = 1; + %Buchserie = (); + for my $id ( @{$c->session->{'book_data_edit'}{'serien'}} ) { + $Buchserie{$id} = $i; + $i++; + } + } + } + } + # ISBN $c->session->{'book_data_edit'}{'isbn'} = $c->request->params->{'book_isbn'} if defined $c->request->params->{'book_isbn'}; @@ -441,6 +499,17 @@ sub prepare_data_structures : Private { } $c->log->debug( get_output_string( $K . "Verlage: ", $c->stash->{'verlagsliste'} ) ); + # Buchserien zusamensammeln + my $serienliste = get_serienliste($c); + $c->log->debug( get_output_string( $K . "Serien gesamt: ", $serienliste ) ); + $c->stash->{'serienliste'} = {}; + $c->stash->{'serien_ids'} = []; + for my $serie ( @$serienliste ) { + push @{$c->stash->{'serien_ids'}}, $serie->{'id'}; + $c->stash->{'serienliste'}{$serie->{'id'}} = $serie->{'name'}; + } + $c->log->debug( get_output_string( $K . "Serien: ", $c->stash->{'serienliste'} ) ); + return 1; } diff --git a/lib/FrBr/Books/Util/Serie.pm b/lib/FrBr/Books/Util/Serie.pm new file mode 100644 index 0000000..1cecc61 --- /dev/null +++ b/lib/FrBr/Books/Util/Serie.pm @@ -0,0 +1,145 @@ +package FrBr::Books::Util::Serie; + +# $Id$ +# $URL$ + +use strict; +use warnings; + +use FrBr::Common; + +# 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_serienliste + ); + + #%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 Buchserien + +=head1 METHODS + +=cut + +#----------------------------------------------------------------------------------- + +=head2 get_serienliste( $c, $params ) + +Sammelt alle Buchserien zusammen. + +Folgende benannte Parameter koennen ueber $params uebergeben werden: + +Rueckgabe: Eine Array-Ref von Hash-Refs mit allen verlagen, die den uebergebenen Suchkriterien entsprechen: + + $res = [ + { 'id' => 1, + 'name' => 'Perry Rhodan', + 'descr' => 'Abenteuer des Weltraumspezis', + 'anzahl_buecher' => 60, + }, + { 'id' => 2, + ... + }, + ... + ]; + +Die Liste ist nach den Serien-Namen alphabetisch sortiert. + +=cut + +sub get_serienliste { + + my $c = shift; + my $K = __PACKAGE__ . "::get_serienliste(): "; + + $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 $search_params = undef; + + my $other_params = {}; + $other_params->{'order_by'} = [ 'serien_name' ]; + $other_params->{'select'} = [ + 'id', + 'serien_name', + 'descr', + ]; + $other_params->{'as'} = [ + 'id', + 'serien_name', + 'descr', + ]; + + my %SidMap; + + my $i = 0; + for my $serie_rs ( $c->model('Schema::Serien')->search( $search_params, $other_params )->all() ) { + my $serie = {}; + $serie->{'id'} = $serie_rs->id(); + $serie->{'name'} = $serie_rs->serien_name(); + $serie->{'descr'} = $serie_rs->descr(); + $serie->{'anzahl_buecher'} = 0; + push @$list, $serie; + $SidMap{$serie->{'id'}} = $i; + $i++; + } + + $search_params = undef; + $other_params = {}; + $other_params->{'select'} = [ 'serien_id', { 'count' => 'buch_id' } ]; + $other_params->{'as'} = [ 'serien_id', 'anzahl_buecher' ]; + $other_params->{'group_by'} = [ 'serien_id', ]; + for my $rs ( $c->model('Schema::Buch2serie')->search( $search_params, $other_params )->all() ) { + my $sid = $rs->serien_id(); + my $j = $SidMap{$sid}; + $list->[$j]{'anzahl_buecher'} = $rs->get_column('anzahl_buecher'); + } + + return $list; +} + +#----------------------------------------------------------------------------------- + +=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; diff --git a/root/src/books/book_form.tt2 b/root/src/books/book_form.tt2 index e7410a2..4561da3 100644 --- a/root/src/books/book_form.tt2 +++ b/root/src/books/book_form.tt2 @@ -75,6 +75,28 @@ [% END %] + + Buchserien: + + + + + + + + + + +
Verfügbare BuchserienSerien des Buchs


+

+ +
ISBN: