$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'};
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;
}
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');
# 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;
$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'} ) );
$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'} ) );
__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
$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,
...
];
-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;
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;
}
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 = <<ENDE;
INSERT INTO `autoren` (
- `id`, `autor_name`, `autor_descr` )
+ `id`, `titel`, `vorname`, `mittelname`, `nachname`, `name_suffix`, `autor_descr` )
VALUES (
- ?, ?, ? )
+ ?, ?, ?, ?, ?, ?, ? )
ON DUPLICATE KEY UPDATE
- `id` = LAST_INSERT_ID(`id`), `autor_name` = ?, `autor_descr` = ?
+ `id` = LAST_INSERT_ID(`id`),
+ `titel` = ?,
+ `vorname` = ?,
+ `mittelname` = ?,
+ `nachname` = ?,
+ `name_suffix` = ?,
+ `autor_descr` = ?
ENDE
+ my @P = ();
+ push @P, $autor_id;
+ push @P, $titel;
+ push @P, $vorname;
+ push @P, $mittelname;
+ push @P, $nachname;
+ push @P, $suffix;
+ push @P, $desc;
+ push @P, $titel;
+ push @P, $vorname;
+ push @P, $mittelname;
+ push @P, $nachname;
+ push @P, $suffix;
+ push @P, $desc;
+
if ( $storage->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();
$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];
</tr><tr>
<td colspan="2"> </td>
</tr><tr>
- <th>Name des Autors:</th>
- <td><input type="text" name="autor_name" size="50" maxlength="250" value="[% autor_edit.name | html %]" /></td>
+ <th>Titel des Autors (Dr. o.ä.):</th>
+ <td><input type="text" name="autor_titel" size="50" maxlength="100" value="[% autor_edit.titel | html %]" /></td>
+ </tr><tr>
+ <th>Vorname des Autors:</th>
+ <td><input type="text" name="autor_vorname" size="50" maxlength="150" value="[% autor_edit.vorname | html %]" /></td>
+ </tr><tr>
+ <th>Zweiter Vorname des Autors (oder Vatersname o.ä.):</th>
+ <td><input type="text" name="autor_mittelname" size="50" maxlength="150" value="[% autor_edit.mittelname | html %]" /></td>
+ </tr><tr>
+ <th>Nachname des Autors:</th>
+ <td><input type="text" name="autor_nachname" size="50" maxlength="150" value="[% autor_edit.nachname | html %]" /></td>
+ </tr><tr>
+ <th>Namenssuffix (Jr. o.ä.):</th>
+ <td><input type="text" name="autor_name_suffix" size="50" maxlength="100" value="[% autor_edit.name_suffix | html %]" /></td>
</tr><tr>
<th>Zusätzliche Angaben:</th>
<td><textarea name="autor_desc" cols="50" rows="5">[% autor_edit.desc | html %]</textarea></td>
-%]
<div style="text-align: center">
-Der Autor <b>"[% autor_edit.name %]</b> wurde erfolgreich gespeichert.
+Der Autor <b>"[% autor_edit.titel %] [% autor_edit.vorname %] [% autor_edit.mittelname %] [% autor_edit.nachname %] [% autor_edit.name_suffix %]</b> wurde erfolgreich gespeichert.
<h2><a href="[% return_target_autor_save %]">OK</a></h2>