1 package Koha::Old::Checkouts;
3 # This file is part of Koha.
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.
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.
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>.
21 use Koha::DateUtils qw( dt_from_string );
22 use Koha::Old::Checkout;
24 use base qw(Koha::Objects);
28 Koha::Old::Checkouts - Koha Old Checkouts object set class
30 This object represents a set of completed checkouts
36 =head3 filter_by_anonymizable
38 my $checkouts = $patron->old_checkouts;
39 my $anonymizable_checkouts = $checkouts->filter_by_anonymizable;
41 This method filters the resultset, so it only contains checkouts that can be
42 anonymized given the patron privacy settings.
46 sub filter_by_anonymizable {
47 my ( $self, $params ) = @_;
49 my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef;
53 'me.borrowernumber' => { 'not' => undef },
54 'patron.privacy' => { '<>' => 0 },
57 ? ( 'me.borrowernumber' => { '!=' => $anonymous_patron } )
67 =head3 filter_by_todays_checkins
71 sub filter_by_todays_checkins {
74 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
75 my $today = dt_from_string;
76 my $today_start = $today->clone->set( hour => 0, minute => 0, second => 0 );
77 my $today_end = $today->clone->set( hour => 23, minute => 59, second => 59 );
78 $today_start = $dtf->format_datetime( $today_start );
79 $today_end = $dtf->format_datetime( $today_end );
80 return $self->search({
90 $patron->old_checkouts->anonymize();
92 Anonymize the given I<Koha::Old::Checkouts> resultset.
97 my ( $self, $params ) = @_;
99 my $anonymous_id = C4::Context->preference('AnonymousPatron');
101 Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
102 unless $anonymous_id;
104 return $self->update( { borrowernumber => $anonymous_id }, { no_triggers => 1 } );
107 =head2 Internal methods
122 return 'Koha::Old::Checkout';