Lines 22-27
use Modern::Perl;
Link Here
|
22 |
use Koha::Database; |
22 |
use Koha::Database; |
23 |
use Koha::Exceptions; |
23 |
use Koha::Exceptions; |
24 |
use Koha::Patron::Categories; |
24 |
use Koha::Patron::Categories; |
|
|
25 |
use Koha::Patron::Message::Preferences; |
25 |
use Koha::Patrons; |
26 |
use Koha::Patrons; |
26 |
|
27 |
|
27 |
use base qw(Koha::Object); |
28 |
use base qw(Koha::Object); |
Lines 36-52
Koha::Patron::Message::Preference - Koha Patron Message Preference object class
Link Here
|
36 |
|
37 |
|
37 |
=cut |
38 |
=cut |
38 |
|
39 |
|
|
|
40 |
=head3 new |
41 |
|
42 |
my $preference = Koha::Patron::Message::Preference->new({ |
43 |
borrowernumber => 123, |
44 |
#categorycode => 'ABC', |
45 |
message_attribute_id => 4, |
46 |
wants_digest => 1, |
47 |
days_in_advance => 7, |
48 |
}); |
49 |
|
50 |
Creates a new messaging preference if no existing duplicates are found. Takes |
51 |
either borrowernumber or categorycode, but not both. |
52 |
|
53 |
Throws Koha::Exceptions::DuplicateObject if trying to create a preference that |
54 |
already exists for the same message_attribute_id and borrowernumber/categorycode. |
55 |
|
56 |
=cut |
57 |
|
58 |
sub new { |
59 |
my ($class, $params) = shift; |
60 |
|
61 |
my $self = $class->SUPER::new(@_); |
62 |
|
63 |
my $previous = Koha::Patron::Message::Preferences->search({ |
64 |
'-and' => [ |
65 |
borrowernumber => $self->borrowernumber, |
66 |
categorycode => $self->categorycode, |
67 |
message_attribute_id => $self->message_attribute_id, |
68 |
] |
69 |
}); |
70 |
if ($previous->count) { |
71 |
Koha::Exceptions::DuplicateObject->throw( |
72 |
error => "A preference for this borrower/category and" |
73 |
." message_attribute_id already exists", |
74 |
); |
75 |
} |
76 |
|
77 |
return $self; |
78 |
} |
79 |
|
39 |
=head3 store |
80 |
=head3 store |
40 |
|
81 |
|
41 |
Makes a validation before actual Koha::Object->store so that proper exceptions |
82 |
Makes a validation before actual Koha::Object->store so that proper exceptions |
42 |
can be thrown. See C<validate()> for documentation about exceptions. |
83 |
can be thrown. See C<validate()> for documentation about exceptions. |
43 |
|
84 |
|
|
|
85 |
Deletes any previous messaging preferences to avoid duplication. |
86 |
|
44 |
=cut |
87 |
=cut |
45 |
|
88 |
|
46 |
sub store { |
89 |
sub store { |
47 |
my $self = shift; |
90 |
my $self = shift; |
48 |
|
91 |
|
49 |
return $self->validate->SUPER::store(@_); |
92 |
$self->validate; |
|
|
93 |
|
94 |
return $self->SUPER::store(@_); |
50 |
} |
95 |
} |
51 |
|
96 |
|
52 |
=head3 validate |
97 |
=head3 validate |