1 package Koha
::AudioAlerts
;
3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 use base
qw(Koha::Objects);
32 Koha::AudioAlerts - Koha Audio Alert object set class
40 Overrides default search such that
41 the default ordering is by precedence
46 my ( $self, $params, $attributes ) = @_;
48 $attributes->{order_by
} ||= 'precedence';
50 return $self->SUPER::search
( $params, $attributes );
53 =head3 get_next_precedence
55 Gets the next precedence value for audio alerts
59 sub get_next_precedence
{
62 return $self->get_last_precedence() + 1;
65 =head3 get_last_precedence
67 Gets the last precedence value for audio alerts
71 sub get_last_precedence
{
74 return $self->_resultset()->get_column('precedence')->max() || 0;
79 Koha::AudioAlerts->move( { audio_alert => $audio_alert, where => $where } );
81 Moves the given alert precedence 'up', 'down', 'top' or 'bottom'
86 my ( $self, $params ) = @_;
88 my $alert = $params->{audio_alert
};
89 my $where = $params->{where
};
91 return unless ( $alert && $where );
93 if ( $where eq 'up' ) {
94 unless ( $alert->precedence() == 1 ) {
95 my ($other) = $self->search( { precedence
=> $alert->precedence() - 1 } );
96 $other->precedence( $alert->precedence() )->store();
97 $alert->precedence( $alert->precedence() - 1 )->store();
100 elsif ( $where eq 'down' ) {
101 unless ( $alert->precedence() == $self->get_last_precedence() ) {
102 my ($other) = $self->search( { precedence
=> $alert->precedence() + 1 } );
103 $other->precedence( $alert->precedence() )->store();
104 $alert->precedence( $alert->precedence() + 1 )->store();
107 elsif ( $where eq 'top' ) {
108 $alert->precedence(0)->store();
109 $self->fix_precedences();
111 elsif ( $where eq 'bottom' ) {
112 $alert->precedence( $self->get_next_precedence() )->store();
113 $self->fix_precedences();
117 =head3 fix_precedences
119 Koha::AudioAlerts->fix_precedences();
121 Updates precedence numbers to start with 1
126 sub fix_precedences
{
129 my @alerts = $self->search();
132 map { $_->precedence( $i++ )->store() } @alerts;
148 return 'Koha::AudioAlert';
153 Kyle M Hall <kyle@bywatersolutions.com>