Koha/admin
Jonathan Druart 19a977dc7b Bug 15758: Koha::Libraries - Remove GetBranchName
This is the fourth and last patch set to remove C4::Branch.
The real purpose of this patch is to standardise and refactor some code
which is related to the libraries selection/display.
Its unconfessed purpose is to remove the C4::Branch package.

Before this patch set, only 6 subroutines still existed in the C4::Branch
package:
- GetBranchName
- GetBranchesLoop
- mybranch
- onlymine
- GetBranches
- GetBranch

GetBranchName basically returns the branchname for a given branchcode.
The branchname is only used for a display purpose and we don't need to
retrieve it in package or pl scripts (unless for a few exceptions).
We have a `Branches` template plugin with a `GetName` method which does
exactly this job.
To achieve this removal, we will use this template plugin and delete the
GetBranchName from pl and pm files.
The `Branches.all()` will now select the library of the logged in user
if no `selected` parameter has been passed.
This new behavior could cause regressions, for instance there are some
places where we do not want an option preselected (batch item
modification for instance), keep that in mind when testing.

GetBranchesLoop took 3 parameters: $branch and $onlymine.
The first one was used to set a "selected" flag, for a display purpose:
select an option in the libraries dropdown lists.
The second one was useless: If not passed or set to 0, the
`C4::Branch::onlymine` subroutine was called.
This onlymine flag was use to know if the logged in user was able to see
other libraries infos.
A patron can see the infos from other libraries if IndependentBranches
is not set OR if he has the superlibrarian permission.
Prior to this patch set, the "onlymine test" was done on different
places (neworderempty.pl, additem.pl, holidays.pl, etc.), including the
Branches TT plugin. In this patch set, this test is only done on one
place (C4::Context::only_my_library, code moved from
C4::Branch::onlymine).
To accomplish the same job as this subroutine, we just need to call the
`Branches.all()` method from the `Branches` TT plugin. It already
accepts a `selected` parameter to set a flag on the option to select.
To avoid the repetitive
  [% IF selected %]<option selected="selected">[% ELSE %]<option>[% END %]
pattern, a new `html_helpers` TT include file has been created, it
defines an `options_for_libraries` block, which takes a `selected`
parameter. We could imagine to use this include file for other
selects.

The 'mybranch` and `onlymine` subroutines of the C4::Branch package have
been moved to C4::Context. onlymine has been renamed with
only_my_library. There are only 4 occurrences of it, against 11 before
this patch set.
There 2 subroutines are Context-centric and it makes sense to put them
in `C4::Context` (at least it's the least worst place!)

GetBranches is the tricky part of this patch set: It retrieves all the
libraries, independently of the value of IndependentBranches.
To keep the same way as the existing calls of `Branches.all()`, I have
added a `unfiltered` parameter. If set, the `Branches.all()` will call
a usual Koha::Libraries->search method, otherwise
Koha::Libraries->search_filtered will be called. This new method will
check if the logged in user is allowed to see other libraries or only
its library.
Note that this `GetBranches` subroutine also created a `category` key:
it allowed to get the list of groups (of libraries) where this library
existed. Thanks to a previous patch set (bug 15295), this value was
not used anymore (I may have missed something!).

Note that the only use of `GetBranch` was buggy (see bug 15746).

Test plan (for the whole patch set):
The best way to test this whole patch set is to test with 2 instances: 1
with the patch set applied, 1 using master, to be sure there is no
regression.
It would be good to test the same with `IndependentBranches` and the
without `IndependentBranches`.
No difference should be found.
The tester must focus on the library dropdowns on as many forms as
possible.
You will notice changes in the order of the options: the libraries will
now be ordered by branchname (instead of branchcode in some places).
A special attention will be given to the following page:
- acqui/neworderempty.pl
- catalogue/search.pl
- members/members-home.pl (header?)
- opac/opac-topissues.pl
- tools/holidays.pl
- admin/branch_transfer_limits.pl
- admin/item_circulation_alerts.pl
- rotating_collections/transferCollection.pl
- suggestion/suggestion.pl
- tools/export.pl

Notes for QA:
- There are 2 FIXMEs in the patch set, I have kept the existing behavior,
but I am not sure it's the good one. Feel free to open a bug report and
I will fill a patch if you think it's not correct. Otherwise, remove the
FIXME lines in a follow-up patch.
- The whole patch set is huge and makes a lot of changes.
But it finally will tremendously reduce the number of lines:
716 insertions for 1910 deletions

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-09-08 14:36:01 +00:00
..
searchengine/elasticsearch Bug 12748: (QA followup) fix several tiny QA tools warnings 2016-04-26 20:20:13 +00:00
add_user_search.pl Bug 15407: Koha::Patron::Categories - replace C4::Category->all 2016-09-08 13:29:03 +00:00
admin-home.pl Bug 9021 [QA Followup] - Use TT plugin instead of passing syspref via script 2016-02-14 12:40:05 +00:00
aqbudgetperiods.pl Bug 16154: Fix some other occurrences 2016-04-26 23:16:44 +00:00
aqbudgets.pl Bug 16154: CGI->multi_param - Force scalar context 2016-04-26 23:16:43 +00:00
aqcontract.pl Bug 16154: Fix some other occurrences 2016-04-26 23:16:44 +00:00
aqplan.pl Bug 15009: QA follow-up 2016-04-29 13:00:21 +00:00
audio_alerts.pl Bug 16154: CGI->multi_param - Declare a list 2016-04-26 23:16:42 +00:00
auth_subfields_structure.pl Bug 16154: CGI->multi_param - Declare a list 2016-04-26 23:16:42 +00:00
auth_tag_structure.pl Bug 15381: Remove getauthtypes and getauthtype 2015-12-31 18:59:02 +00:00
authorised_values.pl Bug 16154: Fix some other occurrences 2016-04-26 23:16:44 +00:00
authtypes.pl Bug 16012: Restore the ability to edit default authority type 2016-03-21 22:41:44 +00:00
biblio_framework.pl Bug 17189: Replace occurrences of 'use Koha::Cache' 2016-09-08 10:24:47 +00:00
branch_transfer_limits.pl Bug 15758: Koha::Libraries - Remove GetBranchName 2016-09-08 14:36:01 +00:00
branches.pl Bug 16259: Replace CGI->param with CGI->multi_param in list context - part 2 2016-05-16 17:28:06 +00:00
categories.pl Bug 6906 - show 'Borrower has previously issued... 2016-07-08 13:40:08 +00:00
check_budget_parent.pl Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
check_parent_total.pl Bug 14383: admin: Fix some typos in comments and documentation 2015-06-22 17:34:46 -03:00
checkmarc.pl Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
cities.pl Bug 14888: Update copyright and wording 2015-10-05 12:00:38 -03:00
classsources.pl Bug 16013: Make classification sources deletable 2016-03-21 22:40:37 +00:00
clone-rules.pl Bug 15758: Koha::Libraries - Remove GetBranchName 2016-09-08 14:36:01 +00:00
columns_settings.pl Bug 16154: CGI->multi_param - Declare a list 2016-04-26 23:16:42 +00:00
columns_settings.yml Bug 14753: Add the "page" parameter in the yml file 2016-03-02 04:18:33 +00:00
currency.pl Bug 15962: Block the currency deletion if used 2016-03-21 22:56:11 +00:00
didyoumean.pl Bug 11944: use CGI( -utf8 ) everywhere 2015-01-13 13:07:21 -03:00
edi_accounts.pl Bug 16237: Allow entering of EDI accounts with plugins disabled 2016-04-20 16:46:34 +00:00
edi_ean_accounts.pl Bug 16256 - Can't edit library EAN if you leave EAN empty 2016-04-20 16:52:17 +00:00
env_tz_test.pl Bug 14383: admin: Fix some typos in comments and documentation 2015-06-22 17:34:46 -03:00
fieldmapping.pl Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
import_export_framework.pl Bug 16035: MARC default bibliographic framework Export fix 2016-09-08 12:07:55 +00:00
item_circulation_alerts.pl Bug 15407: Koha::Patron::Categories - replace C4::Category->all 2016-09-08 13:29:03 +00:00
items_search_field.pl Bug 11425: Add item search form in staff interface 2014-11-04 19:08:12 -03:00
items_search_fields.pl Bug 11425: Add item search form in staff interface 2014-11-04 19:08:12 -03:00
itemtypes.pl Bug 16157: Move the selected flag from GetAuthorisedValues to the templates 2016-04-07 00:16:09 +00:00
koha2marclinks.pl Bug 17189: Add the ability to define several memcached namespaces - replace existing occurrences 2016-09-08 10:24:46 +00:00
localization.pl Bug 14100: Generic solution for language overlay - Item types 2015-10-27 12:34:06 -03:00
marc_subfields_structure.pl Bug 17189: Add the ability to define several memcached namespaces - replace existing occurrences 2016-09-08 10:24:46 +00:00
marctagstructure.pl Bug 17189: Replace occurrences of 'use Koha::Cache' 2016-09-08 10:24:47 +00:00
matching-rules.pl Bug 16154: Fix some other occurrences 2016-04-26 23:16:44 +00:00
oai_set_mappings.pl Bug 16154: CGI->multi_param - Declare a list 2016-04-26 23:16:42 +00:00
oai_sets.pl Bug 16154: CGI->multi_param - Declare a list 2016-04-26 23:16:42 +00:00
patron-attr-types.pl Bug 15407: Uniformise calls in patron-attr-types 2016-09-08 13:29:23 +00:00
preferences.pl Bug 11998: Use Koha::Cache to cache sysprefs 2016-03-15 07:08:28 +00:00
printers.pl Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
smart-rules.pl Bug 15407: Koha::Patron::Categories - remove sql queries in some pl and pm 2016-09-08 13:29:03 +00:00
sms_providers.pl Bug 9021 [QA Followup] - Switch to Koha::Object(s) 2016-02-14 12:40:06 +00:00
sru_modmapping.pl Bug 6536: Add a form for SRU Field mapping 2014-09-01 10:08:50 -03:00
systempreferences.pl Bug 11998: Use Koha::Cache to cache sysprefs 2016-03-15 07:08:28 +00:00
transport-cost-matrix.pl Bug 15258: Fix Perl scripts declaring unused variables 2015-12-30 17:24:45 -07:00
z3950servers.pl Bug 16154: CGI->multi_param - Force scalar context 2016-04-26 23:16:43 +00:00