From: Frank Brehm Date: Thu, 27 Mar 2008 16:30:12 +0000 (+0000) Subject: Verlag mit ins Buchformular hinein X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=58adf455a690353b8c782533d1dbefd0bf09ec97;p=books.git Verlag mit ins Buchformular hinein --- diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index 4107d85..aff8712 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -9,8 +9,9 @@ use base 'Catalyst::Controller'; use FrBr::Common; use FrBr::Books::Util::Author; -use FrBr::Books::Util::Category; use FrBr::Books::Util::Book; +use FrBr::Books::Util::Category; +use FrBr::Books::Util::Verlag; =head1 NAME @@ -195,15 +196,16 @@ sub bookdata_session2stash : Private { } $c->log->debug( get_output_string( $K . "Kategorien, die fehlen: ", $c->stash->{'kategorie_list_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'}{'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'}; - $c->stash->{'book_edit'}{'isbn'} = $c->session->{'book_data_edit'}{'isbn'}; - $c->stash->{'book_edit'}{'book_nr'} = $c->session->{'book_data_edit'}{'book_nr'}; - $c->stash->{'book_edit'}{'ausgabejahr'} = $c->session->{'book_data_edit'}{'ausgabejahr'}; - $c->stash->{'book_edit'}{'druckjahr'} = $c->session->{'book_data_edit'}{'druckjahr'}; - $c->stash->{'book_edit'}{'seiten'} = $c->session->{'book_data_edit'}{'seiten'}; - $c->stash->{'book_edit'}{'preis'} = $c->session->{'book_data_edit'}{'preis'}; + $c->stash->{'book_edit'}{'verlags_id'} = $c->session->{'book_data_edit'}{'verlags_id'}; + $c->stash->{'book_edit'}{'isbn'} = $c->session->{'book_data_edit'}{'isbn'}; + $c->stash->{'book_edit'}{'book_nr'} = $c->session->{'book_data_edit'}{'book_nr'}; + $c->stash->{'book_edit'}{'ausgabejahr'} = $c->session->{'book_data_edit'}{'ausgabejahr'}; + $c->stash->{'book_edit'}{'druckjahr'} = $c->session->{'book_data_edit'}{'druckjahr'}; + $c->stash->{'book_edit'}{'seiten'} = $c->session->{'book_data_edit'}{'seiten'}; + $c->stash->{'book_edit'}{'preis'} = $c->session->{'book_data_edit'}{'preis'}; return 1; @@ -329,6 +331,9 @@ sub bookdata_cgi2session : Private { # Original-Titel $c->session->{'book_data_edit'}{'original_title'} = $c->request->params->{'book_original_title'} if defined $c->request->params->{'book_original_title'}; + # Verlag + $c->session->{'book_data_edit'}{'verlags_id'} = $c->request->params->{'verlags_id'} if defined $c->request->params->{'verlags_id'}; + # Kategorien $c->session->{'book_data_edit'}{'kategorien'} = [] unless $c->session->{'book_data_edit'}{'kategorien'}; @@ -425,6 +430,17 @@ sub prepare_data_structures : Private { } $c->log->debug( get_output_string( $K . "Kategorien: ", $c->stash->{'kategorie_list'} ) ); + # Verlage zusamensammeln + my $verlagsliste = get_verlagsliste($c); + $c->log->debug( get_output_string( $K . "Verlage gesamt: ", $verlagsliste ) ); + $c->stash->{'verlagsliste'} = {}; + $c->stash->{'verlags_ids'} = []; + for my $verlag ( @$verlagsliste ) { + push @{$c->stash->{'verlags_ids'}}, $verlag->{'id'}; + $c->stash->{'verlagsliste'}{$verlag->{'id'}} = $verlag->{'name'}; + } + $c->log->debug( get_output_string( $K . "Verlage: ", $c->stash->{'verlagsliste'} ) ); + return 1; } diff --git a/lib/FrBr/Books/Util/Verlag.pm b/lib/FrBr/Books/Util/Verlag.pm new file mode 100644 index 0000000..41e7d18 --- /dev/null +++ b/lib/FrBr/Books/Util/Verlag.pm @@ -0,0 +1,127 @@ +package FrBr::Books::Util::Verlag; + +# $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_verlagsliste + ); + + #%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_verlagsliste( $c, $params ) + +Sammelt alle Verlage 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' => 'Heyne', + 'name_long' => 'Heyne-Verlag usw. GmbH & Co. KG', + }, + { 'id' => 2, + ... + }, + ... + ]; + +Die Liste ist nach den Verlags-Namen alphabetisch sortiert. + +=cut + +sub get_verlagsliste { + + my $c = shift; + my $K = __PACKAGE__ . "::get_verlagsliste(): "; + + $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'} = [ 'name_short' ]; + $other_params->{'select'} = [ + 'id', + 'name_short', + 'name_long', + ]; + $other_params->{'as'} = [ + 'id', + 'name_short', + 'name_long', + ]; + + for my $verlag_rs ( $c->model('Schema::Verlage')->search( $search_params, $other_params )->all() ) { + my $verlag = {}; + $verlag->{'id'} = $verlag_rs->id(); + $verlag->{'name'} = $verlag_rs->name_short(); + $verlag->{'descr'} = $verlag_rs->name_long(); + push @$list, $verlag; + } + + 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 7b5b6bb..e7410a2 100644 --- a/root/src/books/book_form.tt2 +++ b/root/src/books/book_form.tt2 @@ -47,6 +47,12 @@ Original-Titel: + + Verlag: +   Kategorie(n):