In order to keep you logged in, we need your consent to process personal data as specified in the privacy policy linked below.
-Please save your consent below or log out. Thank you!
-@@ -, +, @@ --- Koha/Patron.pm | 24 +++++ Koha/Patron/Consents.pm | 27 ++++++ .../en/modules/opac-patron-consent.tt | 94 ++++++++++--------- opac/opac-patron-consent.pl | 57 +++++------ t/db_dependent/Koha/Patron.t | 22 ++++- t/db_dependent/Koha/Patron/Consents.t | 45 ++++++++- 6 files changed, 189 insertions(+), 80 deletions(-) --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -44,6 +44,7 @@ use Koha::CurbsidePickups; use Koha::Old::Checkouts; use Koha::Patron::Attributes; use Koha::Patron::Categories; +use Koha::Patron::Consents; use Koha::Patron::Debarments; use Koha::Patron::HouseboundProfile; use Koha::Patron::HouseboundRole; @@ -2490,6 +2491,29 @@ sub get_savings { )->next->get_column('total_savings') // 0; } +=head3 consent + + my $consent = $patron->consent(TYPE); + + Returns the first consent of type TYPE (there should be only one) or a new instance + of Koha::Patron::Consent. + +=cut + +sub consent { + my ( $self, $type ) = @_; + Koha::Exceptions::MissingParameter->throw('Missing consent type') if !$type; + my $consents = Koha::Patron::Consents->search( + { + borrowernumber => $self->borrowernumber, + type => $type, + } + ); + return $consents && $consents->count + ? $consents->next + : Koha::Patron::Consent->new( { borrowernumber => $self->borrowernumber, type => $type } ); +} + =head2 Internal methods =head3 _type --- a/Koha/Patron/Consents.pm +++ a/Koha/Patron/Consents.pm @@ -20,7 +20,10 @@ package Koha::Patron::Consents; use Modern::Perl; use base qw(Koha::Objects); + +use C4::Context; use Koha::Patron::Consent; +use Koha::Plugins; =head1 NAME @@ -34,8 +37,32 @@ Koha::Objects class for handling patron consents =head2 Class Methods +=head3 available_types + + Returns an HASHref of available consent types like: + { type1 => {}, type2 => {}, .. } + + Checks preferences OPACCustomConsentTypes and PrivacyPolicyConsent. + Calls patron_consent_type plugins (if pref enabled). + + Note: The plugins return an ARRAYref with type, title and description like: + [ my_type => { title => { lang => 1, .. }, description => { lang => 2, .. } } ] + =cut +sub available_types { + my ($self) = shift; + my $response = {}; + $response->{GDPR_PROCESSING} = 1 if C4::Context->preference('PrivacyPolicyConsent'); + if ( C4::Context->preference('OPACCustomConsentTypes') ) { + foreach my $return ( Koha::Plugins->call('patron_consent_type') ) { + next if ref($return) ne 'ARRAY' or @$return != 2; # ignoring bad input + $response->{ $return->[0] } = $return->[1]; + } + } + return $response; +} + =head3 _type =cut --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-patron-consent.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-patron-consent.tt @@ -36,41 +36,45 @@
In order to keep you logged in, we need your consent to process personal data as specified in the privacy policy linked below.
-Please save your consent below or log out. Thank you!
-