1 package Koha::Plugin::Test;
3 ## It's good practice to use Modern::Perl
7 use Koha::Plugins::Tab;
10 use Mojo::JSON qw( decode_json );
12 ## Required for all plugins
13 use base qw(Koha::Plugins::Base);
15 our $VERSION = "v1.01";
17 name => 'Test Plugin',
18 author => 'Kyle M Hall',
19 description => 'Test plugin',
20 date_authored => '2013-01-14',
21 date_updated => '2013-01-14',
22 minimum_version => '3.11',
23 maximum_version => undef,
26 my_example_tag => 'find_me',
29 ## This is the minimum code required for a plugin's 'new' method
30 ## More can be added, but none should be removed
32 my ( $class, $args ) = @_;
33 $args->{'metadata'} = $metadata;
34 my $self = $class->SUPER::new($args);
39 my ( $self, $args ) = @_;
40 return "Koha::Plugin::Test::report";
44 my ( $self, $args ) = @_;
45 return "Koha::Plugin::Test::tool";
49 my ( $self, $args ) = @_;
50 return "Koha::Plugin::Test::to_marc";
53 sub intranet_catalog_biblio_enhancements_toolbar_button {
54 my ( $self, $args ) = @_;
55 return "Koha::Plugin::Test::intranet_catalog_biblio_enhancements_toolbar_button";
58 sub intranet_catalog_biblio_enhancements {
59 my ( $self, $args ) = @_;
60 return "Koha::Plugin::Test::intranet_catalog_biblio_enhancements";
63 sub opac_online_payment {
64 my ( $self, $args ) = @_;
65 return "Koha::Plugin::Test::opac_online_payment";
68 sub opac_online_payment_begin {
69 my ( $self, $args ) = @_;
70 return "Koha::Plugin::Test::opac_online_payment_begin";
73 sub opac_online_payment_end {
74 my ( $self, $args ) = @_;
75 return "Koha::Plugin::Test::opac_online_payment_end";
79 my ( $self, $args ) = @_;
80 return "Koha::Plugin::Test::opac_head";
84 my ( $self, $args ) = @_;
85 return "Koha::Plugin::Test::opac_js";
89 my ( $self, $args ) = @_;
90 return "Koha::Plugin::Test::intranet_head";
94 my ( $self, $args ) = @_;
95 return "Koha::Plugin::Test::intranet_js";
98 sub item_barcode_transform {
99 my ( $self, $barcode ) = @_;
100 my $param = $$barcode;
101 if ( Scalar::Util::looks_like_number( $$barcode ) ) {
102 $$barcode = $$barcode * 2
104 Koha::Exception->throw("item_barcode_transform called with parameter: $param");
107 sub patron_barcode_transform {
108 my ( $self, $barcode ) = @_;
110 Koha::Exception->throw("patron_barcode_transform called with parameter: $$barcode");
114 my ( $self, $args ) = @_;
115 return "Koha::Plugin::Test::configure";
119 my ( $self, $args ) = @_;
120 return "Koha::Plugin::Test::install";
124 my ( $self, $args ) = @_;
125 return "Koha::Plugin::Test::upgrade";
129 my ( $self, $args ) = @_;
130 return "Koha::Plugin::Test::uninstall";
135 $self->output( '¡Hola output!', 'json' );
138 sub test_output_html {
140 $self->output_html( '¡Hola output_html!' );
147 sub after_hold_create {
148 my ( $self, $param ) = @_;
149 Koha::Exception->throw("after_hold_create called with parameter " . ref($param) );
152 sub before_biblio_metadata_store {
153 my ( $self, $record ) = @_;
155 $record->insert_fields_ordered(
165 sub after_biblio_action {
166 my ( $self, $params ) = @_;
167 my $action = $params->{action} // '';
168 my $biblio = $params->{biblio};
169 my $biblio_id = $params->{biblio_id};
171 if ( $action ne 'delete' ) {
172 Koha::Exception->throw("after_biblio_action called with action: $action, ref: " . ref($biblio) );
175 Koha::Exception->throw("after_biblio_action called with action: $action, id: $biblio_id") if $biblio_id;
179 sub after_item_action {
180 my ( $self, $params ) = @_;
181 my $action = $params->{action} // '';
182 my $item = $params->{item};
183 my $item_id = $params->{item_id};
185 if ( $action ne 'delete' ) {
186 my $itemnumber_defined = (defined $item->itemnumber) ? 'yes' : 'no';
187 my $item_id_defined = (defined $item_id) ? 'yes' : 'no';
188 Koha::Exception->throw("after_item_action called with action: $action, ref: " . ref($item) . " ".
189 "item_id defined: $item_id_defined ".
190 "itemnumber defined: $itemnumber_defined" );
193 Koha::Exception->throw("after_item_action called with action: $action, id: $item_id" ) if $item_id;
197 sub after_authority_action {
198 my ( $self, $params ) = @_;
199 my $action = $params->{action} // q{};
200 my $id = $params->{authority_id} // 0;
201 Koha::Exception->throw("after_authority_action called with action: $action, id: $id");
204 sub after_circ_action {
205 my ( $self, $params ) = @_;
207 my $action = $params->{action};
208 my $checkout = $params->{payload}->{checkout};
209 my $payload = $params->{payload};
211 my $type = $payload->{type};
213 if ( $action eq 'renewal' ) {
214 Koha::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
216 elsif ( $action eq 'checkout') {
217 Koha::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout) . " type: $type");
219 elsif ( $action eq 'checkin' ) {
220 Koha::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
224 sub after_hold_action {
225 my ( $self, $params ) = @_;
227 my $action = $params->{action};
228 my $hold = $params->{payload}->{hold};
230 Koha::Exception->throw(
231 "after_hold_action called with action: $action, ref: " . ref($hold) );
235 my ( $self, $args ) = @_;
241 "x-mojo-to": "Test::Controller#bother",
242 "operationId": "BotherPatron",
249 "description": "A bothered patron",
254 "description": "If the patron has been bothered",
261 "description": "An error occurred",
266 "description": "An explanation for the error",
273 "x-koha-authorization": {
280 "/public/patrons/bother": {
282 "x-mojo-to": "Test::Controller#bother",
283 "operationId": "PubliclyBotherPatron",
290 "description": "A bothered patron",
295 "description": "If the patron has been bothered",
302 "description": "Authentication required",
307 "description": "An explanation for the error",
319 return decode_json($spec);
323 my ( $self, $args ) = @_;
325 my $password = $args->{'password'};
326 if ( $password && $password =~ m/^\d{4}$/ ) {
327 return { error => 0 };
332 msg => "PIN should be four digits"
337 sub intranet_catalog_biblio_tab {
340 Koha::Plugins::Tab->new(
343 content => 'This is content for tab 1'
348 Koha::Plugins::Tab->new(
351 content => 'This is content for tab 2'
358 sub background_tasks {
360 foo => 'MyPlugin::Class::Foo',
361 bar => 'MyPlugin::Class::Bar',
365 sub after_account_action {
366 my ( $self, $params ) = @_;
368 my $action = $params->{action};
369 my $line = $params->{payload}->{line};
370 my $type = $params->{payload}->{type};
372 Koha::Exception->throw(
373 "after_account_action called with action: $action, type: $type, ref: " . ref($line) );
376 sub after_recall_action {
377 my ( $self, $params ) = @_;
379 my $action = $params->{action};
380 my $recall = $params->{payload}->{recall};
382 Koha::Exception->throw(
383 "after_recall_action called with action: $action, ref: " . ref($recall) );
386 sub template_include_paths {
390 $self->mbf_path('inc'),
394 sub ill_table_actions {
395 my ( $self, $table_actions ) = @_;
400 button_link_text => 'Test text',
401 append_column_data_to_link => 1,
402 button_class => 'test class',
403 button_link => 'test link'