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

(-)a/C4/Biblio.pm (-7 / +40 lines)
Lines 1128-1134 sub GetMarcSubfieldStructureFromKohaField { Link Here
1128
  my $record = GetMarcBiblio({
1128
  my $record = GetMarcBiblio({
1129
      biblionumber => $biblionumber,
1129
      biblionumber => $biblionumber,
1130
      embed_items  => $embeditems,
1130
      embed_items  => $embeditems,
1131
      opac         => $opac });
1131
      opac         => $opac,
1132
      borcat       => $patron_category });
1132
1133
1133
Returns MARC::Record representing a biblio record, or C<undef> if the
1134
Returns MARC::Record representing a biblio record, or C<undef> if the
1134
biblionumber doesn't exist.
1135
biblionumber doesn't exist.
Lines 1152-1157 set to true to include item information. Link Here
1152
set to true to make the result suited for OPAC view. This causes things like
1153
set to true to make the result suited for OPAC view. This causes things like
1153
OpacHiddenItems to be applied.
1154
OpacHiddenItems to be applied.
1154
1155
1156
=item C<$borcat>
1157
1158
If the OpacHiddenItemsExceptions system preference is set, this patron category
1159
can be used to make visible OPAC items which would be normally hidden.
1160
It only makes sense in combination both embed_items and opac values true.
1161
1155
=back
1162
=back
1156
1163
1157
=cut
1164
=cut
Lines 1167-1172 sub GetMarcBiblio { Link Here
1167
    my $biblionumber = $params->{biblionumber};
1174
    my $biblionumber = $params->{biblionumber};
1168
    my $embeditems   = $params->{embed_items} || 0;
1175
    my $embeditems   = $params->{embed_items} || 0;
1169
    my $opac         = $params->{opac} || 0;
1176
    my $opac         = $params->{opac} || 0;
1177
    my $borcat       = $params->{borcat} // q{};
1170
1178
1171
    if (not defined $biblionumber) {
1179
    if (not defined $biblionumber) {
1172
        carp 'GetMarcBiblio called with undefined biblionumber';
1180
        carp 'GetMarcBiblio called with undefined biblionumber';
Lines 1194-1200 sub GetMarcBiblio { Link Here
1194
1202
1195
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1203
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1196
            $biblioitemnumber );
1204
            $biblioitemnumber );
1197
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1205
        C4::Biblio::EmbedItemsInMarcBiblio({
1206
            marc_record  => $record,
1207
            biblionumber => $biblionumber,
1208
            opac         => $opac,
1209
            borcat       => $borcat })
1198
          if ($embeditems);
1210
          if ($embeditems);
1199
1211
1200
        return $record;
1212
        return $record;
Lines 2772-2778 sub ModZebra { Link Here
2772
2784
2773
=head2 EmbedItemsInMarcBiblio
2785
=head2 EmbedItemsInMarcBiblio
2774
2786
2775
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2787
    EmbedItemsInMarcBiblio({
2788
        marc_record  => $marc,
2789
        biblionumber => $biblionumber,
2790
        item_numbers => $itemnumbers,
2791
        opac         => $opac });
2776
2792
2777
Given a MARC::Record object containing a bib record,
2793
Given a MARC::Record object containing a bib record,
2778
modify it to include the items attached to it as 9XX
2794
modify it to include the items attached to it as 9XX
Lines 2781-2794 if $itemnumbers is defined, only specified itemnumbers are embedded. Link Here
2781
2797
2782
If $opac is true, then opac-relevant suppressions are included.
2798
If $opac is true, then opac-relevant suppressions are included.
2783
2799
2800
If opac filtering will be done, borcat should be passed to properly
2801
override if necessary.
2802
2784
=cut
2803
=cut
2785
2804
2786
sub EmbedItemsInMarcBiblio {
2805
sub EmbedItemsInMarcBiblio {
2787
    my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
2806
    my ($params) = @_;
2807
    my ($marc, $biblionumber, $itemnumbers, $opac, $borcat);
2808
    $marc = $params->{marc_record};
2788
    if ( !$marc ) {
2809
    if ( !$marc ) {
2789
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2810
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2790
        return;
2811
        return;
2791
    }
2812
    }
2813
    $biblionumber = $params->{biblionumber};
2814
    $itemnumbers = $params->{item_numbers};
2815
    $opac = $params->{opac};
2816
    $borcat = $params->{borcat} // q{};
2792
2817
2793
    $itemnumbers = [] unless defined $itemnumbers;
2818
    $itemnumbers = [] unless defined $itemnumbers;
2794
2819
Lines 2799-2818 sub EmbedItemsInMarcBiblio { Link Here
2799
    my $dbh = C4::Context->dbh;
2824
    my $dbh = C4::Context->dbh;
2800
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2825
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2801
    $sth->execute($biblionumber);
2826
    $sth->execute($biblionumber);
2802
    my @item_fields;
2803
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2827
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2804
    my @items;
2828
2829
    my @item_fields; # Array holding the actual MARC data for items to be included.
2830
    my @items;       # Array holding items which are both in the list (sitenumbers)
2831
                     # and on this biblionumber
2832
2833
    # Flag indicating if there is potential hiding.
2805
    my $opachiddenitems = $opac
2834
    my $opachiddenitems = $opac
2806
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2835
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2836
2807
    require C4::Items;
2837
    require C4::Items;
2808
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2838
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2809
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2839
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2810
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2840
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2811
        push @items, { itemnumber => $itemnumber, item => $i };
2841
        push @items, { itemnumber => $itemnumber, item => $i };
2812
    }
2842
    }
2843
    my @items2pass = map { $_->{item} } @items;
2813
    my @hiddenitems =
2844
    my @hiddenitems =
2814
      $opachiddenitems
2845
      $opachiddenitems
2815
      ? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
2846
      ? C4::Items::GetHiddenItemnumbers({
2847
            items  => \@items2pass,
2848
            borcat => $borcat })
2816
      : ();
2849
      : ();
2817
    # Convert to a hash for quick searching
2850
    # Convert to a hash for quick searching
2818
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2851
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
(-)a/C4/Record.pm (-1 / +4 lines)
Lines 472-478 sub marcrecord2csv { Link Here
472
    # Getting the record
472
    # Getting the record
473
    my $record = GetMarcBiblio({ biblionumber => $biblio });
473
    my $record = GetMarcBiblio({ biblionumber => $biblio });
474
    return unless $record;
474
    return unless $record;
475
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblio, $itemnumbers );
475
    C4::Biblio::EmbedItemsInMarcBiblio({
476
        marc_record  => $record,
477
        biblionumber => $biblio,
478
        item_numbers => $itemnumbers });
476
    # Getting the framework
479
    # Getting the framework
477
    my $frameworkcode = GetFrameworkCode($biblio);
480
    my $frameworkcode = GetFrameworkCode($biblio);
478
481
(-)a/C4/Search.pm (-3 / +3 lines)
Lines 1905-1911 sub searchResults { Link Here
1905
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1905
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1906
1906
1907
    # set stuff for XSLT processing here once, not later again for every record we retrieved
1907
    # set stuff for XSLT processing here once, not later again for every record we retrieved
1908
    my $interface = $search_context eq 'opac' ? 'OPAC' : '';
1908
    my $interface = $is_opac ? 'OPAC' : '';
1909
    my $xslsyspref = $interface . "XSLTResultsDisplay";
1909
    my $xslsyspref = $interface . "XSLTResultsDisplay";
1910
    my $xslfile = C4::Context->preference($xslsyspref);
1910
    my $xslfile = C4::Context->preference($xslsyspref);
1911
    my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
1911
    my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
Lines 2206-2212 sub searchResults { Link Here
2206
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2206
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2207
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2207
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2208
					$other_items->{$key}->{description} = $item->{description};
2208
					$other_items->{$key}->{description} = $item->{description};
2209
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2209
                    $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2210
                }
2210
                }
2211
                # item is available
2211
                # item is available
2212
                else {
2212
                else {
Lines 2217-2223 sub searchResults { Link Here
2217
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2217
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2218
					}
2218
					}
2219
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2219
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2220
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2220
                    $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} );
2221
                }
2221
                }
2222
            }
2222
            }
2223
        }    # notforloan, item level and biblioitem level
2223
        }    # 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 735-741 my @big_array; Link Here
735
#---- finds where items.itemnumber is stored
735
#---- finds where items.itemnumber is stored
736
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
736
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
737
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
737
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
738
C4::Biblio::EmbedItemsInMarcBiblio($temp, $biblionumber);
738
C4::Biblio::EmbedItemsInMarcBiblio({
739
    marc_record  => $temp,
740
    biblionumber => $biblionumber });
739
my @fields = $temp->fields();
741
my @fields = $temp->fields();
740
742
741
743
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt (+2 lines)
Lines 130-135 Link Here
130
                                <thead><tr><th>&nbsp;</th><th>Term</th><th>Title</th><th>Date added</th></tr></thead>
130
                                <thead><tr><th>&nbsp;</th><th>Term</th><th>Title</th><th>Date added</th></tr></thead>
131
                                <tbody>
131
                                <tbody>
132
                                    [% FOREACH MY_TAG IN MY_TAGS %]
132
                                    [% FOREACH MY_TAG IN MY_TAGS %]
133
                                        [% IF MY_TAG.visible %]
133
                                        <tr>
134
                                        <tr>
134
                                            <td>
135
                                            <td>
135
                                                <input type="checkbox" name="del[% MY_TAG.tag_id | html %]" value="del[% MY_TAG.tag_id | html %]">
136
                                                <input type="checkbox" name="del[% MY_TAG.tag_id | html %]" value="del[% MY_TAG.tag_id | html %]">
Lines 167-172 Link Here
167
                                                </span>
168
                                                </span>
168
                                            </td>
169
                                            </td>
169
                                        </tr>
170
                                        </tr>
171
                                        [% END %]
170
                                    [% END %]
172
                                    [% END %]
171
                                </tbody>
173
                                </tbody>
172
                            </table>
174
                            </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 64-109 use Koha::ItemTypes; Link Here
64
use Koha::Patrons;
64
use Koha::Patrons;
65
use Koha::RecordProcessor;
65
use Koha::RecordProcessor;
66
66
67
my $query = new CGI;
67
my $query = CGI->new();
68
69
my $dbh = C4::Context->dbh;
70
68
71
my $biblionumber = $query->param('biblionumber');
69
my $biblionumber = $query->param('biblionumber');
72
if ( ! $biblionumber ) {
70
if ( ! $biblionumber ) {
73
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
71
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
74
    exit;
72
    exit;
75
}
73
}
74
$biblionumber = int($biblionumber);
75
76
# open template
77
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78
    {
79
        template_name   => "opac-MARCdetail.tt",
80
        query           => $query,
81
        type            => "opac",
82
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
83
        debug           => 1,
84
    }
85
);
86
87
my $patron = Koha::Patrons->find( $loggedinuser );
88
my $borcat = q{};
89
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
90
    # we need to fetch the borrower info here, so we can pass the category
91
    $borcat = $patron ? $patron->categorycode : $borcat;
92
}
76
93
77
my $record = GetMarcBiblio({
94
my $record = GetMarcBiblio({
78
    biblionumber => $biblionumber,
95
    biblionumber => $biblionumber,
79
    embed_items  => 1 });
96
    embed_items  => 1,
97
    opac         => 1,
98
    borcat       => $borcat });
80
if ( ! $record ) {
99
if ( ! $record ) {
81
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
100
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
82
    exit;
101
    exit;
83
}
102
}
84
103
85
my @all_items = GetItemsInfo($biblionumber);
104
my @all_items = GetItemsInfo($biblionumber);
86
my @items2hide;
105
my $biblio = Koha::Biblios->find( $biblionumber );
87
if (scalar @all_items >= 1) {
106
my $framework = $biblio ? $biblio->frameworkcode : q{};
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
    push @items2hide, GetHiddenItemnumbers({ items => \@all_items, borcat => $botcat });
96
97
    if (scalar @items2hide == scalar @all_items ) {
98
        print $query->redirect("/cgi-bin/koha/errors/404.pl");
99
        exit;
100
    }
101
}
102
103
my $framework = &GetFrameworkCode( $biblionumber );
104
my $tagslib = &GetMarcStructure( 0, $framework );
107
my $tagslib = &GetMarcStructure( 0, $framework );
105
my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
108
my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
106
my $biblio = Koha::Biblios->find( $biblionumber );
109
my @nonhiddenitems = $record->field($tag_itemnumber);
110
if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) {
111
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
112
    exit;
113
}
107
114
108
my $record_processor = Koha::RecordProcessor->new({
115
my $record_processor = Koha::RecordProcessor->new({
109
    filters => 'ViewPolicy',
116
    filters => 'ViewPolicy',
Lines 114-136 my $record_processor = Koha::RecordProcessor->new({ Link Here
114
});
121
});
115
$record_processor->process($record);
122
$record_processor->process($record);
116
123
117
# open template
118
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
119
    {
120
        template_name   => "opac-MARCdetail.tt",
121
        query           => $query,
122
        type            => "opac",
123
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
124
        debug           => 1,
125
    }
126
);
127
128
my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework);
129
$template->param(
130
    bibliotitle => $biblio->title,
131
) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible.
132
     $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8;   # except -8;
133
134
# get biblionumbers stored in the cart
124
# get biblionumbers stored in the cart
135
if(my $cart_list = $query->cookie("bib_list")){
125
if(my $cart_list = $query->cookie("bib_list")){
136
    my @cart_list = split(/\//, $cart_list);
126
    my @cart_list = split(/\//, $cart_list);
Lines 139-146 if(my $cart_list = $query->cookie("bib_list")){ Link Here
139
    }
129
    }
140
}
130
}
141
131
132
my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework);
133
$template->param(
134
    bibliotitle => $biblio->title,
135
) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible.
136
     $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8;   # except -8;
137
142
my $allow_onshelf_holds;
138
my $allow_onshelf_holds;
143
my $patron = Koha::Patrons->find( $loggedinuser );
144
for my $itm (@all_items) {
139
for my $itm (@all_items) {
145
    my $item = Koha::Items->find( $itm->{itemnumber} );
140
    my $item = Koha::Items->find( $itm->{itemnumber} );
146
    $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
141
    $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
Lines 279-284 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) { Link Here
279
# loop through each tag
274
# loop through each tag
280
# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
275
# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
281
# then construct template.
276
# then construct template.
277
# $record has already had all the item fields filtered above.
282
my @fields = $record->fields();
278
my @fields = $record->fields();
283
my %witness
279
my %witness
284
  ; #---- stores the list of subfields used at least once, with the "meaning" of the code
280
  ; #---- stores the list of subfields used at least once, with the "meaning" of the code
Lines 286-294 my @item_subfield_codes; Link Here
286
my @item_loop;
282
my @item_loop;
287
foreach my $field (@fields) {
283
foreach my $field (@fields) {
288
    next if ( $field->tag() < 10 );
284
    next if ( $field->tag() < 10 );
289
    next if ( ( $field->tag() eq $tag_itemnumber ) &&
290
              ( any { $field->subfield($subtag_itemnumber) eq $_ }
291
                   @items2hide) );
292
    my @subf = $field->subfields;
285
    my @subf = $field->subfields;
293
    my $item;
286
    my $item;
294
287
(-)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 239-248 if ($session->param('busc')) { Link Here
239
        };
240
        };
240
        my $hits;
241
        my $hits;
241
        my @newresults;
242
        my @newresults;
243
        my $search_context = {
244
            'interface' => 'opac',
245
            'category'  => $borcat
246
        };
242
        for (my $i=0;$i<@servers;$i++) {
247
        for (my $i=0;$i<@servers;$i++) {
243
            my $server = $servers[$i];
248
            my $server = $servers[$i];
244
            $hits = $results_hashref->{$server}->{"hits"};
249
            $hits = $results_hashref->{$server}->{"hits"};
245
            @newresults = searchResults({ 'interface' => 'opac' }, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
250
            @newresults = searchResults( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
246
        }
251
        }
247
        return \@newresults;
252
        return \@newresults;
248
    }#searchAgain
253
    }#searchAgain
Lines 670-676 if ( not $viewallitems and @items > $max_items_to_display ) { Link Here
670
        items_count => scalar( @items ),
675
        items_count => scalar( @items ),
671
    );
676
    );
672
} else {
677
} else {
673
  my $patron = Koha::Patrons->find( $borrowernumber );
674
  for my $itm (@items) {
678
  for my $itm (@items) {
675
    my $item = Koha::Items->find( $itm->{itemnumber} );
679
    my $item = Koha::Items->find( $itm->{itemnumber} );
676
    $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
680
    $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
Lines 865-880 if ( C4::Context->preference('reviewson') ) { Link Here
865
        }
869
        }
866
    }
870
    }
867
    for my $review (@$reviews) {
871
    for my $review (@$reviews) {
868
        my $patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
872
        my $review_patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
869
873
870
        # setting some borrower info into this hash
874
        # setting some borrower info into this hash
871
        if ( $patron ) {
875
        if ( $review_patron ) {
872
            $review->{patron} = $patron;
876
            $review->{patron} = $review_patron;
873
            if ( $libravatar_enabled and $patron->email ) {
877
            if ( $libravatar_enabled and $review_patron->email ) {
874
                $review->{avatarurl} = libravatar_url( email => $patron->email, https => $ENV{HTTPS} );
878
                $review->{avatarurl} = libravatar_url( email => $review_patron->email, https => $ENV{HTTPS} );
875
            }
879
            }
876
880
877
            if ( $patron->borrowernumber eq $borrowernumber ) {
881
            if ( $review_patron->borrowernumber eq $borrowernumber ) {
878
                $loggedincommenter = 1;
882
                $loggedincommenter = 1;
879
            }
883
            }
880
        }
884
        }
(-)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 596-601 if ($tag) { Link Here
596
    $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
596
    $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
597
    $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
597
    $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
598
    # FIXME: tag search and standard search should work together, not exclusively
598
    # FIXME: tag search and standard search should work together, not exclusively
599
    # FIXME: Because search and standard search don't work together OpacHiddenItems
600
    #        displays search results which should be hidden.
599
    # FIXME: No facets for tags search.
601
    # FIXME: No facets for tags search.
600
} elsif ($build_grouped_results) {
602
} elsif ($build_grouped_results) {
601
    eval {
603
    eval {
Lines 626-633 my $search_context = {}; Link Here
626
$search_context->{'interface'} = 'opac';
628
$search_context->{'interface'} = 'opac';
627
if (C4::Context->preference('OpacHiddenItemsExceptions')){
629
if (C4::Context->preference('OpacHiddenItemsExceptions')){
628
    # we need to fetch the borrower info here, so we can pass the category
630
    # we need to fetch the borrower info here, so we can pass the category
629
    my $borrower = GetMember( borrowernumber => $borrowernumber );
631
    my $patron = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
630
    $search_context->{'category'} = $borrower->{'categorycode'};
632
    $search_context->{'category'} = $patron ? $patron->categorycode : q{};
631
}
633
}
632
634
633
for (my $i=0;$i<@servers;$i++) {
635
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 79-84 if ( $email ) { Link Here
79
        }
79
        }
80
    );
80
    );
81
81
82
    my $patron = Koha::Patrons->find( $borrowernumber );
83
    my $borcat = $patron ? $patron->categorycode : q{};
84
82
    my $shelf = Koha::Virtualshelves->find( $shelfid );
85
    my $shelf = Koha::Virtualshelves->find( $shelfid );
83
    my $contents = $shelf->get_contents;
86
    my $contents = $shelf->get_contents;
84
    my $marcflavour         = C4::Context->preference('marcflavour');
87
    my $marcflavour         = C4::Context->preference('marcflavour');
Lines 87-97 if ( $email ) { Link Here
87
90
88
    while ( my $content = $contents->next ) {
91
    while ( my $content = $contents->next ) {
89
        my $biblionumber = $content->biblionumber;
92
        my $biblionumber = $content->biblionumber;
90
        my $fw               = GetFrameworkCode($biblionumber);
91
        my $dat              = GetBiblioData($biblionumber);
92
        my $record           = GetMarcBiblio({
93
        my $record           = GetMarcBiblio({
93
            biblionumber => $biblionumber,
94
            biblionumber => $biblionumber,
94
            embed_items  => 1 });
95
            embed_items  => 1,
96
            opac         => 1,
97
            borcat       => $borcat });
98
        next unless $record;
99
        my $fw               = GetFrameworkCode($biblionumber);
100
        my $dat              = GetBiblioData($biblionumber);
101
95
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
102
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
96
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
103
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
97
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
104
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
Lines 111-118 if ( $email ) { Link Here
111
        push( @results, $dat );
118
        push( @results, $dat );
112
    }
119
    }
113
120
114
    my $patron = Koha::Patrons->find( $borrowernumber );
115
116
    $template2->param(
121
    $template2->param(
117
        BIBLIO_RESULTS => \@results,
122
        BIBLIO_RESULTS => \@results,
118
        comment        => $comment,
123
        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 90-95 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth Link Here
90
# get borrower information ....
90
# get borrower information ....
91
my $patron = Koha::Patrons->find( $borrowernumber );
91
my $patron = Koha::Patrons->find( $borrowernumber );
92
my $borr = $patron->unblessed;
92
my $borr = $patron->unblessed;
93
# unblessed is a hash vs. object/undef. Hence the use of curly braces here.
94
my $borcat = $borr ? $borr->{categorycode} : q{};
93
95
94
my (  $today_year,   $today_month,   $today_day) = Today();
96
my (  $today_year,   $today_month,   $today_day) = Today();
95
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
97
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
Lines 215-221 if ( $pending_checkouts->count ) { # Useless test Link Here
215
        );
217
        );
216
        $issue->{rentalfines} = $rental_fines->count ? $rental_fines->next->get_column('rental_fines') : 0;
218
        $issue->{rentalfines} = $rental_fines->count ? $rental_fines->next->get_column('rental_fines') : 0;
217
219
218
        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
220
        my $marcrecord = GetMarcBiblio({
221
            biblionumber => $issue->{'biblionumber'},
222
            embed_items  => 1,
223
            opac         => 1,
224
            borcat       => $borcat });
219
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
225
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
220
        # check if item is renewable
226
        # check if item is renewable
221
        my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
227
        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 113-118 subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes Link Here
113
    $schema->resultset( 'BorrowerAttributeType' )->delete_all;
113
    $schema->resultset( 'BorrowerAttributeType' )->delete_all;
114
    $schema->resultset( 'Category' )->delete_all;
114
    $schema->resultset( 'Category' )->delete_all;
115
    $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
115
    $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
116
    $schema->resultset( 'Club' )->delete_all;
116
    $schema->resultset( 'Branch' )->delete_all;
117
    $schema->resultset( 'Branch' )->delete_all;
117
118
118
    # Configure Koha to enable ILS-DI server and extended attributes:
119
    # Configure Koha to enable ILS-DI server and extended attributes:
Lines 287-289 subtest 'LookupPatron test' => sub { Link Here
287
    # Cleanup
288
    # Cleanup
288
    $schema->storage->txn_rollback;
289
    $schema->storage->txn_rollback;
289
};
290
};
291
292
# This is a stub, as it merely is for triggering the GetMarcBiblio call.
293
subtest 'GetRecords' => sub {
294
295
    plan tests => 1;
296
297
    $schema->storage->txn_begin;
298
299
    my $biblio = $builder->build({
300
        source => 'Biblio',
301
        value  => {
302
            title => 'Title 1',    },
303
    });
304
305
    my $item = $builder->build({
306
        source => 'Item',
307
        value  => {
308
            biblionumber => $biblio->{biblionumber},
309
        },
310
    });
311
312
    my $biblioitem = $builder->build({
313
        source => 'Biblioitem',
314
        value  => {
315
            biblionumber => $biblio->{biblionumber},
316
            itemnumber   => $item->{itemnumber},
317
        },
318
    });
319
320
    my $query = CGI->new({
321
        'schema' => 'MARCXML',
322
        'id'     => [ $biblio->{biblionumber} ]
323
    });
324
325
    my $result = C4::ILSDI::Services::GetRecords($query);
326
    ok($result,'There is a result');
327
328
    $schema->storage->txn_rollback;
329
}
(-)a/t/db_dependent/Items.t (-14 / +39 lines)
Lines 34-40 use t::lib::Mocks; Link Here
34
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
35
35
36
use Test::More tests => 12;
36
use Test::More tests => 12;
37
38
use Test::Warn;
37
use Test::Warn;
39
38
40
my $schema = Koha::Database->new->schema;
39
my $schema = Koha::Database->new->schema;
Lines 142-148 subtest 'ModItem tests' => sub { Link Here
142
141
143
subtest 'GetHiddenItemnumbers tests' => sub {
142
subtest 'GetHiddenItemnumbers tests' => sub {
144
143
145
    plan tests => 9;
144
    plan tests => 11;
146
145
147
    # This sub is controlled by the OpacHiddenItems system preference.
146
    # This sub is controlled by the OpacHiddenItems system preference.
148
147
Lines 192-203 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
192
    push @items, GetItem( $item2_itemnumber );
191
    push @items, GetItem( $item2_itemnumber );
193
192
194
    # Empty OpacHiddenItems
193
    # Empty OpacHiddenItems
195
    C4::Context->set_preference('OpacHiddenItems','');
194
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
196
    ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ),
195
    ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ),
197
        "Hidden items list undef if OpacHiddenItems empty");
196
        "Hidden items list undef if OpacHiddenItems empty");
198
197
199
    # Blank spaces
198
    # Blank spaces
200
    C4::Context->set_preference('OpacHiddenItems','  ');
199
    t::lib::Mocks::mock_preference('OpacHiddenItems','  ');
201
    ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0,
200
    ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0,
202
        "Hidden items list empty if OpacHiddenItems only contains blanks");
201
        "Hidden items list empty if OpacHiddenItems only contains blanks");
203
202
Lines 213-219 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
213
    $opachiddenitems = "
212
    $opachiddenitems = "
214
        withdrawn: [1,0]";
213
        withdrawn: [1,0]";
215
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
214
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
216
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
217
    @hidden = GetHiddenItemnumbers( { items => \@items } );
215
    @hidden = GetHiddenItemnumbers( { items => \@items } );
218
    ok( scalar @hidden == 2, "Two items hidden");
216
    ok( scalar @hidden == 2, "Two items hidden");
219
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
217
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
Lines 228-233 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
228
    ok( scalar @hidden == 2, "Two items hidden");
226
    ok( scalar @hidden == 2, "Two items hidden");
229
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
227
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
230
228
229
    # Override hidden with patron category
230
    t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', 'S' );
231
    @hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'PT' } );
232
    ok( scalar @hidden == 2, "Two items still hidden");
233
    @hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'S' } );
234
    ok( scalar @hidden == 0, "Two items not hidden");
235
231
    # Valid OpacHiddenItems, empty list
236
    # Valid OpacHiddenItems, empty list
232
    @items = ();
237
    @items = ();
233
    @hidden = GetHiddenItemnumbers( { items => \@items } );
238
    @hidden = GetHiddenItemnumbers( { items => \@items } );
Lines 548-554 subtest 'Koha::Item(s) tests' => sub { Link Here
548
};
553
};
549
554
550
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
555
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
551
    plan tests => 7;
556
    plan tests => 8;
552
557
553
    $schema->storage->txn_begin();
558
    $schema->storage->txn_begin();
554
559
Lines 599-616 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
599
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
604
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
600
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
605
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
601
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
606
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
602
      'Should crap is no record passed.';
607
      'Should carp is no record passed.';
603
608
604
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
609
    C4::Biblio::EmbedItemsInMarcBiblio({
610
        marc_record  => $record,
611
        biblionumber => $biblionumber });
605
    my @items = $record->field($itemfield);
612
    my @items = $record->field($itemfield);
606
    is( scalar @items, $number_of_items, 'Should return all items' );
613
    is( scalar @items, $number_of_items, 'Should return all items' );
607
614
608
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber,
615
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
609
        [ $itemnumbers[1], $itemnumbers[3] ] );
616
        biblionumber => $biblionumber,
617
        embed_items  => 1 });
618
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
619
620
    C4::Biblio::EmbedItemsInMarcBiblio({
621
        marc_record  => $record,
622
        biblionumber => $biblionumber,
623
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
610
    @items = $record->field($itemfield);
624
    @items = $record->field($itemfield);
611
    is( scalar @items, 2, 'Should return all items present in the list' );
625
    is( scalar @items, 2, 'Should return all items present in the list' );
612
626
613
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
627
    C4::Biblio::EmbedItemsInMarcBiblio({
628
        marc_record  => $record,
629
        biblionumber => $biblionumber,
630
        opac         => 1 });
614
    @items = $record->field($itemfield);
631
    @items = $record->field($itemfield);
615
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
632
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
616
633
Lines 618-630 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
618
        homebranch: ['$library1->{branchcode}']";
635
        homebranch: ['$library1->{branchcode}']";
619
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
636
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
620
637
621
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
638
    C4::Biblio::EmbedItemsInMarcBiblio({
639
        marc_record  => $record,
640
        biblionumber => $biblionumber });
622
    @items = $record->field($itemfield);
641
    @items = $record->field($itemfield);
623
    is( scalar @items,
642
    is( scalar @items,
624
        $number_of_items,
643
        $number_of_items,
625
        'Even with OpacHiddenItems set, all items should have been embedded' );
644
        'Even with OpacHiddenItems set, all items should have been embedded' );
626
645
627
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
646
    C4::Biblio::EmbedItemsInMarcBiblio({
647
        marc_record  => $record,
648
        biblionumber => $biblionumber,
649
        opac         => 1 });
628
    @items = $record->field($itemfield);
650
    @items = $record->field($itemfield);
629
    is(
651
    is(
630
        scalar @items,
652
        scalar @items,
Lines 635-641 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
635
    $opachiddenitems = "
657
    $opachiddenitems = "
636
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
658
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
637
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
659
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
638
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
660
    C4::Biblio::EmbedItemsInMarcBiblio({
661
        marc_record  => $record,
662
        biblionumber => $biblionumber,
663
        opac         => 1 });
639
    @items = $record->field($itemfield);
664
    @items = $record->field($itemfield);
640
    is(
665
    is(
641
        scalar @items,
666
        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