1 package Koha::Suggestion;
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>.
24 use Koha::DateUtils qw( dt_from_string );
26 use Koha::AuthorisedValues;
27 use Koha::Exceptions::Suggestion;
29 use base qw(Koha::Object);
33 Koha::Suggestion - Koha Suggestion object class
43 Override the default store behavior so that new suggestions have
44 a suggesteddate of today
51 $self->STATUS("ASKED") unless $self->STATUS;
52 my @status_constants = qw(ASKED CHECKED ACCEPTED REJECTED ORDERED AVAILABLE);
53 Koha::Exceptions::Suggestion::StatusForbidden->throw( STATUS => $self->STATUS )
54 unless ( grep { $self->STATUS eq $_ } @status_constants )
55 || Koha::AuthorisedValues->search(
57 category => 'SUGGEST_STATUS',
58 authorised_value => $self->STATUS
62 $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
63 unless ( $self->suggesteddate() ) {
64 $self->suggesteddate( dt_from_string()->ymd );
67 return $self->SUPER::store();
72 my $patron = $suggestion->suggester
74 Returns the I<Koha::Patron> for the suggestion generator. I<undef> is
75 returned if no suggester is linked.
82 my $suggester_rs = $self->_result->suggester;
83 return unless $suggester_rs;
84 return Koha::Patron->_new_from_dbic($suggester_rs);
89 my $manager = $suggestion->manager;
91 Returns the manager of the suggestion (Koha::Patron for managedby field)
97 my $manager_rs = $self->_result->managedby;
98 return unless $manager_rs;
99 return Koha::Patron->_new_from_dbic($manager_rs);
104 my $rejecter = $suggestion->rejecter;
106 Returns the rejecter of the suggestion (Koha::Patron for rejectebby field)
112 my $rejecter_rs = $self->_result->managedby;
113 return unless $rejecter_rs;
114 return Koha::Patron->_new_from_dbic($rejecter_rs);
119 my $last_modifier = $suggestion->last_modifier;
121 Returns the librarian who last modified the suggestion (Koha::Patron for lastmodificationby field)
127 my $last_modifier_rs = $self->_result->managedby;
128 return unless $last_modifier_rs;
129 return Koha::Patron->_new_from_dbic($last_modifier_rs);
134 my $fund = $suggestion->fund;
136 Return the fund associated to the suggestion
142 my $fund_rs = $self->_result->budgetid;
143 return unless $fund_rs;
144 return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
155 =head3 to_api_mapping
157 This method returns the mapping for representing a Koha::Patron object
164 suggestionid => 'suggestion_id',
165 suggestedby => 'suggested_by',
166 suggesteddate => 'suggestion_date',
167 managedby => 'managed_by',
168 manageddate => 'managed_date',
169 acceptedby => 'accepted_by',
170 accepteddate => 'accepted_date',
171 rejectedby => 'rejected_by',
172 rejecteddate => 'rejected_date',
173 lastmodificationdate => 'last_status_change_date',
174 lastmodificationby => 'last_status_change_by',
177 staff_note => 'staff_note',
180 copyrightdate => 'copyright_date',
181 publishercode => 'publisher_code',
183 volumedesc => 'volume_desc',
184 publicationyear => 'publication_year',
185 place => 'publication_place',
187 biblionumber => 'biblio_id',
189 patronreason => 'patron_reason',
190 budgetid => 'budget_id',
191 branchcode => 'library_id',
192 collectiontitle => 'collection_title',
193 itemtype => 'item_type',
194 quantity => 'quantity',
195 currency => 'currency',
196 price => 'item_price',
197 total => 'total_price',
198 archived => 'archived',
204 Kyle M Hall <kyle@bywatersolutions.com>