1 package C4::Serials::Frequency;
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);
28 # set the version for version checking
33 &GetSubscriptionFrequencies
34 &GetSubscriptionFrequency
35 &AddSubscriptionFrequency
36 &ModSubscriptionFrequency
37 &DelSubscriptionFrequency
39 &GetSubscriptionsWithFrequency
43 =head3 GetSubscriptionFrequencies
47 =item C<@frequencies> = &GetSubscriptionFrequencies();
49 gets frequencies restricted on filters
55 sub GetSubscriptionFrequencies {
56 my $dbh = C4::Context->dbh;
59 FROM subscription_frequencies
62 my $sth = $dbh->prepare($query);
65 my $results = $sth->fetchall_arrayref( {} );
69 =head3 GetSubscriptionFrequency
73 =item $frequency = &GetSubscriptionFrequency($frequencyid);
75 gets frequency where $frequencyid is the identifier
81 sub GetSubscriptionFrequency {
82 my ($frequencyid) = @_;
84 my $dbh = C4::Context->dbh;
87 FROM subscription_frequencies
90 my $sth = $dbh->prepare($query);
91 $sth->execute($frequencyid);
93 return $sth->fetchrow_hashref;
96 =head3 AddSubscriptionFrequency
100 =item C<$frequencyid> = &AddSubscriptionFrequency($frequency);
104 =item C<$frequency> is a hashref that can contains the following keys
112 =item * issuesperunit
114 =item * unitsperissue
116 =item * expectedissuesayear
122 Only description is mandatory.
128 sub AddSubscriptionFrequency {
129 my $frequency = shift;
131 unless(ref($frequency) eq 'HASH' && defined $frequency->{'description'} && $frequency->{'description'} ne '') {
137 foreach (qw/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
138 if(exists $frequency->{$_}) {
140 push @values, $frequency->{$_};
144 my $dbh = C4::Context->dbh;
145 my $query = "INSERT INTO subscription_frequencies";
146 $query .= '(' . join(',', @keys) . ')';
147 $query .= ' VALUES (' . ('?,' x (scalar(@keys)-1)) . '?)';
148 my $sth = $dbh->prepare($query);
149 my $rv = $sth->execute(@values);
152 return $dbh->last_insert_id(undef, undef, "subscription_frequencies", undef);
158 =head3 ModSubscriptionFrequency
162 =item &ModSubscriptionFrequency($frequency);
166 =item C<$frequency> is a hashref that can contains the following keys
176 =item * issuesperunit
178 =item * unitsperissue
180 =item * expectedissuesayear
186 Only id is mandatory.
192 sub ModSubscriptionFrequency {
193 my $frequency = shift;
196 ref($frequency) eq 'HASH'
197 && defined $frequency->{'id'} && $frequency->{'id'} > 0
199 (defined $frequency->{'description'}
200 && $frequency->{'description'} ne '')
201 || !defined $frequency->{'description'}
209 foreach (qw/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
210 if(exists $frequency->{$_}) {
212 push @values, $frequency->{$_};
216 my $dbh = C4::Context->dbh;
217 my $query = "UPDATE subscription_frequencies";
218 $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
219 $query .= ' WHERE id = ?';
220 my $sth = $dbh->prepare($query);
222 return $sth->execute(@values, $frequency->{'id'});
225 =head3 DelSubscriptionFrequency
229 =item &DelSubscriptionFrequency($frequencyid);
237 sub DelSubscriptionFrequency {
238 my $frequencyid = shift;
240 my $dbh = C4::Context->dbh;
242 DELETE FROM subscription_frequencies
245 my $sth = $dbh->prepare($query);
246 $sth->execute($frequencyid);
249 =head3 GetSubscriptionsWithFrequency
251 my @subs = GetSubscriptionsWithFrequency($frequencyid);
253 Returns all subscriptions that are using a particular frequency
257 sub GetSubscriptionsWithFrequency {
258 my ($frequencyid) = @_;
260 return unless $frequencyid;
262 my $dbh = C4::Context->dbh;
266 LEFT JOIN biblio ON subscription.biblionumber = biblio.biblionumber
267 WHERE periodicity = ?
269 my $sth = $dbh->prepare($query);
271 if ($sth->execute($frequencyid)) {
272 @results = @{ $sth->fetchall_arrayref({}) };
283 Koha Developement team <info@koha.org>