+my $branches = GetBranches();
+my $branch = '';
+if (C4::Context->userenv){
+ $branch = C4::Context->userenv->{branch};
+}
+if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
+ if (
+ ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
+ ||
+ C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
+ ) {
+ my $branchname;
+ if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
+ $branchname = $branches->{$branch}->{'branchname'};
+ }
+ elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
+ $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
+ }
+
+ my @our_items;
+ my @other_items;
+
+ foreach my $item ( @items ) {
+ if ( $item->{'branchname'} eq $branchname ) {
+ $item->{'this_branch'} = 1;
+ push( @our_items, $item );
+ } else {
+ push( @other_items, $item );
+ }
+ }
+
+ @items = ( @our_items, @other_items );
+ }
+}
+