From: Frank Brehm Date: Tue, 18 Nov 2008 21:36:37 +0000 (+0000) Subject: Datenmodell bei Autoren geändert X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=9ccdb40c6494db9e44209a53200a7ac75a24d705;p=books.git Datenmodell bei Autoren geändert --- diff --git a/lib/FrBr/Books/Controller/Autor.pm b/lib/FrBr/Books/Controller/Autor.pm index 19e4723..1efb318 100644 --- a/lib/FrBr/Books/Controller/Autor.pm +++ b/lib/FrBr/Books/Controller/Autor.pm @@ -113,7 +113,7 @@ sub form_new : Path('new') { $c->stash->{'autor_edit'} = {} unless $c->stash->{'autor_edit'}; $self->autor_session2stash($c); - $c->stash->{'autor_edit'}{'name'} = "Neuer Autor" unless $c->stash->{'autor_edit'}{'name'}; + $c->stash->{'autor_edit'}{'nachname'} = "Neuer Autor" unless $c->stash->{'autor_edit'}{'nachname'}; return 1 unless $c->request->params->{'autor_form_sent'} and $c->request->params->{'do_save'}; @@ -158,8 +158,8 @@ sub check_formparams : Private { return undef; } - unless ( $c->stash->{'autor_edit'}{'name'} ) { - $c->stash->{'error_message'} = "Kein Name des Autors angegeben."; + unless ( $c->stash->{'autor_edit'}{'nachname'} ) { + $c->stash->{'error_message'} = "Kein Nachname des Autors angegeben."; return undef; } @@ -175,9 +175,14 @@ sub autor_session2stash : Private { my $K = ( caller(0) )[3] . "(): "; $c->stash->{'autor_edit'} = {} unless $c->stash->{'autor_edit'}; - $c->stash->{'autor_edit'}{'id'} = $c->session->{'autor_data_edit'}{'id'} if $c->session->{'autor_data_edit'}{'id'}; - $c->stash->{'autor_edit'}{'name'} = $c->session->{'autor_data_edit'}{'name'} if $c->session->{'autor_data_edit'}{'name'}; - $c->stash->{'autor_edit'}{'desc'} = $c->session->{'autor_data_edit'}{'desc'} if $c->session->{'autor_data_edit'}{'desc'}; + + $c->stash->{'autor_edit'}{'id'} = $c->session->{'autor_data_edit'}{'id'} if $c->session->{'autor_data_edit'}{'id'}; + $c->stash->{'autor_edit'}{'titel'} = $c->session->{'autor_data_edit'}{'titel'} if exists $c->session->{'autor_data_edit'}{'titel'}; + $c->stash->{'autor_edit'}{'vorname'} = $c->session->{'autor_data_edit'}{'vorname'} if exists $c->session->{'autor_data_edit'}{'vorname'}; + $c->stash->{'autor_edit'}{'mittelname'} = $c->session->{'autor_data_edit'}{'mittelname'} if exists $c->session->{'autor_data_edit'}{'mittelname'}; + $c->stash->{'autor_edit'}{'nachname'} = $c->session->{'autor_data_edit'}{'nachname'} if $c->session->{'autor_data_edit'}{'nachname'}; + $c->stash->{'autor_edit'}{'name_suffix'} = $c->session->{'autor_data_edit'}{'name_suffix'} if exists $c->session->{'autor_data_edit'}{'name_suffix'}; + $c->stash->{'autor_edit'}{'desc'} = $c->session->{'autor_data_edit'}{'desc'} if exists $c->session->{'autor_data_edit'}{'desc'}; $c->stash->{'return_target_autor_save'} = $c->session->{'return_target_autor_save'} || $c->web_path('/autor'); @@ -202,15 +207,51 @@ sub autor_cgi2session : Private { # Autor-Id eintragen, wenn notwendig $c->session->{'autor_data_edit'}{'id'} = $c->request->params->{'autor_id'} if $c->request->params->{'autor_id'}; - # Name des Autors - if ( defined $c->request->params->{'autor_name'} ) { - my $name = $c->request->params->{'autor_name'}; + # Titel des Autors + if ( defined $c->request->params->{'autor_titel'} ) { + my $titel = $c->request->params->{'autor_titel'}; + $titel =~ s/^\s+//; + $titel =~ s/\s+$//; + $titel = undef if $titel eq ''; + $c->session->{'autor_data_edit'}{'titel'} = $titel; + } + + # Vorname des Autors + if ( defined $c->request->params->{'autor_vorname'} ) { + my $vorname = $c->request->params->{'autor_vorname'}; + $vorname =~ s/^\s+//; + $vorname =~ s/\s+$//; + $vorname = undef if $vorname eq ''; + $c->session->{'autor_data_edit'}{'vorname'} = $vorname; + } + + # Mittelname des Autors + if ( defined $c->request->params->{'autor_mittelname'} ) { + my $name = $c->request->params->{'autor_mittelname'}; $name =~ s/^\s+//; $name =~ s/\s+$//; - $c->session->{'autor_data_edit'}{'name'} = $name; + $name = undef if $name eq ''; + $c->session->{'autor_data_edit'}{'mittelname'} = $name; + } + + # Nachname des Autors + if ( defined $c->request->params->{'autor_nachname'} ) { + my $name = $c->request->params->{'autor_nachname'}; + $name =~ s/^\s+//; + $name =~ s/\s+$//; + $c->session->{'autor_data_edit'}{'nachname'} = $name; + } + + # Namens-Suffix des Autors + if ( defined $c->request->params->{'autor_name_suffix'} ) { + my $suffix = $c->request->params->{'autor_name_suffix'}; + $suffix =~ s/^\s+//; + $suffix =~ s/\s+$//; + $suffix = undef if $suffix eq ''; + $c->session->{'autor_data_edit'}{'name_suffix'} = $suffix; } - # Untertitel + # Genauere Beschreibung des Autors $c->session->{'autor_data_edit'}{'desc'} = $c->request->params->{'autor_desc'} if defined $c->request->params->{'autor_desc'}; return 1; diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index 17239e2..7a420c8 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -237,7 +237,7 @@ sub bookdata_session2stash : Private { $c->log->debug( get_output_string( $K . "Autoren des Buches: ", $c->stash->{'autor_list_book'} ) ); $c->stash->{'autor_list_no'} = []; - for my $autor_id ( sort { lc($c->stash->{'autor_list'}{$a}) cmp lc($c->stash->{'autor_list'}{$b}) } keys %{$c->stash->{'autor_list'}} ) { + for my $autor_id ( @{$c->stash->{'autor_array_sorted'}} ) { push @{$c->stash->{'autor_list_no'}}, $autor_id unless $Autor{$autor_id}; } $c->log->debug( get_output_string( $K . "Autoren, die fehlen: ", $c->stash->{'autor_list_no'} ) ); @@ -565,8 +565,10 @@ sub prepare_data_structures : Private { $c->log->debug( get_output_string( $K . "Autoren gesamt: ", $autor_list_complete ) ); $c->stash->{'autor_list'} = {}; + $c->stash->{'autor_array_sorted'} = []; for my $autor ( @$autor_list_complete ) { $c->stash->{'autor_list'}{ $autor->{'id'} } = $autor->{'name'}; + push @{$c->stash->{'autor_array_sorted'}}, $autor->{'id'}; } $c->log->debug( get_output_string( $K . "Autoren-Hash: ", $c->stash->{'autor_list'} ) ); diff --git a/lib/FrBr/Books/Db/Autoren.pm b/lib/FrBr/Books/Db/Autoren.pm index 0bab31d..fc17146 100644 --- a/lib/FrBr/Books/Db/Autoren.pm +++ b/lib/FrBr/Books/Db/Autoren.pm @@ -12,11 +12,15 @@ __PACKAGE__->load_components("Core"); __PACKAGE__->table("autoren"); __PACKAGE__->add_columns( "id" => { data_type => "INT", default_value => undef, is_nullable => 0, size => 10 }, - "autor_name" => { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 250, }, + "titel" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 100, }, + "vorname" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 150, }, + "mittelname" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 150, }, + "nachname" => { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 150, }, + "name_suffix" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 100, }, "autor_descr" => { data_type => "TEXT", default_value => undef, is_nullable => 0, size => 65535, }, ); __PACKAGE__->set_primary_key("id"); -__PACKAGE__->add_unique_constraint("autor_name", ["autor_name"]); +__PACKAGE__->add_unique_constraint( "name", [ "nachname", "vorname", "mittelname", "name_suffix" ] ); # Created by DBIx::Class::Schema::Loader v0.04004 @ 2008-03-17 17:53:52 diff --git a/lib/FrBr/Books/Util/Author.pm b/lib/FrBr/Books/Util/Author.pm index cafd723..91a4701 100644 --- a/lib/FrBr/Books/Util/Author.pm +++ b/lib/FrBr/Books/Util/Author.pm @@ -56,6 +56,11 @@ Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen $res = [ { 'id' => 1, 'name' => 'J.R.R. Tolkien', + 'titel' => undef, + 'vorname' => 'J.R.R.', + 'mittelname' => undef, + 'nachname' => 'Tolkien', + 'name_suffix' => undef, 'descr' => 'Bla Blub', }, { 'id' => 2, @@ -64,14 +69,14 @@ Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen ... ]; -Die Liste ist nach den Autor-Namen alphabetisch sortiert. +Die Liste ist nach den Nachnamen, Vornamen, Mittelnamen und Namens-Suffixen alphabetisch sortiert. =cut sub get_author_list { my $c = shift; - my $K = __PACKAGE__ . "::get_author_list(): "; + my $K = ( caller(0) )[3] . "(): "; $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; @@ -89,23 +94,42 @@ sub get_author_list { my $search_params = undef; my $other_params = {}; - $other_params->{'order_by'} = [ 'autor_name' ]; + $other_params->{'order_by'} = [ 'nachname', 'vorname', 'mittelname', 'name_suffix' ]; $other_params->{'select'} = [ 'id', - 'autor_name', + 'titel', + 'vorname', + 'mittelname', + 'nachname', + 'name_suffix', 'autor_descr', ]; $other_params->{'as'} = [ 'id', - 'autor_name', + 'titel', + 'vorname', + 'mittelname', + 'nachname', + 'name_suffix', 'autor_descr', ]; for my $autor_rs ( $c->model('Schema::Autoren')->search( $search_params, $other_params )->all() ) { my $autor = {}; - $autor->{'id'} = $autor_rs->id(); - $autor->{'name'} = $autor_rs->autor_name(); - $autor->{'descr'} = $autor_rs->autor_descr(); + $autor->{'id'} = $autor_rs->id(); + $autor->{'titel'} = $autor_rs->titel(); + $autor->{'vorname'} = $autor_rs->vorname(); + $autor->{'mittelname'} = $autor_rs->mittelname(); + $autor->{'nachname'} = $autor_rs->nachname(); + $autor->{'name_suffix'} = $autor_rs->name_suffix(); + $autor->{'descr'} = $autor_rs->autor_descr(); + my @N; + push @N, $autor->{'titel'} if $autor->{'titel'}; + push @N, $autor->{'vorname'} if $autor->{'vorname'}; + push @N, $autor->{'mittelname'} if $autor->{'mittelname'}; + push @N, $autor->{'nachname'}; + push @N, $autor->{'name_suffix'} if $autor->{'name_suffix'}; + $autor->{'name'} = join( " ", @N ); push @$list, $autor; } @@ -129,29 +153,85 @@ sub save_autor { my $storage = $c->stash->{'storage'}; my $save_func = sub { - my ( $storage, $dbh, $autor_id, $name, $desc ) = @_; + my ( $storage, $dbh, $autor_id, $titel, $vorname, $mittelname, $nachname, $suffix, $desc ) = @_; $desc = '' unless defined $desc; my $sql = <debug() ) { my $text = $sql; $text =~ s/\s+$//; - $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $autor_id, $name, $desc, $name, $desc ) ) . "\n"; + $text .= ": " . join( ", ", map { $dbh->quote($_) } @P ) . "\n"; warn $text; } my $sth = $dbh->prepare($sql); - $sth->execute( $autor_id, $name, $desc, $name, $desc ); + $sth->execute( @P ); }; - $storage->dbh_do( $save_func, $autor->{'id'}, $autor->{'name'}, $autor->{'desc'} ); + my @Params = (); + push @Params, $autor->{'id'}; + + my $tmp = $autor->{'titel'}; + $tmp = '' unless defined $tmp; + $tmp =~ s/^\s+//; + $tmp =~ s/\s+$//; + push @Params, ( $tmp ? $tmp : undef ); + + $tmp = $autor->{'vorname'}; + $tmp = '' unless defined $tmp; + $tmp =~ s/^\s+//; + $tmp =~ s/\s+$//; + push @Params, ( $tmp ? $tmp : undef ); + + $tmp = $autor->{'mittelname'}; + $tmp = '' unless defined $tmp; + $tmp =~ s/^\s+//; + $tmp =~ s/\s+$//; + push @Params, ( $tmp ? $tmp : undef ); + + $tmp = $autor->{'nachname'}; + $tmp = '' unless defined $tmp; + $tmp =~ s/^\s+//; + $tmp =~ s/\s+$//; + push @Params, $tmp; + + $tmp = $autor->{'name_suffix'}; + $tmp = '' unless defined $tmp; + $tmp =~ s/^\s+//; + $tmp =~ s/\s+$//; + push @Params, ( $tmp ? $tmp : undef ); + + push @Params, $autor->{'desc'}; + + $storage->dbh_do( $save_func, @Params ); return $storage->last_insert_id(); diff --git a/lib/FrBr/Books/Util/Book.pm b/lib/FrBr/Books/Util/Book.pm index 75669ea..55be7da 100644 --- a/lib/FrBr/Books/Util/Book.pm +++ b/lib/FrBr/Books/Util/Book.pm @@ -183,15 +183,29 @@ sub get_booklist { $other_params->{'join'} = [ 'autor' ]; $other_params->{'select'} = [ 'me.buch_id', - 'autor.autor_name', + 'autor.titel', + 'autor.vorname', + 'autor.mittelname', + 'autor.nachname', + 'autor.name_suffix', ]; $other_params->{'as'} = [ 'buch_id', - 'autor_name', + 'titel', + 'vorname', + 'mittelname', + 'nachname', + 'name_suffix', ]; for my $ref ( $c->model('Schema::Autor2buch')->search( $a_search_params, $other_params )->all() ) { my $bid = $ref->get_column('buch_id'); - my $autor = $ref->get_column('autor_name'); + 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 ); my $j = $buchmap->{$bid}; next unless defined $j; my $buch = $list->[$j]; diff --git a/root/src/autor/autor_form.tt2 b/root/src/autor/autor_form.tt2 index f9ac637..5b981d0 100644 --- a/root/src/autor/autor_form.tt2 +++ b/root/src/autor/autor_form.tt2 @@ -19,8 +19,20 @@   - Name des Autors: - + Titel des Autors (Dr. o.ä.): + + + Vorname des Autors: + + + Zweiter Vorname des Autors (oder Vatersname o.ä.): + + + Nachname des Autors: + + + Namenssuffix (Jr. o.ä.): + Zusätzliche Angaben: diff --git a/root/src/autor/save_success.tt2 b/root/src/autor/save_success.tt2 index 5e88d9b..3b849d2 100644 --- a/root/src/autor/save_success.tt2 +++ b/root/src/autor/save_success.tt2 @@ -10,7 +10,7 @@ -%]
-Der Autor "[% autor_edit.name %] wurde erfolgreich gespeichert. +Der Autor "[% autor_edit.titel %] [% autor_edit.vorname %] [% autor_edit.mittelname %] [% autor_edit.nachname %] [% autor_edit.name_suffix %] wurde erfolgreich gespeichert.

OK