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
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 Koha::Acquisition::Booksellers;
26 use Koha::Biblioitems;
27 use Koha::Subscriptions;
28 use Koha::Subscription::Frequencies;
29 use Koha::Subscription::Numberpatterns;
31 use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
35 Koha::Subscription - Koha Subscription Object class
45 Returns the biblio linked to this subscription as a Koha::Biblio object
52 return Koha::Biblios->find($self->biblionumber);
57 Returns the vendor/supplier linked to this subscription as a Koha::Acquisition::Bookseller object
63 return Koha::Acquisition::Booksellers->find($self->aqbooksellerid);
68 my $subscribers = $subscription->subscribers;
70 return a Koha::Patrons object
76 my $schema = Koha::Database->new->schema;
77 my @borrowernumbers = $schema->resultset('Alert')->search({ externalid => $self->subscriptionid })->get_column( 'borrowernumber' )->all;
78 return Koha::Patrons->search({ borrowernumber => {-in => \@borrowernumbers } });
83 $subscription->add_subscriber( $patron );
85 Add a new subscriber (Koha::Patron) to this subscription
90 my ( $self, $patron ) = @_;
91 my $schema = Koha::Database->new->schema;
92 my $rs = $schema->resultset('Alert');
93 $rs->create({ externalid => $self->subscriptionid, borrowernumber => $patron->borrowernumber });
96 =head3 remove_subscriber
98 $subscription->remove_subscriber( $subscriber );
100 Remove a subscriber (Koha::Patron) from this subscription
104 sub remove_subscriber {
105 my ($self, $patron) = @_;
106 my $schema = Koha::Database->new->schema;
107 my $rs = $schema->resultset('Alert');
108 my $subscriber = $rs->find({ externalid => $self->subscriptionid, borrowernumber => $patron->borrowernumber });
109 $subscriber->delete if $subscriber;
114 my $frequency = $subscription->frequency
116 Return the subscription frequency
122 my $frequency_rs= $self->_result->periodicity;
123 return Koha::Subscription::Frequency->_new_from_dbic($frequency_rs);
126 =head3 get_search_info
130 sub get_search_info {
132 my $searched_sub_id = shift;
133 my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } );
134 return unless $biblio;
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 =head3 get_sharable_info
151 sub get_sharable_info {
153 my $shared_sub_id = shift;
154 my $subscription = Koha::Subscriptions->find($shared_sub_id);
155 my $biblio = Koha::Biblios->find( $subscription->biblionumber );
156 my $biblioitem = Koha::Biblioitems->find(
157 { 'biblionumber' => $subscription->biblionumber } );
159 Koha::Subscription::Frequencies->find( $subscription->periodicity );
160 my $sub_numberpatteern =
161 Koha::Subscription::Numberpatterns->find( $subscription->numberpattern );
163 my $sub_mana_info = {
164 'title' => $biblio->title,
165 'sfdescription' => $sub_frequency->description,
166 'unit' => $sub_frequency->unit,
167 'unitsperissue' => $sub_frequency->unitsperissue,
168 'issuesperunit' => $sub_frequency->issuesperunit,
169 'label' => $sub_numberpatteern->label,
170 'sndescription' => $sub_numberpatteern->description,
171 'numberingmethod' => $sub_numberpatteern->numberingmethod,
172 'label1' => $sub_numberpatteern->label1,
173 'add1' => $sub_numberpatteern->add1,
174 'every1' => $sub_numberpatteern->every1,
175 'whenmorethan1' => $sub_numberpatteern->whenmorethan1,
176 'setto1' => $sub_numberpatteern->setto1,
177 'numbering1' => $sub_numberpatteern->numbering1,
178 'label2' => $sub_numberpatteern->label2,
179 'add2' => $sub_numberpatteern->add2,
180 'every2' => $sub_numberpatteern->every2,
181 'whenmorethan2' => $sub_numberpatteern->whenmorethan2,
182 'setto2' => $sub_numberpatteern->setto2,
183 'numbering2' => $sub_numberpatteern->numbering2,
184 'label3' => $sub_numberpatteern->label3,
185 'add3' => $sub_numberpatteern->add3,
186 'every3' => $sub_numberpatteern->every3,
187 'whenmorethan3' => $sub_numberpatteern->whenmorethan3,
188 'setto3' => $sub_numberpatteern->setto3,
189 'numbering3' => $sub_numberpatteern->numbering3,
190 'issn' => $biblioitem->issn,
191 'ean' => $biblioitem->ean,
192 'publishercode' => $biblioitem->publishercode
194 return $sub_mana_info;
203 return 'Subscription';
208 Kyle M Hall <kyle@bywatersolutions.com>