1 package Koha
::Subscription
;
3 # Copyright ByWater Solutions 2015
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 3 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.
26 use Koha
::Acquisition
::Booksellers
;
27 use Koha
::Biblioitems
;
28 use Koha
::Subscriptions
;
29 use Koha
::Subscription
::Frequencies
;
30 use Koha
::Subscription
::Numberpatterns
;
33 use base
qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
37 Koha::Subscription - Koha Subscription Object class
47 Returns the biblio linked to this subscription as a Koha::Biblio object
54 return scalar Koha
::Biblios
->find($self->biblionumber);
59 Returns the vendor/supplier linked to this subscription as a Koha::Acquisition::Bookseller object
65 return scalar Koha
::Acquisition
::Booksellers
->find($self->aqbooksellerid);
70 my $subscribers = $subscription->subscribers;
72 return a Koha::Patrons object
78 my $schema = Koha
::Database
->new->schema;
79 my @borrowernumbers = $schema->resultset('Alert')->search({ externalid
=> $self->subscriptionid })->get_column( 'borrowernumber' )->all;
80 return Koha
::Patrons
->search({ borrowernumber
=> {-in => \
@borrowernumbers } });
85 $subscription->add_subscriber( $patron );
87 Add a new subscriber (Koha::Patron) to this subscription
92 my ( $self, $patron ) = @_;
93 my $schema = Koha
::Database
->new->schema;
94 my $rs = $schema->resultset('Alert');
95 $rs->create({ externalid
=> $self->subscriptionid, borrowernumber
=> $patron->borrowernumber });
98 =head3 remove_subscriber
100 $subscription->remove_subscriber( $subscriber );
102 Remove a subscriber (Koha::Patron) from this subscription
106 sub remove_subscriber
{
107 my ($self, $patron) = @_;
108 my $schema = Koha
::Database
->new->schema;
109 my $rs = $schema->resultset('Alert');
110 my $subscriber = $rs->find({ externalid
=> $self->subscriptionid, borrowernumber
=> $patron->borrowernumber });
111 $subscriber->delete if $subscriber;
116 my $frequency = $subscription->frequency
118 Return the subscription frequency
124 my $frequency_rs= $self->_result->periodicity;
125 return Koha
::Subscription
::Frequency
->_new_from_dbic($frequency_rs);
128 =head3 get_search_info
132 sub get_search_info
{
134 my $searched_sub_id = shift;
135 my $biblio = Koha
::Biblios
->find( { 'biblionumber' => $searched_sub_id } );
136 return unless $biblio;
138 Koha
::Biblioitems
->find( { 'biblionumber' => $searched_sub_id } );
140 my $sub_mana_info = {
141 'title' => $biblio->title,
142 'issn' => $biblioitem->issn,
143 'ean' => $biblioitem->ean,
144 'publishercode' => $biblioitem->publishercode
146 return $sub_mana_info;
149 =head3 get_sharable_info
153 sub get_sharable_info
{
155 my $shared_sub_id = shift;
156 my $subscription = Koha
::Subscriptions
->find($shared_sub_id);
157 my $biblio = Koha
::Biblios
->find( $subscription->biblionumber );
158 my $biblioitem = Koha
::Biblioitems
->find(
159 { 'biblionumber' => $subscription->biblionumber } );
161 Koha
::Subscription
::Frequencies
->find( $subscription->periodicity );
162 my $sub_numberpatteern =
163 Koha
::Subscription
::Numberpatterns
->find( $subscription->numberpattern );
165 my $sub_mana_info = {
166 'title' => $biblio->title,
167 'sfdescription' => $sub_frequency->description,
168 'unit' => $sub_frequency->unit,
169 'unitsperissue' => $sub_frequency->unitsperissue,
170 'issuesperunit' => $sub_frequency->issuesperunit,
171 'label' => $sub_numberpatteern->label,
172 'sndescription' => $sub_numberpatteern->description,
173 'numberingmethod' => $sub_numberpatteern->numberingmethod,
174 'label1' => $sub_numberpatteern->label1,
175 'add1' => $sub_numberpatteern->add1,
176 'every1' => $sub_numberpatteern->every1,
177 'whenmorethan1' => $sub_numberpatteern->whenmorethan1,
178 'setto1' => $sub_numberpatteern->setto1,
179 'numbering1' => $sub_numberpatteern->numbering1,
180 'label2' => $sub_numberpatteern->label2,
181 'add2' => $sub_numberpatteern->add2,
182 'every2' => $sub_numberpatteern->every2,
183 'whenmorethan2' => $sub_numberpatteern->whenmorethan2,
184 'setto2' => $sub_numberpatteern->setto2,
185 'numbering2' => $sub_numberpatteern->numbering2,
186 'label3' => $sub_numberpatteern->label3,
187 'add3' => $sub_numberpatteern->add3,
188 'every3' => $sub_numberpatteern->every3,
189 'whenmorethan3' => $sub_numberpatteern->whenmorethan3,
190 'setto3' => $sub_numberpatteern->setto3,
191 'numbering3' => $sub_numberpatteern->numbering3,
192 'issn' => $biblioitem->issn,
193 'ean' => $biblioitem->ean,
194 'publishercode' => $biblioitem->publishercode
196 return $sub_mana_info;
205 return 'Subscription';
210 Kyle M Hall <kyle@bywatersolutions.com>