1 package C4
::Serials
::Numberpattern
;
3 # Copyright 2011-2013 Biblibre SARL
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>.
25 use vars
qw($VERSION @ISA @EXPORT);
29 # set the version for version checking
34 &GetSubscriptionNumberpatterns
35 &GetSubscriptionNumberpattern
36 &GetSubscriptionNumberpatternByName
37 &AddSubscriptionNumberpattern
38 &ModSubscriptionNumberpattern
39 &DelSubscriptionNumberpattern
41 &GetSubscriptionsWithNumberpattern
48 C4::Serials::Numberpattern - Serials numbering pattern module
52 =head2 GetSubscriptionNumberpatterns
54 @results = GetSubscriptionNumberpatterns;
55 this function get all subscription number patterns entered in table
59 sub GetSubscriptionNumberpatterns
{
60 my $dbh = C4
::Context
->dbh;
63 FROM subscription_numberpatterns
66 my $sth = $dbh->prepare($query);
68 my $results = $sth->fetchall_arrayref({});
73 =head2 GetSubscriptionNumberpattern
75 $result = GetSubscriptionNumberpattern($numberpatternid);
76 this function get the data of the subscription numberpatterns which id is $numberpatternid
80 sub GetSubscriptionNumberpattern
{
81 my $numberpatternid = shift;
82 my $dbh = C4
::Context
->dbh;
85 FROM subscription_numberpatterns
88 my $sth = $dbh->prepare($query);
89 $sth->execute($numberpatternid);
91 return $sth->fetchrow_hashref;
94 =head2 GetSubscriptionNumberpatternByName
96 $result = GetSubscriptionNumberpatternByName($name);
97 this function get the data of the subscription numberpatterns which name is $name
101 sub GetSubscriptionNumberpatternByName
{
103 my $dbh = C4
::Context
->dbh;
106 FROM subscription_numberpatterns
109 my $sth = $dbh->prepare($query);
110 my $rv = $sth->execute($name);
112 return $sth->fetchrow_hashref;
115 =head2 AddSubscriptionNumberpattern
119 =item C<$numberpatternid> = &AddSubscriptionNumberpattern($numberpattern)
121 Add a new numberpattern
123 =item C<$frequency> is a hashref that contains values of the number pattern
125 =item Only label and numberingmethod are mandatory
131 sub AddSubscriptionNumberpattern
{
132 my $numberpattern = shift;
135 ref($numberpattern) eq 'HASH'
136 && defined $numberpattern->{'label'}
137 && $numberpattern->{'label'} ne ''
138 && defined $numberpattern->{'numberingmethod'}
139 && $numberpattern->{'numberingmethod'} ne ''
146 foreach (qw
/ label description numberingmethod displayorder
147 label1 label2 label3 add1 add2 add3 every1 every2 every3
148 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
149 numbering1 numbering2 numbering3
/) {
150 if(exists $numberpattern->{$_}) {
152 push @values, $numberpattern->{$_};
156 my $dbh = C4
::Context
->dbh;
157 my $query = "INSERT INTO subscription_numberpatterns";
158 $query .= '(' . join(',', @keys) . ')';
159 $query .= ' VALUES (' . ('?,' x
(scalar(@keys)-1)) . '?)';
160 my $sth = $dbh->prepare($query);
161 my $rv = $sth->execute(@values);
164 return $dbh->last_insert_id(undef, undef, "subscription_numberpatterns", undef);
170 =head2 ModSubscriptionNumberpattern
174 =item &ModSubscriptionNumberpattern($numberpattern)
176 Modifies a numberpattern
178 =item C<$frequency> is a hashref that contains values of the number pattern
180 =item Only id is mandatory
186 sub ModSubscriptionNumberpattern
{
187 my $numberpattern = shift;
190 ref($numberpattern) eq 'HASH'
191 && defined $numberpattern->{'id'}
192 && $numberpattern->{'id'} > 0
194 (defined $numberpattern->{'label'}
195 && $numberpattern->{'label'} ne '')
196 || !defined $numberpattern->{'label'}
199 (defined $numberpattern->{'numberingmethod'}
200 && $numberpattern->{'numberingmethod'} ne '')
201 || !defined $numberpattern->{'numberingmethod'}
209 foreach (qw
/ label description numberingmethod displayorder
210 label1 label2 label3 add1 add2 add3 every1 every2 every3
211 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
212 numbering1 numbering2 numbering3
/) {
213 if(exists $numberpattern->{$_}) {
215 push @values, $numberpattern->{$_};
219 my $dbh = C4
::Context
->dbh;
220 my $query = "UPDATE subscription_numberpatterns";
221 $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
222 $query .= ' WHERE id = ?';
223 my $sth = $dbh->prepare($query);
225 return $sth->execute(@values, $numberpattern->{'id'});
228 =head2 DelSubscriptionNumberpattern
232 =item &DelSubscriptionNumberpattern($numberpatternid)
234 Delete a number pattern
240 sub DelSubscriptionNumberpattern
{
241 my $numberpatternid = shift;
243 my $dbh = C4
::Context
->dbh;
245 DELETE FROM subscription_numberpatterns
248 my $sth = $dbh->prepare($query);
249 $sth->execute($numberpatternid);
252 =head2 GetSubscriptionsWithNumberpattern
254 my @subs = GetSubscriptionsWithNumberpattern($numberpatternid);
256 Returns all subscriptions that are using a particular numbering pattern
260 sub GetSubscriptionsWithNumberpattern
{
261 my ($numberpatternid) = @_;
263 return unless $numberpatternid;
265 my $dbh = C4
::Context
->dbh;
269 LEFT JOIN biblio ON subscription
.biblionumber
= biblio
.biblionumber
270 WHERE numberpattern
= ?
272 my $sth = $dbh->prepare($query);
274 if ($sth->execute($numberpatternid)) {
275 @results = @
{ $sth->fetchall_arrayref({}) };
287 Koha Development team <info@koha.org>