]> Frank Brehm's Git Trees - books.git/commitdiff
Änder Buch abgesclossen
authorFrank Brehm <frank@brehm-online.com>
Wed, 10 Dec 2008 11:05:26 +0000 (11:05 +0000)
committerFrank Brehm <frank@brehm-online.com>
Wed, 10 Dec 2008 11:05:26 +0000 (11:05 +0000)
db/buchautoren.sql [new file with mode: 0644]
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Util/Book.pm
root/src/books/save_success.tt2

diff --git a/db/buchautoren.sql b/db/buchautoren.sql
new file mode 100644 (file)
index 0000000..df5b96e
--- /dev/null
@@ -0,0 +1,77 @@
+
+-- $Id: $
+-- $URL: $
+
+drop view if exists `v_autoren`;
+
+create view `v_autoren` as
+select `id`,
+       concat( ifnull( `titel`, '' ), if( isnull(`titel`), '', ' ' ), 
+               ifnull( `vorname`, '' ), if( isnull(`vorname`), '', ' ' ), 
+               ifnull( `mittelname`, '' ), if( isnull(`mittelname`), '', ' ' ), 
+               `nachname`,
+               if( isnull( `name_suffix` ), '', ' ' ), ifnull( `name_suffix`, '' )
+       ) as `name`,
+       `titel`,
+       `vorname`,
+       `mittelname`,
+       `nachname`,
+       `name_suffix`,
+       `autor_descr`
+ from `autoren`
+ order by `nachname`, `vorname`, `mittelname`, `name_suffix` ;
+
+SELECT * FROM (
+    SELECT ab.`id`            AS `autor2buch_id`,
+           ab.`buch_id`       AS `buch_id`, 
+           ab.`autor_id`      AS `autor_id`, 
+           CONCAT( IFNULL( a.`titel`, '' ),      IF( ISNULL(a.`titel`), '', ' ' ), 
+                   IFNULL( a.`vorname`, '' ),    IF( ISNULL(a.`vorname`), '', ' ' ), 
+                   IFNULL( a.`mittelname`, '' ), IF( ISNULL(a.`mittelname`), '', ' ' ), 
+                   a.`nachname`,
+                   IF( ISNULL( a.`name_suffix` ), '', ' ' ), IFNULL( a.`name_suffix`, '' )
+           )                  AS `autor_name`,
+           ab.`ord_num`       AS `autor_ord_num`,
+           a.`titel`          AS `autor_titel`,
+           a.`vorname`        AS `autor_vorname`,
+           a.`mittelname`     AS `autor_mittelname`,
+           a.`nachname`       AS `autor_nachname`,
+           a.`name_suffix`    AS `autor_name_suffix`,
+           a.`autor_descr`    AS `autor_descr`,
+           b.`title`          AS `title`,
+           b.`title_original` AS `title_original`,
+           b.`untertitel`     AS `untertitel`
+      FROM autor2buch AS ab 
+      LEFT  JOIN `autoren` a ON ab.`autor_id` = a.`id` 
+      RIGHT JOIN `buecher` b ON ab.`buch_id`  = b.`id`
+     GROUP BY b.`id` ) AS c
+ORDER BY c.`autor_nachname`, c.`autor_vorname`, c.`autor_mittelname`, c.`autor_name_suffix`, c.`title`;
+
+DROP VIEW IF EXISTS `v_autor_buecher`;
+
+CREATE VIEW `v_autor_buecher` AS
+SELECT ab.`id`            AS `autor2buch_id`,
+       ab.`buch_id`       AS `buch_id`, 
+       b.`title`          AS `title`,
+       b.`title_original` AS `title_original`,
+       b.`untertitel`     AS `untertitel`,
+       ab.`autor_id`      AS `autor_id`, 
+       CONCAT( IFNULL( a.`titel`, '' ),      IF( ISNULL(a.`titel`), '', ' ' ), 
+               IFNULL( a.`vorname`, '' ),    IF( ISNULL(a.`vorname`), '', ' ' ), 
+               IFNULL( a.`mittelname`, '' ), IF( ISNULL(a.`mittelname`), '', ' ' ), 
+               a.`nachname`,
+               IF( ISNULL( a.`name_suffix` ), '', ' ' ), IFNULL( a.`name_suffix`, '' )
+       )                  AS `autor_name`,
+       ab.`ord_num`       AS `autor_ord_num`,
+       a.`titel`          AS `autor_titel`,
+       a.`vorname`        AS `autor_vorname`,
+       a.`mittelname`     AS `autor_mittelname`,
+       a.`nachname`       AS `autor_nachname`,
+       a.`name_suffix`    AS `autor_name_suffix`,
+       a.`autor_descr`    AS `autor_descr`
+  FROM autor2buch AS ab 
+  LEFT  JOIN `autoren` a ON ab.`autor_id` = a.`id` 
+  RIGHT JOIN `buecher` b ON ab.`buch_id`  = b.`id`
+  ORDER BY b.`title`, ab.`buch_id`, ab.`ord_num`;
+
+-- vim: noai : ts=4 fenc=utf-8 filetype=sql expandtab :
index 8758495cb7c4209adb1f97896bafa6a0d21aabfd..464d956ccaaa5416f348d1b5ac1582a0c286dd4a 100644 (file)
@@ -53,6 +53,8 @@ sub auto : Private {
     $c->session->{'return_target_del'} = $c->web_path("/books") unless $c->session->{'return_target_del'};
     $c->session->{'return_target_new'} = $c->web_path("/books") unless $c->session->{'return_target_new'};
 
+    $c->stash->{'return_target_action'} = $c->web_path("/books");
+
     $c->stash->{'cssfiles'} = [] unless $c->stash->{'cssfiles'};
     push @{$c->stash->{'cssfiles'}}, 'books/styles.css';
 
@@ -75,6 +77,8 @@ sub index : Private {
     $c->session->{'return_target_del'} = $c->web_path("/books");
     $c->session->{'return_target_new'} = $c->web_path("/books");
 
+    delete $c->session->{'from_book_list'} if exists $c->session->{'from_book_list'};
+
 }
 
 #-------------------------------------------------------
@@ -98,6 +102,20 @@ sub default : Private {
 } ## end sub default :
 
 
+#-------------------------------------------------------
+
+sub add_booklist_menu : Private {
+
+    my ( $self, $c ) = @_;
+    my $K = ( caller(0) )[3] . "(): ";
+
+    push @{ $c->stash->{'menu_path'} }, {
+        'path' => $c->web_path("/books/list"),
+        'name' => "Liste"
+    };
+
+}
+
 #-------------------------------------------------------
 
 =head2 list
@@ -112,10 +130,7 @@ sub list : Local {
     my $K = ( caller(0) )[3] . "(): ";
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
-    push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->web_path("/books/list"),
-        'name' => "Liste"
-    };
+    $self->add_booklist_menu($c);
 
     my $buchliste = get_booklist( $c );
     $c->log->debug( get_output_string( $K, "Erhaltene Buchliste: ", $buchliste ) ) if $c->stash->{'debug_level'} >= 2;
@@ -126,7 +141,7 @@ sub list : Local {
     $c->session->{'return_target_edit'} = $c->web_path("/books/list");
     $c->session->{'return_target_del'} = $c->web_path("/books/list");
     $c->session->{'return_target_new'} = $c->web_path("/books/list");
-
+    $c->session->{'from_book_list'} = 1;
 }
 
 #-------------------------------------------------------
@@ -145,6 +160,7 @@ sub form_new : Path('new') {
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
     $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+    $self->add_booklist_menu($c) if $c->session->{'from_book_list'};
     push @{ $c->stash->{'menu_path'} }, {
         'path' => $c->web_path("/books/new"),
         'name' => "Neu"
@@ -157,6 +173,10 @@ sub form_new : Path('new') {
 
     $c->stash->{'error_message'} = '';
 
+    if ( $c->session->{'book_data_edit'} and $c->session->{'book_data_edit'}{'id'} ) {
+        delete $c->session->{'book_data_edit'};
+    }
+
     $self->prepare_data_structures($c);
 
     $self->bookdata_cgi2session($c);
@@ -174,6 +194,7 @@ sub form_new : Path('new') {
         return 1;
     }
 
+    $c->stash->{'return_target_action'} = $c->session->{'return_target_new'};
     return $self->do_save_book($c);
 
 }
@@ -194,6 +215,7 @@ sub form_view : Path('view') {
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
     $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+    $self->add_booklist_menu($c) if $c->session->{'from_book_list'};
     push @{ $c->stash->{'menu_path'} }, {
         'path' => $c->web_path("/books/view"),
         'name' => "Betrachten"
@@ -242,6 +264,7 @@ sub form_edit : Path('edit') {
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
     $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+    $self->add_booklist_menu($c) if $c->session->{'from_book_list'};
     push @{ $c->stash->{'menu_path'} }, {
         'path' => $c->web_path("/books/edit"),
         'name' => "&Auml;ndern"
@@ -249,15 +272,24 @@ sub form_edit : Path('edit') {
 
     $c->stash->{'error_message'} = '';
 
+    # Zu bearbeitende Buch-Id ermitteln
     my $buch_id = to_int( $c->request->params->{'edit_book_id'} || 0 );
+
+    unless ( $buch_id ) {
+        if ( $c->session->{'book_data_edit'} and $c->session->{'book_data_edit'}{'id'} ) {
+            $buch_id = $c->session->{'book_data_edit'}{'id'};
+        }
+    }
+
+    # Keine Buch-Id da?
     unless ( $buch_id ) {
         $c->stash->{'template'} = 'error.tt2';
         $c->stash->{'error'}    = 'Keine oder ung&uuml;ltige Buch-Id &uuml;bergeben.';
         return 1;
     }
 
+    # Angaben zum Buch aus der Datenbank holen
     my $buchliste = get_booklist( $c, 'buch_id' => $buch_id );
-    $c->log->debug( get_output_string( $K, "Erhaltene Buchliste: ", $buchliste ) ) if $c->stash->{'debug_level'} >= 2;
 
     unless ( $buchliste and scalar( @$buchliste ) ) {
         $c->stash->{'template'} = 'error.tt2';
@@ -267,6 +299,9 @@ sub form_edit : Path('edit') {
 
     my $buch = $buchliste->[0];
 
+    $c->log->debug( get_output_string( $K, "Buch aus Datenbank: ", $buch ) ) if $c->stash->{'debug_level'} >= 2;
+
+    # Umbiegen der Datenstrukturen (keine Konsistenz - narf!)
     $buch->{'autoren'} = $buch->{'autor_ids'};
     delete $buch->{'autor_ids'} if exists $buch->{'autor_ids'};
 
@@ -276,10 +311,22 @@ sub form_edit : Path('edit') {
     $buch->{'serien'} = $buch->{'serien_ids'};
     delete $buch->{'serien_ids'} if exists $buch->{'serien_ids'};
 
+    $buch->{'original_title'} = $buch->{'title_original'};
+
+    $c->log->debug( get_output_string( $K, "Buch nach Bereinigung: ", $buch ) ) if $c->stash->{'debug_level'} >= 2;
+
+    # Ruecksprung-URL bestimmen
     $c->stash->{'return_target'} = $c->session->{'return_target_edit'} or $c->web_path("/books/list");
 
-    $c->stash->{'book_edit'}        = $buch;
-    $c->session->{'book_data_edit'} = $buch;
+    # Sitzungsdaten vorbelegen, falls noch nicht geschehen
+    if ( $c->session->{'book_data_edit'} ) {
+        if ( ! $c->session->{'book_data_edit'}{'id'} or $c->session->{'book_data_edit'}{'id'} != $buch_id ) {
+            $c->session->{'book_data_edit'} = $buch;
+        }
+    }
+    else {
+        $c->session->{'book_data_edit'} = $buch;
+    }
     $buchliste = undef;
 
     $self->prepare_data_structures($c);
@@ -294,6 +341,7 @@ sub form_edit : Path('edit') {
         return 1;
     }
 
+    $c->stash->{'return_target_action'} = $c->session->{'return_target_edit'};
     return $self->do_save_book($c);
 
 }
@@ -307,12 +355,15 @@ sub do_save_book : Private {
 
     my $book = $c->stash->{'book_edit'};
 
+    # Felder vorbereiten
     $book->{'autoren'}    = $c->stash->{'autor_list_book'};
     $book->{'kategorien'} = $c->stash->{'kategorie_list_book'};
     $book->{'serien'}     = $c->stash->{'serienliste_book'};
+
     $c->log->debug( get_output_string( $K . "Buchangaben, die gesichert werden sollen: ", $book ) );
 
     return 1 unless $self->check_formparams( $c, $book );
+    $c->log->debug( get_output_string( $K . "Buchangaben, die gesichert werden: ", $book ) );
 
     my $book_id = undef;
 
@@ -332,7 +383,10 @@ sub do_save_book : Private {
     }
 
     $c->stash->{'template'} = 'books/save_success.tt2';
-    delete $c->session->{'book_data_edit'} if exists $c->session->{'book_data_edit'};
+    if ( exists $c->session->{'book_data_edit'} ) {
+        $c->log->debug( $K . "Loesche Buchdaten in der Session ..." );
+        delete $c->session->{'book_data_edit'};
+    }
 
     return 1;
 
@@ -345,6 +399,69 @@ sub check_formparams : Private {
     my ( $self, $c, $book ) = @_;
     my $K = ( caller(0) )[3] . "(): ";
 
+    # Titel trimmen
+    $book->{'title'} = '' unless defined $book->{'title'};
+    $book->{'title'} =~ s/^\s+//;
+    $book->{'title'} =~ s/\s+$//;
+
+    # Untertitel trimmen
+    if ( defined $book->{'untertitel'} ) {
+        $book->{'untertitel'} =~ s/^\s+//;
+        $book->{'untertitel'} =~ s/\s+$//;
+        $book->{'untertitel'} = undef if $book->{'untertitel'} eq "";
+    }
+
+    # Original-Titel trimmen
+    if ( defined $book->{'original_title'} ) {
+        $book->{'original_title'} =~ s/^\s+//;
+        $book->{'original_title'} =~ s/\s+$//;
+        $book->{'original_title'} = undef if $book->{'original_title'} eq "";
+    }
+
+    # ISBN trimmen
+    if ( defined $book->{'isbn'} ) {
+        $book->{'isbn'} =~ s/^\s+//;
+        $book->{'isbn'} =~ s/\s+$//;
+        $book->{'isbn'} = undef if $book->{'isbn'} eq "";
+    }
+
+    # Verlags-Buchnummer trimmen
+    if ( defined $book->{'book_nr'} ) {
+        $book->{'book_nr'} =~ s/^\s+//;
+        $book->{'book_nr'} =~ s/\s+$//;
+        $book->{'book_nr'} = undef if $book->{'book_nr'} eq "";
+    }
+
+    # Ausgabejahr trimmen
+    if ( defined $book->{'ausgabejahr'} ) {
+        my ( $jahr ) = $book->{'ausgabejahr'} =~ /(\d+)/;
+        $book->{'ausgabejahr'} = $jahr;
+    }
+
+    # Druckjahr trimmen
+    if ( defined $book->{'druckjahr'} ) {
+        my ( $jahr ) = $book->{'druckjahr'} =~ /(\d+)/;
+        $book->{'druckjahr'} = $jahr;
+    }
+
+    # Seitenzahl trimmen
+    if ( defined $book->{'seiten'} ) {
+        my ( $seiten ) = $book->{'seiten'} =~ /(\d+)/;
+        $book->{'seiten'} = $seiten;
+    }
+
+    # Preis trimmen
+    if ( defined $book->{'preis'} ) {
+        $book->{'preis'} =~ s/^\s+//;
+        $book->{'preis'} =~ s/\s+$//;
+        if ( $book->{'preis'} =~ /\d/ ) {
+            $book->{'preis'} = to_float( $book->{'preis'} ) + 0;
+        }
+        else {
+            $book->{'preis'} = undef;
+        }
+    }
+
     unless ( $book->{'title'} ) {
         $c->stash->{'error_message'} = "Kein Buchtitel angegeben.";
         return undef;
index a2a4ab7a1d21894e1f19760d7c4c7af606e53b45..ecabb907a89e4df3d691ccb8cb8a44e95c919e6f 100644 (file)
@@ -370,7 +370,7 @@ sub save_book {
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
     my $storage = $c->stash->{'storage'};
-    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+    #$c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
 
     my $save_func = sub {
 
@@ -419,8 +419,8 @@ ENDE
 
         push @params, $buch->{'title'};
         push @params, $buch->{'original_title'};
-        push @params, $buch->{'verlags_id'};
         push @params, $buch->{'untertitel'};
+        push @params, $buch->{'verlags_id'};
         push @params, $buch->{'orts_id'};
         push @params, $buch->{'bindungsart_id'};
         push @params, $buch->{'isbn'};
@@ -472,9 +472,9 @@ sub save_buch_autoren {
     my $K    = ( caller(0) )[3] . "(): ";
 
     my $storage = $c->stash->{'storage'};
-    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
     my $dbh = $storage->dbh();
-    $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
+    $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
 
     my $anzahl = 0;
     $anzahl = scalar( @$autor_ids ) if $autor_ids and ref($autor_ids) and ref($autor_ids) eq 'ARRAY';
@@ -554,9 +554,9 @@ sub save_buch_serien {
     my $K    = ( caller(0) )[3] . "(): ";
 
     my $storage = $c->stash->{'storage'};
-    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
     my $dbh = $storage->dbh();
-    $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
+    $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
 
     my $anzahl = 0;
     $anzahl = scalar( @$serien_ids ) if $serien_ids and ref($serien_ids) and ref($serien_ids) eq 'ARRAY';
@@ -636,9 +636,9 @@ sub save_buch_kategorien {
     my $K    = ( caller(0) )[3] . "(): ";
 
     my $storage = $c->stash->{'storage'};
-    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
+    $c->log->debug( get_output_string( $K . "Storage: ", $storage ) ) if $c->stash->{'debug_level'} > 4;
     my $dbh = $storage->dbh();
-    $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
+    $c->log->debug( get_output_string( $K . "DBH: ", $dbh ) ) if $c->stash->{'debug_level'} > 2;
 
     my $anzahl = 0;
     $anzahl = scalar( @$kategorie_ids ) if $kategorie_ids and ref($kategorie_ids) and ref($kategorie_ids) eq 'ARRAY';
index 523efbb411ef14385ed5e676690f3006a5901da9..c9eab07f453336482baffda8a1bf73f07fed61b2 100644 (file)
@@ -12,6 +12,6 @@
 
 Das Buch <b>&quot;[% book_edit.title %]</b> wurde erfolgreich gespeichert.
 
-<h2><a href="[% path('/books') %]">OK</a></h2>
+<h2><a href="[% return_target_action %]">OK</a></h2>
 
 </div>