View | Details | Raw Unified | Return to bug 14385
Collapse All | Expand All

(-)a/C4/Biblio.pm (-7 / +40 lines)
Lines 1090-1096 sub GetMarcSubfieldStructureFromKohaField { Link Here
1090
  my $record = GetMarcBiblio({
1090
  my $record = GetMarcBiblio({
1091
      biblionumber => $biblionumber,
1091
      biblionumber => $biblionumber,
1092
      embed_items  => $embeditems,
1092
      embed_items  => $embeditems,
1093
      opac         => $opac });
1093
      opac         => $opac,
1094
      borcat       => $patron_category });
1094
1095
1095
Returns MARC::Record representing a biblio record, or C<undef> if the
1096
Returns MARC::Record representing a biblio record, or C<undef> if the
1096
biblionumber doesn't exist.
1097
biblionumber doesn't exist.
Lines 1114-1119 set to true to include item information. Link Here
1114
set to true to make the result suited for OPAC view. This causes things like
1115
set to true to make the result suited for OPAC view. This causes things like
1115
OpacHiddenItems to be applied.
1116
OpacHiddenItems to be applied.
1116
1117
1118
=item C<$borcat>
1119
1120
If the OpacHiddenItemsExceptions system preference is set, this patron category
1121
can be used to make visible OPAC items which would be normally hidden.
1122
It only makes sense in combination both embed_items and opac values true.
1123
1117
=back
1124
=back
1118
1125
1119
=cut
1126
=cut
Lines 1129-1134 sub GetMarcBiblio { Link Here
1129
    my $biblionumber = $params->{biblionumber};
1136
    my $biblionumber = $params->{biblionumber};
1130
    my $embeditems   = $params->{embed_items} || 0;
1137
    my $embeditems   = $params->{embed_items} || 0;
1131
    my $opac         = $params->{opac} || 0;
1138
    my $opac         = $params->{opac} || 0;
1139
    my $borcat       = $params->{borcat} // q{};
1132
1140
1133
    if (not defined $biblionumber) {
1141
    if (not defined $biblionumber) {
1134
        carp 'GetMarcBiblio called with undefined biblionumber';
1142
        carp 'GetMarcBiblio called with undefined biblionumber';
Lines 1156-1162 sub GetMarcBiblio { Link Here
1156
1164
1157
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1165
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1158
            $biblioitemnumber );
1166
            $biblioitemnumber );
1159
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1167
        C4::Biblio::EmbedItemsInMarcBiblio({
1168
            marc_record  => $record,
1169
            biblionumber => $biblionumber,
1170
            opac         => $opac,
1171
            borcat       => $borcat })
1160
          if ($embeditems);
1172
          if ($embeditems);
1161
1173
1162
        return $record;
1174
        return $record;
Lines 2729-2735 sub ModZebra { Link Here
2729
2741
2730
=head2 EmbedItemsInMarcBiblio
2742
=head2 EmbedItemsInMarcBiblio
2731
2743
2732
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2744
    EmbedItemsInMarcBiblio({
2745
        marc_record  => $marc,
2746
        biblionumber => $biblionumber,
2747
        item_numbers => $itemnumbers,
2748
        opac         => $opac });
2733
2749
2734
Given a MARC::Record object containing a bib record,
2750
Given a MARC::Record object containing a bib record,
2735
modify it to include the items attached to it as 9XX
2751
modify it to include the items attached to it as 9XX
Lines 2738-2751 if $itemnumbers is defined, only specified itemnumbers are embedded. Link Here
2738
2754
2739
If $opac is true, then opac-relevant suppressions are included.
2755
If $opac is true, then opac-relevant suppressions are included.
2740
2756
2757
If opac filtering will be done, borcat should be passed to properly
2758
override if necessary.
2759
2741
=cut
2760
=cut
2742
2761
2743
sub EmbedItemsInMarcBiblio {
2762
sub EmbedItemsInMarcBiblio {
2744
    my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
2763
    my ($params) = @_;
2764
    my ($marc, $biblionumber, $itemnumbers, $opac, $borcat);
2765
    $marc = $params->{marc_record};
2745
    if ( !$marc ) {
2766
    if ( !$marc ) {
2746
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2767
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2747
        return;
2768
        return;
2748
    }
2769
    }
2770
    $biblionumber = $params->{biblionumber};
2771
    $itemnumbers = $params->{item_numbers};
2772
    $opac = $params->{opac};
2773
    $borcat = $params->{borcat} // q{};
2749
2774
2750
    $itemnumbers = [] unless defined $itemnumbers;
2775
    $itemnumbers = [] unless defined $itemnumbers;
2751
2776
Lines 2756-2775 sub EmbedItemsInMarcBiblio { Link Here
2756
    my $dbh = C4::Context->dbh;
2781
    my $dbh = C4::Context->dbh;
2757
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2782
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2758
    $sth->execute($biblionumber);
2783
    $sth->execute($biblionumber);
2759
    my @item_fields;
2760
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2784
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2761
    my @items;
2785
2786
    my @item_fields; # Array holding the actual MARC data for items to be included.
2787
    my @items;       # Array holding items which are both in the list (sitenumbers)
2788
                     # and on this biblionumber
2789
2790
    # Flag indicating if there is potential hiding.
2762
    my $opachiddenitems = $opac
2791
    my $opachiddenitems = $opac
2763
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2792
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2793
2764
    require C4::Items;
2794
    require C4::Items;
2765
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2795
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2766
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2796
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2767
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2797
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2768
        push @items, { itemnumber => $itemnumber, item => $i };
2798
        push @items, { itemnumber => $itemnumber, item => $i };
2769
    }
2799
    }
2800
    my @items2pass = map { $_->{item} } @items;
2770
    my @hiddenitems =
2801
    my @hiddenitems =
2771
      $opachiddenitems
2802
      $opachiddenitems
2772
      ? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
2803
      ? C4::Items::GetHiddenItemnumbers({
2804
            items  => \@items2pass,
2805
            borcat => $borcat })
2773
      : ();
2806
      : ();
2774
    # Convert to a hash for quick searching
2807
    # Convert to a hash for quick searching
2775
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2808
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
(-)a/C4/Record.pm (-1 / +4 lines)
Lines 473-479 sub marcrecord2csv { Link Here
473
    # Getting the record
473
    # Getting the record
474
    my $record = GetMarcBiblio({ biblionumber => $biblio });
474
    my $record = GetMarcBiblio({ biblionumber => $biblio });
475
    return unless $record;
475
    return unless $record;
476
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblio, $itemnumbers );
476
    C4::Biblio::EmbedItemsInMarcBiblio({
477
        marc_record  => $record,
478
        biblionumber => $biblio,
479
        item_numbers => $itemnumbers });
477
    # Getting the framework
480
    # Getting the framework
478
    my $frameworkcode = GetFrameworkCode($biblio);
481
    my $frameworkcode = GetFrameworkCode($biblio);
479
482
(-)a/C4/Search.pm (-3 / +3 lines)
Lines 1900-1906 sub searchResults { Link Here
1900
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1900
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1901
1901
1902
    # set stuff for XSLT processing here once, not later again for every record we retrieved
1902
    # set stuff for XSLT processing here once, not later again for every record we retrieved
1903
    my $interface = $search_context eq 'opac' ? 'OPAC' : '';
1903
    my $interface = $is_opac ? 'OPAC' : '';
1904
    my $xslsyspref = $interface . "XSLTResultsDisplay";
1904
    my $xslsyspref = $interface . "XSLTResultsDisplay";
1905
    my $xslfile = C4::Context->preference($xslsyspref);
1905
    my $xslfile = C4::Context->preference($xslsyspref);
1906
    my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
1906
    my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
Lines 2202-2208 sub searchResults { Link Here
2202
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2202
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2203
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2203
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2204
					$other_items->{$key}->{description} = $item->{description};
2204
					$other_items->{$key}->{description} = $item->{description};
2205
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2205
                    $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2206
                }
2206
                }
2207
                # item is available
2207
                # item is available
2208
                else {
2208
                else {
Lines 2213-2219 sub searchResults { Link Here
2213
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2213
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2214
					}
2214
					}
2215
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2215
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2216
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2216
                    $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2217
                }
2217
                }
2218
            }
2218
            }
2219
        }    # notforloan, item level and biblioitem level
2219
        }    # notforloan, item level and biblioitem level
(-)a/Koha/BiblioUtils/Iterator.pm (-1 / +3 lines)
Lines 108-114 sub next { Link Here
108
          if ( !defined($bibnum) );
108
          if ( !defined($bibnum) );
109
109
110
        # TODO this should really be in Koha::BiblioUtils or something similar.
110
        # TODO this should really be in Koha::BiblioUtils or something similar.
111
        C4::Biblio::EmbedItemsInMarcBiblio( $marc, $bibnum );
111
        C4::Biblio::EmbedItemsInMarcBiblio({
112
            marc_record  => $marc,
113
            biblionumber => $bibnum });
112
    }
114
    }
113
115
114
    if (wantarray) {
116
    if (wantarray) {
(-)a/Koha/Exporter/Record.pm (-1 / +4 lines)
Lines 70-76 sub _get_biblio_for_export { Link Here
70
    return if $@ or not defined $record;
70
    return if $@ or not defined $record;
71
71
72
    if ($export_items) {
72
    if ($export_items) {
73
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, $itemnumbers );
73
        C4::Biblio::EmbedItemsInMarcBiblio({
74
            marc_record  => $record,
75
            biblionumber => $biblionumber,
76
            item_numbers => $itemnumbers });
74
        if ($only_export_items_for_branches && @$only_export_items_for_branches) {
77
        if ($only_export_items_for_branches && @$only_export_items_for_branches) {
75
            my %export_items_for_branches = map { $_ => 1 } @$only_export_items_for_branches;
78
            my %export_items_for_branches = map { $_ => 1 } @$only_export_items_for_branches;
76
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch', '' );    # Should be GetFrameworkCode( $biblionumber )?
79
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch', '' );    # Should be GetFrameworkCode( $biblionumber )?
(-)a/cataloguing/additem.pl (-1 / +3 lines)
Lines 734-740 my @big_array; Link Here
734
#---- finds where items.itemnumber is stored
734
#---- finds where items.itemnumber is stored
735
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
735
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
736
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
736
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
737
C4::Biblio::EmbedItemsInMarcBiblio($temp, $biblionumber);
737
C4::Biblio::EmbedItemsInMarcBiblio({
738
    marc_record  => $temp,
739
    biblionumber => $biblionumber });
738
my @fields = $temp->fields();
740
my @fields = $temp->fields();
739
741
740
742
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt (+2 lines)
Lines 126-131 Link Here
126
                                <thead><tr><th>&nbsp;</th><th>Term</th><th>Title</th><th>Date added</th></tr></thead>
126
                                <thead><tr><th>&nbsp;</th><th>Term</th><th>Title</th><th>Date added</th></tr></thead>
127
                                <tbody>
127
                                <tbody>
128
                                    [% FOREACH MY_TAG IN MY_TAGS %]
128
                                    [% FOREACH MY_TAG IN MY_TAGS %]
129
                                        [% IF MY_TAG.visible %]
129
                                        <tr>
130
                                        <tr>
130
                                            <td>
131
                                            <td>
131
                                                <input type="checkbox" name="del[% MY_TAG.tag_id %]" value="del[% MY_TAG.tag_id %]">
132
                                                <input type="checkbox" name="del[% MY_TAG.tag_id %]" value="del[% MY_TAG.tag_id %]">
Lines 163-168 Link Here
163
                                                </span>
164
                                                </span>
164
                                            </td>
165
                                            </td>
165
                                        </tr>
166
                                        </tr>
167
                                        [% END %]
166
                                    [% END %]
168
                                    [% END %]
167
                                </tbody>
169
                                </tbody>
168
                            </table>
170
                            </table>
(-)a/misc/migration_tools/build_oai_sets.pl (-1 / +3 lines)
Lines 127-133 foreach my $res (@$results) { Link Here
127
        next;
127
        next;
128
    }
128
    }
129
    if($embed_items) {
129
    if($embed_items) {
130
        C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber);
130
        C4::Biblio::EmbedItemsInMarcBiblio({
131
            marc_record  => $record,
132
            biblionumber => $biblionumber });
131
    }
133
    }
132
134
133
    my @biblio_sets = CalcOAISetsBiblio($record, $mappings);
135
    my @biblio_sets = CalcOAISetsBiblio($record, $mappings);
(-)a/opac/opac-ISBDdetail.pl (-33 / +35 lines)
Lines 60-65 use Koha::RecordProcessor; Link Here
60
use Koha::Biblios;
60
use Koha::Biblios;
61
61
62
my $query = CGI->new();
62
my $query = CGI->new();
63
my $biblionumber = $query->param('biblionumber');
64
if ( !$biblionumber ) {
65
    print $query->redirect('/cgi-bin/koha/errors/404.pl');
66
    exit;
67
}
68
$biblionumber = int($biblionumber);
69
70
#open template
63
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
71
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64
    {
72
    {
65
        template_name   => "opac-ISBDdetail.tt",
73
        template_name   => "opac-ISBDdetail.tt",
Lines 70-117 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
70
    }
78
    }
71
);
79
);
72
80
73
my $biblionumber = $query->param('biblionumber');
81
my $borcat = q{};
74
$biblionumber = int($biblionumber);
82
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
75
83
    # we need to fetch the borrower info here, so we can pass the category
76
# get biblionumbers stored in the cart
84
    my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
77
if(my $cart_list = $query->cookie("bib_list")){
85
    $borcat = $patron ? $patron->categorycode : $borcat;
78
    my @cart_list = split(/\//, $cart_list);
79
    if ( grep {$_ eq $biblionumber} @cart_list) {
80
        $template->param( incart => 1 );
81
    }
82
}
83
84
my $marcflavour      = C4::Context->preference("marcflavour");
85
86
my @items = GetItemsInfo($biblionumber);
87
if (scalar @items >= 1) {
88
    my $borcat;
89
    if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
90
91
        # we need to fetch the borrower info here, so we can pass the category
92
        my $borrower = GetMember( borrowernumber => $borrowernumber );
93
        $borcat = $borrower->{categorycode};
94
    }
95
96
    my @hiddenitems = GetHiddenItemnumbers( { items => \@items, borcat => $borcat });
97
98
    if (scalar @hiddenitems == scalar @items ) {
99
        print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
100
        exit;
101
    }
102
}
86
}
103
87
104
my $record = GetMarcBiblio({
88
my $record = GetMarcBiblio({
105
    biblionumber => $biblionumber,
89
    biblionumber => $biblionumber,
106
    embed_items  => 1 });
90
    embed_items  => 1,
91
    opac         => 1,
92
    borcat       => $borcat });
107
if ( ! $record ) {
93
if ( ! $record ) {
108
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
94
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
109
    exit;
95
    exit;
110
}
96
}
111
97
98
my @all_items = GetItemsInfo($biblionumber);
112
my $biblio = Koha::Biblios->find( $biblionumber );
99
my $biblio = Koha::Biblios->find( $biblionumber );
100
my $framework = $biblio ? $biblio->frameworkcode : q{};
101
my ($tag_itemnumber, $subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
102
my @nonhiddenitems = $record->field($tag_itemnumber);
103
if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) {
104
    print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early
105
    exit;
106
}
113
107
114
my $framework = GetFrameworkCode( $biblionumber );
115
my $record_processor = Koha::RecordProcessor->new({
108
my $record_processor = Koha::RecordProcessor->new({
116
    filters => 'ViewPolicy',
109
    filters => 'ViewPolicy',
117
    options => {
110
    options => {
Lines 121-126 my $record_processor = Koha::RecordProcessor->new({ Link Here
121
});
114
});
122
$record_processor->process($record);
115
$record_processor->process($record);
123
116
117
# get biblionumbers stored in the cart
118
if(my $cart_list = $query->cookie("bib_list")){
119
    my @cart_list = split(/\//, $cart_list);
120
    if ( grep {$_ eq $biblionumber} @cart_list) {
121
        $template->param( incart => 1 );
122
    }
123
}
124
125
my $marcflavour      = C4::Context->preference("marcflavour");
126
124
# some useful variables for enhanced content;
127
# some useful variables for enhanced content;
125
# in each case, we're grabbing the first value we find in
128
# in each case, we're grabbing the first value we find in
126
# the record and normalizing it
129
# the record and normalizing it
Lines 142-148 $template->param( Link Here
142
145
143
#coping with subscriptions
146
#coping with subscriptions
144
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
147
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
145
my $dbh = C4::Context->dbh;
146
my $dat                 = TransformMarcToKoha( $record );
148
my $dat                 = TransformMarcToKoha( $record );
147
149
148
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
150
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
Lines 178-184 my $res = GetISBDView({ Link Here
178
180
179
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
181
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
180
my $patron = Koha::Patrons->find( $loggedinuser );
182
my $patron = Koha::Patrons->find( $loggedinuser );
181
for my $itm (@items) {
183
for my $itm (@all_items) {
182
    my $item = Koha::Items->find( $itm->{itemnumber} );
184
    my $item = Koha::Items->find( $itm->{itemnumber} );
183
    $norequests = 0
185
    $norequests = 0
184
      if $norequests
186
      if $norequests
(-)a/opac/opac-MARCdetail.pl (-44 / +37 lines)
Lines 63-108 use Koha::Items; Link Here
63
use Koha::Patrons;
63
use Koha::Patrons;
64
use Koha::RecordProcessor;
64
use Koha::RecordProcessor;
65
65
66
my $query = new CGI;
66
my $query = CGI->new();
67
68
my $dbh = C4::Context->dbh;
69
67
70
my $biblionumber = $query->param('biblionumber');
68
my $biblionumber = $query->param('biblionumber');
71
if ( ! $biblionumber ) {
69
if ( ! $biblionumber ) {
72
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
70
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
73
    exit;
71
    exit;
74
}
72
}
73
$biblionumber = int($biblionumber);
74
75
# open template
76
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
77
    {
78
        template_name   => "opac-MARCdetail.tt",
79
        query           => $query,
80
        type            => "opac",
81
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
82
        debug           => 1,
83
    }
84
);
85
86
my $patron = Koha::Patrons->find( $loggedinuser );
87
my $borcat = q{};
88
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
89
    # we need to fetch the borrower info here, so we can pass the category
90
    $borcat = $patron ? $patron->categorycode : $borcat;
91
}
75
92
76
my $record = GetMarcBiblio({
93
my $record = GetMarcBiblio({
77
    biblionumber => $biblionumber,
94
    biblionumber => $biblionumber,
78
    embed_items  => 1 });
95
    embed_items  => 1,
96
    opac         => 1,
97
    borcat       => $borcat });
79
if ( ! $record ) {
98
if ( ! $record ) {
80
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
99
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
81
    exit;
100
    exit;
82
}
101
}
83
102
84
my @all_items = GetItemsInfo($biblionumber);
103
my @all_items = GetItemsInfo($biblionumber);
85
my @items2hide;
104
my $biblio = Koha::Biblios->find( $biblionumber );
86
if (scalar @all_items >= 1) {
105
my $framework = $biblio ? $biblio->frameworkcode : q{};
87
    my $borcat;
88
    if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
89
90
        # we need to fetch the borrower info here, so we can pass the category
91
        my $borrower = GetMember( borrowernumber => $borrowernumber );
92
        $borcat = $borrower->{categorycode};
93
    }
94
    push @items2hide, GetHiddenItemnumbers({ items => \@all_items, borcat => $botcat });
95
96
    if (scalar @items2hide == scalar @all_items ) {
97
        print $query->redirect("/cgi-bin/koha/errors/404.pl");
98
        exit;
99
    }
100
}
101
102
my $framework = &GetFrameworkCode( $biblionumber );
103
my $tagslib = &GetMarcStructure( 0, $framework );
106
my $tagslib = &GetMarcStructure( 0, $framework );
104
my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
107
my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
105
my $biblio = Koha::Biblios->find( $biblionumber );
108
my @nonhiddenitems = $record->field($tag_itemnumber);
109
if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) {
110
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
111
    exit;
112
}
106
113
107
my $record_processor = Koha::RecordProcessor->new({
114
my $record_processor = Koha::RecordProcessor->new({
108
    filters => 'ViewPolicy',
115
    filters => 'ViewPolicy',
Lines 113-135 my $record_processor = Koha::RecordProcessor->new({ Link Here
113
});
120
});
114
$record_processor->process($record);
121
$record_processor->process($record);
115
122
116
# open template
117
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
118
    {
119
        template_name   => "opac-MARCdetail.tt",
120
        query           => $query,
121
        type            => "opac",
122
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
123
        debug           => 1,
124
    }
125
);
126
127
my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework);
128
$template->param(
129
    bibliotitle => $biblio->title,
130
) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible.
131
     $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8;   # except -8;
132
133
# get biblionumbers stored in the cart
123
# get biblionumbers stored in the cart
134
if(my $cart_list = $query->cookie("bib_list")){
124
if(my $cart_list = $query->cookie("bib_list")){
135
    my @cart_list = split(/\//, $cart_list);
125
    my @cart_list = split(/\//, $cart_list);
Lines 138-145 if(my $cart_list = $query->cookie("bib_list")){ Link Here
138
    }
128
    }
139
}
129
}
140
130
131
my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework);
132
$template->param(
133
    bibliotitle => $biblio->title,
134
) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible.
135
     $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8;   # except -8;
136
141
my $allow_onshelf_holds;
137
my $allow_onshelf_holds;
142
my $patron = Koha::Patrons->find( $loggedinuser );
143
for my $itm (@all_items) {
138
for my $itm (@all_items) {
144
    my $item = Koha::Items->find( $itm->{itemnumber} );
139
    my $item = Koha::Items->find( $itm->{itemnumber} );
145
    $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
140
    $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
Lines 278-283 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) { Link Here
278
# loop through each tag
273
# loop through each tag
279
# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
274
# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
280
# then construct template.
275
# then construct template.
276
# $record has already had all the item fields filtered above.
281
my @fields = $record->fields();
277
my @fields = $record->fields();
282
my %witness
278
my %witness
283
  ; #---- stores the list of subfields used at least once, with the "meaning" of the code
279
  ; #---- stores the list of subfields used at least once, with the "meaning" of the code
Lines 285-293 my @item_subfield_codes; Link Here
285
my @item_loop;
281
my @item_loop;
286
foreach my $field (@fields) {
282
foreach my $field (@fields) {
287
    next if ( $field->tag() < 10 );
283
    next if ( $field->tag() < 10 );
288
    next if ( ( $field->tag() eq $tag_itemnumber ) &&
289
              ( any { $field->subfield($subtag_itemnumber) eq $_ }
290
                   @items2hide) );
291
    my @subf = $field->subfields;
284
    my @subf = $field->subfields;
292
    my $item;
285
    my $item;
293
286
(-)a/opac/opac-basket.pl (-1 / +27 lines)
Lines 56-61 if (C4::Context->preference('TagsEnabled')) { Link Here
56
	}
56
	}
57
}
57
}
58
58
59
my $borcat = q{};
60
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
61
    # we need to fetch the borrower info here, so we can pass the category
62
    my $borrower = Koha::Patron->find( { borrowernumber -> $borrowernumber } );
63
    $borcat = $borrower ? $borrower->categorycode : $borcat;
64
}
65
59
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
66
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
60
foreach my $biblionumber ( @bibs ) {
67
foreach my $biblionumber ( @bibs ) {
61
    $template->param( biblionumber => $biblionumber );
68
    $template->param( biblionumber => $biblionumber );
Lines 63-68 foreach my $biblionumber ( @bibs ) { Link Here
63
    my $dat              = &GetBiblioData($biblionumber);
70
    my $dat              = &GetBiblioData($biblionumber);
64
    next unless $dat;
71
    next unless $dat;
65
72
73
    # No filtering on the item records needed for the record itself
74
    # since the only reason item information is grabbed is because of branchcodes.
66
    my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
75
    my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
67
    my $framework = &GetFrameworkCode( $biblionumber );
76
    my $framework = &GetFrameworkCode( $biblionumber );
68
    $record_processor->options({
77
    $record_processor->options({
Lines 76-82 foreach my $biblionumber ( @bibs ) { Link Here
76
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
85
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
86
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
78
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
87
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
79
    my @items            = &GetItemsInfo( $biblionumber );
88
89
    # grab all the items...
90
    my @all_items        = &GetItemsInfo( $biblionumber );
91
92
    # determine which ones should be hidden / visible
93
    my @hidden_items     = GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat });
94
95
    # If every item is hidden, then the biblio should be hidden too.
96
    next if (scalar @all_items >= 1 && scalar @hidden_items == scalar @all_items);
97
98
    # copy the visible ones into the items array.
99
    my @items;
100
    foreach my $item (@all_items) {
101
        if ( none { $item->{itemnumber} ne $_ } @hidden_items ) {
102
            push @items, $item;
103
        }
104
    }
105
80
    my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
106
    my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
81
107
82
    my $hasauthors = 0;
108
    my $hasauthors = 0;
(-)a/opac/opac-detail.pl (-26 / +30 lines)
Lines 68-74 BEGIN { Link Here
68
	}
68
	}
69
}
69
}
70
70
71
my $query = new CGI;
71
my $query = CGI->new();
72
73
my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
74
$biblionumber = int($biblionumber);
75
72
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
76
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
73
    {
77
    {
74
        template_name   => "opac-detail.tt",
78
        template_name   => "opac-detail.tt",
Lines 78-97 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
78
    }
82
    }
79
);
83
);
80
84
81
my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
82
$biblionumber = int($biblionumber);
83
84
my @all_items = GetItemsInfo($biblionumber);
85
my @all_items = GetItemsInfo($biblionumber);
85
my @hiddenitems;
86
my @hiddenitems;
86
if ( scalar @all_items >= 1 ) {
87
my $patron = Koha::Patrons->find( $borrowernumber );
87
    my $borcat;
88
my $borcat= q{};
88
    if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
89
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
90
    $borcat = $patron ? $patron->categorycode : q{};
91
}
89
92
90
        # we need to fetch the borrower info here, so we can pass the category
93
my $record = GetMarcBiblio({
91
        my $borrower = GetMember( borrowernumber => $borrowernumber );
94
    biblionumber => $biblionumber,
92
        $borcat = $borrower->{categorycode};
95
    opac         => 1 });
93
    }
96
if ( ! $record ) {
97
    print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
98
    exit;
99
}
94
100
101
if ( scalar @all_items >= 1 ) {
95
    push @hiddenitems,
102
    push @hiddenitems,
96
      GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } );
103
      GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } );
97
104
Lines 101-114 if ( scalar @all_items >= 1 ) { Link Here
101
    }
108
    }
102
}
109
}
103
110
104
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
105
if ( ! $record ) {
106
    print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
107
    exit;
108
}
109
110
my $biblio = Koha::Biblios->find( $biblionumber );
111
my $biblio = Koha::Biblios->find( $biblionumber );
111
my $framework = &GetFrameworkCode( $biblionumber );
112
my $framework = $biblio ? $biblio->frameworkcode : q{};
112
my $record_processor = Koha::RecordProcessor->new({
113
my $record_processor = Koha::RecordProcessor->new({
113
    filters => 'ViewPolicy',
114
    filters => 'ViewPolicy',
114
    options => {
115
    options => {
Lines 240-249 if ($session->param('busc')) { Link Here
240
        };
241
        };
241
        my $hits;
242
        my $hits;
242
        my @newresults;
243
        my @newresults;
244
        my $search_context = {
245
            'interface' => 'opac',
246
            'category'  => $borcat
247
        };
243
        for (my $i=0;$i<@servers;$i++) {
248
        for (my $i=0;$i<@servers;$i++) {
244
            my $server = $servers[$i];
249
            my $server = $servers[$i];
245
            $hits = $results_hashref->{$server}->{"hits"};
250
            $hits = $results_hashref->{$server}->{"hits"};
246
            @newresults = searchResults({ 'interface' => 'opac' }, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
251
            @newresults = searchResults( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
247
        }
252
        }
248
        return \@newresults;
253
        return \@newresults;
249
    }#searchAgain
254
    }#searchAgain
Lines 671-677 if ( not $viewallitems and @items > $max_items_to_display ) { Link Here
671
        items_count => scalar( @items ),
676
        items_count => scalar( @items ),
672
    );
677
    );
673
} else {
678
} else {
674
  my $patron = Koha::Patrons->find( $borrowernumber );
675
  for my $itm (@items) {
679
  for my $itm (@items) {
676
    my $item = Koha::Items->find( $itm->{itemnumber} );
680
    my $item = Koha::Items->find( $itm->{itemnumber} );
677
    $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
681
    $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
Lines 858-873 if ( C4::Context->preference('reviewson') ) { Link Here
858
        }
862
        }
859
    }
863
    }
860
    for my $review (@$reviews) {
864
    for my $review (@$reviews) {
861
        my $patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
865
        my $review_patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
862
866
863
        # setting some borrower info into this hash
867
        # setting some borrower info into this hash
864
        if ( $patron ) {
868
        if ( $review_patron ) {
865
            $review->{patron} = $patron;
869
            $review->{patron} = $review_patron;
866
            if ( $libravatar_enabled and $patron->email ) {
870
            if ( $libravatar_enabled and $review_patron->email ) {
867
                $review->{avatarurl} = libravatar_url( email => $patron->email, https => $ENV{HTTPS} );
871
                $review->{avatarurl} = libravatar_url( email => $review_patron->email, https => $ENV{HTTPS} );
868
            }
872
            }
869
873
870
            if ( $patron->borrowernumber eq $borrowernumber ) {
874
            if ( $review_patron->borrowernumber eq $borrowernumber ) {
871
                $loggedincommenter = 1;
875
                $loggedincommenter = 1;
872
            }
876
            }
873
        }
877
        }
(-)a/opac/opac-downloadcart.pl (-2 / +11 lines)
Lines 32-38 use Koha::CsvProfiles; Link Here
32
use Koha::RecordProcessor;
32
use Koha::RecordProcessor;
33
33
34
use utf8;
34
use utf8;
35
my $query = new CGI;
35
my $query = CGI->new();
36
36
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
38
    {
38
    {
Lines 49-54 my $dbh = C4::Context->dbh; Link Here
49
49
50
if ($bib_list && $format) {
50
if ($bib_list && $format) {
51
51
52
    my $borcat = q{};
53
    if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
54
        # we need to fetch the borrower info here, so we can pass the category
55
        my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
56
        $borcat = $borrower ? $borrower->categorycode : $borcat;
57
    }
58
52
    my @bibs = split( /\//, $bib_list );
59
    my @bibs = split( /\//, $bib_list );
53
60
54
    my $marcflavour = C4::Context->preference('marcflavour');
61
    my $marcflavour = C4::Context->preference('marcflavour');
Lines 70-76 if ($bib_list && $format) { Link Here
70
77
71
            my $record = GetMarcBiblio({
78
            my $record = GetMarcBiblio({
72
                biblionumber => $biblio,
79
                biblionumber => $biblio,
73
                embed_items  => 1 });
80
                embed_items  => 1,
81
                opac         => 1,
82
                borcat       => $borcat });
74
            my $framework = &GetFrameworkCode( $biblio );
83
            my $framework = &GetFrameworkCode( $biblio );
75
            $record_processor->options({
84
            $record_processor->options({
76
                interface => 'opac',
85
                interface => 'opac',
(-)a/opac/opac-downloadshelf.pl (-1 / +10 lines)
Lines 50-55 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
50
    }
50
    }
51
);
51
);
52
52
53
my $borcat = q{};
54
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
55
    # we need to fetch the borrower info here, so we can pass the category
56
    my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
57
    $borcat = $borrower ? $borrower->categorycode : $borcat;
58
}
59
53
my $shelfnumber = $query->param('shelfnumber');
60
my $shelfnumber = $query->param('shelfnumber');
54
my $format  = $query->param('format');
61
my $format  = $query->param('format');
55
my $context = $query->param('context');
62
my $context = $query->param('context');
Lines 83-89 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
83
90
84
                my $record = GetMarcBiblio({
91
                my $record = GetMarcBiblio({
85
                    biblionumber => $biblionumber,
92
                    biblionumber => $biblionumber,
86
                    embed_items  => 1 });
93
                    embed_items  => 1,
94
                    opac         => 1,
95
                    borcat       => $borcat });
87
                my $framework = &GetFrameworkCode( $biblionumber );
96
                my $framework = &GetFrameworkCode( $biblionumber );
88
                $record_processor->options({
97
                $record_processor->options({
89
                    interface => 'opac',
98
                    interface => 'opac',
(-)a/opac/opac-export.pl (-1 / +15 lines)
Lines 35-45 my $biblionumber = $query->param("bib")||0; Link Here
35
$biblionumber = int($biblionumber);
35
$biblionumber = int($biblionumber);
36
my $error = q{};
36
my $error = q{};
37
37
38
# Determine logged in user's patron category.
39
# Blank if not logged in.
40
my $userenv = C4::Context->userenv;
41
my $borcat = q{};
42
if ($userenv) {
43
    my $borrowernumber = $userenv->{'number'};
44
    if ($borrowernumber) {
45
        my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
46
        $borcat = $borrower ? $borrower->categorycode : $borcat;
47
    }
48
}
49
38
my $include_items = ($format =~ /bibtex/) ? 0 : 1;
50
my $include_items = ($format =~ /bibtex/) ? 0 : 1;
39
my $marc = $biblionumber
51
my $marc = $biblionumber
40
    ? GetMarcBiblio({
52
    ? GetMarcBiblio({
41
        biblionumber => $biblionumber,
53
        biblionumber => $biblionumber,
42
        embed_items  => $include_items })
54
        embed_items  => $include_items,
55
        opac         => 1,
56
        borcat       => $borcat })
43
    : undef;
57
    : undef;
44
58
45
if(!$marc) {
59
if(!$marc) {
(-)a/opac/opac-search.pl (-3 / +5 lines)
Lines 51-58 use C4::Koha; Link Here
51
use C4::Tags qw(get_tags);
51
use C4::Tags qw(get_tags);
52
use C4::SocialData;
52
use C4::SocialData;
53
use C4::External::OverDrive;
53
use C4::External::OverDrive;
54
use C4::Members qw(GetMember);
55
54
55
use Koha::Libraries;
56
use Koha::ItemTypes;
56
use Koha::ItemTypes;
57
use Koha::Ratings;
57
use Koha::Ratings;
58
use Koha::Virtualshelves;
58
use Koha::Virtualshelves;
Lines 595-600 if ($tag) { Link Here
595
    $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
595
    $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
596
    $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
596
    $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
597
    # FIXME: tag search and standard search should work together, not exclusively
597
    # FIXME: tag search and standard search should work together, not exclusively
598
    # FIXME: Because search and standard search don't work together OpacHiddenItems
599
    #        displays search results which should be hidden.
598
    # FIXME: No facets for tags search.
600
    # FIXME: No facets for tags search.
599
} elsif ($build_grouped_results) {
601
} elsif ($build_grouped_results) {
600
    eval {
602
    eval {
Lines 625-632 my $search_context = {}; Link Here
625
$search_context->{'interface'} = 'opac';
627
$search_context->{'interface'} = 'opac';
626
if (C4::Context->preference('OpacHiddenItemsExceptions')){
628
if (C4::Context->preference('OpacHiddenItemsExceptions')){
627
    # we need to fetch the borrower info here, so we can pass the category
629
    # we need to fetch the borrower info here, so we can pass the category
628
    my $borrower = GetMember( borrowernumber => $borrowernumber );
630
    my $patron = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
629
    $search_context->{'category'} = $borrower->{'categorycode'};
631
    $search_context->{'category'} = $patron ? $patron->categorycode : q{};
630
}
632
}
631
633
632
for (my $i=0;$i<@servers;$i++) {
634
for (my $i=0;$i<@servers;$i++) {
(-)a/opac/opac-sendbasket.pl (-1 / +4 lines)
Lines 59-64 if ( $email_add ) { Link Here
59
    });
59
    });
60
    my $email = Koha::Email->new();
60
    my $email = Koha::Email->new();
61
    my $patron = Koha::Patrons->find( $borrowernumber );
61
    my $patron = Koha::Patrons->find( $borrowernumber );
62
    my $borcat = $patron ? $patron->categorycode : q{};
62
    my $user_email = $patron->first_valid_email_address
63
    my $user_email = $patron->first_valid_email_address
63
    || C4::Context->preference('KohaAdminEmailAddress');
64
    || C4::Context->preference('KohaAdminEmailAddress');
64
65
Lines 89-95 if ( $email_add ) { Link Here
89
        next unless $dat;
90
        next unless $dat;
90
        my $record           = GetMarcBiblio({
91
        my $record           = GetMarcBiblio({
91
            biblionumber => $biblionumber,
92
            biblionumber => $biblionumber,
92
            embed_items  => 1 });
93
            embed_items  => 1,
94
            opac         => 1,
95
            borcat       => $borcat });
93
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
96
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
94
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
97
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
95
98
(-)a/opac/opac-sendshelf.pl (-5 / +10 lines)
Lines 80-85 if ( $email ) { Link Here
80
        }
80
        }
81
    );
81
    );
82
82
83
    my $patron = Koha::Patrons->find( $borrowernumber );
84
    my $borcat = $patron ? $patron->categorycode : q{};
85
83
    my $shelf = Koha::Virtualshelves->find( $shelfid );
86
    my $shelf = Koha::Virtualshelves->find( $shelfid );
84
    my $contents = $shelf->get_contents;
87
    my $contents = $shelf->get_contents;
85
    my $marcflavour         = C4::Context->preference('marcflavour');
88
    my $marcflavour         = C4::Context->preference('marcflavour');
Lines 88-98 if ( $email ) { Link Here
88
91
89
    while ( my $content = $contents->next ) {
92
    while ( my $content = $contents->next ) {
90
        my $biblionumber = $content->biblionumber;
93
        my $biblionumber = $content->biblionumber;
91
        my $fw               = GetFrameworkCode($biblionumber);
92
        my $dat              = GetBiblioData($biblionumber);
93
        my $record           = GetMarcBiblio({
94
        my $record           = GetMarcBiblio({
94
            biblionumber => $biblionumber,
95
            biblionumber => $biblionumber,
95
            embed_items  => 1 });
96
            embed_items  => 1,
97
            opac         => 1,
98
            borcat       => $borcat });
99
        next unless $record;
100
        my $fw               = GetFrameworkCode($biblionumber);
101
        my $dat              = GetBiblioData($biblionumber);
102
96
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
103
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
97
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
104
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
98
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
105
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
Lines 112-119 if ( $email ) { Link Here
112
        push( @results, $dat );
119
        push( @results, $dat );
113
    }
120
    }
114
121
115
    my $patron = Koha::Patrons->find( $borrowernumber );
116
117
    $template2->param(
122
    $template2->param(
118
        BIBLIO_RESULTS => \@results,
123
        BIBLIO_RESULTS => \@results,
119
        comment        => $comment,
124
        comment        => $comment,
(-)a/opac/opac-tags.pl (-2 / +44 lines)
Lines 41-46 use C4::Debug; Link Here
41
use C4::Output qw(:html :ajax pagination_bar);
41
use C4::Output qw(:html :ajax pagination_bar);
42
use C4::Scrubber;
42
use C4::Scrubber;
43
use C4::Biblio;
43
use C4::Biblio;
44
use C4::Items qw(GetItemsInfo GetHiddenItemnumbers);
44
use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag stratify_tags);
45
use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag stratify_tags);
45
use C4::XSLT;
46
use C4::XSLT;
46
47
Lines 226-238 if ($is_ajax) { Link Here
226
227
227
my $results = [];
228
my $results = [];
228
my $my_tags = [];
229
my $my_tags = [];
230
my $borcat  = q{};
229
231
230
if ($loggedinuser) {
232
if ($loggedinuser) {
233
    my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
234
    $borcat = $patron ? $patron->categorycode : $borcat;
235
    my $should_hide = C4::Context->preference('OpacHiddenItems') // q{};
236
    $should_hide = ( $should_hide =~ /\S/ ) ? 1 : 0;
231
    $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
237
    $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
232
    my $my_approved_tags = get_approval_rows({ approved => 1 });
238
    my $my_approved_tags = get_approval_rows({ approved => 1 });
233
    foreach my $tag (@$my_tags) {
239
    foreach my $tag (@$my_tags) {
240
        $tag->{visible} = 0;
234
        my $biblio = Koha::Biblios->find( $tag->{biblionumber} );
241
        my $biblio = Koha::Biblios->find( $tag->{biblionumber} );
235
        my $record = &GetMarcBiblio({ biblionumber => $tag->{biblionumber} });
242
        my $record = &GetMarcBiblio({
243
            biblionumber => $tag->{biblionumber},
244
            embed_items  => 1,
245
            opac         => 1,
246
            borcat       => $borcat });
247
        next unless $record;
248
        my $hidden_items = undef;
249
        my @hidden_itemnumbers;
250
        my @all_items;
251
        if ($should_hide) {
252
            @all_items = GetItemsInfo( $tag->{biblionumber} );
253
            @hidden_itemnumbers = GetHiddenItemnumbers({
254
                items => \@all_items,
255
                borcat => $borcat });
256
            $hidden_items = \@hidden_itemnumbers;
257
        }
258
        next if ( $should_hide && scalar @all_items == scalar @hidden_itemnumbers );
236
        $tag->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $tag->{biblionumber} ) );
259
        $tag->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $tag->{biblionumber} ) );
237
        $tag->{title} = $biblio->title;
260
        $tag->{title} = $biblio->title;
238
        $tag->{author} = $biblio->author;
261
        $tag->{author} = $biblio->author;
Lines 244-250 if ($loggedinuser) { Link Here
244
        if ( $xslfile ) {
267
        if ( $xslfile ) {
245
            $tag->{XSLTBloc} = XSLTParse4Display(
268
            $tag->{XSLTBloc} = XSLTParse4Display(
246
                    $tag->{ biblionumber }, $record, "OPACXSLTResultsDisplay",
269
                    $tag->{ biblionumber }, $record, "OPACXSLTResultsDisplay",
247
                    1, undef, $sysxml, $xslfile, $lang
270
                    1, $hidden_items, $sysxml, $xslfile, $lang
248
            );
271
            );
249
        }
272
        }
250
273
Lines 252-257 if ($loggedinuser) { Link Here
252
        $date =~ /\s+(\d{2}\:\d{2}\:\d{2})/;
275
        $date =~ /\s+(\d{2}\:\d{2}\:\d{2})/;
253
        $tag->{time_created_display} = $1;
276
        $tag->{time_created_display} = $1;
254
        $tag->{approved} = ( grep { $_->{term} eq $tag->{term} and $_->{approved} } @$my_approved_tags );
277
        $tag->{approved} = ( grep { $_->{term} eq $tag->{term} and $_->{approved} } @$my_approved_tags );
278
        $tag->{visible} = 1;
255
    }
279
    }
256
}
280
}
257
281
Lines 281-286 if ($add_op) { Link Here
281
		$arghash->{biblionumber} = $arg;
305
		$arghash->{biblionumber} = $arg;
282
	}
306
	}
283
	$results = get_approval_rows($arghash);
307
	$results = get_approval_rows($arghash);
308
    my @filtered_results;
309
    foreach my $my_tag (@$my_tags) {
310
        if (grep { $_->{term} eq $my_tag->{term} } @$results) {
311
            if (! $my_tag->{visible} ) {
312
                my $check_biblio = GetMarcBiblio({
313
                    biblionumber => $my_tag->{biblionumber},
314
                    embed_items  => 1,
315
                    opac         => 1,
316
                    borcat       => $borcat });
317
                if ($check_biblio) {
318
                    push @filtered_results, $my_tag;
319
                }
320
            } else {
321
                push @filtered_results, $my_tag;
322
            }
323
        }
324
    }
325
    $results = \@filtered_results;
284
    stratify_tags(10, $results); # work out the differents sizes for things
326
    stratify_tags(10, $results); # work out the differents sizes for things
285
	my $count = scalar @$results;
327
	my $count = scalar @$results;
286
	$template->param(TAGLOOP_COUNT => $count, mine => $mine);
328
	$template->param(TAGLOOP_COUNT => $count, mine => $mine);
(-)a/opac/opac-user.pl (-1 / +7 lines)
Lines 95-100 if (!$borrowernumber) { Link Here
95
# get borrower information ....
95
# get borrower information ....
96
my $patron = Koha::Patrons->find( $borrowernumber );
96
my $patron = Koha::Patrons->find( $borrowernumber );
97
my $borr = $patron->unblessed;
97
my $borr = $patron->unblessed;
98
# unblessed is a hash vs. object/undef. Hence the use of curly braces here.
99
my $borcat = $borr ? $borr->{categorycode} : q{};
98
100
99
my (  $today_year,   $today_month,   $today_day) = Today();
101
my (  $today_year,   $today_month,   $today_day) = Today();
100
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
102
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
Lines 220-226 if ( $pending_checkouts->count ) { # Useless test Link Here
220
        );
222
        );
221
        $issue->{rentalfines} = $charges->count ? $charges->next->get_column('rental_fines') : 0;
223
        $issue->{rentalfines} = $charges->count ? $charges->next->get_column('rental_fines') : 0;
222
224
223
        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
225
        my $marcrecord = GetMarcBiblio({
226
            biblionumber => $issue->{'biblionumber'},
227
            embed_items  => 1,
228
            opac         => 1,
229
            borcat       => $borcat });
224
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
230
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
225
        # check if item is renewable
231
        # check if item is renewable
226
        my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
232
        my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
(-)a/t/db_dependent/ILSDI_Services.t (-1 / +41 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
use Test::MockModule;
23
use Test::MockModule;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 105-110 subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes Link Here
105
    $schema->resultset( 'BorrowerAttributeType' )->delete_all;
105
    $schema->resultset( 'BorrowerAttributeType' )->delete_all;
106
    $schema->resultset( 'Category' )->delete_all;
106
    $schema->resultset( 'Category' )->delete_all;
107
    $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
107
    $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
108
    $schema->resultset( 'Club' )->delete_all;
108
    $schema->resultset( 'Branch' )->delete_all;
109
    $schema->resultset( 'Branch' )->delete_all;
109
110
110
    # Configure Koha to enable ILS-DI server and extended attributes:
111
    # Configure Koha to enable ILS-DI server and extended attributes:
Lines 262-264 subtest 'LookupPatron test' => sub { Link Here
262
    # Cleanup
263
    # Cleanup
263
    $schema->storage->txn_rollback;
264
    $schema->storage->txn_rollback;
264
};
265
};
266
267
# This is a stub, as it merely is for triggering the GetMarcBiblio call.
268
subtest 'GetRecords' => sub {
269
270
    plan tests => 1;
271
272
    $schema->storage->txn_begin;
273
274
    my $biblio = $builder->build({
275
        source => 'Biblio',
276
        value  => {
277
            title => 'Title 1',    },
278
    });
279
280
    my $item = $builder->build({
281
        source => 'Item',
282
        value  => {
283
            biblionumber => $biblio->{biblionumber},
284
        },
285
    });
286
287
    my $biblioitem = $builder->build({
288
        source => 'Biblioitem',
289
        value  => {
290
            biblionumber => $biblio->{biblionumber},
291
            itemnumber   => $item->{itemnumber},
292
        },
293
    });
294
295
    my $query = CGI->new({
296
        'schema' => 'MARCXML',
297
        'id'     => [ $biblio->{biblionumber} ]
298
    });
299
300
    my $result = C4::ILSDI::Services::GetRecords($query);
301
    ok($result,'There is a result');
302
303
    $schema->storage->txn_rollback;
304
}
(-)a/t/db_dependent/Items.t (-14 / +39 lines)
Lines 32-38 use t::lib::Mocks; Link Here
32
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
33
33
34
use Test::More tests => 14;
34
use Test::More tests => 14;
35
36
use Test::Warn;
35
use Test::Warn;
37
36
38
BEGIN {
37
BEGIN {
Lines 145-151 subtest 'ModItem tests' => sub { Link Here
145
144
146
subtest 'GetHiddenItemnumbers tests' => sub {
145
subtest 'GetHiddenItemnumbers tests' => sub {
147
146
148
    plan tests => 9;
147
    plan tests => 11;
149
148
150
    # This sub is controlled by the OpacHiddenItems system preference.
149
    # This sub is controlled by the OpacHiddenItems system preference.
151
150
Lines 195-206 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
195
    push @items, GetItem( $item2_itemnumber );
194
    push @items, GetItem( $item2_itemnumber );
196
195
197
    # Empty OpacHiddenItems
196
    # Empty OpacHiddenItems
198
    C4::Context->set_preference('OpacHiddenItems','');
197
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
199
    ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ),
198
    ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ),
200
        "Hidden items list undef if OpacHiddenItems empty");
199
        "Hidden items list undef if OpacHiddenItems empty");
201
200
202
    # Blank spaces
201
    # Blank spaces
203
    C4::Context->set_preference('OpacHiddenItems','  ');
202
    t::lib::Mocks::mock_preference('OpacHiddenItems','  ');
204
    ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0,
203
    ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0,
205
        "Hidden items list empty if OpacHiddenItems only contains blanks");
204
        "Hidden items list empty if OpacHiddenItems only contains blanks");
206
205
Lines 216-222 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
216
    $opachiddenitems = "
215
    $opachiddenitems = "
217
        withdrawn: [1,0]";
216
        withdrawn: [1,0]";
218
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
217
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
219
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
220
    @hidden = GetHiddenItemnumbers( { items => \@items } );
218
    @hidden = GetHiddenItemnumbers( { items => \@items } );
221
    ok( scalar @hidden == 2, "Two items hidden");
219
    ok( scalar @hidden == 2, "Two items hidden");
222
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
220
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
Lines 231-236 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
231
    ok( scalar @hidden == 2, "Two items hidden");
229
    ok( scalar @hidden == 2, "Two items hidden");
232
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
230
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
233
231
232
    # Override hidden with patron category
233
    t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', 'S' );
234
    @hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'PT' } );
235
    ok( scalar @hidden == 2, "Two items still hidden");
236
    @hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'S' } );
237
    ok( scalar @hidden == 0, "Two items not hidden");
238
234
    # Valid OpacHiddenItems, empty list
239
    # Valid OpacHiddenItems, empty list
235
    @items = ();
240
    @items = ();
236
    @hidden = GetHiddenItemnumbers( { items => \@items } );
241
    @hidden = GetHiddenItemnumbers( { items => \@items } );
Lines 551-557 subtest 'Koha::Item(s) tests' => sub { Link Here
551
};
556
};
552
557
553
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
558
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
554
    plan tests => 7;
559
    plan tests => 8;
555
560
556
    $schema->storage->txn_begin();
561
    $schema->storage->txn_begin();
557
562
Lines 602-619 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
602
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
607
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
603
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
608
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
604
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
609
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
605
      'Should crap is no record passed.';
610
      'Should carp is no record passed.';
606
611
607
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
612
    C4::Biblio::EmbedItemsInMarcBiblio({
613
        marc_record  => $record,
614
        biblionumber => $biblionumber });
608
    my @items = $record->field($itemfield);
615
    my @items = $record->field($itemfield);
609
    is( scalar @items, $number_of_items, 'Should return all items' );
616
    is( scalar @items, $number_of_items, 'Should return all items' );
610
617
611
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber,
618
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
612
        [ $itemnumbers[1], $itemnumbers[3] ] );
619
        biblionumber => $biblionumber,
620
        embed_items  => 1 });
621
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
622
623
    C4::Biblio::EmbedItemsInMarcBiblio({
624
        marc_record  => $record,
625
        biblionumber => $biblionumber,
626
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
613
    @items = $record->field($itemfield);
627
    @items = $record->field($itemfield);
614
    is( scalar @items, 2, 'Should return all items present in the list' );
628
    is( scalar @items, 2, 'Should return all items present in the list' );
615
629
616
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
630
    C4::Biblio::EmbedItemsInMarcBiblio({
631
        marc_record  => $record,
632
        biblionumber => $biblionumber,
633
        opac         => 1 });
617
    @items = $record->field($itemfield);
634
    @items = $record->field($itemfield);
618
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
635
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
619
636
Lines 621-633 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
621
        homebranch: ['$library1->{branchcode}']";
638
        homebranch: ['$library1->{branchcode}']";
622
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
639
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
623
640
624
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
641
    C4::Biblio::EmbedItemsInMarcBiblio({
642
        marc_record  => $record,
643
        biblionumber => $biblionumber });
625
    @items = $record->field($itemfield);
644
    @items = $record->field($itemfield);
626
    is( scalar @items,
645
    is( scalar @items,
627
        $number_of_items,
646
        $number_of_items,
628
        'Even with OpacHiddenItems set, all items should have been embedded' );
647
        'Even with OpacHiddenItems set, all items should have been embedded' );
629
648
630
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
649
    C4::Biblio::EmbedItemsInMarcBiblio({
650
        marc_record  => $record,
651
        biblionumber => $biblionumber,
652
        opac         => 1 });
631
    @items = $record->field($itemfield);
653
    @items = $record->field($itemfield);
632
    is(
654
    is(
633
        scalar @items,
655
        scalar @items,
Lines 638-644 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
638
    $opachiddenitems = "
660
    $opachiddenitems = "
639
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
661
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
640
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
662
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
641
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
663
    C4::Biblio::EmbedItemsInMarcBiblio({
664
        marc_record  => $record,
665
        biblionumber => $biblionumber,
666
        opac         => 1 });
642
    @items = $record->field($itemfield);
667
    @items = $record->field($itemfield);
643
    is(
668
    is(
644
        scalar @items,
669
        scalar @items,
(-)a/t/db_dependent/Koha/BiblioUtils/Iterator.t (+76 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
22
use_ok('Koha::BiblioUtils');
23
use_ok('Koha::BiblioUtils::Iterator');
24
25
use C4::Biblio;
26
use C4::Items;
27
use DBI;
28
use t::lib::TestBuilder;
29
use t::lib::Mocks;
30
31
my $schema = Koha::Database->new()->schema();
32
$schema->storage->txn_begin();
33
34
# Delete issues to prevent foreign constraint failures.
35
# blank all biblios, biblioitems, and items.
36
$schema->resultset('Issue')->delete();
37
$schema->resultset('Biblio')->delete();
38
39
my $location = 'My Location';
40
my $builder = t::lib::TestBuilder->new;
41
my $library = $builder->build({
42
    source => 'Branch',
43
});
44
my $itemtype = $builder->build({
45
   source => 'Itemtype',
46
});
47
48
# Create a biblio instance for testing
49
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
50
my ($bibnum, $bibitemnum) = get_biblio();
51
52
# Add an item.
53
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
54
55
my $rs = $schema->resultset('Biblioitem')->search({});
56
my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 );
57
my $record = $iterator->next();
58
my $expected_tags = [ 100, 245, 952, 999 ];
59
my @result_tags = map { $_->tag() } $record->field('...');
60
my @sorted_tags = sort @result_tags;
61
is_deeply(\@sorted_tags,$expected_tags, "Got the same tags as expected");
62
63
$schema->storage->txn_rollback();
64
65
# Helper method to set up a Biblio.
66
sub get_biblio {
67
    my ( $frameworkcode ) = @_;
68
    $frameworkcode //= '';
69
    my $bib = MARC::Record->new();
70
    $bib->append_fields(
71
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
72
        MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
73
    );
74
    my ($bibnum, $bibitemnum) = AddBiblio($bib, $frameworkcode);
75
    return ($bibnum, $bibitemnum);
76
}
(-)a/t/db_dependent/Labels/t_Label.t (+147 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2017  Mark Tompsett
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 3;
23
use t::lib::TestBuilder;
24
25
use MARC::Record;
26
use MARC::Field;
27
use Data::Dumper;
28
29
use C4::Biblio;
30
use C4::Items;
31
use C4::Labels::Layout;
32
33
use Koha::Database;
34
35
use_ok('C4::Labels::Label');
36
37
my $database = Koha::Database->new();
38
my $schema   = $database->schema();
39
$schema->storage->txn_begin();
40
41
my $batch_id;
42
my ( $llx, $lly ) = ( 0, 0 );
43
my $frameworkcode = q{};
44
45
## Setup Test
46
my $builder = t::lib::TestBuilder->new;
47
48
# Add branch
49
my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode};
50
51
# Add categories
52
my $category_1 = $builder->build( { source => 'Category' } )->{categorycode};
53
54
# Add an item type
55
my $itemtype =
56
  $builder->build( { source => 'Itemtype', value => { notforloan => undef } } )
57
  ->{itemtype};
58
59
C4::Context->set_userenv( undef, undef, undef, undef, undef, undef, $branch_1 );
60
61
# Create a helper biblio
62
my $bib   = MARC::Record->new();
63
my $title = 'Silence in the library';
64
if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
65
    $bib->append_fields(
66
        MARC::Field->new( '600', q{}, '1', a => 'Moffat, Steven' ),
67
        MARC::Field->new( '200', q{}, q{}, a => $title ),
68
    );
69
}
70
else {
71
    $bib->append_fields(
72
        MARC::Field->new( '100', q{}, q{}, a => 'Moffat, Steven' ),
73
        MARC::Field->new( '245', q{}, q{}, a => $title ),
74
    );
75
}
76
my ($bibnum) = AddBiblio( $bib, $frameworkcode );
77
78
# Create a helper item instance for testing
79
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
80
    {
81
        homebranch    => $branch_1,
82
        holdingbranch => $branch_1,
83
        itype         => $itemtype
84
    },
85
    $bibnum
86
);
87
88
# Modify item; setting barcode.
89
my $testbarcode = '97531';
90
ModItem( { barcode => $testbarcode }, $bibnum, $itemnumber );
91
92
my $layout = C4::Labels::Layout->new( layout_name => 'TEST' );
93
94
my $dummy_template_values = {
95
    creator          => 'Labels',
96
    profile_id       => 0,
97
    template_code    => 'Avery 5160 | 1 x 2-5/8',
98
    template_desc    => '3 columns, 10 rows of labels',
99
    page_width       => 8.5,
100
    page_height      => 11,
101
    label_width      => 2.63,
102
    label_height     => 1,
103
    top_text_margin  => 0.139,
104
    left_text_margin => 0.0417,
105
    top_margin       => 0.35,
106
    left_margin      => 0.23,
107
    cols             => 3,
108
    rows             => 10,
109
    col_gap          => 0.13,
110
    row_gap          => 0,
111
    units            => 'INCH',
112
    template_stat    => 1,
113
};
114
115
my $label = C4::Labels::Label->new(
116
    batch_id         => $batch_id,
117
    item_number      => $itemnumber,
118
    llx              => $llx,
119
    lly              => $lly,
120
    width            => $dummy_template_values->{'label_width'},
121
    height           => $dummy_template_values->{'label_height'},
122
    top_text_margin  => $dummy_template_values->{'top_text_margin'},
123
    left_text_margin => $dummy_template_values->{'left_text_margin'},
124
    barcode_type     => $layout->get_attr('barcode_type'),
125
    printing_type    => 'BIB',
126
    guidebox         => $layout->get_attr('guidebox'),
127
    oblique_title    => $layout->get_attr('oblique_title'),
128
    font             => $layout->get_attr('font'),
129
    font_size        => $layout->get_attr('font_size'),
130
    callnum_split    => $layout->get_attr('callnum_split'),
131
    justify          => $layout->get_attr('text_justify'),
132
    format_string    => $layout->get_attr('format_string'),
133
    text_wrap_cols   => $layout->get_text_wrap_cols(
134
        label_width      => $dummy_template_values->{'label_width'},
135
        left_text_margin => $dummy_template_values->{'left_text_margin'}
136
    ),
137
);
138
139
my $label_text = $label->create_label();
140
ok( defined $label_text, 'Label Text Value defined.' );
141
142
my $label_csv_data = $label->csv_data();
143
ok( defined $label_csv_data, 'Label CSV Data defined' );
144
145
$schema->storage->txn_rollback();
146
147
1;
(-)a/t/db_dependent/Record/marcrecord2csv.t (-2 / +6 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl;
1
#!/usr/bin/perl;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 11;
4
use Test::More tests => 12;
5
use Test::MockModule;
5
use Test::MockModule;
6
use MARC::Record;
6
use MARC::Record;
7
use MARC::Field;
7
use MARC::Field;
Lines 29-35 my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a); Link Here
29
my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content });
29
my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content });
30
my $csv = Text::CSV::Encoded->new();
30
my $csv = Text::CSV::Encoded->new();
31
31
32
my $csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_1, 1, $csv );
32
# Test bad biblionumber case
33
my $csv_output = C4::Record::marcrecord2csv( -1, $csv_profile_id_1, 1, $csv );
34
ok(! defined $csv_output, 'Bad biblionumber gives undef as expected.');
35
36
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_1, 1, $csv );
33
37
34
is( $csv_output, q[Title|Author|Subject
38
is( $csv_output, q[Title|Author|Subject
35
"The art of computer programming,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"Computer programming.,Computer algorithms."
39
"The art of computer programming,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"Computer programming.,Computer algorithms."
(-)a/t/db_dependent/Search.t (-1 / +38 lines)
Lines 22-27 use utf8; Link Here
22
use YAML;
22
use YAML;
23
23
24
use C4::Debug;
24
use C4::Debug;
25
use C4::XSLT;
25
require C4::Context;
26
require C4::Context;
26
27
27
# work around spurious wide character warnings
28
# work around spurious wide character warnings
Lines 99-104 our $QueryFuzzy = 0; Link Here
99
our $UseQueryParser = 0;
100
our $UseQueryParser = 0;
100
our $SearchEngine = 'Zebra';
101
our $SearchEngine = 'Zebra';
101
our $marcflavour = 'MARC21';
102
our $marcflavour = 'MARC21';
103
our $htdocs = File::Spec->rel2abs(dirname($0));
104
my @htdocs = split /\//, $htdocs;
105
$htdocs[-2] = 'koha-tmpl';
106
$htdocs[-1] = 'opac-tmpl';
107
$htdocs = join '/', @htdocs;
102
our $contextmodule = new Test::MockModule('C4::Context');
108
our $contextmodule = new Test::MockModule('C4::Context');
103
$contextmodule->mock('preference', sub {
109
$contextmodule->mock('preference', sub {
104
    my ($self, $pref) = @_;
110
    my ($self, $pref) = @_;
Lines 140-145 $contextmodule->mock('preference', sub { Link Here
140
        return '';
146
        return '';
141
    } elsif ($pref eq 'template') {
147
    } elsif ($pref eq 'template') {
142
        return 'prog';
148
        return 'prog';
149
    } elsif ($pref eq 'OPACXSLTResultsDisplay') {
150
        return C4::XSLT::_get_best_default_xslt_filename($htdocs, 'bootstrap','en',$marcflavour . 'slim2OPACResults.xsl');
151
    } elsif ($pref eq 'BiblioDefaultView') {
152
        return 'normal';
153
    } elsif ($pref eq 'IdRef') {
154
        return '0';
155
    } elsif ($pref eq 'IntranetBiblioDefaultView') {
156
        return 'normal';
157
    } elsif ($pref eq 'OPACBaseURL') {
158
        return 'http://library.mydnsname.org';
159
    } elsif ($pref eq 'OPACResultsLibrary') {
160
        return 'homebranch';
161
    } elsif ($pref eq 'OpacSuppression') {
162
        return '0';
163
    } elsif ($pref eq 'OPACURLOpenInNewWindow') {
164
        return '0';
165
    } elsif ($pref eq 'TraceCompleteSubfields') {
166
        return '0';
167
    } elsif ($pref eq 'TraceSubjectSubdivisions') {
168
        return '0';
169
    } elsif ($pref eq 'TrackClicks') {
170
        return '0';
171
    } elsif ($pref eq 'URLLinkText') {
172
        return q{};
173
    } elsif ($pref eq 'UseAuthoritiesForTracings') {
174
        return '1';
175
    } elsif ($pref eq 'UseControlNumber') {
176
        return '0';
177
    } elsif ($pref eq 'UseICU') {
178
        return '0';
179
    } elsif ($pref eq 'viewISBD') {
180
        return '1';
143
    } else {
181
    } else {
144
        warn "The syspref $pref was requested but I don't know what to say; this indicates that the test requires updating"
182
        warn "The syspref $pref was requested but I don't know what to say; this indicates that the test requires updating"
145
            unless $pref =~ m/(XSLT|item|branch|holding|image)/i;
183
            unless $pref =~ m/(XSLT|item|branch|holding|image)/i;
146
- 

Return to bug 14385