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);
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);
132 sub get_search_info {
133 my $searched_sub_id = shift;
134 my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } );
136 Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } );
138 my $sub_mana_info = {
139 'title' => $biblio->title,
140 'issn' => $biblioitem->issn,
141 'ean' => $biblioitem->ean,
142 'publishercode' => $biblioitem->publishercode
144 return $sub_mana_info;
147 sub get_sharable_info {
148 my $shared_sub_id = shift;
149 my $subscription = Koha::Subscriptions->find($shared_sub_id);
150 my $biblio = Koha::Biblios->find( $subscription->biblionumber );
151 my $biblioitem = Koha::Biblioitems->find(
152 { 'biblionumber' => $subscription->biblionumber } );
154 Koha::Subscription::Frequencies->find( $subscription->periodicity );
155 my $sub_numberpatteern =
156 Koha::Subscription::Numberpatterns->find( $subscription->numberpattern );
158 my $sub_mana_info = {
159 'title' => $biblio->title,
160 'sfdescription' => $sub_frequency->description,
161 'unit' => $sub_frequency->unit,
162 'unitsperissue' => $sub_frequency->unitsperissue,
163 'issuesperunit' => $sub_frequency->issuesperunit,
164 'label' => $sub_numberpatteern->label,
165 'sndescription' => $sub_numberpatteern->description,
166 'numberingmethod' => $sub_numberpatteern->numberingmethod,
167 'label1' => $sub_numberpatteern->label1,
168 'add1' => $sub_numberpatteern->add1,
169 'every1' => $sub_numberpatteern->every1,
170 'whenmorethan1' => $sub_numberpatteern->whenmorethan1,
171 'setto1' => $sub_numberpatteern->setto1,
172 'numbering1' => $sub_numberpatteern->numbering1,
173 'label2' => $sub_numberpatteern->label2,
174 'add2' => $sub_numberpatteern->add2,
175 'every2' => $sub_numberpatteern->every2,
176 'whenmorethan2' => $sub_numberpatteern->whenmorethan2,
177 'setto2' => $sub_numberpatteern->setto2,
178 'numbering2' => $sub_numberpatteern->numbering2,
179 'label3' => $sub_numberpatteern->label3,
180 'add3' => $sub_numberpatteern->add3,
181 'every3' => $sub_numberpatteern->every3,
182 'whenmorethan3' => $sub_numberpatteern->whenmorethan3,
183 'setto3' => $sub_numberpatteern->setto3,
184 'numbering3' => $sub_numberpatteern->numbering3,
185 'issn' => $biblioitem->issn,
186 'ean' => $biblioitem->ean,
187 'publishercode' => $biblioitem->publishercode
189 return $sub_mana_info;
193 return 'Subscription';
198 Kyle M Hall <kyle@bywatersolutions.com>