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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use base qw(Koha::Objects);
31 Koha::AudioAlerts - Koha Audio Alert object set class
39 Overrides default search such that
40 the default ordering is by precedence
45 my ( $self, $params, $attributes ) = @_;
47 $attributes->{order_by} ||= 'precedence';
49 return $self->SUPER::search( $params, $attributes );
52 =head3 get_next_precedence
54 Gets the next precedence value for audio alerts
58 sub get_next_precedence {
61 return $self->get_last_precedence() + 1;
64 =head3 get_last_precedence
66 Gets the last precedence value for audio alerts
70 sub get_last_precedence {
73 return $self->_resultset()->get_column('precedence')->max() || 0;
78 Koha::AudioAlerts->move( { audio_alert => $audio_alert, where => $where } );
80 Moves the given alert precedence 'up', 'down', 'top' or 'bottom'
85 my ( $self, $params ) = @_;
87 my $alert = $params->{audio_alert};
88 my $where = $params->{where};
90 return unless ( $alert && $where );
92 if ( $where eq 'up' ) {
93 unless ( $alert->precedence() == 1 ) {
94 my $other = $self->search( { precedence => $alert->precedence() - 1 } )->next;
95 $other->precedence( $alert->precedence() )->store();
96 $alert->precedence( $alert->precedence() - 1 )->store();
99 elsif ( $where eq 'down' ) {
100 unless ( $alert->precedence() == $self->get_last_precedence() ) {
101 my $other = $self->search( { precedence => $alert->precedence() + 1 } )->next;
102 $other->precedence( $alert->precedence() )->store();
103 $alert->precedence( $alert->precedence() + 1 )->store();
106 elsif ( $where eq 'top' ) {
107 $alert->precedence(0)->store();
108 $self->fix_precedences();
110 elsif ( $where eq 'bottom' ) {
111 $alert->precedence( $self->get_next_precedence() )->store();
112 $self->fix_precedences();
116 =head3 fix_precedences
118 Koha::AudioAlerts->fix_precedences();
120 Updates precedence numbers to start with 1
125 sub fix_precedences {
128 my @alerts = $self->search->as_list;
131 map { $_->precedence( $i++ )->store() } @alerts;
147 return 'Koha::AudioAlert';
152 Kyle M Hall <kyle@bywatersolutions.com>