Bug 25501: Supress warnings on installing translation
[koha.git] / Koha / Subscription / Numberpatterns.pm
blob37d6e9a2da25f6585656342430aefcef403aa2b5
1 package Koha::Subscription::Numberpatterns;
3 # Copyright 2016 BibLibre Morgane Alonso
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>.
20 use Modern::Perl;
21 use Koha::Database;
22 use Koha::Subscription::Numberpattern;
23 use base qw(Koha::Objects);
25 =head1 NAME
27 Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set class
29 =head1 API
31 =head2 Class Methods
33 =cut
35 =head3 uniqueLabel
37 =cut
39 sub uniqueLabel {
40 my ($self, $label) = @_;
42 my $samelabel = Koha::Subscription::Numberpatterns->search({label => $label})->next();
43 if ($samelabel) {
44 my $i = 2;
45 my $newlabel = $samelabel->label . " ($i)";
46 while (my $othersamelabel = $self->search({label => $newlabel})->next()) {
47 $i++;
48 $newlabel = $samelabel->label . " ($i)";
50 $label = $newlabel;
52 return $label;
55 =head3 new_or_existing
57 =cut
59 sub new_or_existing {
60 my ($self, $params) = @_;
62 my $params_np;
63 if ( $params->{'numbering_pattern'} eq 'mana' ) {
64 foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
65 numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
66 label3 add3 every3 whenmorethan3 setto3 numbering3/) {
67 $params_np->{$_} = $params->{$_} if $params->{$_};
70 my $existing = Koha::Subscription::Numberpatterns->search($params_np)->next();
72 if ($existing) {
73 return $existing->id;
76 $params_np->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($params->{'patternname'});
77 $params_np->{description} = $params->{'sndescription'};
80 my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params_np)->store();
81 return $subscription_np->id;
84 return $params->{'numbering_pattern'};
87 =head3 type
89 =cut
91 sub _type {
92 return 'SubscriptionNumberpattern';
95 =head3 object_class
97 =cut
99 sub object_class {
100 return 'Koha::Subscription::Numberpattern';
103 =head1 AUTHOR
105 Morgane Alonso <morgane.alonso@biblibre.com>
107 =cut