[Koha-patches] [PATCH] wr76595 (bug 4157): Control barcode display with a borrower attribute

Srdjan Jankovic srdjan at catalyst.net.nz
Thu Mar 31 07:07:54 CEST 2011


---
 C4/Members/AttributeTypes.pm                       |   18 ++++++++++++++-
 C4/Members/Attributes.pm                           |   24 +++++++++++++++++++-
 installer/data/mysql/en/mandatory/auth_values.sql  |    2 +
 installer/data/mysql/en/mandatory/auth_values.txt  |    1 +
 .../data/mysql/en/optional/patron_atributes.sql    |    2 +
 .../data/mysql/en/optional/patron_atributes.txt    |    2 +
 installer/data/mysql/updatedatabase.pl             |   10 ++++++++
 koha-tmpl/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 21d17eb..3a05268 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 1db9424..24c6f71 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 0000000..d7fb280
--- /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 0000000..effc454
--- /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 0000000..17d7b8a
--- /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 0000000..50d91d1
--- /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 f2d6776..955b55f 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4166,6 +4166,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 5513f13..08a33da 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({
 		<!-- TMPL_IF NAME="JacketImages" --><th>&nbsp;</th><!-- /TMPL_IF -->
         <th>Title</th>
 		<!-- TMPL_UNLESS NAME="item_level_itypes" --><th>Item Type</th> <!-- /TMPL_UNLESS -->
-        <th>Barcode</th>
+        <!-- TMPL_IF NAME="show_barcode" --><th>Barcode</th><!-- /TMPL_IF -->
         <th>Call No.</th>
         <th>Due</th>
         <!-- TMPL_IF name="OpacRenewalAllowed" -->
@@ -242,7 +242,7 @@ $.tablesorter.addParser({
                         <!-- TMPL_VAR NAME="author" -->
                     </span></td>
                 <!-- TMPL_UNLESS NAME="item_level_itypes" --><td><!-- TMPL_IF NAME="imageurl" --><img src="<!-- TMPL_VAR NAME="imageurl" -->" title="<!-- TMPL_VAR name="description" -->" alt="<!-- TMPL_VAR NAME="description" -->" /><!-- /TMPL_IF --> <!-- TMPL_VAR name="description" --></td><!-- /TMPL_UNLESS -->
-                <td><!-- TMPL_VAR NAME="barcode" --></td>
+                <!-- TMPL_IF NAME="show_barcode" --><td><!-- TMPL_VAR NAME="barcode" --></td><!-- /TMPL_IF -->
                 <td><!-- TMPL_VAR NAME="itemcallnumber" --></td>
                 <!-- TMPL_IF NAME="overdue" -->
                     <td class="overdue"><!-- TMPL_VAR NAME="date_due" --></td>
@@ -294,7 +294,7 @@ $.tablesorter.addParser({
 <!-- TMPL_IF NAME="JacketImages" --><th>&nbsp;</th><!-- /TMPL_IF -->
 <th>Title</th>
 <!-- TMPL_UNLESS NAME="item_level_itypes" --><th>Item Type</th> <!-- /TMPL_UNLESS -->
-<th>Barcode</th>
+<!-- TMPL_IF NAME="show_barcode" --><th>Barcode</th><!-- /TMPL_IF -->
 <th>Call No.</th>
 <th>Due</th>
 <!-- TMPL_IF name="OpacRenewalAllowed" -->
@@ -326,7 +326,7 @@ $.tablesorter.addParser({
 <td><a href="/cgi-bin/koha/opac-detail.pl?bib=<!-- TMPL_VAR NAME="biblionumber" -->"><!-- TMPL_VAR NAME="title" escape="html" --></a> <span class="item-details"><!-- TMPL_VAR NAME="author" --></span></td>
 
 <!-- TMPL_UNLESS NAME="item_level_itypes" --><td><!-- TMPL_IF NAME="imageurl" --><img src="<!-- TMPL_VAR NAME="imageurl" -->" title="<!-- TMPL_VAR name="description" -->" alt="<!-- TMPL_VAR NAME="description" -->" /><!-- /TMPL_IF --> <!-- TMPL_VAR name="description" --></td><!-- /TMPL_UNLESS -->
-<td><!-- TMPL_VAR NAME="barcode" --></td>
+<!-- TMPL_IF NAME="show_barcode" --><td><!-- TMPL_VAR NAME="barcode" --></td><!-- /TMPL_IF -->
 <td><!-- TMPL_VAR NAME="itemcallnumber" --></td>
 <td><!-- TMPL_VAR NAME="date_due" --></td>
                 <!-- TMPL_IF name="OpacRenewalAllowed" -->
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index 23de179..c16eaaf 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;
-- 
1.6.5



More information about the Koha-patches mailing list