Bug 17499: Add Koha-objects for messaging preferences
authorLari Taskula <lari.taskula@hypernova.fi>
Fri, 21 Oct 2016 14:26:24 +0000 (17:26 +0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 12 Sep 2023 13:16:06 +0000 (10:16 -0300)
commitb5b88b053d1ccfa11fce4a0002e01cf13ab64f8e
tree860f7b11e1c4332caf0db10c5652d76cb4e9e52c
parent9da5895d79163a518825fbb102526aef119a93fe
Bug 17499: Add Koha-objects for messaging preferences

This patch adds Koha-objects for messaging preferences.

Adds simple validation for messaging preferences.

The validation includes
- throw exception if both borrowernumber or categorycode is given for a new pref
- throw exception if patron for the given borrowernumber is not found
- throw exception if category for the given categorycode is not found
- throw exception if days in advance cannot be configured but is given
- throw exception if days in advance configuration is invalid (value between 0-30)
- throw exception if digest is not available but attempted to set on
- throw exception if digest must be enabled but attempted to set off
- throw exception on duplicate messaging preference

Adds a method for getting available messaging options.

Adds a method for setting default messaging preferenes.
  $patron->set_default_messaging_preferences (where $patron is a Koha::Patron)
  ...or...
  Koha::Patron::Message::Preference->new_from_default({
    borrowernumber => 123,
    categorycode => "ABC",
    message_attribute_id => 1,
  });

Since messaging preference is a feature that has multiple related database tables,
usage via Koha-objects is sometimes frustrating. This patch adds easy access to
message transport types via
  $preference->message_transport_types                              (for getting)
  $preference->set({ message_transport_types => ['email', 'sms'] }) (for setting)
  (also supports other calling conventions, see documentation for more)

Adds optional parameter message_name for Koha::Patron::Message::Preferences->find
and ->search. Simplifies the Koha-object usage by allowing developer to skip joins
and / or querying the message name via attribute_id from message_attributes table.

Includes test coverage for basic usage.

To test:
1. prove t/db_dependent/Koha/Patron/Message/*

Following Bug 17499, check also Bug 18595 that replaces C4::Members::Messaging
with these new Koha-objects.

Signed-off-by: Dominic Pichette <dominic@inlibro.com>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
17 files changed:
Koha/Exceptions.pm
Koha/Patron.pm
Koha/Patron/Message/Attribute.pm [new file with mode: 0644]
Koha/Patron/Message/Attributes.pm [new file with mode: 0644]
Koha/Patron/Message/Preference.pm [new file with mode: 0644]
Koha/Patron/Message/Preferences.pm [new file with mode: 0644]
Koha/Patron/Message/Transport.pm [new file with mode: 0644]
Koha/Patron/Message/Transport/Preference.pm [new file with mode: 0644]
Koha/Patron/Message/Transport/Preferences.pm [new file with mode: 0644]
Koha/Patron/Message/Transport/Type.pm [new file with mode: 0644]
Koha/Patron/Message/Transport/Types.pm [new file with mode: 0644]
Koha/Patron/Message/Transports.pm [new file with mode: 0644]
t/db_dependent/Koha/Patron/Message/Attributes.t [new file with mode: 0644]
t/db_dependent/Koha/Patron/Message/Preferences.t [new file with mode: 0644]
t/db_dependent/Koha/Patron/Message/Transport/Preferences.t [new file with mode: 0644]
t/db_dependent/Koha/Patron/Message/Transport/Types.t [new file with mode: 0644]
t/db_dependent/Koha/Patron/Message/Transports.t [new file with mode: 0644]