Lines 20-25
use Modern::Perl;
Link Here
|
20 |
use Mojo::Base 'Mojolicious::Controller'; |
20 |
use Mojo::Base 'Mojolicious::Controller'; |
21 |
|
21 |
|
22 |
use Koha::Biblios; |
22 |
use Koha::Biblios; |
|
|
23 |
use Koha::RecordProcessor; |
23 |
use C4::Biblio qw(DelBiblio); |
24 |
use C4::Biblio qw(DelBiblio); |
24 |
|
25 |
|
25 |
use MARC::Record::MiJ; |
26 |
use MARC::Record::MiJ; |
Lines 148-151
sub delete {
Link Here
|
148 |
}; |
149 |
}; |
149 |
} |
150 |
} |
150 |
|
151 |
|
|
|
152 |
=head3 get_public |
153 |
|
154 |
Controller function that handles retrieving a single biblio object |
155 |
|
156 |
=cut |
157 |
|
158 |
sub get_public { |
159 |
my $c = shift->openapi->valid_input or return; |
160 |
|
161 |
my $biblio = Koha::Biblios->find( |
162 |
{ biblionumber => $c->validation->param('biblio_id') }, |
163 |
{ prefetch => ['metadata'] } ); |
164 |
|
165 |
unless ($biblio) { |
166 |
return $c->render( |
167 |
status => 404, |
168 |
openapi => { |
169 |
error => "Object not found." |
170 |
} |
171 |
); |
172 |
} |
173 |
|
174 |
return try { |
175 |
|
176 |
my $record = $biblio->metadata->record; |
177 |
|
178 |
my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); |
179 |
my $patron = $c->stash('koha.user'); |
180 |
|
181 |
# Check if the biblio should be hidden for unprivileged access |
182 |
# unless there's a logged in user, and there's an exception for it's |
183 |
# category |
184 |
unless ( $patron and $patron->category->override_hidden_items ) { |
185 |
if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) |
186 |
{ |
187 |
return $c->render( |
188 |
status => 404, |
189 |
openapi => { |
190 |
error => "Object not found." |
191 |
} |
192 |
); |
193 |
} |
194 |
} |
195 |
|
196 |
my $marcflavour = C4::Context->preference("marcflavour"); |
197 |
|
198 |
my $record_processor = Koha::RecordProcessor->new({ |
199 |
filters => 'ViewPolicy', |
200 |
options => { |
201 |
interface => 'opac', |
202 |
frameworkcode => $biblio->frameworkcode |
203 |
} |
204 |
}); |
205 |
# Apply framework's filtering to MARC::Record object |
206 |
$record_processor->process($record); |
207 |
|
208 |
$c->respond_to( |
209 |
marcxml => { |
210 |
status => 200, |
211 |
format => 'marcxml', |
212 |
text => $record->as_xml_record |
213 |
}, |
214 |
mij => { |
215 |
status => 200, |
216 |
format => 'mij', |
217 |
text => $record->to_mij |
218 |
}, |
219 |
marc => { |
220 |
status => 200, |
221 |
format => 'marc', |
222 |
text => $record->as_usmarc |
223 |
}, |
224 |
txt => { |
225 |
status => 200, |
226 |
format => 'text/plain', |
227 |
text => $record->as_formatted |
228 |
}, |
229 |
any => { |
230 |
status => 406, |
231 |
openapi => [ |
232 |
"application/marcxml+xml", |
233 |
"application/marc-in-json", |
234 |
"application/marc", |
235 |
"text/plain" |
236 |
] |
237 |
} |
238 |
); |
239 |
} |
240 |
catch { |
241 |
return $c->render( |
242 |
status => 500, |
243 |
openapi => { error => "Something went wrong, check the logs ($_)" } |
244 |
); |
245 |
}; |
246 |
} |
247 |
|
151 |
1; |
248 |
1; |
152 |
- |
|
|