]> Frank Brehm's Git Trees - books.git/commitdiff
Aus Util::Category mach Plugin::Category
authorFrank Brehm <frank@brehm-online.com>
Thu, 18 Feb 2010 21:07:29 +0000 (21:07 +0000)
committerFrank Brehm <frank@brehm-online.com>
Thu, 18 Feb 2010 21:07:29 +0000 (21:07 +0000)
lib/FrBr/Books.pm
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Controller/Cron.pm
lib/FrBr/Books/Controller/Kategorie.pm
lib/FrBr/Books/Plugin/Author.pm
lib/FrBr/Books/Plugin/Category.pm [new file with mode: 0644]
lib/FrBr/Books/Util/Category.pm [deleted file]

index 1c5e6f9ced9a7a8db7d51742a3afc431a279025a..e3f677d0dd1f9a6396714b6263b611558287a52e 100644 (file)
@@ -43,6 +43,7 @@ use Catalyst qw/
     +FrBr::Books::Plugin::Author
     +FrBr::Books::Plugin::Bindungsart
     +FrBr::Books::Plugin::BookAdd
+    +FrBr::Books::Plugin::Category
     +FrBr::Books::Plugin::Ort
     +FrBr::Books::Plugin::Serie
     +FrBr::Books::Plugin::User
index a06b3041789fe97c484352f794d0a9a7b3585eb5..9e5e01700dd85d979537cb8d4449bf94999481ca 100644 (file)
@@ -9,7 +9,6 @@ use base 'Catalyst::Controller';
 
 use FrBr::Common;
 use FrBr::Books::Util::Book;
-use FrBr::Books::Util::Category;
 
 =head1 NAME
 
@@ -1278,7 +1277,7 @@ sub prepare_data_structures : Private {
     $c->log->debug( get_output_string( $K . "Autoren-Hash: ", $c->stash->{'autor_list'} ) );
 
     # Kategorien zusammensammeln
-    my $cat_list_complete = get_category_list($c);
+    my $cat_list_complete = $c->b_get_category_list();
     $c->log->debug( get_output_string( $K . "Kategorien gesamt: ", $cat_list_complete ) );
 
     $c->stash->{'kategorie_list'} = {};
index bcd2de2c7537b0037a20790524998efc7b9e718b..e73fe6365f7744283bbff0b71970317db521b3e1 100644 (file)
@@ -8,7 +8,6 @@ use warnings;
 use base 'Catalyst::Controller';
 
 use FrBr::Common;
-use FrBr::Books::Util::Category;
 
 =head1 NAME
 
index ae49aa04c85c4ea79009080f42dad61b6772019b..e0090133c4f14bb76ec00cb93e654d0e5f464c2f 100644 (file)
@@ -8,7 +8,6 @@ use warnings;
 use base 'Catalyst::Controller';
 
 use FrBr::Common;
-use FrBr::Books::Util::Category;
 
 =head1 NAME
 
@@ -123,7 +122,7 @@ sub list : Local {
         $c->session->{'category_list_page'} = $page;
     }
 
-    my ( $liste, $anzahl ) = get_category_list( $c, 'get_books' => undef, 'page' => $page );
+    my ( $liste, $anzahl ) = $c->b_get_category_list( 'get_books' => undef, 'page' => $page );
     $c->log->debug( get_output_string( $K, "Erhaltene Liste der Kategorien: ", $liste ) ) if $c->stash->{'debug_level'} >= 2;
     $c->stash->{'kategorien'} = $liste;
 
@@ -192,7 +191,7 @@ sub form_view : Path('view') {
        }
 
 
-       my $category_list = get_category_list( $c, 'category_id' => $category_id, 'get_books' => 1, );
+       my $category_list = $c->b_get_category_list( 'category_id' => $category_id, 'get_books' => 1, );
        $c->log->debug( get_output_string( $K, "Erhaltene Kategorieliste: ", $category_list ) ) if $c->stash->{'debug_level'} >= 2;
 
        unless ( $category_list and scalar( @$category_list ) ) {
@@ -301,7 +300,7 @@ sub form_edit : Path('edit') {
     }
 
     # Angaben zur Kategorie aus der Datenbank holen
-       my $cliste = get_category_list( $c, 'category_id' => $cid, );
+       my $cliste = $c->b_get_category_list( 'category_id' => $cid, );
 
     unless ( $cliste and scalar( @$cliste ) ) {
         $c->stash->{'template'} = 'error.tt2';
@@ -381,7 +380,7 @@ sub delete_category_form : Path('delete') {
     $c->session->{'delete_category_id'} = $cid;
 
     # Angaben zur Kategorie aus der Datenbank holen
-    my $cliste = get_category_list( $c, 'category_id' => $cid );
+    my $cliste = $c->b_get_category_list( 'category_id' => $cid );
 
     unless ( $cliste and scalar( @$cliste ) ) {
         $c->stash->{'template'} = 'error.tt2';
@@ -410,7 +409,7 @@ sub delete_category_form : Path('delete') {
 
     if ( $c->request->params->{'really_delete_category'} and $c->request->params->{'really_delete_category'} eq 'yes' and $c->request->params->{'do_delete'} ) {
         eval {
-            delete_category( $c, $cid );
+            $c->b_delete_category( $cid );
         };
         if ( $@ ) {
             $c->stash->{'error_message'} = $@;
@@ -434,7 +433,7 @@ sub do_save_category : Private {
        my $cid = undef;
 
     eval {
-               $cid = save_category( $c, $c->stash->{'category_edit'} );
+               $cid = $c->b_save_category( $c->stash->{'category_edit'} );
     };
     if ( $@ ) {
         $c->stash->{'error_message'} = $@;
index 12391650f80b36d1d16d05a087d0acfc8f63e7ec..6df42eb8a415f22d25cc85aeb74b2e85b9f27d16 100644 (file)
@@ -241,7 +241,7 @@ sub b_save_autor {
        $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
     my $storage = $c->model('Schema')->storage;
-       $c->stash->{'storage'}{'save_autor_result'} = '';
+       $c->stash->{'save_autor_result'} = '';
 
        my $search_params = {};
        my $row = {};
@@ -388,7 +388,6 @@ sub b_get_autor_id {
     $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'};
diff --git a/lib/FrBr/Books/Plugin/Category.pm b/lib/FrBr/Books/Plugin/Category.pm
new file mode 100644 (file)
index 0000000..f61bfc4
--- /dev/null
@@ -0,0 +1,374 @@
+package FrBr::Books::Plugin::Category;
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use Carp qw/croak/;
+use FrBr::Common;
+
+our $VERSION = '0.2';
+{
+    my ($rev) = '$Revision$' =~ /(\d+)/;
+    $VERSION = sprintf( $VERSION . ".%d", $rev );
+}
+
+=head1 NAME
+
+FrBr::Books::Plugin::Category - Plugin-Modul fuer Funktionen rund um Kategorien
+
+=head1 METHODS
+
+=cut
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_get_category_list( $params )
+
+Sammelt alle Kategorien zusammen.
+
+Folgende benannte Parameter koennen ueber $params uebergeben werden:
+
+=over 4
+
+=item B<category_id>: Die ID einer konkreten Kategorie
+
+=item B<get_books>: Bool. Zeigt an, daß zu den gefundenen Kategorien die dazugehörigen
+Bücher geholt werden sollen.
+
+=item B<page>
+
+Integer: Zeigt an, welche Seite von Kategorien dargestellt werden soll.
+
+Wenn nicht angegeben, werden alle Kategorien zurückgegeben.
+
+=back
+
+Rueckgabe: Im skalaren Kontext eine Array-Ref von Hash-Refs mit allen Kategorien, die den uebergebenen Suchkriterien entsprechen:
+
+  $res = [
+    { 'id'          => 1,
+      'name'        => 'Science Fiction',
+      'count_books'    => 22,
+    },
+    { 'id'     => 2,
+      ...
+    },
+    ...
+  ];
+
+Die Liste ist nach den Kategorie-Namen alphabetisch sortiert.
+
+Im Listenkontext wird als zweiter Rückgabewert die Gesamtzahl aller Kategorien zurueckgegeben.
+
+=cut
+
+sub b_get_category_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_kategorien = 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->{'category_id'} ) {
+               $search_params = {
+                       'me.id' => $params->{'category_id'},
+               };
+       }
+
+       $anzahl_kategorien = $c->model('Schema::Kategorien')->count( $search_params );
+    $c->log->debug(  get_output_string( $K, "Anzahl gefundene Kategorien: ", $anzahl_kategorien ) ) if $c->stash->{'debug_level'} >= 2;
+
+    my $other_params = {};
+    $other_params->{'order_by'} = [ 'kategorie_name' ];
+    $other_params->{'select'} = [
+        'me.id',
+        'me.kategorie_name',
+               { 'count' => 'buch_kategorie.id' }
+    ];
+    $other_params->{'as'} = [
+        'id',
+        'kategorie_name',
+               'count_books',
+    ];
+       $other_params->{'join'} = [ 'buch_kategorie'];
+       $other_params->{'group_by'} = [ 'me.id' ];
+       if ( $page ) {
+               $other_params->{'rows'} = $rows;
+               $other_params->{'page'} = $page;
+       }
+    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();
+        $cat->{'count_books'} = $cat_rs->get_column('count_books');
+        push @$list, $cat;
+    }
+
+    return ( wantarray ? ( $list, 0 ) : $list ) unless scalar @$list;
+    return ( wantarray ? ( $list, $anzahl_kategorien ) : $list ) unless $params->{'get_books'};
+
+       for my $cat ( @$list ) {
+
+               $cat->{'books'} = [];
+
+               $search_params = {
+                       "buch_kategorie.kategorie_id" => $cat->{'id'},
+               };
+               $other_params = {};
+               $other_params->{'join'}     = [ 'waehrung', 'ort', 'bindungsart', 'buch_kategorie', 'verlag', ];
+
+               $other_params->{'select'} = [
+                       'me.id',
+                       'me.title',
+                       'me.title_original',
+                       'me.untertitel',
+                       'me.bindungsart_id',
+                       'bindungsart.art_name',
+                       'me.orts_id',
+                       'me.isbn',
+                       'me.buch_nr',
+                       'me.ausgabejahr',
+                       'me.druckjahr',
+                       'me.seiten',
+                       'me.preis',
+                       'me.waehrungs_id',
+                       'waehrung.waehrungs_kuerzel',
+                       'waehrung.waehrungs_name',
+                       'waehrung.umrechnung_in_euro',
+                       'ort.name',
+                       'ort.descr',
+                       'ort.statisch',
+            'buch_kategorie.kategorie_id',
+            'verlag.name_short',
+            'verlag.name_long',
+               ];
+               $other_params->{'as'} = [
+                       'id',
+                       'title',
+                       'title_original',
+                       'untertitel',
+                       'bindungsart_id',
+                       'bindungsart',
+                       'orts_id',
+                       'isbn',
+                       'buch_nr',
+                       'ausgabejahr',
+                       'druckjahr',
+                       'seiten',
+                       'preis',
+                       'waehrungs_id',
+                       'waehrungs_kuerzel',
+                       'waehrungs_name',
+                       'umrechnung_in_euro',
+                       'ortsname',
+                       'ort_beschreibung',
+                       'ort_ist_statisch',
+            'kategorie_id',
+            'verlags_name_short',
+            'verlags_name_long',
+               ];
+
+               for my $book ( $c->model('Schema::Buecher')->search( $search_params, $other_params )->all() ) {
+                       my $buch = {};
+                       $buch->{'id'}                 = $book->id();
+                       $buch->{'title'}              = $book->title();
+                       $buch->{'title_original'}     = $book->title_original();
+                       $buch->{'untertitel'}         = $book->untertitel();
+                       $buch->{'bindungsart_id'}     = $book->bindungsart_id();
+                       $buch->{'bindungsart'}        = $book->get_column('bindungsart');
+                       $buch->{'orts_id'}            = $book->orts_id();
+                       $buch->{'isbn'}               = $book->isbn();
+                       $buch->{'buch_nr'}            = $book->buch_nr();
+                       $buch->{'ausgabejahr'}        = $book->ausgabejahr();
+                       $buch->{'druckjahr'}          = $book->druckjahr();
+                       $buch->{'seiten'}             = $book->seiten();
+                       $buch->{'preis'}              = $book->preis();
+                       $buch->{'waehrungs_id'}       = $book->waehrungs_id();
+                       $buch->{'waehrungs_kuerzel'}  = $book->get_column('waehrungs_kuerzel');
+                       $buch->{'waehrungs_name'}     = $book->get_column('waehrungs_name');
+                       $buch->{'umrechnung_in_euro'} = $book->get_column('umrechnung_in_euro');
+                       $buch->{'ortsname'}           = $book->get_column('ortsname');
+                       $buch->{'ort_beschreibung'}   = $book->get_column('ort_beschreibung');
+                       $buch->{'ort_ist_statisch'}   = $book->get_column('ort_ist_statisch');
+                       $buch->{'kategorie_id'}       = $book->get_column('kategorie_id');
+                       $buch->{'verlags_name_short'} = $book->get_column('verlags_name_short');
+                       $buch->{'verlags_name_long'}  = $book->get_column('verlags_name_long');
+                       $buch->{'autoren'}            = [];
+                       $buch->{'autor_ids'}          = [];
+
+                       my $a_search_params = {};
+                       $a_search_params->{'buch_id'} = $buch->{'id'};
+                       $other_params = {};
+                       $other_params->{'order_by'} = [ 'ord_num' ];
+                       $other_params->{'join'}     = [ 'autor' ];
+                       $other_params->{'select'} = [
+                               'me.buch_id',
+                               'autor.id',
+                               'autor.titel',
+                               'autor.vorname',
+                               'autor.mittelname',
+                               'autor.nachname',
+                               'autor.name_suffix',
+                       ];
+                       $other_params->{'as'} = [
+                               'buch_id',
+                               'autor_id',
+                               'titel',
+                               'vorname',
+                               'mittelname',
+                               'nachname',
+                               'name_suffix',
+                       ];
+                       for my $ref ( $c->model('Schema::Autor2buch')->search( $a_search_params, $other_params )->all() ) {
+                               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');
+                               push @N, $ref->get_column('nachname');
+                               push @N, $ref->get_column('name_suffix') if $ref->get_column('name_suffix');
+                               my $autor = join( " ", @N );
+                               push @{ $buch->{'autoren'} },   $autor;
+                               push @{ $buch->{'autor_ids'} }, $aid;
+                       }
+
+                       push @{ $cat->{'books'} }, $buch;
+
+        }
+
+    }
+
+    return ( wantarray ? ( $list, $anzahl_kategorien ) : $list );
+
+}
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_save_category( $category )
+
+=cut
+
+sub b_save_category {
+
+    my $c   = shift;
+    my $cat = shift;
+    my $K = ( caller(0) )[3] . "(): ";
+
+    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+    my $storage = $c->model('Schema')->storage;
+
+    my $save_func = sub {
+        my ( $storage, $dbh, $category_id, $cat_name ) = @_;
+        my $sql = <<ENDE;
+INSERT INTO `kategorien` (
+    `id`, `kategorie_name` )
+  VALUES (
+    ?, ? )
+  ON DUPLICATE KEY UPDATE
+    `id` = LAST_INSERT_ID(`id`), `kategorie_name` = ?
+ENDE
+
+        if ( $storage->debug() ) {
+            my $text = $sql;
+            $text =~ s/\s+$//;
+            $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $category_id, $cat_name, $cat_name ) ) . "\n";
+            warn $text;
+        }
+
+        my $sth = $dbh->prepare($sql);
+        $sth->execute( $category_id, $cat_name, $cat_name );
+    };
+
+    $storage->dbh_do( $save_func, $cat->{'id'}, $cat->{'name'} );
+
+    return $storage->last_insert_id();
+
+}
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->b_delete_category( $category_id )
+
+Loescht die Kategorie mit der uebergebenen Kategorie-Id
+
+=cut
+
+sub b_delete_category {
+
+    my $c      = shift;
+    my $cat_id = shift;
+    my $K      = ( caller(0) )[3] . "(): ";
+
+    $c->log->debug( $K . "aufgerufen fuer Kategorie-Id " . ( defined $cat_id ? $cat_id : '<undef>' ) . "." ) if $c->stash->{'debug_level'} > 2;
+
+    return undef unless $cat_id and to_int($cat_id);
+    $cat_id = to_int($cat_id);
+
+    my $schema =  $c->model('Schema')->{'schema'};
+
+       # Raus, wenn die Kategorie noch Buecher hat ...
+       if ( $c->model('Schema::Buch2kategorie')->count( { 'kategorie_id' => $cat_id, } ) ) {
+               my $msg = 'Es existieren noch Buecher dieser Kategorie.';
+               die $msg . "\n";
+       }
+
+       # Das eigentliche Löschen
+    my $coderef = sub {
+        $c->model('Schema::Kategorien')->search( { 'id' => $cat_id } )->delete();
+    };
+
+    my $rs;
+    eval {
+        $rs = $schema->txn_do($coderef);
+    };
+
+    if ($@) {                             # Transaction failed
+               my $msg = $@ =~ /Rollback failed/i ? "Rollback nicht erfolgreich!" : $@;
+               die $msg . "\n";
+               return undef;
+    }
+       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 :
diff --git a/lib/FrBr/Books/Util/Category.pm b/lib/FrBr/Books/Util/Category.pm
deleted file mode 100644 (file)
index d2fefa2..0000000
+++ /dev/null
@@ -1,395 +0,0 @@
-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
-        &save_category
-        &delete_category
-    );
-
-    #%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:
-
-=over 4
-
-=item B<category_id>: Die ID einer konkreten Kategorie
-
-=item B<get_books>: Bool. Zeigt an, daß zu den gefundenen Kategorien die dazugehörigen
-Bücher geholt werden sollen.
-
-=item B<page>
-
-Integer: Zeigt an, welche Seite von Kategorien dargestellt werden soll.
-
-Wenn nicht angegeben, werden alle Kategorien zurückgegeben.
-
-=back
-
-Rueckgabe: Im skalaren Kontext eine Array-Ref von Hash-Refs mit allen Kategorien, die den uebergebenen Suchkriterien entsprechen:
-
-  $res = [
-    { 'id'          => 1,
-      'name'        => 'Science Fiction',
-      'count_books'    => 22,
-    },
-    { 'id'     => 2,
-      ...
-    },
-    ...
-  ];
-
-Die Liste ist nach den Kategorie-Namen alphabetisch sortiert.
-
-Im Listenkontext wird als zweiter Rückgabewert die Gesamtzahl aller Kategorien zurueckgegeben.
-
-=cut
-
-sub get_category_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_kategorien = 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->{'category_id'} ) {
-               $search_params = {
-                       'me.id' => $params->{'category_id'},
-               };
-       }
-
-       $anzahl_kategorien = $c->model('Schema::Kategorien')->count( $search_params );
-    $c->log->debug(  get_output_string( $K, "Anzahl gefundene Kategorien: ", $anzahl_kategorien ) ) if $c->stash->{'debug_level'} >= 2;
-
-    my $other_params = {};
-    $other_params->{'order_by'} = [ 'kategorie_name' ];
-    $other_params->{'select'} = [
-        'me.id',
-        'me.kategorie_name',
-               { 'count' => 'buch_kategorie.id' }
-    ];
-    $other_params->{'as'} = [
-        'id',
-        'kategorie_name',
-               'count_books',
-    ];
-       $other_params->{'join'} = [ 'buch_kategorie'];
-       $other_params->{'group_by'} = [ 'me.id' ];
-       if ( $page ) {
-               $other_params->{'rows'} = $rows;
-               $other_params->{'page'} = $page;
-       }
-    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();
-        $cat->{'count_books'} = $cat_rs->get_column('count_books');
-        push @$list, $cat;
-    }
-
-    return ( wantarray ? ( $list, 0 ) : $list ) unless scalar @$list;
-    return ( wantarray ? ( $list, $anzahl_kategorien ) : $list ) unless $params->{'get_books'};
-
-       for my $cat ( @$list ) {
-
-               $cat->{'books'} = [];
-
-               $search_params = {
-                       "buch_kategorie.kategorie_id" => $cat->{'id'},
-               };
-               $other_params = {};
-               $other_params->{'join'}     = [ 'waehrung', 'ort', 'bindungsart', 'buch_kategorie', 'verlag', ];
-
-               $other_params->{'select'} = [
-                       'me.id',
-                       'me.title',
-                       'me.title_original',
-                       'me.untertitel',
-                       'me.bindungsart_id',
-                       'bindungsart.art_name',
-                       'me.orts_id',
-                       'me.isbn',
-                       'me.buch_nr',
-                       'me.ausgabejahr',
-                       'me.druckjahr',
-                       'me.seiten',
-                       'me.preis',
-                       'me.waehrungs_id',
-                       'waehrung.waehrungs_kuerzel',
-                       'waehrung.waehrungs_name',
-                       'waehrung.umrechnung_in_euro',
-                       'ort.name',
-                       'ort.descr',
-                       'ort.statisch',
-            'buch_kategorie.kategorie_id',
-            'verlag.name_short',
-            'verlag.name_long',
-               ];
-               $other_params->{'as'} = [
-                       'id',
-                       'title',
-                       'title_original',
-                       'untertitel',
-                       'bindungsart_id',
-                       'bindungsart',
-                       'orts_id',
-                       'isbn',
-                       'buch_nr',
-                       'ausgabejahr',
-                       'druckjahr',
-                       'seiten',
-                       'preis',
-                       'waehrungs_id',
-                       'waehrungs_kuerzel',
-                       'waehrungs_name',
-                       'umrechnung_in_euro',
-                       'ortsname',
-                       'ort_beschreibung',
-                       'ort_ist_statisch',
-            'kategorie_id',
-            'verlags_name_short',
-            'verlags_name_long',
-               ];
-
-               for my $book ( $c->model('Schema::Buecher')->search( $search_params, $other_params )->all() ) {
-                       my $buch = {};
-                       $buch->{'id'}                 = $book->id();
-                       $buch->{'title'}              = $book->title();
-                       $buch->{'title_original'}     = $book->title_original();
-                       $buch->{'untertitel'}         = $book->untertitel();
-                       $buch->{'bindungsart_id'}     = $book->bindungsart_id();
-                       $buch->{'bindungsart'}        = $book->get_column('bindungsart');
-                       $buch->{'orts_id'}            = $book->orts_id();
-                       $buch->{'isbn'}               = $book->isbn();
-                       $buch->{'buch_nr'}            = $book->buch_nr();
-                       $buch->{'ausgabejahr'}        = $book->ausgabejahr();
-                       $buch->{'druckjahr'}          = $book->druckjahr();
-                       $buch->{'seiten'}             = $book->seiten();
-                       $buch->{'preis'}              = $book->preis();
-                       $buch->{'waehrungs_id'}       = $book->waehrungs_id();
-                       $buch->{'waehrungs_kuerzel'}  = $book->get_column('waehrungs_kuerzel');
-                       $buch->{'waehrungs_name'}     = $book->get_column('waehrungs_name');
-                       $buch->{'umrechnung_in_euro'} = $book->get_column('umrechnung_in_euro');
-                       $buch->{'ortsname'}           = $book->get_column('ortsname');
-                       $buch->{'ort_beschreibung'}   = $book->get_column('ort_beschreibung');
-                       $buch->{'ort_ist_statisch'}   = $book->get_column('ort_ist_statisch');
-                       $buch->{'kategorie_id'}       = $book->get_column('kategorie_id');
-                       $buch->{'verlags_name_short'} = $book->get_column('verlags_name_short');
-                       $buch->{'verlags_name_long'}  = $book->get_column('verlags_name_long');
-                       $buch->{'autoren'}            = [];
-                       $buch->{'autor_ids'}          = [];
-
-                       my $a_search_params = {};
-                       $a_search_params->{'buch_id'} = $buch->{'id'};
-                       $other_params = {};
-                       $other_params->{'order_by'} = [ 'ord_num' ];
-                       $other_params->{'join'}     = [ 'autor' ];
-                       $other_params->{'select'} = [
-                               'me.buch_id',
-                               'autor.id',
-                               'autor.titel',
-                               'autor.vorname',
-                               'autor.mittelname',
-                               'autor.nachname',
-                               'autor.name_suffix',
-                       ];
-                       $other_params->{'as'} = [
-                               'buch_id',
-                               'autor_id',
-                               'titel',
-                               'vorname',
-                               'mittelname',
-                               'nachname',
-                               'name_suffix',
-                       ];
-                       for my $ref ( $c->model('Schema::Autor2buch')->search( $a_search_params, $other_params )->all() ) {
-                               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');
-                               push @N, $ref->get_column('nachname');
-                               push @N, $ref->get_column('name_suffix') if $ref->get_column('name_suffix');
-                               my $autor = join( " ", @N );
-                               push @{ $buch->{'autoren'} },   $autor;
-                               push @{ $buch->{'autor_ids'} }, $aid;
-                       }
-
-                       push @{ $cat->{'books'} }, $buch;
-
-        }
-
-    }
-
-    return ( wantarray ? ( $list, $anzahl_kategorien ) : $list );
-
-}
-
-#-----------------------------------------------------------------------------------
-
-=head2 save_category( $c, $category )
-
-=cut
-
-sub save_category {
-
-    my $c   = shift;
-    my $cat = shift;
-    my $K   = __PACKAGE__ . "::save_category(): ";
-
-    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
-
-    my $storage = $c->stash->{'storage'};
-
-    my $save_func = sub {
-        my ( $storage, $dbh, $category_id, $cat_name ) = @_;
-        my $sql = <<ENDE;
-INSERT INTO `kategorien` (
-    `id`, `kategorie_name` )
-  VALUES (
-    ?, ? )
-  ON DUPLICATE KEY UPDATE
-    `id` = LAST_INSERT_ID(`id`), `kategorie_name` = ?
-ENDE
-
-        if ( $storage->debug() ) {
-            my $text = $sql;
-            $text =~ s/\s+$//;
-            $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $category_id, $cat_name, $cat_name ) ) . "\n";
-            warn $text;
-        }
-
-        my $sth = $dbh->prepare($sql);
-        $sth->execute( $category_id, $cat_name, $cat_name );
-    };
-
-    $storage->dbh_do( $save_func, $cat->{'id'}, $cat->{'name'} );
-
-    return $storage->last_insert_id();
-
-}
-
-#-----------------------------------------------------------------------------------
-
-=head2 delete_category( $c, $category_id )
-
-Loescht die Kategorie mit der uebergebenen Kategorie-Id
-
-=cut
-
-sub delete_category {
-
-    my $c      = shift;
-    my $cat_id = shift;
-    my $K      = ( caller(0) )[3] . "(): ";
-
-    $c->log->debug( $K . "aufgerufen fuer Kategorie-Id " . ( defined $cat_id ? $cat_id : '<undef>' ) . "." ) if $c->stash->{'debug_level'} > 2;
-
-    return undef unless $cat_id and to_int($cat_id);
-    $cat_id = to_int($cat_id);
-
-    my $schema =  $c->model('Schema')->{'schema'};
-
-       # Raus, wenn die Kategorie noch Buecher hat ...
-       if ( $c->model('Schema::Buch2kategorie')->count( { 'kategorie_id' => $cat_id, } ) ) {
-               my $msg = 'Es existieren noch Buecher dieser Kategorie.';
-               die $msg . "\n";
-       }
-
-       # Das eigentliche Löschen
-    my $coderef = sub {
-        $c->model('Schema::Kategorien')->search( { 'id' => $cat_id } )->delete();
-    };
-
-    my $rs;
-    eval {
-        $rs = $schema->txn_do($coderef);
-    };
-
-    if ($@) {                             # Transaction failed
-               my $msg = $@ =~ /Rollback failed/i ? "Rollback nicht erfolgreich!" : $@;
-               die $msg . "\n";
-               return undef;
-    }
-       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 :