From 5bcb1529bc3354c9694cae1a5746db534542ec60 Mon Sep 17 00:00:00 2001 From: Srdjan Jankovic Date: Mon, 4 Apr 2011 14:25:27 +0200 Subject: [PATCH] wr76595 (bug 4157): Control barcode display with a borrower attribute Signed-off-by: Matthias Meusburger Signed-off-by: Chris Cormack --- C4/Members/AttributeTypes.pm | 18 +++++++++++++- C4/Members/Attributes.pm | 24 ++++++++++++++++++- .../data/mysql/en/mandatory/auth_values.sql | 2 ++ .../data/mysql/en/mandatory/auth_values.txt | 1 + .../mysql/en/optional/patron_atributes.sql | 2 ++ .../mysql/en/optional/patron_atributes.txt | 2 ++ installer/data/mysql/updatedatabase.pl | 10 ++++++++ .../opac-tmpl/prog/en/modules/opac-user.tmpl | 8 +++---- opac/opac-user.pl | 11 +++++++++ 9 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 installer/data/mysql/en/mandatory/auth_values.sql create mode 100644 installer/data/mysql/en/mandatory/auth_values.txt create mode 100644 installer/data/mysql/en/optional/patron_atributes.sql create mode 100644 installer/data/mysql/en/optional/patron_atributes.txt diff --git a/C4/Members/AttributeTypes.pm b/C4/Members/AttributeTypes.pm index 21d17eb9bf..3a05268c35 100644 --- a/C4/Members/AttributeTypes.pm +++ b/C4/Members/AttributeTypes.pm @@ -69,7 +69,7 @@ If $all_fields is true, then each hashref also contains the other fields from bo =cut sub GetAttributeTypes { - my $all = @_ ? shift : 0; + my ($all) = @_; my $select = $all ? '*' : 'code, description'; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT $select FROM borrower_attribute_types ORDER by code"); @@ -83,6 +83,22 @@ sub GetAttributeTypes_hashref { return \%hash; } +=head2 AttributeTypeExists + + my $have_attr_xyz = C4::Members::AttributeTypes::AttributeTypeExists($code) + +Returns true if we have attribute type C<$code> +in the database. + +=cut + +sub AttributeTypeExists { + my ($code) = @_; + my $dbh = C4::Context->dbh; + my $exists = $dbh->selectrow_array("SELECT code FROM borrower_attribute_types WHERE code = ?", undef, $code); + return $exists; +} + =head1 METHODS my $attr_type = C4::Members::AttributeTypes->new($code, $description); diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index 1db94247c0..24c6f71a5d 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -31,7 +31,7 @@ BEGIN { # set the version for version checking $VERSION = 3.01; @ISA = qw(Exporter); - @EXPORT_OK = qw(GetBorrowerAttributes CheckUniqueness SetBorrowerAttributes + @EXPORT_OK = qw(GetBorrowerAttributes GetBorrowerAttributeValue CheckUniqueness SetBorrowerAttributes extended_attributes_code_value_arrayref extended_attributes_merge SearchIdMatchingAttribute); %EXPORT_TAGS = ( all => \@EXPORT_OK ); @@ -94,6 +94,28 @@ sub GetBorrowerAttributes { return \@results; } +=head2 GetBorrowerAttributeValue + + my $value = C4::Members::Attributes::GetBorrowerAttributeValue($borrowernumber, $attribute_code); + +Retrieve the value of an extended attribute C<$attribute_code> associated with the +patron specified by C<$borrowernumber>. + +=cut + +sub GetBorrowerAttributeValue { + my $borrowernumber = shift; + my $code = shift; + + my $dbh = C4::Context->dbh(); + my $query = "SELECT attribute + FROM borrower_attributes + WHERE borrowernumber = ? + AND code = ?"; + my $value = $dbh->selectrow_array($query, undef, $borrowernumber, $code); + return $value; +} + =head2 SearchIdMatchingAttribute my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter); diff --git a/installer/data/mysql/en/mandatory/auth_values.sql b/installer/data/mysql/en/mandatory/auth_values.sql new file mode 100644 index 0000000000..d7fb280625 --- /dev/null +++ b/installer/data/mysql/en/mandatory/auth_values.sql @@ -0,0 +1,2 @@ +INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES ('YES_NO','0','No','No'); +INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES ('YES_NO','1','Yes','Yes'); diff --git a/installer/data/mysql/en/mandatory/auth_values.txt b/installer/data/mysql/en/mandatory/auth_values.txt new file mode 100644 index 0000000000..effc4542f0 --- /dev/null +++ b/installer/data/mysql/en/mandatory/auth_values.txt @@ -0,0 +1 @@ +Default Koha system authorised values diff --git a/installer/data/mysql/en/optional/patron_atributes.sql b/installer/data/mysql/en/optional/patron_atributes.sql new file mode 100644 index 0000000000..17d7b8a8ba --- /dev/null +++ b/installer/data/mysql/en/optional/patron_atributes.sql @@ -0,0 +1,2 @@ +INSERT INTO `borrower_attribute_types` (`code`, `description`, `repeatable`, `unique_id`, `opac_display`, `password_allowed`, `staff_searchable`, `authorised_value_category`) +VALUES ('SHOW_BCODE', 'Show barcode on the summary screen items listings', 0, 0, 1, 0, 0, 'YES_NO'); diff --git a/installer/data/mysql/en/optional/patron_atributes.txt b/installer/data/mysql/en/optional/patron_atributes.txt new file mode 100644 index 0000000000..50d91d16be --- /dev/null +++ b/installer/data/mysql/en/optional/patron_atributes.txt @@ -0,0 +1,2 @@ +Useful patron atribute types: +* SHOW_BCODE - Show barcode on the patron summary screen items listings diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a39886c42f..e12abb5ad6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4217,6 +4217,16 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.03.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + + $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES ('YES_NO','0','No','No')"); + $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES ('YES_NO','1','Yes','Yes')"); + + print "Upgrade to $DBversion done ( add generic boolean YES_NO authorised_values pair )\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl index 5513f13dee..08a33dab50 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl @@ -201,7 +201,7 @@ $.tablesorter.addParser({   Title Item Type - Barcode + Barcode Call No. Due @@ -242,7 +242,7 @@ $.tablesorter.addParser({ " title="" alt="" /> - + @@ -294,7 +294,7 @@ $.tablesorter.addParser({   Title Item Type -Barcode +Barcode Call No. Due @@ -326,7 +326,7 @@ $.tablesorter.addParser({ "> " title="" alt="" /> - + diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 23de179a46..c16eaaf177 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -27,6 +27,8 @@ use C4::Koha; use C4::Circulation; use C4::Reserves; use C4::Members; +use C4::Members::AttributeTypes; +use C4::Members::Attributes qw/GetBorrowerAttributeValue/; use C4::Output; use C4::Biblio; use C4::Items; @@ -34,6 +36,8 @@ use C4::Dates qw/format_date/; use C4::Letters; use C4::Branch; # GetBranches +use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE'; + my $query = new CGI; BEGIN { @@ -167,6 +171,13 @@ $template->param( issues_count => $count ); $template->param( OVERDUES => \@overdues ); $template->param( overdues_count => $overdues_count ); +my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE ); +if ($show_barcode) { + my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE); + undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode; +} +$template->param( show_barcode => 1 ) if $show_barcode; + # load the branches my $branches = GetBranches(); my @branch_loop; -- 2.39.5