Bugzilla – Attachment 114665 Details for
Bug 24254
Add Koha::Items->filter_by_visible_in_opac
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24254: Add Koha::Items->filter_by_visible_in_opac
Bug-24254-Add-KohaItems-filterbyvisibleinopac.patch (text/plain), 2.67 KB, created by
Martin Renvoize (ashimema)
on 2020-12-23 11:25:44 UTC
(
hide
)
Description:
Bug 24254: Add Koha::Items->filter_by_visible_in_opac
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-12-23 11:25:44 UTC
Size:
2.67 KB
patch
obsolete
>From 6349b071bd0076a7c9ac6431aa23b93c3a89192b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 3 Dec 2020 15:11:14 -0300 >Subject: [PATCH] Bug 24254: Add Koha::Items->filter_by_visible_in_opac > >This patch adds a method based on the original idea from Nick, but on >Koha::Items. > >The idea is to build a proper filter, based on the current rules for >hiding things, directly on the DBIC query. The caller takes care of >knowing if the filtering should apply (i.e. checking the patron category >exceptions) and then it would do something like: > > my @items; > if ( <patron_category_does_not_have_exception> ) { > @items = $biblio->items->filter_by_visible_in_opac( > { > rules => $rules > } > ); > } > else { > # still want to enforce 'hidelostitems' > @items = $biblio->items->filter_by_visible_in_opac; > } > >To test: >1. Apply this patches >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Items.t >=> SUCCESS: Tests pass! >3. Look at the use cases on the tests, read the code >=> SUCCESS: It all makes sense >4. Compare with Koha::Item->hidden_in_opac >=> SUCCESS: It all makes sense >5. Sign off :-D > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Items.pm | 32 ++++++++++++++++++++++++++++++-- > 1 file changed, 30 insertions(+), 2 deletions(-) > >diff --git a/Koha/Items.pm b/Koha/Items.pm >index 057a361f90..78663f0dc8 100644 >--- a/Koha/Items.pm >+++ b/Koha/Items.pm >@@ -33,7 +33,7 @@ Koha::Items - Koha Item object set class > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =cut > >@@ -50,7 +50,35 @@ sub filter_by_for_loan { > return $self->search( { notforloan => [ 0, undef ] } ); > } > >-=head3 type >+=head3 filter_by_visible_in_opac >+ >+ my $filered_items = $items->filter_by_visible_in_opac({ rules => $rules }); >+ >+Returns a new resultset, containing those items that are not expected to be hidden in OPAC. >+If no I<rules> are passed, it returns the whole resultset, with the only caveat that the >+I<hidelostitems> system preference is honoured. >+ >+=cut >+ >+sub filter_by_visible_in_opac { >+ my ($self, $params) = @_; >+ >+ my $rules = $params->{rules} // {}; >+ >+ my $search_params; >+ foreach my $field (keys %$rules){ >+ $search_params->{$field}->{'-not_in'} = $rules->{$field}; >+ } >+ >+ $search_params->{itemlost}->{'<='} = 0 >+ if C4::Context->preference('hidelostitems'); >+ >+ return $self->search( $search_params ); >+} >+ >+=head2 Internal methods >+ >+=head3 _type > > =cut > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24254
:
96373
|
114159
|
114160
|
114206
|
114207
|
114278
|
114279
|
114539
|
114540
|
114548
|
114549
|
114550
|
114551
|
114574
|
114594
|
114595
|
114596
|
114597
|
114598
|
114599
|
114664
|
114665
|
114666
|
114667
|
114668
|
115131
|
115132
|
115147
|
115148
|
115149
|
115150
|
115151
|
115152
|
115153
|
116070
|
116071
|
116072
|
116073
|
116074
|
116075