Commit 4921cf7c authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

Initial commit

parents
RotatingCollections.kpz
package Koha::Plugin::Deichman::RotatingCollections;
## It's good practice to use Modern::Perl
use Modern::Perl;
## Required for all plugins
use base qw(Koha::Plugins::Base);
use CGI "-utf8";
use Koha::Database;
use Koha::Libraries;
use Try::Tiny;
## Here we set our plugin version
our $VERSION = 1.00;
## Here is our metadata, some keys are required, some are optional
our $metadata = {
name => "Rotating Collections",
author => "Benjamin Rokseth",
description => "This plugin handles rotating collections",
date_authored => "2018-04-15",
date_updated => "2018-04-15",
minimum_version => "17.11.000000",
maximum_version => undef,
version => $VERSION,
};
## This is the minimum code required for a plugin's 'new' method
## More can be added, but none should be removed
sub new {
my ( $class, $args ) = @_;
## We need to add our metadata here so our base class can access it
$args->{metadata} = $metadata;
$args->{metadata}->{class} = $class;
## Here, we call the 'new' method for our base class
## This runs some additional magic and checking
## and returns our actual $self
my $self = $class->SUPER::new($args);
return $self;
}
# Main Tool handler
sub tool {
my $self = shift;
my $cgi = $self->{cgi};
my $op = $cgi->param("op") || "";
if ( $op eq "set_homebranch" ) {
$self->set_homebranch_step;
} else {
$self->firstpage;
}
}
# Show status of closed branches, reopen or make new closures
sub firstpage {
my $self = shift;
my $cgi = $self->{cgi};
my @libraries = Koha::Libraries->search;
my @collections = getCollections();
my $template = $self->get_template({ file => "firstpage.tt" });
$template->param(
libraries => \@libraries,
collections => @collections,
);
print $cgi->header(-charset => "UTF-8");
print $template->output();
}
sub set_homebranch_step {
my $self = shift;
my $cgi = $self->{cgi};
my $coll_id = $cgi->param("collection");
my $branchcode = $cgi->param("branchcode");
my $template;
my $collection = getCollection($coll_id);
# do database updates
eval {
update_collection_items_homebranch($collection, $branchcode);
$template ||= $self->get_template( { file => "homebranch_set_success.tt" } );
1;
} or do {
my $error = $@ || "Feil i endring av eksemplarer";
$template ||= $self->get_template( { file => "homebranch_set_failure.tt" } );
$template->param( error => $error );
};
$template->param(
collection => $collection,
branchcode => $branchcode,
);
print $cgi->header(-charset => "UTF-8");
print $template->output();
}
sub update_collection_items_homebranch {
my ($collection, $branch) = @_;
my $dbh = C4::Context->dbh;
my $query = "
UPDATE items i
JOIN collections_tracking coll_track USING (itemnumber)
JOIN collections coll ON (coll.colId = coll_track.colId)
SET i.homebranch = ?
WHERE coll.colId = ?
";
my $sth = $dbh->prepare($query);
$sth->execute($branch, $collection->{colId}) or die $sth->errstr();
$query = "UPDATE collections SET colBranchcode = ? WHERE colId = ?";
$sth = $dbh->prepare($query);
$sth->execute($branch, $collection->{colId}) or die $sth->errstr();
return;
}
# Copied from C4::RotatingCollections until a Koha Object is mande
sub getCollections {
my $sth = C4::Context->dbh->prepare("SELECT * FROM collections");
$sth->execute() or die $sth->errstr();
my @results;
while ( my $row = $sth->fetchrow_hashref ) {
push( @results, $row );
}
return \@results;
}
sub getCollection {
my $coll_id = shift or die "Missing collection ID";
my $sth = C4::Context->dbh->prepare("SELECT * FROM collections WHERE colId = ?");
$sth->execute($coll_id) or die $sth->errstr();
return $sth->fetchrow_hashref;
}
1;
[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha: Tools: Rotating Collections</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<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; Rotating Collections</div>
<div id="doc3">
<h2>Endre hjemmeavdeling for bevegelig samling</h2>
<!-- Notice our form here has no 'action', this is good, it means that our forms will always get passed back to 'plugins/run.pl'. You could hard code it instead if you prefer -->
<form method="post" id="close_branch">
<input type="hidden" name="class" value="[% CLASS %]"/>
<input type="hidden" name="method" value="[% METHOD %]"/>
<input type="hidden" name="op" value="set_homebranch" />
<p>Velg bevegelig samling:</p>
<select name="collection">
[% FOREACH collection IN collections %]
<option value="[% collection.colId %]">
[% collection.colTitle %] | [% collection.colDesc %] | [% collection.colBranchcode %]
</option>
[% END %]
</select><br/><br/>
<p>Flytt alle eksemplarer til til denne avdelingen:</p>
<select name="branchcode">
[% FOREACH library IN libraries %]
<option value="[% library.branchcode %]">
[% library.branchname %]
</option>
[% END %]
</select>
<br /><br />
<input type="submit" value="Flytt eksemplarer" />
</form>
[% INCLUDE 'intranet-bottom.inc' %]
[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha: Tools: Rotating Collections</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<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; Endring av hjemmeavdeling mislyktes</div>
<div id="doc3">
Beklager, men noe gikk galt i flyttingen av eksemplarer for den bevegelige samlingen "[% collection.colTitle %]".<br /><br/>
Mer utfyllende feil:<br/><br/>
<pre>
[% error %]
</pre>
<form>
<input type="hidden" name="class" value="[% CLASS %]"/>
<input type="hidden" name="method" value="[% METHOD %]"/>
<input type="submit" value="gå tilbake" />
</form>
[% INCLUDE 'intranet-bottom.inc' %]
[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha: Tools: Branch Closure</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<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; Endring av hjemmeavdeling lyktes</div>
<div id="doc3">
Alle eksemplarer tilknyttet den bevegelige samlingen "[% collection.colTitle %]" er nå flyttet til [% Branches.GetName(branchcode) %].<br />
<form>
<input type="hidden" name="class" value="[% CLASS %]"/>
<input type="hidden" name="method" value="[% METHOD %]"/>
<input type="submit" value="gå tilbake" />
</form>
[% INCLUDE 'intranet-bottom.inc' %]
MIT License
Copyright (c) 2018 Digital Development Team at Deichman Public Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
## README.pm
# About
This plugin is for special handling of rotating collections.
It currently lets you:
- permanently set homebranch of all items in a rotating collection
# Setup
To enable Koha plugins:
* enable syspref UseKohaPlugins
* in koha-conf.xml (section <config>):
```
<pluginsdir>__PLUGINS_DIR__</pluginsdir>
<enable_plugins>1</enable_plugins>
```
Note: if <plugindir> is not set, it will default to /var/lib/koha/$intance/plugins
# Install
A new plugin must be zip-packed `pluginname.kpz` and contain the correct tree
```
./Koha/
Plugin/
Deichman/ # Optional subfolder to organize plugins
NameOfPlugin.pm # The plugin, containing required methods new, install, uninstall, configure, etc.
NameOfPlugin/ # Subfolder with optional files, accessible to module as current folder, and in templates as [% PLUGIN_PATH %]
configure.tt
report-step1.tt
tool-step1.tt
etc.
```
Plugin can then be uploaded in /cgi-bin/koha/plugins/plugins-home.pl
Optional configuration can be done from there
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment