X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FPatrons.pm;h=24e3d9de8a62e1a8ff5d30d82088b544f97c38e0;hb=ebeb7e61614d8cf348a83ae187d23281f7521129;hp=81c763cfb782d59846b472de749a1372d6a771b0;hpb=b96f8b3e973b18121e57d4cabcebd3315ba18dd1;p=koha-ffzg.git diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 81c763cfb7..24e3d9de8a 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -158,45 +158,6 @@ sub search_patrons_to_anonymise { return Koha::Patrons->_new_from_dbic($rs); } -=head3 anonymise_issue_history - - Koha::Patrons->search->anonymise_issue_history( { [ before => $older_than_date ] } ); - -Anonymise issue history (old_issues) for all patrons older than the given date (optional). -To make sure all the conditions are met, the caller has the responsibility to -call search_patrons_to_anonymise to filter the Koha::Patrons set - -=cut - -sub anonymise_issue_history { - my ( $self, $params ) = @_; - - my $older_than_date = $params->{before}; - - $older_than_date = dt_from_string $older_than_date if $older_than_date; - - # The default of 0 does not work due to foreign key constraints - # The anonymisation should not fail quietly if AnonymousPatron is not a valid entry - # Set it to undef (NULL) - my $dtf = Koha::Database->new->schema->storage->datetime_parser; - my $nb_rows = 0; - while ( my $patron = $self->next ) { - my $old_issues_to_anonymise = $patron->old_checkouts->search( - { - ( - $older_than_date - ? ( returndate => - { '<' => $dtf->format_datetime($older_than_date) } ) - : () - ) - } - ); - my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; - $nb_rows += $old_issues_to_anonymise->update( { 'old_issues.borrowernumber' => $anonymous_patron } ); - } - return $nb_rows; -} - =head3 delete Koha::Patrons->search({ some filters here })->delete({ move => 1 }); @@ -559,6 +520,51 @@ sub filter_by_amount_owed { return $self->search( $where, $attrs ); } +=head3 filter_by_have_permission + + my $patrons = Koha::Patrons->search->filter_by_have_permission('suggestions.suggestions_manage'); + + my $patrons = Koha::Patrons->search->filter_by_have_permission('suggestions'); + +Filter patrons who have a given subpermission or the whole permission. + +=cut + +sub filter_by_have_permission { + my ($self, $subpermission) = @_; + + my ($p, $sp) = split '\.', $subpermission; + + my $perm = Koha::Database->new()->schema()->resultset('Userflag')->find({flag => $p}); + + Koha::Exceptions::ObjectNotFound->throw( sprintf( "Permission %s not found", $p ) ) + unless $perm; + + my $bit = $perm->bit; + + return $self->search( + { + -and => [ + -or => [ + \"me.flags & (1 << $bit)", + { 'me.flags' => 1 }, + ( + $sp + ? { + -and => [ + { 'user_permissions.module_bit' => $bit }, + { 'user_permissions.code' => $sp } + ] + } + : () + ) + ] + ] + }, + { prefetch => 'user_permissions' } + ); +} + =head3 _type =cut