Skip to content

Commit a6e252a

Browse files
Merge pull request #1 from imCodePartnerAB/init_branch
Upload Plugin code
2 parents 318f332 + a8296ae commit a6e252a

File tree

3 files changed

+180
-2
lines changed

3 files changed

+180
-2
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[% INCLUDE 'doc-head-open.inc' %]
2+
<title>Koha: Plugin: Map integration</title>
3+
[% INCLUDE 'doc-head-close.inc' %]
4+
</head>
5+
<body>
6+
[% INCLUDE 'header.inc' %]
7+
[% INCLUDE 'cat-search.inc' %]
8+
9+
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a> &rsaquo; Integrate map</div>
10+
11+
<div id="doc3">
12+
<h3>Configure parameters</h3>
13+
14+
<p>Enter base url of map.</p>
15+
16+
<form method="get">
17+
<input type="hidden" name="class" value="[% CLASS %]"/>
18+
<input type="hidden" name="method" value="[% METHOD %]"/>
19+
<label for="host">Host</label>
20+
<input type="text" name="host" value="[% path_host %]"/>
21+
<input type="hidden" name="save" value="1" />
22+
<p><input type="submit" value="Save configuration"/></p>
23+
</form>
24+
25+
[% INCLUDE 'intranet-bottom.inc' %]

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
# MapIntegration
2-
Projekt av Pontus Österdahl
1+
## MapIntegration ##
2+
This Koha plugin adds configurable links to items in the Opac Details. Links are constructed using a configurable base url and the parameters department (an item's ccode), location (an item's location) and shelf (an item's callnumber).
3+
4+
***Configuration***
5+
After installing the plugin you can set the base url of the generated link.
6+
7+
***Link presentation***
8+
The links are currently added to the call number information in the Opac Details.

0 commit comments

Comments
 (0)