1 package C4::Serials::Numberpattern;
3 # Copyright 2000-2002 Biblibre SARL
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 2 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.
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
45 =head3 GetSubscriptionNumberpatterns
49 @results = GetSubscriptionNumberpatterns;
50 this function get all subscription number patterns entered in table
56 sub GetSubscriptionNumberpatterns {
57 my $dbh = C4::Context->dbh;
60 FROM subscription_numberpatterns
63 my $sth = $dbh->prepare($query);
65 my $results = $sth->fetchall_arrayref({});
70 =head3 GetSubscriptionNumberpattern
74 $result = GetSubscriptionNumberpattern($numberpatternid);
75 this function get the data of the subscription numberpatterns which id is $numberpatternid
81 sub GetSubscriptionNumberpattern {
82 my $numberpatternid = shift;
83 my $dbh = C4::Context->dbh;
86 FROM subscription_numberpatterns
89 my $sth = $dbh->prepare($query);
90 $sth->execute($numberpatternid);
92 return $sth->fetchrow_hashref;
95 =head3 GetSubscriptionNumberpatternByName
99 $result = GetSubscriptionNumberpatternByName($name);
100 this function get the data of the subscription numberpatterns which name is $name
106 sub GetSubscriptionNumberpatternByName {
108 my $dbh = C4::Context->dbh;
111 FROM subscription_numberpatterns
114 my $sth = $dbh->prepare($query);
115 my $rv = $sth->execute($name);
117 return $sth->fetchrow_hashref;
120 =head3 AddSubscriptionNumberpattern
124 =item C<$numberpatternid> = &AddSubscriptionNumberpattern($numberpattern)
126 Add a new numberpattern
128 =item C<$frequency> is a hashref that contains values of the number pattern
130 =item Only label and numberingmethod are mandatory
136 sub AddSubscriptionNumberpattern {
137 my $numberpattern = shift;
140 ref($numberpattern) eq 'HASH'
141 && defined $numberpattern->{'label'}
142 && $numberpattern->{'label'} ne ''
143 && defined $numberpattern->{'numberingmethod'}
144 && $numberpattern->{'numberingmethod'} ne ''
151 foreach (qw/ label description numberingmethod displayorder
152 label1 label2 label3 add1 add2 add3 every1 every2 every3
153 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
154 numbering1 numbering2 numbering3 /) {
155 if(exists $numberpattern->{$_}) {
157 push @values, $numberpattern->{$_};
161 my $dbh = C4::Context->dbh;
162 my $query = "INSERT INTO subscription_numberpatterns";
163 $query .= '(' . join(',', @keys) . ')';
164 $query .= ' VALUES (' . ('?,' x (scalar(@keys)-1)) . '?)';
165 my $sth = $dbh->prepare($query);
166 my $rv = $sth->execute(@values);
169 return $dbh->last_insert_id(undef, undef, "subscription_numberpatterns", undef);
175 =head3 ModSubscriptionNumberpattern
179 =item &ModSubscriptionNumberpattern($numberpattern)
181 Modifies a numberpattern
183 =item C<$frequency> is a hashref that contains values of the number pattern
185 =item Only id is mandatory
191 sub ModSubscriptionNumberpattern {
192 my $numberpattern = shift;
195 ref($numberpattern) eq 'HASH'
196 && defined $numberpattern->{'id'}
197 && $numberpattern->{'id'} > 0
199 (defined $numberpattern->{'label'}
200 && $numberpattern->{'label'} ne '')
201 || !defined $numberpattern->{'label'}
204 (defined $numberpattern->{'numberingmethod'}
205 && $numberpattern->{'numberingmethod'} ne '')
206 || !defined $numberpattern->{'numberingmethod'}
214 foreach (qw/ label description numberingmethod displayorder
215 label1 label2 label3 add1 add2 add3 every1 every2 every3
216 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
217 numbering1 numbering2 numbering3 /) {
218 if(exists $numberpattern->{$_}) {
220 push @values, $numberpattern->{$_};
224 my $dbh = C4::Context->dbh;
225 my $query = "UPDATE subscription_numberpatterns";
226 $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
227 $query .= ' WHERE id = ?';
228 my $sth = $dbh->prepare($query);
230 return $sth->execute(@values, $numberpattern->{'id'});
233 =head3 DelSubscriptionNumberpattern
237 =item &DelSubscriptionNumberpattern($numberpatternid)
239 Delete a number pattern
245 sub DelSubscriptionNumberpattern {
246 my $numberpatternid = shift;
248 my $dbh = C4::Context->dbh;
250 DELETE FROM subscription_numberpatterns
253 my $sth = $dbh->prepare($query);
254 $sth->execute($numberpatternid);
257 =head3 GetSubscriptionsWithNumberpattern
259 my @subs = GetSubscriptionsWithNumberpattern($numberpatternid);
261 Returns all subscriptions that are using a particular numbering pattern
265 sub GetSubscriptionsWithNumberpattern {
266 my ($numberpatternid) = @_;
268 return unless $numberpatternid;
270 my $dbh = C4::Context->dbh;
274 LEFT JOIN biblio ON subscription.biblionumber = biblio.biblionumber
275 WHERE numberpattern = ?
277 my $sth = $dbh->prepare($query);
279 if ($sth->execute($numberpatternid)) {
280 @results = @{ $sth->fetchall_arrayref({}) };
292 Koha Developement team <info@koha.org>