From 89cd09fce8d48ce6ccfcccfafd1aa5b6216e4769 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 30 Mar 2008 21:50:48 +0000 Subject: [PATCH] =?utf8?q?Mit=20W=C3=A4hrungen=20angefangen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/FrBr/Books/Controller/Books.pm | 12 +++ lib/FrBr/Books/Util/Waehrung.pm | 131 +++++++++++++++++++++++++++++ root/src/books/book_form.tt2 | 6 +- 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 lib/FrBr/Books/Util/Waehrung.pm diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index 17fbc67..267af57 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -13,6 +13,7 @@ use FrBr::Books::Util::Book; use FrBr::Books::Util::Category; use FrBr::Books::Util::Serie; use FrBr::Books::Util::Verlag; +use FrBr::Books::Util::Waehrung; =head1 NAME @@ -514,6 +515,17 @@ sub prepare_data_structures : Private { } $c->log->debug( get_output_string( $K . "Serien: ", $c->stash->{'serienliste'} ) ); + # Waehrungen zusammensammeln + my $waehrungsliste = get_waehrungsliste($c); + $c->log->debug( get_output_string( $K . "Waehrungen gesamt: ", $waehrungsliste ) ); + $c->stash->{'waehrungsliste'} = {}; + $c->stash->{'waehrungs_ids'} = []; + for my $waehrung ( @$waehrungsliste ) { + push @{$c->stash->{'waehrungs_ids'}}, $waehrung->{'id'}; + $c->stash->{'waehrungsliste'}{$waehrung->{'id'}} = $waehrung; + } + $c->log->debug( get_output_string( $K . "Waehrungen: ", $c->stash->{'waehrungsliste'} ) ); + return 1; } diff --git a/lib/FrBr/Books/Util/Waehrung.pm b/lib/FrBr/Books/Util/Waehrung.pm new file mode 100644 index 0000000..8a67883 --- /dev/null +++ b/lib/FrBr/Books/Util/Waehrung.pm @@ -0,0 +1,131 @@ +package FrBr::Books::Util::Waehrung; + +# $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_waehrungsliste + ); + + #%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::Waehrung - Modul fuer Funktionen rund um Waehrungen + +=head1 METHODS + +=cut + +#----------------------------------------------------------------------------------- + +=head2 get_waehrungsliste( $c, $params ) + +Sammelt alle Waehrungen zusammen. + +Folgende benannte Parameter koennen ueber $params uebergeben werden: + +Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Waehrungen, die den uebergebenen Suchkriterien entsprechen: + + $res = [ + { 'id' => 1, + 'kuerzel' => '$', + 'name' => 'US-Dollar', + 'in_euro' => 0.66225, + }, + { 'id' => 2, + ... + }, + ... + ]; + +Die Liste ist nach den Waehrungs-Namen alphabetisch sortiert. + +=cut + +sub get_waehrungsliste { + + my $c = shift; + my $K = __PACKAGE__ . "::get_waehrungsliste(): "; + + $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'} = [ 'waehrungs_name' ]; + $other_params->{'select'} = [ + 'id', + 'waehrungs_kuerzel', + 'waehrungs_name', + 'umrechnung_in_euro', + ]; + $other_params->{'as'} = [ + 'id', + 'waehrungs_kuerzel', + 'waehrungs_name', + 'umrechnung_in_euro', + ]; + + for my $waehrung_rs ( $c->model('Schema::Waehrungen')->search( $search_params, $other_params )->all() ) { + my $waehrung = {}; + $waehrung->{'id'} = $waehrung_rs->id(); + $waehrung->{'kuerzel'} = $waehrung_rs->waehrungs_kuerzel(); + $waehrung->{'name'} = $waehrung_rs->waehrungs_name(); + $waehrung->{'in_euro'} = $waehrung_rs->umrechnung_in_euro(); + push @$list, $waehrung; + } + + 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 5995377..4691379 100644 --- a/root/src/books/book_form.tt2 +++ b/root/src/books/book_form.tt2 @@ -125,7 +125,11 @@ function goto_new_author() { Preis: - + +   -- 2.39.5