use base 'Catalyst::Controller';
use FrBr::Common;
-use FrBr::Books::Util::Book;
use FrBr::Books::Util::Author;
+use FrBr::Books::Util::Category;
+use FrBr::Books::Util::Book;
=head1 NAME
}
$c->log->debug( get_output_string( $K . "Autoren, die fehlen: ", $c->stash->{'autor_list_no'} ) );
+ my %Kategorie;
+
+ $c->stash->{'kategorie_list_book'} = [];
+ for my $cat_id ( @{$c->session->{'book_data_edit'}{'kategorien'}} ) {
+ push @{$c->stash->{'kategorie_list_book'}}, $cat_id;
+ $Kategorie{$cat_id} = 1;
+ }
+ $c->log->debug( get_output_string( $K . "Kategorien des Buches: ", $c->stash->{'kategorie_list_book'} ) );
+
+ $c->stash->{'kategorie_list_no'} = [];
+ for my $cat_id ( @{$c->stash->{'kategorie_ids'}} ) {
+ push @{$c->stash->{'kategorie_list_no'}}, $cat_id unless $Kategorie{$cat_id};
+ }
+ $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'}{'original_title'} = $c->session->{'book_data_edit'}{'original_title'};
# Original-Titel
$c->session->{'book_data_edit'}{'original_title'} = $c->request->params->{'book_original_title'} if defined $c->request->params->{'book_original_title'};
+ # Kategorien
+ $c->session->{'book_data_edit'}{'kategorien'} = [] unless $c->session->{'book_data_edit'}{'kategorien'};
+
+ my %Kategorie;
+ $i = 1;
+ for my $cat_id ( @{$c->session->{'book_data_edit'}{'kategorien'}} ) {
+ $Kategorie{$cat_id} = $i;
+ $i++;
+ }
+
+ if ( $c->request->params->{'wird_kategorie'} ) {
+ if ( $c->request->params->{'kategorie_not'} ) {
+ my $kategorien = ref($c->request->params->{'kategorie_not'}) eq 'ARRAY' ? $c->request->params->{'kategorie_not'} : [$c->request->params->{'kategorie_not'}];
+ $c->log->debug( get_output_string( $K . "Fuege Kategorien hinzu: ", $kategorien ) );
+ for my $cat_id ( @$kategorien ) {
+ next unless $cat_id;
+ unless ( $Kategorie{$cat_id} ) {
+ push @{$c->session->{'book_data_edit'}{'kategorien'}}, $cat_id;
+ $Kategorie{$cat_id} = scalar( @{$c->session->{'book_data_edit'}{'kategorien'}} );
+ }
+ }
+ }
+ }
+ elsif ( $c->request->params->{'entf_kategorie'} ) {
+ if ( $c->request->params->{'kategorie_book'} ) {
+ my $kategorien = ref($c->request->params->{'kategorie_book'}) eq 'ARRAY' ? $c->request->params->{'kategorie_book'} : [$c->request->params->{'kategorie_book'}];
+ $c->log->debug( get_output_string( $K . "Loesche Kategorien: ", $kategorien ) );
+ for my $cat_id ( @$kategorien ) {
+ next unless $cat_id;
+ $i = $Kategorie{$cat_id};
+ next unless $i;
+ splice( @{$c->session->{'book_data_edit'}{'kategorien'}}, $i - 1, 1 );
+ $i = 1;
+ %Kategorie = ();
+ for my $id ( @{$c->session->{'book_data_edit'}{'kategorien'}} ) {
+ $Kategorie{$id} = $i;
+ $i++;
+ }
+ }
+ }
+ }
+
# ISBN
$c->session->{'book_data_edit'}{'isbn'} = $c->request->params->{'book_isbn'} if defined $c->request->params->{'book_isbn'};
my ( $self, $c ) = @_;
my $K = __PACKAGE__ . "::prepare_data_structures(): ";
+ # Autoren zusammensammeln
my $autor_list_complete = get_author_list($c);
$c->log->debug( get_output_string( $K . "Autoren gesamt: ", $autor_list_complete ) );
}
$c->log->debug( get_output_string( $K . "Autoren-Hash: ", $c->stash->{'autor_list'} ) );
+ # Kategorien zusammensammeln
+ my $cat_list_complete = get_category_list($c);
+ $c->log->debug( get_output_string( $K . "Kategorien gesamt: ", $cat_list_complete ) );
+
+ $c->stash->{'kategorie_list'} = {};
+ $c->stash->{'kategorie_ids'} = [];
+ for my $cat ( @$cat_list_complete ) {
+ push @{$c->stash->{'kategorie_ids'}}, $cat->{'id'};
+ $c->stash->{'kategorie_list'}{$cat->{'id'}} = $cat->{'name'};
+ }
+ $c->log->debug( get_output_string( $K . "Kategorien: ", $c->stash->{'kategorie_list'} ) );
+
return 1;
}
--- /dev/null
+package FrBr::Books::Util::Category;
+
+# $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_category_list
+ );
+
+ #%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::Category - Modul fuer Funktionen rund um Kategorien
+
+=head1 METHODS
+
+=cut
+
+#-----------------------------------------------------------------------------------
+
+=head2 get_category_list( $c, $params )
+
+Sammelt alle Kategorien zusammen.
+
+Folgende benannte Parameter koennen ueber $params uebergeben werden:
+
+Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Kategorien, die den uebergebenen Suchkriterien entsprechen:
+
+ $res = [
+ { 'id' => 1,
+ 'name' => 'Science Fiction',
+ },
+ { 'id' => 2,
+ ...
+ },
+ ...
+ ];
+
+Die Liste ist nach den Kategorie-Namen alphabetisch sortiert.
+
+=cut
+
+sub get_category_list {
+
+ my $c = shift;
+ my $K = __PACKAGE__ . "::get_category_list(): ";
+
+ $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'} = [ 'kategorie_name' ];
+ $other_params->{'select'} = [
+ 'id',
+ 'kategorie_name',
+ ];
+ $other_params->{'as'} = [
+ 'id',
+ 'kategorie_name',
+ ];
+
+ for my $cat_rs ( $c->model('Schema::Kategorien')->search( $search_params, $other_params )->all() ) {
+ my $cat = {};
+ $cat->{'id'} = $cat_rs->id();
+ $cat->{'name'} = $cat_rs->kategorie_name();
+ push @$list, $cat;
+ }
+
+ 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;
</tr><tr>
<th>Original-Titel:</th>
<td><input type="text" name="book_original_title" size="60" maxlength="250" value="[% book_edit.original_title | html %]" /></td>
+ </tr><tr>
+ <th>Kategorie(n):</th>
+ <td>
+ <table class="two_lists" cellspacing="0">
+ <tr>
+ <th>Verfügbare Kategorien</th>
+ <th></th>
+ <th>Kategorien des Buchs</th>
+ </tr><tr>
+ <td><select name="kategorie_not" size="7" multiple>
+ <option value="">-- Kategorie oder Kategorien wählen --</option>[% FOR cat_id IN kategorie_list_no %]
+ <option value="[% cat_id %]">[% kategorie_list.$cat_id %]</option>
+ [% END %]</select></td>
+ <td><input type="submit" name="wird_kategorie" value="⇒" class="shift_button" title="Wird Kategorie" /><br /><br />
+ <input type="submit" name="neue_kategorie" value="*" class="shift_button" title="Neue Kategorie" /><br /><br />
+ <input type="submit" name="entf_kategorie" value="⇐" class="shift_button" title="Kategorie entfernen" />
+ </td>
+ <td><select name="kategorie_book" size="7" multiple>
+ <option value="">-- Kategorie oder Kategorien entfernen --</option>[% FOR cat_id IN kategorie_list_book %]
+ <option value="[% cat_id %]">[% kategorie_list.$cat_id %]</option>[% END %]
+ </select></td>
+ </tr></table></td>
</tr><tr>
<th>ISBN:</th>
<td><input type="text" name="book_isbn" size="20" maxlength="20" value="[% book_edit.isbn | html %]" /></td>