[Bug 19442] New: add patron attributes into the patron card creator
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 Bug ID: 19442 Summary: add patron attributes into the patron card creator Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Tools Assignee: koha-bugs@lists.koha-community.org Reporter: nick@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org Work to be done: 1 - Add the ability to define fields as attribute.CODE in the card creator template 2 - When these codes are found replace them with the correct value for the patron -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 Marc Véron <veron@veron.ch> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |veron@veron.ch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|Tools |Label/patron card printing Summary|add patron attributes into |Add patron attributes into |the patron card creator |the patron card creator Assignee|koha-bugs@lists.koha-commun |cnighswonger@foundations.ed |ity.org |u CC| |katrin.fischer@bsz-bw.de -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |caroline.cyr-la-rose@inlibr | |o.com --- Comment #1 from Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com> --- +1 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 Rudy Hinojosa <rudy.hinojosa@lifeafter.solutions> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rudy.hinojosa@lifeafter.sol | |utions --- Comment #2 from Rudy Hinojosa <rudy.hinojosa@lifeafter.solutions> --- This already works on version 26.05.02, if you replace the entire routine of get_borrower_attributes() codeblock in /usr/share/koha/lib/C4/patroncard/Lib.pm with the following get_borrower_attributes() below: sub get_borrower_attributes { my ( $borrower_number, @fields ) = @_; my $get_branch = 0; $get_branch = 1 if grep { $_ eq 'branchcode' } @fields; # Get normal borrower table fields my $dbh = C4::Context->dbh; my @borrower_fields = (); my @attribute_fields = (); # Get the actual columns in borrowers my $sth_columns = $dbh->prepare("SHOW COLUMNS FROM borrowers"); $sth_columns->execute(); my %borrower_columns; while ( my $row = $sth_columns->fetchrow_hashref ) { $borrower_columns{ $row->{'Field'} } = 1; } # Separate normal borrower fields from patron attributes foreach my $field (@fields) { if ( $borrower_columns{$field} ) { push @borrower_fields, $field; } else { push @attribute_fields, $field; } } my $borrower_attributes = {}; # Get normal borrower fields if (@borrower_fields) { my $query = "SELECT " . join( ', ', @borrower_fields ) . " FROM borrowers WHERE borrowernumber = ?"; my $sth = $dbh->prepare($query); $sth->execute($borrower_number); if ( $sth->err ) { warn sprintf( 'Database returned the following error: %s', $sth->errstr ); return 1; } $borrower_attributes = $sth->fetchrow_hashref() || {}; } # Get patron attributes such as SID if (@attribute_fields) { my $placeholders = join( ',', ('?') x @attribute_fields ); my $query = " SELECT code, attribute FROM borrower_attributes WHERE borrowernumber = ? AND code IN ($placeholders) "; my $sth = $dbh->prepare($query); $sth->execute( $borrower_number, @attribute_fields ); while ( my $row = $sth->fetchrow_hashref ) { $borrower_attributes->{ $row->{'code'} } = $row->{'attribute'}; } } # Convert branchcode to branch name as before if ($get_branch) { $sth_columns = $dbh->prepare( "SELECT branchname FROM branches WHERE branchcode = ?" ); $sth_columns->execute( $borrower_attributes->{'branchcode'} ); if ( $sth_columns->err ) { warn sprintf( 'Database returned the following error: %s', $sth_columns->errstr ); return 1; } my $branch = $sth_columns->fetchrow_hashref(); $borrower_attributes->{'branchcode'} = $branch->{'branchname'} if $branch; } return $borrower_attributes; } -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 --- Comment #3 from Rudy Hinojosa <rudy.hinojosa@lifeafter.solutions> --- (In reply to Rudy Hinojosa from comment #2)
This already works on version 26.05.02, if you replace the entire routine of get_borrower_attributes() codeblock in /usr/share/koha/lib/C4/patroncard/Lib.pm with the following get_borrower_attributes() below:
sub get_borrower_attributes { my ( $borrower_number, @fields ) = @_;
my $get_branch = 0; $get_branch = 1 if grep { $_ eq 'branchcode' } @fields;
# Get normal borrower table fields my $dbh = C4::Context->dbh;
my @borrower_fields = (); my @attribute_fields = ();
# Get the actual columns in borrowers my $sth_columns = $dbh->prepare("SHOW COLUMNS FROM borrowers"); $sth_columns->execute();
my %borrower_columns; while ( my $row = $sth_columns->fetchrow_hashref ) { $borrower_columns{ $row->{'Field'} } = 1; }
# Separate normal borrower fields from patron attributes foreach my $field (@fields) { if ( $borrower_columns{$field} ) { push @borrower_fields, $field; } else { push @attribute_fields, $field; } }
my $borrower_attributes = {};
# Get normal borrower fields if (@borrower_fields) { my $query = "SELECT " . join( ', ', @borrower_fields ) . " FROM borrowers WHERE borrowernumber = ?";
my $sth = $dbh->prepare($query); $sth->execute($borrower_number);
if ( $sth->err ) { warn sprintf( 'Database returned the following error: %s', $sth->errstr ); return 1; }
$borrower_attributes = $sth->fetchrow_hashref() || {}; }
# Get patron attributes such as SID if (@attribute_fields) { my $placeholders = join( ',', ('?') x @attribute_fields );
my $query = " SELECT code, attribute FROM borrower_attributes WHERE borrowernumber = ? AND code IN ($placeholders) ";
my $sth = $dbh->prepare($query); $sth->execute( $borrower_number, @attribute_fields );
while ( my $row = $sth->fetchrow_hashref ) { $borrower_attributes->{ $row->{'code'} } = $row->{'attribute'}; } }
# Convert branchcode to branch name as before if ($get_branch) { $sth_columns = $dbh->prepare( "SELECT branchname FROM branches WHERE branchcode = ?" ); $sth_columns->execute( $borrower_attributes->{'branchcode'} );
if ( $sth_columns->err ) { warn sprintf( 'Database returned the following error: %s', $sth_columns->errstr ); return 1; }
my $branch = $sth_columns->fetchrow_hashref(); $borrower_attributes->{'branchcode'} = $branch->{'branchname'} if $branch; }
return $borrower_attributes; }
and you simply just use your patron attribute in the tag for example <SID> if SID is your attribute. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 --- Comment #4 from Rudy Hinojosa <rudy.hinojosa@lifeafter.solutions> --- Created attachment 203957 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=203957&action=edit screenshot of attribute screenshot of attribute -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 --- Comment #5 from Rudy Hinojosa <rudy.hinojosa@lifeafter.solutions> --- Created attachment 203958 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=203958&action=edit how to specify the field for the attribute how to specify the field for the attribute -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442 --- Comment #6 from Rudy Hinojosa <rudy.hinojosa@lifeafter.solutions> --- Created attachment 203959 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=203959&action=edit output of patron attribute values in output output of patron attribute values in output -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org