Bug 17047: subscriptions management with Mana-KB
[koha.git] / Koha / Subscription / Numberpatterns.pm
1 package Koha::Subscription::Numberpatterns;
2
3 # Copyright 2016 BibLibre Morgane Alonso
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21 use Koha::Database;
22 use Koha::Subscription::Numberpattern;
23 use base qw(Koha::Objects);
24
25 =head1 NAME
26
27 Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set class
28
29 =head1 API
30
31 =head2 Class Methods
32
33 =cut
34
35 =head3 uniqeLabel
36
37 =cut
38
39 sub uniqueLabel {
40     my ($self, $label) = @_;
41
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)";
49         }
50         $label = $newlabel;
51     }
52     return $label;
53 }
54
55 =head3 type
56
57 =cut
58
59 sub _type {
60     return 'SubscriptionNumberpattern';
61 }
62
63 =head3 object_class
64
65 =cut
66
67 sub object_class {
68     return 'Koha::Subscription::Numberpattern';
69 }
70
71 =head1 AUTHOR
72
73 Morgane Alonso <morgane.alonso@biblibre.com>
74
75 =cut
76
77 1;