[Koha-patches] [PATCH] Extending IndependantBranches to not show copies at other branches
Michael Hafen
mdhafen at washk12.org
Tue May 27 20:24:31 CEST 2008
---
C4/Circulation.pm | 20 +++++++++++++++++---
C4/Search.pm | 20 ++++++++++++++++++++
catalogue/MARCdetail.pl | 10 +++++++++-
catalogue/detail.pl | 4 ++++
catalogue/moredetail.pl | 16 ++++++++++++++++
catalogue/search.pl | 2 +-
cataloguing/additem.pl | 4 +++-
opac/opac-MARCdetail.pl | 10 +++++++++-
opac/opac-detail.pl | 9 +++++++++
9 files changed, 88 insertions(+), 7 deletions(-)
mode change 100755 => 100644 C4/Search.pm
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 5ae067c..bcae2ba 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -1689,7 +1689,9 @@ tables issues and the firstname,surname & cardnumber from borrowers.
sub GetBiblioIssues {
my $biblionumber = shift;
return undef unless $biblionumber;
+ my $bfield = C4::Context->preference('HomeOrHoldingBranch') eq 'holdingbranch' ? 'items.homebranch' : 'items.holdingbranch';
my $dbh = C4::Context->dbh;
+ my @bind;
my $query = "
SELECT issues.*,items.barcode,biblio.biblionumber,biblio.title, biblio.author,borrowers.cardnumber,borrowers.surname,borrowers.firstname
FROM issues
@@ -1697,7 +1699,13 @@ sub GetBiblioIssues {
LEFT JOIN items ON issues.itemnumber = items.itemnumber
LEFT JOIN biblioitems ON items.itemnumber = biblioitems.biblioitemnumber
LEFT JOIN biblio ON biblio.biblionumber = items.biblioitemnumber
- WHERE biblio.biblionumber = ?
+ WHERE biblio.biblionumber = ?";
+ push @bind, $biblionumber;
+ if ( C4::Context->preference("IndependantBranches") ) {
+ $query .= " AND $bfield = ?";
+ push @bind, C4::Context->userenv->{branch};
+ }
+ $query .= "
UNION ALL
SELECT old_issues.*,items.barcode,biblio.biblionumber,biblio.title, biblio.author,borrowers.cardnumber,borrowers.surname,borrowers.firstname
FROM old_issues
@@ -1705,11 +1713,17 @@ sub GetBiblioIssues {
LEFT JOIN items ON old_issues.itemnumber = items.itemnumber
LEFT JOIN biblioitems ON items.itemnumber = biblioitems.biblioitemnumber
LEFT JOIN biblio ON biblio.biblionumber = items.biblioitemnumber
- WHERE biblio.biblionumber = ?
+ WHERE biblio.biblionumber = ?";
+ push @bind, $biblionumber;
+ if ( C4::Context->preference("IndependantBranches") ) {
+ $query .= " AND $bfield = ?";
+ push @bind, C4::Context->userenv->{branch};
+ }
+ $query .= "
ORDER BY timestamp
";
my $sth = $dbh->prepare($query);
- $sth->execute($biblionumber, $biblionumber);
+ $sth->execute( @bind );
my @issues;
while ( my $data = $sth->fetchrow_hashref ) {
diff --git a/C4/Search.pm b/C4/Search.pm
old mode 100755
new mode 100644
index 853ab20..031c929
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1376,6 +1376,14 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
$item->{'branchname'} = $branches{$item->{$otherbranch}};
}
+ # IndependantBranches, etc... dont show copies at other branches
+ if ( C4::Context->preference('IndependantBranches') && C4::Context->userenv && $item->{$hbranch} ne C4::Context->userenv->{branch} ) {
+ $items_count--;
+ $items_counter--;
+ delete $fields[ $items_counter ];
+ next;
+ }
+
my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
if ( $item->{onloan} ) {
@@ -1438,6 +1446,18 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
}
}
} # notforloan, item level and biblioitem level
+ # There may be empty spots in the items array
+ # because of IndependantBranches pruning done above
+ # remove these blank spots here
+ if ( C4::Context->preference('IndependantBranches') ) {
+ for ( my $c = 0; $c < scalar( @fields ); $c++ ) {
+ unless ( exists $fields[ $c ] ) {
+ splice @fields, $c, 1;
+ $c--;
+ }
+ }
+ }
+
my ( $availableitemscount, $onloanitemscount, $otheritemscount );
$maxitems =
( C4::Context->preference('maxItemsinSearchResults') )
diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl
index 40437e6..2c5d7ee 100755
--- a/catalogue/MARCdetail.pl
+++ b/catalogue/MARCdetail.pl
@@ -246,11 +246,14 @@ for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
my @fields = $record->fields();
my %witness
; #---- stores the list of subfields used at least once, with the "meaning" of the code
+my $bfield = C4::Context->preference('HomeOrHoldingBranch') eq 'holdingbranch' ? 'items.homebranch' : 'items.holdingbranch';
+my ($homebrtagf,$homebrtagsubf) = &GetMarcFromKohaField($bfield,$frameworkcode);
my @big_array;
foreach my $field (@fields) {
next if ( $field->tag() < 10 );
my @subf = $field->subfields;
my %this_row;
+ my $homebranch;
# loop through each subfield
for my $i ( 0 .. $#subf ) {
@@ -260,9 +263,14 @@ foreach my $field (@fields) {
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
$this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(),
$subf[$i][0], $subf[$i][1], '', $tagslib);
+ if ( $subf[$i][0] eq $homebrtagsubf ) {
+ $homebranch = $subf[$i][1];
+ }
}
if (%this_row) {
- push( @big_array, \%this_row );
+ unless ( C4::Context->preference("IndependantBranches") && $homebranch ne C4::Context->userenv->{branch} ) {
+ push( @big_array, \%this_row );
+ }
}
}
my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index 782a10d..a3f85cf 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -98,6 +98,10 @@ $dat->{'count'} = @items;
my @itemloop;
my $norequests = 1;
foreach my $item (@items) {
+ my $bfield = C4::Context->preference('HomeOrHoldingBranch') eq 'holdingbranch' ? 'homebranch' : 'holdingbranch';
+ if ( C4::Context->preference("IndependantBranches") && $item->{$bfield} ne C4::Context->userenv->{branch} ) {
+ next;
+ }
# can place holds defaults to yes
$norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl
index 4736ded..95f8b1c 100755
--- a/catalogue/moredetail.pl
+++ b/catalogue/moredetail.pl
@@ -81,9 +81,14 @@ my $order = GetOrder($ordernum);
my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
my $itemtypes = GetItemTypes;
+my $bfield = C4::Context->preference('HomeOrHoldingBranch') eq 'holdingbranch' ? 'homebranch' : 'holdingbranch';
$data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
$results[0]=$data;
foreach my $item (@items){
+ if ( C4::Context->preference("IndependantBranches") && $item->{$bfield} ne C4::Context->userenv->{branch} ) {
+ undef $item;
+ next;
+ }
$item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
$item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
$item->{'collection'} = $ccodes->{$item->{ccode}};
@@ -111,6 +116,17 @@ foreach my $item (@items){
$item->{'issue'}= 1;
}
}
+# There may be empty spots in the items array
+# because of IndependantBranches pruning done above
+# remove these blank spots here
+if ( C4::Context->preference("IndependantBranches") ) {
+ for ( my $c = 0; $c < scalar( @items ); $c++ ) {
+ unless ( $items[ $c ] ) {
+ splice @items, $c, 1;
+ $c--;
+ }
+ }
+}
$template->param(count => $data->{'count'},
subscriptionsnumber => $subscriptionsnumber,
subscriptiontitle => $data->{title},
diff --git a/catalogue/search.pl b/catalogue/search.pl
index 01dd3fb..6c37db7 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -205,7 +205,7 @@ if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
#}
# load the branches
-my $branches = GetBranches();
+my $branches = GetBranches( C4::Context->preference('IndependantBranches') );
my @branch_loop;
for my $branch_hash (sort keys %$branches) {
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index a9ef65e..1eeccb7 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -229,7 +229,9 @@ foreach my $field (@fields) {
$this_row{itemnumber} = $subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield);
}
if (%this_row) {
- push(@big_array, \%this_row);
+ unless ( C4::Context->preference("IndependantBranches") && $this_row{'nomod'} ) {
+ push(@big_array, \%this_row);
+ }
}
}
#fill big_row with missing data
diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl
index 8359760..4a87848 100755
--- a/opac/opac-MARCdetail.pl
+++ b/opac/opac-MARCdetail.pl
@@ -209,11 +209,14 @@ for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
my @fields = $record->fields();
my %witness
; #---- stores the list of subfields used at least once, with the "meaning" of the code
+my $bfield = C4::Context->preference('HomeOrHoldingBranch') eq 'holdingbranch' ? 'items.homebranch' : 'items.holdingbranch';
+my ($homebrtagf,$homebrtagsubf) = &GetMarcFromKohaField($bfield,$itemtype);
my @big_array;
foreach my $field (@fields) {
next if ( $field->tag() < 10 );
my @subf = $field->subfields;
my %this_row;
+ my $homebranch;
# loop through each subfield
for my $i ( 0 .. $#subf ) {
@@ -234,9 +237,14 @@ foreach my $field (@fields) {
GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
$subf[$i][1], '', $tagslib );
}
+ if ( $subf[$i][0] eq $homebrtagsubf ) {
+ $homebranch = $subf[$i][1];
+ }
}
if (%this_row) {
- push( @big_array, \%this_row );
+ unless ( C4::Context->preference("IndependantBranches") && C4::Context->userenv && $homebranch ne C4::Context->userenv->{branch} ) {
+ push( @big_array, \%this_row );
+ }
}
}
my ( $holdingbrtagf, $holdingbrtagsubf ) =
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index 2a28ca5..bc45a68 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -74,6 +74,15 @@ if (C4::Context->preference('hidelostitems')) {
push @items, $itm unless $itm->{itemlost};
}
}
+if ( C4::Context->preference("IndependantBranches") ) {
+ @all_items = ();
+ my $bfield = C4::Context->preference('HomeOrHoldingBranch') eq 'holdingbranch' ? 'homebranch' : 'holdingbranch';
+ for my $item ( @items ) {
+ push @all_items, $item unless (C4::Context->userenv && $item->{$bfield} ne C4::Context->userenv->{branch});
+ }
+ @items = @all_items;
+}
+
my $dat = &GetBiblioData($biblionumber);
if (!$dat) {
--
1.5.4.3
More information about the Koha-patches
mailing list