1 package Koha::Suggestions;
3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
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.
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.
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>.
25 use Koha::DateUtils qw(dt_from_string);
28 use base qw(Koha::Objects);
32 Koha::Suggestions - Koha Suggestion object set class
40 my $suggestions = Koha::Suggestions->search_limited( $params, $attributes );
42 Returns all the suggestions the logged in user is allowed to see.
47 my ( $self, $params, $attributes ) = @_;
49 my $resultset = $self;
51 # filter on user branch
52 if ( C4::Context->preference('IndependentBranches')
53 && !C4::Context->IsSuperLibrarian() )
55 # If IndependentBranches is set and the logged in user is not superlibrarian
56 # Then we want to filter by the user's library (i.e. cannot see suggestions
57 # from other libraries)
58 my $userenv = C4::Context->userenv;
60 $resultset = $self->search({ branchcode => $userenv->{branch} })
61 if $userenv && $userenv->{branch};
64 return $resultset->search( $params, $attributes);
67 =head3 filter_by_pending
69 my $open = $suggestions->filter_by_pending;
71 Filters the resultset on those that are considered pending (i.e. STATUS = ASKED).
75 sub filter_by_pending {
78 return $self->search( { STATUS => 'ASKED' } );
81 =head3 filter_by_suggested_days_range
83 my $suggestions = $suggestions->filter_by_suggested_days_range( $days );
85 Filters the resultset on those placed within some I<$days> range.
89 sub filter_by_suggested_days_range {
90 my ( $self, $days ) = @_;
92 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
95 { suggesteddate => { '>=' => $dtf->format_date( dt_from_string->subtract( days => $days ) ) } } );
98 =head2 Internal methods
113 return 'Koha::Suggestion';
118 Kyle M Hall <kyle@bywatersolutions.com>