Line 0
Link Here
|
|
|
1 |
package Koha::Serial::Subscription; |
2 |
|
3 |
# Copyright KohaSuomi 2015 |
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 3 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 Modern::Perl; |
21 |
|
22 |
use Carp; |
23 |
|
24 |
use Koha::Database; |
25 |
use Koha::Serial::Subscription::Frequencies; |
26 |
use Koha::Serial::Subscription::Numberpatterns; |
27 |
use Koha::Serial::Serials; |
28 |
use Koha::Borrowers; |
29 |
use Koha::Biblios; |
30 |
use Koha::Acquisition::Booksellers; |
31 |
use Koha::Items; |
32 |
|
33 |
use base qw(Koha::Object); |
34 |
|
35 |
sub type { |
36 |
return 'Subscription'; |
37 |
} |
38 |
|
39 |
sub periodicity { |
40 |
my ($self, $periodicity) = @_; |
41 |
|
42 |
if ($periodicity) { |
43 |
$periodicity = Koha::Serial::Subscription::Frequencies->cast($periodicity); |
44 |
$self->{periodicity} = $periodicity; |
45 |
$self->set({periodicity => $periodicity->_result()->id}); |
46 |
$self->store(); |
47 |
} |
48 |
|
49 |
unless ($self->{periodicity}) { |
50 |
my $frequency = $self->_result()->periodicity(); |
51 |
$self->{periodicity} = Koha::Serial::Subscription::Frequencies->cast($frequency); |
52 |
} |
53 |
|
54 |
return $self->{periodicity}; |
55 |
} |
56 |
|
57 |
sub numberpattern { |
58 |
my ($self, $numberpattern) = @_; |
59 |
|
60 |
if ($numberpattern) { |
61 |
$numberpattern = Koha::Serial::Subscription::Numberpatterns->cast($numberpattern); |
62 |
$self->{numberpattern} = $numberpattern; |
63 |
$self->set({numberpattern => $numberpattern->_result()->id}); |
64 |
$self->store(); |
65 |
} |
66 |
|
67 |
unless ($self->{numberpattern}) { |
68 |
my $numberpattern = $self->_result()->numberpattern(); |
69 |
$self->{numberpattern} = Koha::Serial::Subscription::Numberpatterns->cast($numberpattern); |
70 |
} |
71 |
|
72 |
return $self->{numberpattern}; |
73 |
} |
74 |
|
75 |
sub biblio { |
76 |
my ($self, $biblio) = @_; |
77 |
|
78 |
if ($biblio) { |
79 |
$biblio = Koha::Biblios->cast($biblio); |
80 |
$self->{biblio} = $biblio; |
81 |
$self->set({biblio => $biblio->_result()->id}); |
82 |
$self->store(); |
83 |
} |
84 |
|
85 |
unless ($self->{biblio}) { |
86 |
my $biblio = $self->_result()->biblio(); |
87 |
$self->{biblio} = Koha::Biblios->cast($biblio); |
88 |
} |
89 |
|
90 |
return $self->{biblio}; |
91 |
} |
92 |
|
93 |
sub borrower { |
94 |
my ($self, $borrower) = @_; |
95 |
|
96 |
if ($borrower) { |
97 |
$borrower = Koha::Borrowers->cast($borrower); |
98 |
$self->{borrower} = $borrower; |
99 |
$self->set({librarian => $borrower->_result()->id}); |
100 |
$self->store(); |
101 |
} |
102 |
|
103 |
unless ($self->{borrower}) { |
104 |
my $borrower = $self->_result()->librarian(); |
105 |
$self->{borrower} = Koha::Borrowers->cast($borrower); |
106 |
} |
107 |
|
108 |
return $self->{borrower}; |
109 |
} |
110 |
|
111 |
sub bookseller { |
112 |
my ($self, $bookseller) = @_; |
113 |
|
114 |
if ($bookseller) { |
115 |
$bookseller = Koha::Acquisition::Booksellers->cast($bookseller); |
116 |
$self->{bookseller} = $bookseller; |
117 |
$self->set({bookseller => $bookseller->_result()->id}); |
118 |
$self->store(); |
119 |
} |
120 |
|
121 |
unless ($self->{bookseller}) { |
122 |
my $booksellerid = $self->_result()->aqbooksellerid(); |
123 |
$self->{bookseller} = Koha::Acquisition::Booksellers->cast($booksellerid); |
124 |
} |
125 |
|
126 |
return $self->{bookseller}; |
127 |
} |
128 |
|
129 |
sub serials { |
130 |
my ($self) = @_; |
131 |
|
132 |
unless ($self->{serials}) { |
133 |
my @serials = Koha::Serial::Serials->search({subscriptionid => $self->subscriptionid}); |
134 |
$self->{serials} = \@serials; |
135 |
} |
136 |
|
137 |
return $self->{serials}; |
138 |
} |
139 |
|
140 |
sub items { |
141 |
my ($self) = @_; |
142 |
|
143 |
unless ($self->{items}) { |
144 |
my @items; |
145 |
my $serials = $self->serials(); |
146 |
for (my $i=0 ; $i<scalar(@$serials) ; $i++) { |
147 |
my @serialitems = $serials->[$i]->_result()->serialitems(); |
148 |
foreach my $si (@serialitems) { |
149 |
my $item = $si->itemnumber; |
150 |
$item = Koha::Items->cast($item); |
151 |
push @items, $item; |
152 |
} |
153 |
} |
154 |
$self->{items} = \@items; |
155 |
} |
156 |
|
157 |
return $self->{items}; |
158 |
} |
159 |
|
160 |
1; |