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>.
24 use Koha::DateUtils qw(dt_from_string);
27 use base qw(Koha::Objects);
31 Koha::Suggestions - Koha Suggestion object set class
39 my $suggestions = Koha::Suggestions->search_limited( $params, $attributes );
41 Returns all the suggestions the logged in user is allowed to see.
46 my ( $self, $params, $attributes ) = @_;
48 my $resultset = $self;
50 # filter on user branch
51 if ( C4::Context->preference('IndependentBranches')
52 && !C4::Context->IsSuperLibrarian() )
54 # If IndependentBranches is set and the logged in user is not superlibrarian
55 # Then we want to filter by the user's library (i.e. cannot see suggestions
56 # from other libraries)
57 my $userenv = C4::Context->userenv;
59 $resultset = $self->search({ 'me.branchcode' => $userenv->{branch} })
60 if $userenv && $userenv->{branch};
63 return $resultset->search( $params, $attributes);
66 =head3 filter_by_pending
68 my $open = $suggestions->filter_by_pending;
70 Filters the resultset on those that are considered pending (i.e. STATUS = ASKED).
74 sub filter_by_pending {
77 return $self->search( { STATUS => 'ASKED' } );
80 =head3 filter_by_suggested_days_range
82 my $suggestions = $suggestions->filter_by_suggested_days_range( $days );
84 Filters the resultset on those placed within some I<$days> range.
88 sub filter_by_suggested_days_range {
89 my ( $self, $days ) = @_;
91 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
94 { suggesteddate => { '>=' => $dtf->format_date( dt_from_string->subtract( days => $days ) ) } } );
97 =head2 Internal methods
112 return 'Koha::Suggestion';
117 Kyle M Hall <kyle@bywatersolutions.com>