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);
31 &GetSubscriptionFrequencies
32 &GetSubscriptionFrequency
33 &AddSubscriptionFrequency
34 &ModSubscriptionFrequency
35 &DelSubscriptionFrequency
37 &GetSubscriptionsWithFrequency
44 C4::Serials::Frequency - Serials Frequency module
48 =head2 GetSubscriptionFrequencies
52 =item C<@frequencies> = &GetSubscriptionFrequencies();
54 gets frequencies restricted on filters
60 sub GetSubscriptionFrequencies
{
61 my $dbh = C4
::Context
->dbh;
64 FROM subscription_frequencies
67 my $sth = $dbh->prepare($query);
70 my $results = $sth->fetchall_arrayref( {} );
74 =head2 GetSubscriptionFrequency
78 =item $frequency = &GetSubscriptionFrequency($frequencyid);
80 gets frequency where $frequencyid is the identifier
86 sub GetSubscriptionFrequency
{
87 my ($frequencyid) = @_;
89 my $dbh = C4
::Context
->dbh;
92 FROM subscription_frequencies
95 my $sth = $dbh->prepare($query);
96 $sth->execute($frequencyid);
98 return $sth->fetchrow_hashref;
101 =head2 AddSubscriptionFrequency
105 =item C<$frequencyid> = &AddSubscriptionFrequency($frequency);
109 =item C<$frequency> is a hashref that can contains the following keys
117 =item * issuesperunit
119 =item * unitsperissue
121 =item * expectedissuesayear
127 Only description is mandatory.
133 sub AddSubscriptionFrequency
{
134 my $frequency = shift;
136 unless(ref($frequency) eq 'HASH' && defined $frequency->{'description'} && $frequency->{'description'} ne '') {
142 foreach (qw
/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
143 if(exists $frequency->{$_}) {
145 push @values, $frequency->{$_};
149 my $dbh = C4
::Context
->dbh;
150 my $query = "INSERT INTO subscription_frequencies";
151 $query .= '(' . join(',', @keys) . ')';
152 $query .= ' VALUES (' . ('?,' x
(scalar(@keys)-1)) . '?)';
153 my $sth = $dbh->prepare($query);
154 my $rv = $sth->execute(@values);
157 return $dbh->last_insert_id(undef, undef, "subscription_frequencies", undef);
163 =head2 ModSubscriptionFrequency
167 =item &ModSubscriptionFrequency($frequency);
171 =item C<$frequency> is a hashref that can contains the following keys
181 =item * issuesperunit
183 =item * unitsperissue
185 =item * expectedissuesayear
191 Only id is mandatory.
197 sub ModSubscriptionFrequency
{
198 my $frequency = shift;
201 ref($frequency) eq 'HASH'
202 && defined $frequency->{'id'} && $frequency->{'id'} > 0
204 (defined $frequency->{'description'}
205 && $frequency->{'description'} ne '')
206 || !defined $frequency->{'description'}
214 foreach (qw
/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
215 if(exists $frequency->{$_}) {
217 push @values, $frequency->{$_};
221 my $dbh = C4
::Context
->dbh;
222 my $query = "UPDATE subscription_frequencies";
223 $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
224 $query .= ' WHERE id = ?';
225 my $sth = $dbh->prepare($query);
227 return $sth->execute(@values, $frequency->{'id'});
230 =head2 DelSubscriptionFrequency
234 =item &DelSubscriptionFrequency($frequencyid);
242 sub DelSubscriptionFrequency
{
243 my $frequencyid = shift;
245 my $dbh = C4
::Context
->dbh;
247 DELETE FROM subscription_frequencies
250 my $sth = $dbh->prepare($query);
251 $sth->execute($frequencyid);
254 =head2 GetSubscriptionsWithFrequency
256 my @subs = GetSubscriptionsWithFrequency($frequencyid);
258 Returns all subscriptions that are using a particular frequency
262 sub GetSubscriptionsWithFrequency
{
263 my ($frequencyid) = @_;
265 return unless $frequencyid;
267 my $dbh = C4
::Context
->dbh;
271 LEFT JOIN biblio ON subscription
.biblionumber
= biblio
.biblionumber
272 WHERE periodicity
= ?
274 my $sth = $dbh->prepare($query);
276 if ($sth->execute($frequencyid)) {
277 @results = @
{ $sth->fetchall_arrayref({}) };
288 Koha Development team <info@koha.org>