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

(-)a/C4/Biblio.pm (-7 / +40 lines)
Lines 1166-1172 sub GetMarcSubfieldStructureFromKohaField { Link Here
1166
  my $record = GetMarcBiblio({
1166
  my $record = GetMarcBiblio({
1167
      biblionumber => $biblionumber,
1167
      biblionumber => $biblionumber,
1168
      embed_items  => $embeditems,
1168
      embed_items  => $embeditems,
1169
      opac         => $opac });
1169
      opac         => $opac,
1170
      borcat       => $patron_category });
1170
1171
1171
Returns MARC::Record representing a biblio record, or C<undef> if the
1172
Returns MARC::Record representing a biblio record, or C<undef> if the
1172
biblionumber doesn't exist.
1173
biblionumber doesn't exist.
Lines 1190-1195 set to true to include item information. Link Here
1190
set to true to make the result suited for OPAC view. This causes things like
1191
set to true to make the result suited for OPAC view. This causes things like
1191
OpacHiddenItems to be applied.
1192
OpacHiddenItems to be applied.
1192
1193
1194
=item C<$borcat>
1195
1196
If the OpacHiddenItemsExceptions system preference is set, this patron category
1197
can be used to make visible OPAC items which would be normally hidden.
1198
It only makes sense in combination both embed_items and opac values true.
1199
1193
=back
1200
=back
1194
1201
1195
=cut
1202
=cut
Lines 1205-1210 sub GetMarcBiblio { Link Here
1205
    my $biblionumber = $params->{biblionumber};
1212
    my $biblionumber = $params->{biblionumber};
1206
    my $embeditems   = $params->{embed_items} || 0;
1213
    my $embeditems   = $params->{embed_items} || 0;
1207
    my $opac         = $params->{opac} || 0;
1214
    my $opac         = $params->{opac} || 0;
1215
    my $borcat       = $params->{borcat} // q{};
1208
1216
1209
    if (not defined $biblionumber) {
1217
    if (not defined $biblionumber) {
1210
        carp 'GetMarcBiblio called with undefined biblionumber';
1218
        carp 'GetMarcBiblio called with undefined biblionumber';
Lines 1232-1238 sub GetMarcBiblio { Link Here
1232
1240
1233
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1241
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1234
            $biblioitemnumber );
1242
            $biblioitemnumber );
1235
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1243
        C4::Biblio::EmbedItemsInMarcBiblio({
1244
            marc_record  => $record,
1245
            biblionumber => $biblionumber,
1246
            opac         => $opac,
1247
            borcat       => $borcat })
1236
          if ($embeditems);
1248
          if ($embeditems);
1237
1249
1238
        return $record;
1250
        return $record;
Lines 2805-2811 sub ModZebra { Link Here
2805
2817
2806
=head2 EmbedItemsInMarcBiblio
2818
=head2 EmbedItemsInMarcBiblio
2807
2819
2808
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2820
    EmbedItemsInMarcBiblio({
2821
        marc_record  => $marc,
2822
        biblionumber => $biblionumber,
2823
        item_numbers => $itemnumbers,
2824
        opac         => $opac });
2809
2825
2810
Given a MARC::Record object containing a bib record,
2826
Given a MARC::Record object containing a bib record,
2811
modify it to include the items attached to it as 9XX
2827
modify it to include the items attached to it as 9XX
Lines 2814-2827 if $itemnumbers is defined, only specified itemnumbers are embedded. Link Here
2814
2830
2815
If $opac is true, then opac-relevant suppressions are included.
2831
If $opac is true, then opac-relevant suppressions are included.
2816
2832
2833
If opac filtering will be done, borcat should be passed to properly
2834
override if necessary.
2835
2817
=cut
2836
=cut
2818
2837
2819
sub EmbedItemsInMarcBiblio {
2838
sub EmbedItemsInMarcBiblio {
2820
    my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
2839
    my ($params) = @_;
2840
    my ($marc, $biblionumber, $itemnumbers, $opac, $borcat);
2841
    $marc = $params->{marc_record};
2821
    if ( !$marc ) {
2842
    if ( !$marc ) {
2822
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2843
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2823
        return;
2844
        return;
2824
    }
2845
    }
2846
    $biblionumber = $params->{biblionumber};
2847
    $itemnumbers = $params->{item_numbers};
2848
    $opac = $params->{opac};
2849
    $borcat = $params->{borcat} // q{};
2825
2850
2826
    $itemnumbers = [] unless defined $itemnumbers;
2851
    $itemnumbers = [] unless defined $itemnumbers;
2827
2852
Lines 2832-2851 sub EmbedItemsInMarcBiblio { Link Here
2832
    my $dbh = C4::Context->dbh;
2857
    my $dbh = C4::Context->dbh;
2833
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2858
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2834
    $sth->execute($biblionumber);
2859
    $sth->execute($biblionumber);
2835
    my @item_fields;
2836
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2860
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2837
    my @items;
2861
2862
    my @item_fields; # Array holding the actual MARC data for items to be included.
2863
    my @items;       # Array holding items which are both in the list (sitenumbers)
2864
                     # and on this biblionumber
2865
2866
    # Flag indicating if there is potential hiding.
2838
    my $opachiddenitems = $opac
2867
    my $opachiddenitems = $opac
2839
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2868
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2869
2840
    require C4::Items;
2870
    require C4::Items;
2841
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2871
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2842
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2872
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2843
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2873
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2844
        push @items, { itemnumber => $itemnumber, item => $i };
2874
        push @items, { itemnumber => $itemnumber, item => $i };
2845
    }
2875
    }
2876
    my @items2pass = map { $_->{item} } @items;
2846
    my @hiddenitems =
2877
    my @hiddenitems =
2847
      $opachiddenitems
2878
      $opachiddenitems
2848
      ? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
2879
      ? C4::Items::GetHiddenItemnumbers({
2880
            items  => \@items2pass,
2881
            borcat => $borcat })
2849
      : ();
2882
      : ();
2850
    # Convert to a hash for quick searching
2883
    # Convert to a hash for quick searching
2851
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2884
    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 58-63 if (C4::Context->preference('TagsEnabled')) { Link Here
58
	}
58
	}
59
}
59
}
60
60
61
my $borcat = q{};
62
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
63
    # we need to fetch the borrower info here, so we can pass the category
64
    my $borrower = Koha::Patron->find( { borrowernumber -> $borrowernumber } );
65
    $borcat = $borrower ? $borrower->categorycode : $borcat;
66
}
67
61
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
68
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
62
foreach my $biblionumber ( @bibs ) {
69
foreach my $biblionumber ( @bibs ) {
63
    $template->param( biblionumber => $biblionumber );
70
    $template->param( biblionumber => $biblionumber );
Lines 65-70 foreach my $biblionumber ( @bibs ) { Link Here
65
    my $dat              = &GetBiblioData($biblionumber);
72
    my $dat              = &GetBiblioData($biblionumber);
66
    next unless $dat;
73
    next unless $dat;
67
74
75
    # No filtering on the item records needed for the record itself
76
    # since the only reason item information is grabbed is because of branchcodes.
68
    my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
77
    my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
69
    my $framework = &GetFrameworkCode( $biblionumber );
78
    my $framework = &GetFrameworkCode( $biblionumber );
70
    $record_processor->options({
79
    $record_processor->options({
Lines 78-84 foreach my $biblionumber ( @bibs ) { Link Here
78
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
79
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
88
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
80
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
89
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
81
    my @items            = &GetItemsInfo( $biblionumber );
90
91
    # grab all the items...
92
    my @all_items        = &GetItemsInfo( $biblionumber );
93
94
    # determine which ones should be hidden / visible
95
    my @hidden_items     = GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat });
96
97
    # If every item is hidden, then the biblio should be hidden too.
98
    next if (scalar @all_items >= 1 && scalar @hidden_items == scalar @all_items);
99
100
    # copy the visible ones into the items array.
101
    my @items;
102
    foreach my $item (@all_items) {
103
        if ( none { $item->{itemnumber} ne $_ } @hidden_items ) {
104
            push @items, $item;
105
        }
106
    }
107
82
    my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
108
    my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
83
109
84
    my $hasauthors = 0;
110
    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 857-872 if ( C4::Context->preference('reviewson') ) { Link Here
857
        }
861
        }
858
    }
862
    }
859
    for my $review (@$reviews) {
863
    for my $review (@$reviews) {
860
        my $patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
864
        my $review_patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
861
865
862
        # setting some borrower info into this hash
866
        # setting some borrower info into this hash
863
        if ( $patron ) {
867
        if ( $review_patron ) {
864
            $review->{patron} = $patron;
868
            $review->{patron} = $review_patron;
865
            if ( $libravatar_enabled and $patron->email ) {
869
            if ( $libravatar_enabled and $review_patron->email ) {
866
                $review->{avatarurl} = libravatar_url( email => $patron->email, https => $ENV{HTTPS} );
870
                $review->{avatarurl} = libravatar_url( email => $review_patron->email, https => $ENV{HTTPS} );
867
            }
871
            }
868
872
869
            if ( $patron->borrowernumber eq $borrowernumber ) {
873
            if ( $review_patron->borrowernumber eq $borrowernumber ) {
870
                $loggedincommenter = 1;
874
                $loggedincommenter = 1;
871
            }
875
            }
872
        }
876
        }
(-)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 598-603 if ($tag) { Link Here
598
    $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
598
    $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
599
    $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
599
    $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
600
    # FIXME: tag search and standard search should work together, not exclusively
600
    # FIXME: tag search and standard search should work together, not exclusively
601
    # FIXME: Because search and standard search don't work together OpacHiddenItems
602
    #        displays search results which should be hidden.
601
    # FIXME: No facets for tags search.
603
    # FIXME: No facets for tags search.
602
} elsif ($build_grouped_results) {
604
} elsif ($build_grouped_results) {
603
    eval {
605
    eval {
Lines 628-635 my $search_context = {}; Link Here
628
$search_context->{'interface'} = 'opac';
630
$search_context->{'interface'} = 'opac';
629
if (C4::Context->preference('OpacHiddenItemsExceptions')){
631
if (C4::Context->preference('OpacHiddenItemsExceptions')){
630
    # we need to fetch the borrower info here, so we can pass the category
632
    # we need to fetch the borrower info here, so we can pass the category
631
    my $borrower = GetMember( borrowernumber => $borrowernumber );
633
    my $patron = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
632
    $search_context->{'category'} = $borrower->{'categorycode'};
634
    $search_context->{'category'} = $patron ? $patron->categorycode : q{};
633
}
635
}
634
636
635
for (my $i=0;$i<@servers;$i++) {
637
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 : q{};
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 91-96 if (!$borrowernumber) { Link Here
91
# get borrower information ....
91
# get borrower information ....
92
my $patron = Koha::Patrons->find( $borrowernumber );
92
my $patron = Koha::Patrons->find( $borrowernumber );
93
my $borr = $patron->unblessed;
93
my $borr = $patron->unblessed;
94
# unblessed is a hash vs. object/undef. Hence the use of curly braces here.
95
my $borcat = $borr ? $borr->{categorycode} : q{};
94
96
95
my (  $today_year,   $today_month,   $today_day) = Today();
97
my (  $today_year,   $today_month,   $today_day) = Today();
96
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
98
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
Lines 215-221 if ($issues){ Link Here
215
        );
217
        );
216
        $issue->{rentalfines} = $charges->count ? $charges->next->get_column('rental_fines') : 0;
218
        $issue->{rentalfines} = $charges->count ? $charges->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 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 (-13 / +39 lines)
Lines 32-38 use t::lib::TestBuilder; Link Here
32
use Koha::MarcSubfieldStructures;
32
use Koha::MarcSubfieldStructures;
33
use Koha::Caches;
33
use Koha::Caches;
34
34
35
use Test::More tests => 13;
35
use Test::More tests => 15;
36
36
37
use Test::Warn;
37
use Test::Warn;
38
38
Lines 196-207 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
196
    push @items, GetItem( $item2_itemnumber );
196
    push @items, GetItem( $item2_itemnumber );
197
197
198
    # Empty OpacHiddenItems
198
    # Empty OpacHiddenItems
199
    C4::Context->set_preference('OpacHiddenItems','');
199
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
200
    ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ),
200
    ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ),
201
        "Hidden items list undef if OpacHiddenItems empty");
201
        "Hidden items list undef if OpacHiddenItems empty");
202
202
203
    # Blank spaces
203
    # Blank spaces
204
    C4::Context->set_preference('OpacHiddenItems','  ');
204
    t::lib::Mocks::mock_preference('OpacHiddenItems','  ');
205
    ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0,
205
    ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0,
206
        "Hidden items list empty if OpacHiddenItems only contains blanks");
206
        "Hidden items list empty if OpacHiddenItems only contains blanks");
207
207
Lines 217-223 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
217
    $opachiddenitems = "
217
    $opachiddenitems = "
218
        withdrawn: [1,0]";
218
        withdrawn: [1,0]";
219
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
219
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
220
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
221
    @hidden = GetHiddenItemnumbers( { items => \@items } );
220
    @hidden = GetHiddenItemnumbers( { items => \@items } );
222
    ok( scalar @hidden == 2, "Two items hidden");
221
    ok( scalar @hidden == 2, "Two items hidden");
223
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
222
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
Lines 232-237 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
232
    ok( scalar @hidden == 2, "Two items hidden");
231
    ok( scalar @hidden == 2, "Two items hidden");
233
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
232
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
234
233
234
    # Override hidden with patron category
235
    t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', 'S' );
236
    @hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'PT' } );
237
    ok( scalar @hidden == 2, "Two items still hidden");
238
    @hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'S' } );
239
    ok( scalar @hidden == 0, "Two items not hidden");
240
235
    # Valid OpacHiddenItems, empty list
241
    # Valid OpacHiddenItems, empty list
236
    @items = ();
242
    @items = ();
237
    @hidden = GetHiddenItemnumbers( { items => \@items } );
243
    @hidden = GetHiddenItemnumbers( { items => \@items } );
Lines 552-558 subtest 'Koha::Item(s) tests' => sub { Link Here
552
};
558
};
553
559
554
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
560
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
555
    plan tests => 7;
561
    plan tests => 8;
556
562
557
    $schema->storage->txn_begin();
563
    $schema->storage->txn_begin();
558
564
Lines 603-620 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
603
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
609
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
604
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
610
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
605
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
611
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
606
      'Should crap is no record passed.';
612
      'Should carp is no record passed.';
607
613
608
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
614
    C4::Biblio::EmbedItemsInMarcBiblio({
615
        marc_record  => $record,
616
        biblionumber => $biblionumber });
609
    my @items = $record->field($itemfield);
617
    my @items = $record->field($itemfield);
610
    is( scalar @items, $number_of_items, 'Should return all items' );
618
    is( scalar @items, $number_of_items, 'Should return all items' );
611
619
612
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber,
620
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
613
        [ $itemnumbers[1], $itemnumbers[3] ] );
621
        biblionumber => $biblionumber,
622
        embed_items  => 1 });
623
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
624
625
    C4::Biblio::EmbedItemsInMarcBiblio({
626
        marc_record  => $record,
627
        biblionumber => $biblionumber,
628
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
614
    @items = $record->field($itemfield);
629
    @items = $record->field($itemfield);
615
    is( scalar @items, 2, 'Should return all items present in the list' );
630
    is( scalar @items, 2, 'Should return all items present in the list' );
616
631
617
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
632
    C4::Biblio::EmbedItemsInMarcBiblio({
633
        marc_record  => $record,
634
        biblionumber => $biblionumber,
635
        opac         => 1 });
618
    @items = $record->field($itemfield);
636
    @items = $record->field($itemfield);
619
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
637
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
620
638
Lines 622-634 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
622
        homebranch: ['$library1->{branchcode}']";
640
        homebranch: ['$library1->{branchcode}']";
623
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
641
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
624
642
625
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
643
    C4::Biblio::EmbedItemsInMarcBiblio({
644
        marc_record  => $record,
645
        biblionumber => $biblionumber });
626
    @items = $record->field($itemfield);
646
    @items = $record->field($itemfield);
627
    is( scalar @items,
647
    is( scalar @items,
628
        $number_of_items,
648
        $number_of_items,
629
        'Even with OpacHiddenItems set, all items should have been embedded' );
649
        'Even with OpacHiddenItems set, all items should have been embedded' );
630
650
631
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
651
    C4::Biblio::EmbedItemsInMarcBiblio({
652
        marc_record  => $record,
653
        biblionumber => $biblionumber,
654
        opac         => 1 });
632
    @items = $record->field($itemfield);
655
    @items = $record->field($itemfield);
633
    is(
656
    is(
634
        scalar @items,
657
        scalar @items,
Lines 639-645 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
639
    $opachiddenitems = "
662
    $opachiddenitems = "
640
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
663
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
641
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
664
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
642
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
665
    C4::Biblio::EmbedItemsInMarcBiblio({
666
        marc_record  => $record,
667
        biblionumber => $biblionumber,
668
        opac         => 1 });
643
    @items = $record->field($itemfield);
669
    @items = $record->field($itemfield);
644
    is(
670
    is(
645
        scalar @items,
671
        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