Bug 37762: Hook to holds preparation: DRY holdfor and searchToOrder

In preparation to implement 'hold for supply ILL'
This DRYs the existing functionality, meaning the new similar functionality will only be added once in the Controller::Catalogue

IMPORTANT:
The following command must only return occurrences in
Koha::Controller::Catalogue before this is pushed to main:
git grep "\->cookie(\"holdfor\")"

Signed-off-by: Jason Robb <jrobb@sekls.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2026-02-25 11:09:28 -01:00 committed by Lucas Gass
parent 87961beb4d
commit 1d6fb7f57d
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
8 changed files with 97 additions and 131 deletions

View File

@ -0,0 +1,82 @@
package Koha::Controller::Catalogue;
use Modern::Perl;
use C4::Auth qw( get_template_and_user );
use Koha::Patrons;
=head1 NAME
Koha::Controller::Catalogue - Koha Controller
=head1 API
=head2 Class Methods
=cut
=head3 init
my ( $template, $loggedinuser, $cookie, $flags ) = Koha::Controller::Catalogue->init( $args );
Initializes the catalogue controller by generating the template, authenticating the user, and populating the template with standard search-related variables.
Takes a hashref C<$args> containing the CGI C<query>, C<template_name>, C<type>, and C<flagsrequired>.
Returns a list containing the C<$template> object, the C<$loggedinuser> ID, the session C<$cookie>, and the user's C<$flags>.
=cut
sub init {
my ( $class, $args ) = @_;
my $query = $args->{query};
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
{
template_name => $args->{template_name},
query => $query,
type => $args->{type},
flagsrequired => $args->{flagsrequired},
}
);
_prep_searchto_template_params( $template, $query );
return ( $template, $loggedinuser, $cookie, $flags );
}
=head3 _prep_searchto_template_params
This prepares the common 'search to' functionality params e.g.:
- 'Search to hold'
- 'Search to order'
- etc
=cut
sub _prep_searchto_template_params {
my ( $template, $query ) = @_;
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
if ($holdfor_patron) {
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
return 1;
}
1;

View File

@ -36,7 +36,6 @@ This script needs a biblionumber as parameter
use Modern::Perl;
use HTML::Entities;
use C4::Auth qw( get_template_and_user );
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
use CGI qw ( -utf8 );
@ -45,6 +44,7 @@ use C4::Serials qw( CountSubscriptionFromBiblionumber GetSubscription GetSubscri
use C4::Search qw( z3950_search_args enabled_staff_search_views );
use Koha::Biblios;
use Koha::Controller::Catalogue;
use Koha::Patrons;
use Koha::RecordProcessor;
use Koha::Virtualshelves;
@ -56,7 +56,7 @@ my $biblionumber = $query->param('biblionumber');
$biblionumber = HTML::Entities::encode($biblionumber);
# open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my ( $template, $loggedinuser, $cookie ) = Koha::Controller::Catalogue->init(
{
template_name => "catalogue/ISBDdetail.tt",
query => $query,
@ -98,22 +98,6 @@ my $res = GetISBDView(
}
);
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
# count of item linked with biblio
my $itemcount = $biblio->items->count;
$template->param( count => $itemcount );

View File

@ -47,7 +47,6 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use HTML::Entities;
use C4::Auth qw( get_template_and_user );
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
use C4::Koha;
@ -63,6 +62,7 @@ use C4::Search qw( z3950_search_args enabled_staff_search_views );
use Koha::Biblios;
use Koha::BiblioFrameworks;
use Koha::Controller::Catalogue;
use Koha::Patrons;
use Koha::DateUtils qw( output_pref );
use Koha::Virtualshelves;
@ -78,7 +78,7 @@ my $popup = $query->param('popup'); # if set to 1, then don't insert
my $subscriptionid = $query->param('subscriptionid');
# open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my ( $template, $loggedinuser, $cookie ) = Koha::Controller::Catalogue->init(
{
template_name => "catalogue/MARCdetail.tt",
query => $query,
@ -104,22 +104,6 @@ if ( !$record ) {
my $tagslib = &GetMarcStructure( 1, $frameworkcode );
my $biblio = GetBiblioData($biblionumber);
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
$template->param( ocoins => $biblio_object->get_coins );
#count of item linked

View File

@ -19,7 +19,6 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use HTML::Entities;
use C4::Auth qw( get_template_and_user );
use C4::Context;
use C4::Koha qw(
GetAuthorisedValues
@ -47,6 +46,7 @@ use Koha::AuthorisedValues;
use Koha::Biblios;
use Koha::Biblio::ItemGroup::Items;
use Koha::Biblio::ItemGroups;
use Koha::Controller::Catalogue;
use Koha::CoverImages;
use Koha::DateUtils;
use Koha::Database::DataInconsistency;
@ -66,7 +66,7 @@ my $query = CGI->new();
my $analyze = $query->param('analyze');
my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
my ( $template, $borrowernumber, $cookie, $flags ) = Koha::Controller::Catalogue->init(
{
template_name => 'catalogue/detail.tt',
query => $query,
@ -152,24 +152,6 @@ if ( $op eq 'set_item_group' ) {
}
}
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
if ($holdfor_patron) {
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
my $fw = GetFrameworkCode($biblionumber);
my $showallitems = $query->param('showallitems');
my $marcflavour = C4::Context->preference("marcflavour");

View File

@ -20,16 +20,16 @@
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use C4::Search qw( enabled_staff_search_views );
use Koha::Biblios;
use Koha::Controller::Catalogue;
use Koha::Items;
use Koha::Patrons;
my $query = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
my ( $template, $borrowernumber, $cookie ) = Koha::Controller::Catalogue->init(
{
template_name => "catalogue/imageviewer.tt",
query => $query,
@ -45,22 +45,6 @@ my $imagenumber = $query->param('imagenumber');
my $biblio = Koha::Biblios->find($biblionumber);
my $itemcount = $biblio ? $biblio->items->count : 0;
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
if ( C4::Context->preference("LocalCoverImages") ) {
my $images;
if ($itemnumber) {

View File

@ -20,7 +20,6 @@
use Modern::Perl;
use CGI qw ( -utf8 );
use HTML::Entities;
use C4::Auth qw( get_template_and_user );
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
use C4::Biblio qw(
@ -33,6 +32,7 @@ use C4::Serials qw( CountSubscriptionFromBiblionumber );
use Koha::Biblios;
use Koha::BiblioFrameworks;
use Koha::Controller::Catalogue;
use Koha::Patrons;
use Koha::Virtualshelves;
@ -44,7 +44,7 @@ my $frameworkcode = $query->param('frameworkcode') // GetFrameworkCode($biblionu
my $popup = $query->param('popup'); # if set to 1, then don't insert links, it's just to show the biblio
# open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my ( $template, $loggedinuser, $cookie ) = Koha::Controller::Catalogue->init(
{
template_name => "catalogue/labeledMARCdetail.tt",
query => $query,
@ -69,22 +69,6 @@ my $record = $biblio_object->metadata->record;
my $tagslib = GetMarcStructure( 1, $frameworkcode );
my $biblio = GetBiblioData($biblionumber);
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
#count of item linked
my $itemcount = $biblio_object->items->count;
$template->param(

View File

@ -25,19 +25,19 @@ use HTML::Entities;
use C4::Biblio qw( GetBiblioData GetFrameworkCode );
use C4::Acquisition qw( GetOrderFromItemnumber GetBasket GetInvoice );
use C4::Output qw( output_and_exit output_html_with_http_headers );
use C4::Auth qw( get_template_and_user );
use C4::Serials qw( CountSubscriptionFromBiblionumber );
use C4::Search qw( enabled_staff_search_views z3950_search_args );
use Koha::Acquisition::Booksellers;
use Koha::AuthorisedValues;
use Koha::Biblios;
use Koha::Controller::Catalogue;
use Koha::Items;
use Koha::Patrons;
my $query = CGI->new;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my ( $template, $loggedinuser, $cookie ) = Koha::Controller::Catalogue->init(
{
template_name => 'catalogue/moredetail.tt',
query => $query,
@ -49,22 +49,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
$template->param(
updated_exclude_from_local_holds_priority => scalar( $query->param('updated_exclude_from_local_holds_priority') ) );
if ( $query->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
if ( $query->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
# get variables
my $biblionumber;
my $itemnumber;

View File

@ -142,13 +142,13 @@ use Modern::Perl;
use C4::Context;
use C4::Output qw( output_html_with_http_headers pagination_bar );
use C4::Circulation qw( barcodedecode );
use C4::Auth qw( get_template_and_user );
use C4::Search qw( searchResults enabled_staff_search_views z3950_search_args new_record_from_zebra );
use C4::Languages qw( getlanguage getLanguages );
use C4::Koha qw( getitemtypeimagelocation GetAuthorisedValues );
use URI::Escape;
use POSIX qw(ceil floor);
use Koha::Controller::Catalogue;
use Koha::ItemTypes;
use Koha::Library::Groups;
use Koha::Patrons;
@ -189,7 +189,7 @@ if ( !$cgi->param('edit_search')
}
# load the template
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
my ( $template, $borrowernumber, $cookie ) = Koha::Controller::Catalogue->init(
{
template_name => $template_name,
query => $cgi,
@ -207,19 +207,9 @@ if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
$template->param( 'UNIMARC' => 1 );
}
if ( $cgi->cookie("holdfor") ) {
my $holdfor_patron = Koha::Patrons->find( $cgi->cookie("holdfor") );
if ($holdfor_patron) { # may have been deleted in the meanwhile
$template->param(
holdfor => $cgi->cookie("holdfor"),
holdfor_patron => $holdfor_patron,
);
}
}
if ( $cgi->cookie("holdforclub") ) {
my $holdfor_club = Koha::Clubs->find( $cgi->cookie("holdforclub") );
if ($holdfor_club) { # May have been deleted in the meanwhile
if ($holdfor_club) { # May have been deleted in the meanwhile
$template->param(
holdforclub => $cgi->cookie("holdforclub"),
holdforclub_name => $holdfor_club->name,
@ -227,14 +217,6 @@ if ( $cgi->cookie("holdforclub") ) {
}
}
if ( $cgi->cookie("searchToOrder") ) {
my ( $basketno, $vendorid ) = split( /\//, $cgi->cookie("searchToOrder") );
$template->param(
searchtoorder_basketno => $basketno,
searchtoorder_vendorid => $vendorid
);
}
# get biblionumbers stored in the cart
my @cart_list;