replace references to defunct info email address
[koha.git] / C4 / Serials / Frequency.pm
1 package C4::Frequency;
2
3 # Copyright 2000-2002 Biblibre SARL
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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.
19
20 use strict;
21 #use warnings; FIXME - Bug 2505
22 use C4::Context;
23 use C4::SQLHelper qw<:all>;
24 use C4::Debug;
25
26 use vars qw($VERSION @ISA @EXPORT);
27
28 BEGIN {
29         # set the version for version checking
30         $VERSION = 3.01;
31         require Exporter;
32         @ISA    = qw(Exporter);
33         @EXPORT = qw(
34
35         &GetFrequencies
36         &GetFrequency
37                 &new
38                 &all
39             &AddFrequency
40         &ModFrequency
41         &DelFrequency
42
43         );
44 }
45
46 # -------------------------------------------------------------------
47 my %count_issues_a_year=(
48         day=>365,
49         week=>52,
50         month=>12,
51         quarter=>4,
52         year=>1
53 );
54
55 sub new {
56     my ($class, $opts) = @_;
57     bless $opts => $class;
58 }
59
60
61 sub AddFrequency {
62     my ($class,$frequency) = @_;
63         return InsertInTable("subscription_frequency",$frequency);
64 }
65
66 sub GetExpectedissuesayear {
67     my ($class,$unit,$issuesperunit,$unitperissues) = @_;
68         return Int($count_issues_a_year{$unit}/$issuesperunit)*$unitperissues;
69 }
70
71 # -------------------------------------------------------------------
72 sub ModFrequency {
73     my ($class,$frequency) = @_;
74         return UpdateInTable("subscription_frequency",$frequency);
75 }
76
77 # -------------------------------------------------------------------
78 sub DelFrequency {
79         my ($class,$frequency) = @_;
80         return DeleteInTable("subscription_frequency",$frequency);
81 }
82
83 sub all {
84     my ($class) = @_;
85     my $dbh = C4::Context->dbh;
86     return    map { $class->new($_) }    @{$dbh->selectall_arrayref(
87         # The subscription_frequency table is small enough for
88         # `SELECT *` to be harmless.
89         "SELECT * FROM subscription_frequency ORDER BY description",
90         { Slice => {} },
91     )};
92 }
93
94 =head3 GetFrequency
95
96 =over 4
97
98 &GetFrequency($freq_id);
99
100 gets frequency where $freq_id is the identifier
101
102 =back
103
104 =cut
105
106 # -------------------------------------------------------------------
107 sub GetFrequency {
108     my ($freq_id) = @_;
109         return undef unless $freq_id;
110     my $results= SearchInTable("subscription_frequency",{frequency_id=>$freq_id}, undef, undef,undef, undef, "wide");
111         return undef unless ($results);
112         return $$results[0];
113 }
114
115 =head3 GetFrequencies
116
117 =over 4
118
119 &GetFrequencies($filter, $order_by);
120
121 gets frequencies restricted on filters
122
123 =back
124
125 =cut
126
127 # -------------------------------------------------------------------
128 sub GetFrequencies {
129     my ($filters,$orderby) = @_;
130     return SearchInTable("subscription_frequency",$filters, $orderby, undef,undef, undef, "wide");
131 }
132
133 END { }    # module clean-up code here (global destructor)
134
135 1;
136 __END__
137
138 =head1 AUTHOR
139
140 Koha Development Team <http://koha-community.org/>
141
142 =cut