Bugzilla – Attachment 91604 Details for
Bug 23342
Branch Transfer Limits branch_transfer_limits.pl DBI to Koha::Object, fix variable semantics
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23342 - Branch Transfer Limits branch_transfer_limits.pl DBI to Koha::Object, fix variable semantics
Bug-23342---Branch-Transfer-Limits-branchtransferl.patch (text/plain), 8.72 KB, created by
Olli-Antti Kivilahti
on 2019-07-18 17:52:04 UTC
(
hide
)
Description:
Bug 23342 - Branch Transfer Limits branch_transfer_limits.pl DBI to Koha::Object, fix variable semantics
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2019-07-18 17:52:04 UTC
Size:
8.72 KB
patch
obsolete
>From d202f32d12813c395134b877c7aaabf57fdbfab3 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> >Date: Thu, 18 Jul 2019 19:53:13 +0300 >Subject: [PATCH] Bug 23342 - Branch Transfer Limits branch_transfer_limits.pl > DBI to Koha::Object, fix variable semantics > >branch_transfer_limits.pl uses DBI SQL statements in the controller. >Replace those with Koha::Objects. > >change term 'branchcode' to 'fromBranch' to clarify what is the purpose of the branchcode. > >Prepare for more BranchTransferLimit authorised value limiting types. > >Sponsored-by: The National Library of Finland >--- > admin/branch_transfer_limits.pl | 55 +++++++------------ > .../modules/admin/branch_transfer_limits.tt | 22 +++++--- > 2 files changed, 34 insertions(+), 43 deletions(-) > >diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl >index 82a8d214c9..0334950b26 100755 >--- a/admin/branch_transfer_limits.pl >+++ b/admin/branch_transfer_limits.pl >@@ -37,63 +37,48 @@ my ($template, $loggedinuser, $cookie) > debug => 1, > }); > >-my $dbh = C4::Context->dbh; >-my $branchcode; >-if((!defined($input->param('branchcode'))) & C4::Context::mybranch() ne '') >+my $fromBranch; >+if((!defined($input->param('fromBranch'))) && C4::Context::mybranch() ne '') > { >- $branchcode = C4::Context::mybranch(); >+ $fromBranch = Koha::Libraries->find(C4::Context::mybranch()); > } > else > { >- $branchcode = $input->param('branchcode'); >+ $fromBranch = Koha::Libraries->find($input->param('fromBranch')); > } > > # Set the template language for the correct limit type using $limitType > my $limitType = C4::Context->preference("BranchTransferLimitsType") || "ccode"; > >+my @branches = Koha::Libraries->search({}); > my @codes; >-my @branchcodes; > >-my $sth; > if ( $limitType eq 'ccode' ) { >- $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"'); >-} elsif ( $limitType eq 'itemtype' ) { >- $sth = $dbh->prepare('SELECT itemtype FROM itemtypes'); >+ @codes = map {$_->authorised_value} Koha::AuthorisedValues->search({category => 'CCODE'}, {columns => ['authorised_value']}); > } >-$sth->execute(); >-while ( my $row = $sth->fetchrow_hashref ) { >- push( @codes, $row->{ $limitType } ); >-} >- >-$sth = $dbh->prepare("SELECT branchcode FROM branches"); >-$sth->execute(); >-while ( my $row = $sth->fetchrow_hashref ) { >- push( @branchcodes, $row->{'branchcode'} ); >+elsif ( $limitType eq 'itemtype' ) { >+ @codes = map {$_->itemtype} Koha::ItemTypes->search({}, {columns => ['itemtype']}); > } > > ## If Form Data Passed, Update the Database > if ( $input->param('updateLimits') ) { >- DeleteBranchTransferLimits($branchcode); >- >+ DeleteBranchTransferLimits($fromBranch->branchcode); > > foreach my $code ( @codes ) { >- foreach my $toBranch ( @branchcodes ) { >- my $isSet = not $input->param( $code . "_" . $toBranch); >+ foreach my $toBranch ( @branches ) { >+ my $isSet = not $input->param( $code . "_" . $toBranch->branchcode); > if ( $isSet ) { >- CreateBranchTransferLimit( $toBranch, $branchcode, $code ); >+ CreateBranchTransferLimit( $toBranch->branchcode, $fromBranch->branchcode, $code ); > } > } > } > } > >-## Build branchcode loop >-my @branchcode_loop; >-foreach my $branchcode ( @branchcodes ) { >- my %row_data; >- $row_data{ branchcode } = $branchcode; >- push ( @branchcode_loop, \%row_data ); >+## Caclulate the selected branch here, this is to avoid calling Branches.all(selected...) in the Template Toolkit since we already need all the branches here. >+foreach my $branch ( @branches ) { >+ $branch->selected(1) if $branch->branchcode eq $fromBranch->branchcode; > } >-my $branchcount = scalar(@branchcode_loop); >+my $branchcount = scalar(@branches); > > ## Build the default data > my @codes_loop; >@@ -102,9 +87,9 @@ foreach my $code ( @codes ) { > my %row_data; > $row_data{ code } = $code; > $row_data{ to_branch_loop } = \@to_branch_loop; >- foreach my $toBranch ( @branchcodes ) { >+ foreach my $toBranch ( @branches ) { > my %row_data; >- my $isChecked = IsBranchTransferAllowed( $toBranch, $branchcode, $code ); >+ my $isChecked = IsBranchTransferAllowed( $toBranch->branchcode, $fromBranch->branchcode, $code ); > $row_data{ code } = $code; > $row_data{ toBranch } = $toBranch; > $row_data{ isChecked } = $isChecked; >@@ -118,8 +103,8 @@ foreach my $code ( @codes ) { > $template->param( > branchcount => $branchcount, > codes_loop => \@codes_loop, >- branchcode_loop => \@branchcode_loop, >- branchcode => $branchcode, >+ branches => \@branches, >+ fromBranch => $fromBranch, > limitType => $limitType, > ); > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt >index e3cc5bb6ae..0d656e7bef 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt >@@ -19,16 +19,22 @@ > <div class="col-sm-10 col-sm-push-2"> > <main> > >-<h1>Library [% branchcode | html %] - [% Branches.GetName( branchcode ) | html %] Checkin and transfer policy</h1> >+<h1>Library [% fromBranch.branchcode | html %] - [% fromBranch.branchname | html %] Checkin and transfer policy</h1> > <form method="get" action="/cgi-bin/koha/admin/branch_transfer_limits.pl" id="selectlibrary"> > <label for="branchselect">Select a library :</label> >- <select name="branchcode" id="branchselect"> >- [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1 ) %] >+ <select name="fromBranch" id="branchselect"> >+ [% PROCESS options_for_libraries libraries => branches %] > </select> > </form> > > <p class="help">Check the boxes for the libraries you accept to checkin items from.</p> >-<fieldset>[% IF ( limitType == 'ccode' ) %]<strong>For all collection codes: </strong>[% ELSE %]<strong>For all item types: </strong>[% END %]<a id="CheckAll" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="UncheckAll" href="#"><i class="fa fa-remove"></i> Clear all</a></fieldset> >+<fieldset> >+ [% IF ( limitType == 'ccode' ) %] >+ <strong>For all collection codes: </strong> >+ [% ELSIF ( limitType == 'itype' ) %] >+ <strong>For all item types: </strong> >+ [% END %] >+ <a id="CheckAll" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="UncheckAll" href="#"><i class="fa fa-remove"></i> Clear all</a></fieldset> > > > <div id="transferlimit_tabs" class="toptabs"> >@@ -54,12 +60,12 @@ > <tbody> > [% FOREACH to_branch_loo IN codes_loo.to_branch_loop %] > <tr> >- <td><label style="min-width:400px;" for="[% to_branch_loo.code | html %][% to_branch_loo.toBranch | html %]row">[% to_branch_loo.toBranch | html %] - [% Branches.GetName( to_branch_loo.toBranch ) | html %]</label></td> >+ <td><label style="min-width:400px;" for="[% to_branch_loo.code | html %][% to_branch_loo.toBranch.branchcode | html %]row">[% to_branch_loo.toBranch.branchcode | html %] - [% to_branch_loo.toBranch.branchname | html %]</label></td> > <td> > [% IF ( to_branch_loo.isChecked ) %] >- <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch | html %]" checked="checked" /> >+ <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch.branchcode | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch.branchcode | html %]" checked="checked" /> > [% ELSE %] >- <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch | html %]" /> >+ <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch.branchcode | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch.branchcode | html %]" /> > [% END %] > </td> > </tr> >@@ -71,7 +77,7 @@ > > <fieldset class="action"> > <input type="hidden" name="updateLimits" value="1" /> >- <input type="hidden" name="branchcode" value="[% branchcode | html %]" /> >+ <input type="hidden" name="fromBranch" value="[% fromBranch.branchcode | html %]" /> > <input type="submit" value="Save" /> > <a class="cancel" href="/cgi-bin/koha/admin/admin-home.pl">Cancel</a> > </fieldset> >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23342
: 91604