1 package C4
::Serials
::Frequency
;
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(@ISA @EXPORT);
28 # set the version for version checking
33 &GetSubscriptionFrequencies
34 &GetSubscriptionFrequency
35 &AddSubscriptionFrequency
36 &ModSubscriptionFrequency
37 &DelSubscriptionFrequency
39 &GetSubscriptionsWithFrequency
46 C4::Serials::Frequency - Serials Frequency module
50 =head2 GetSubscriptionFrequencies
54 =item C<@frequencies> = &GetSubscriptionFrequencies();
56 gets frequencies restricted on filters
62 sub GetSubscriptionFrequencies
{
63 my $dbh = C4
::Context
->dbh;
66 FROM subscription_frequencies
69 my $sth = $dbh->prepare($query);
72 my $results = $sth->fetchall_arrayref( {} );
76 =head2 GetSubscriptionFrequency
80 =item $frequency = &GetSubscriptionFrequency($frequencyid);
82 gets frequency where $frequencyid is the identifier
88 sub GetSubscriptionFrequency
{
89 my ($frequencyid) = @_;
91 my $dbh = C4
::Context
->dbh;
94 FROM subscription_frequencies
97 my $sth = $dbh->prepare($query);
98 $sth->execute($frequencyid);
100 return $sth->fetchrow_hashref;
103 =head2 AddSubscriptionFrequency
107 =item C<$frequencyid> = &AddSubscriptionFrequency($frequency);
111 =item C<$frequency> is a hashref that can contains the following keys
119 =item * issuesperunit
121 =item * unitsperissue
123 =item * expectedissuesayear
129 Only description is mandatory.
135 sub AddSubscriptionFrequency
{
136 my $frequency = shift;
138 unless(ref($frequency) eq 'HASH' && defined $frequency->{'description'} && $frequency->{'description'} ne '') {
144 foreach (qw
/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
145 if(exists $frequency->{$_}) {
147 push @values, $frequency->{$_};
151 my $dbh = C4
::Context
->dbh;
152 my $query = "INSERT INTO subscription_frequencies";
153 $query .= '(' . join(',', @keys) . ')';
154 $query .= ' VALUES (' . ('?,' x
(scalar(@keys)-1)) . '?)';
155 my $sth = $dbh->prepare($query);
156 my $rv = $sth->execute(@values);
159 return $dbh->last_insert_id(undef, undef, "subscription_frequencies", undef);
165 =head2 ModSubscriptionFrequency
169 =item &ModSubscriptionFrequency($frequency);
173 =item C<$frequency> is a hashref that can contains the following keys
183 =item * issuesperunit
185 =item * unitsperissue
187 =item * expectedissuesayear
193 Only id is mandatory.
199 sub ModSubscriptionFrequency
{
200 my $frequency = shift;
203 ref($frequency) eq 'HASH'
204 && defined $frequency->{'id'} && $frequency->{'id'} > 0
206 (defined $frequency->{'description'}
207 && $frequency->{'description'} ne '')
208 || !defined $frequency->{'description'}
216 foreach (qw
/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
217 if(exists $frequency->{$_}) {
219 push @values, $frequency->{$_};
223 my $dbh = C4
::Context
->dbh;
224 my $query = "UPDATE subscription_frequencies";
225 $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
226 $query .= ' WHERE id = ?';
227 my $sth = $dbh->prepare($query);
229 return $sth->execute(@values, $frequency->{'id'});
232 =head2 DelSubscriptionFrequency
236 =item &DelSubscriptionFrequency($frequencyid);
244 sub DelSubscriptionFrequency
{
245 my $frequencyid = shift;
247 my $dbh = C4
::Context
->dbh;
249 DELETE FROM subscription_frequencies
252 my $sth = $dbh->prepare($query);
253 $sth->execute($frequencyid);
256 =head2 GetSubscriptionsWithFrequency
258 my @subs = GetSubscriptionsWithFrequency($frequencyid);
260 Returns all subscriptions that are using a particular frequency
264 sub GetSubscriptionsWithFrequency
{
265 my ($frequencyid) = @_;
267 return unless $frequencyid;
269 my $dbh = C4
::Context
->dbh;
273 LEFT JOIN biblio ON subscription
.biblionumber
= biblio
.biblionumber
274 WHERE periodicity
= ?
276 my $sth = $dbh->prepare($query);
278 if ($sth->execute($frequencyid)) {
279 @results = @
{ $sth->fetchall_arrayref({}) };
290 Koha Development team <info@koha.org>