1+ package Koha::Plugin::MapIntegration ;
2+
3+ use C4::Languages;
4+ use Modern::Perl;
5+ use Koha::AuthorisedValues;
6+ use Koha::Biblios;
7+ use Koha::Items;
8+ use Koha::Item;
9+
10+ use C4::Biblio qw(
11+ GetBiblioData) ;
12+
13+ use base qw( Koha::Plugins::Base) ;
14+
15+ our $VERSION = " 0.1.3" ;
16+
17+ our $metadata = {
18+ name => ' Map Integration' ,
19+ author => ' imCode.com' ,
20+ date_authored => ' 2023-12-01' ,
21+ date_updated => " 2024-01-15" ,
22+ minimum_version => ' 21.11.00.000' ,
23+ maximum_version => undef ,
24+ version => $VERSION ,
25+ description => ' This plugin integrates map links for items.' ,
26+ };
27+
28+ sub new {
29+ my ( $class , $args ) = @_ ;
30+
31+ $args -> {' metadata' } = $metadata ;
32+ $args -> {' metadata' }-> {' class' } = $class ;
33+
34+ my $self = $class -> SUPER::new($args );
35+ $self -> {cgi } = CGI-> new();
36+
37+ return $self ;
38+ }
39+
40+ sub configure {
41+ my ( $self , $args ) = @_ ;
42+
43+ my $cgi = $self -> {' cgi' };
44+
45+ unless ( $cgi -> param(' save' )) {
46+
47+ my $template = $self -> get_template( { file => ' configure.tt' } );
48+
49+ # # Grab value if exist
50+ $template -> param(
51+ path_host => $self -> retrieve_data(' path_host' ),
52+ );
53+
54+ return $self -> output_html( $template -> output() );
55+ }
56+ else {
57+ $self -> store_data(
58+ {
59+ path_host => $cgi -> param(' host' )
60+ }
61+ );
62+ $self -> go_home();
63+ }
64+ }
65+
66+ sub opac_js {
67+ my ( $self ) = @_ ;
68+ my $cgi = $self -> {' cgi' };
69+ my $script_name = $cgi -> script_name;
70+
71+ if ($script_name =~ / opac-detail\. pl/ ) {
72+
73+ my $language = C4::Languages::getlanguage();
74+
75+ my $prompt = " Locate shelf" ;
76+ if ($language eq " sv-SE" ) {
77+ $prompt = " Hitta till hyllan" ;
78+ }
79+
80+ my $biblionumber = $cgi -> param(' biblionumber' );
81+
82+ my $biblio = Koha::Biblios-> find($biblionumber );
83+
84+ my $items = Koha::Items-> search( { biblionumber => $biblionumber });
85+
86+ my $dat = &GetBiblioData($biblionumber );
87+
88+ # inspired by opac-detail.pl
89+ my $shelflocations =
90+ { map { $_ -> {authorised_value } => $_ -> {opac_description } } Koha::AuthorisedValues-> get_descriptions_by_koha_field( { frameworkcode => $dat -> {frameworkcode }, kohafield => ' items.location' } ) };
91+ my $collections =
92+ { map { $_ -> {authorised_value } => $_ -> {opac_description } } Koha::AuthorisedValues-> get_descriptions_by_koha_field( { frameworkcode => $dat -> {frameworkcode }, kohafield => ' items.ccode' } ) };
93+
94+ my $js = " <script> const item_paths = [];" ;
95+ my $host = $self -> retrieve_data(' path_host' );
96+ $js .= " var host = \" " . $host . " \" ;" ;
97+ $js .= " var prompt = \" " . $prompt . " \" ;" ;
98+ $js .= " var collections = {};" ;
99+ $js .= " var locations = {};" ;
100+
101+ while (my $item = $items -> next) {
102+
103+ if (defined $item -> ccode && $item -> ccode ne " " ) {
104+ $js .= " collections[\" " . $collections -> {$item -> ccode} . " \" ] = \" " . $item -> ccode . " \" ;" ;
105+ }
106+ if (defined $item -> location && $item -> location ne " " ) {
107+ $js .= " locations[\" " . $shelflocations -> {$item -> location} . " \" ] = \" " . $item -> location . " \" ;" ;
108+ }
109+ }
110+
111+
112+
113+
114+ $js .= <<'JS' ;
115+
116+ $('#holdingst').find("tbody").find("tr").each(function(index) {
117+
118+ var collectionDesc = $(this).find(".collection").text();
119+ var shelvingLocationspan = $(this).find(".shelving_location").find(".shelvingloc");
120+ var shelvingLocation = $(shelvingLocationspan).text();
121+
122+ var callNoTd = $(this).find(".call_no");
123+
124+ var t = $(callNoTd).text();
125+
126+ var b = $.trim(t).split(' ');
127+
128+ var shelf = b[0];
129+
130+ var location = shelvingLocation in locations ? locations[shelvingLocation] : "";
131+ var ccode = collectionDesc in collections ? collections[collectionDesc] : "";
132+
133+ var wagnerGuidePath = host + "?department=" + ccode + "&location=" + location + "&shelf=" + shelf;
134+
135+ $(callNoTd).append("<a href=\"" + wagnerGuidePath + "\">" + prompt + "</a>");
136+ });
137+
138+ JS
139+
140+ $js .= " </script>" ;
141+
142+ return $js ;
143+
144+ }
145+ }
146+
147+ 1;
0 commit comments