Skip to content

Commit ac12aa3

Browse files
committed
Exclude suspended holds from queue length by default.
Suspended holds can be included by including query parameter include_suspended_in_hold_queue=1. Closes #33.
1 parent be2435a commit ac12aa3

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Koha/Plugin/Fi/KohaSuomi/DI/AvailabilityController.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ sub biblio_hold {
9595
my $ignore_patron_holds = $c->validation->param('ignore_patron_holds');
9696
my $limit_items = $c->validation->param('limit_items');
9797
my $include_found_in_hold_queue = $c->validation->param('include_found_in_hold_queue');
98+
my $include_suspended_in_hold_queue = $c->validation->param('include_suspended_in_hold_queue');
9899

99100
return try {
100101
my $patron = Koha::Patrons->find($borrowernumber);
@@ -106,6 +107,7 @@ sub biblio_hold {
106107
$params->{'query_pickup_locations'} = 1 if $query_pickup_locations;
107108
$params->{'ignore_patron_holds'} = 1 if $ignore_patron_holds;
108109
$params->{'include_found_in_hold_queue'} = 1 if $include_found_in_hold_queue;
110+
$params->{'include_suspended_in_hold_queue'} = 1 if $include_suspended_in_hold_queue;
109111
$params->{'to_branch'} = $to_branch if $to_branch;
110112
$params->{'limit'} = $limit_items if $limit_items;
111113

@@ -140,6 +142,7 @@ sub biblio_search {
140142

141143
my $biblionumber = $c->validation->param('biblio_id');
142144
my $include_found_in_hold_queue = $c->validation->param('include_found_in_hold_queue');
145+
my $include_suspended_in_hold_queue = $c->validation->param('include_suspended_in_hold_queue');
143146

144147
return try {
145148
my $availability = undef;
@@ -148,6 +151,7 @@ sub biblio_search {
148151
biblio => $biblio,
149152
};
150153
$params->{'include_found_in_hold_queue'} = 1 if $include_found_in_hold_queue;
154+
$params->{'include_suspended_in_hold_queue'} = 1 if $include_suspended_in_hold_queue;
151155
$availability = Koha::Plugin::Fi::KohaSuomi::DI::Koha::Availability::Search->biblio($params);
152156
return $c->render(status => 200, openapi => $availability->in_opac->to_api);
153157
}
@@ -257,6 +261,7 @@ sub item_hold {
257261
my $query_pickup_locations = $c->validation->param('query_pickup_locations');
258262
my $to_branch = $c->validation->param('library_id');
259263
my $include_found_in_hold_queue = $c->validation->param('include_found_in_hold_queue');
264+
my $include_suspended_in_hold_queue = $c->validation->param('include_suspended_in_hold_queue');
260265

261266
return try {
262267
my $patron = Koha::Patrons->find($borrowernumber);
@@ -272,6 +277,7 @@ sub item_hold {
272277
$params->{'to_branch'} = $to_branch;
273278
}
274279
$params->{'include_found_in_hold_queue'} = 1 if $include_found_in_hold_queue;
280+
$params->{'include_suspended_in_hold_queue'} = 1 if $include_suspended_in_hold_queue;
275281

276282
my $availability = undef;
277283
if (my $item = Koha::Items->find($itemnumber)) {

Koha/Plugin/Fi/KohaSuomi/DI/Koha/Biblio/Availability.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ sub new {
7777

7878
# Optionally include found holds in hold queue length calculation.
7979
$self->{'include_found_in_hold_queue'} = $params->{'include_found_in_hold_queue'};
80-
80+
81+
# Optionally include suspended holds in hold queue length calculation.
82+
$self->{'include_suspended_in_hold_queue'} = $params->{'include_suspended_in_hold_queue'};
83+
8184
if (exists $params->{'biblio'}) {
8285
unless (ref($params->{'biblio'}) eq 'Koha::Biblio') {
8386
Koha::Plugin::Fi::KohaSuomi::DI::Koha::Exceptions::BadParameter->throw(
@@ -199,6 +202,9 @@ sub get_hold_queue_length
199202
if (!$self->{'include_found_in_hold_queue'}) {
200203
$hold_params->{found} = undef;
201204
}
205+
if (!$self->{'include_suspended_in_hold_queue'}) {
206+
$hold_params->{suspend} = 0;
207+
}
202208
return Koha::Holds->search($hold_params)->count;
203209
}
204210

Koha/Plugin/Fi/KohaSuomi/DI/Koha/Item/Availability.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ sub new {
7373
# Optionally include found holds in hold queue length calculation.
7474
$self->{'include_found_in_hold_queue'} = $params->{'include_found_in_hold_queue'};
7575

76+
# Optionally include suspended holds in hold queue length calculation.
77+
$self->{'include_suspended_in_hold_queue'} = $params->{'include_suspended_in_hold_queue'};
78+
7679
if (exists $params->{'item'}) {
7780
unless (ref($params->{'item'}) eq 'Koha::Item') {
7881
Koha::Plugin::Fi::KohaSuomi::DI::Koha::Exceptions::BadParameter->throw(
@@ -200,6 +203,9 @@ sub get_hold_queue_length
200203
if (!$self->{'include_found_in_hold_queue'}) {
201204
$hold_params->{found} = undef;
202205
}
206+
if (!$self->{'include_suspended_in_hold_queue'}) {
207+
$hold_params->{suspend} = 0;
208+
}
203209
return Koha::Holds->search($hold_params)->count;
204210
}
205211

Koha/Plugin/Fi/KohaSuomi/DI/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ paths:
160160
name: include_found_in_hold_queue
161161
required: false
162162
type: integer
163+
- description: "Whether to include suspended holds in hold queue length. 1 = yes, 0 or no parameter = no."
164+
in: query
165+
name: include_suspended_in_hold_queue
166+
required: false
167+
type: integer
163168
produces:
164169
- application/json
165170
responses:
@@ -217,6 +222,11 @@ paths:
217222
name: include_found_in_hold_queue
218223
required: false
219224
type: integer
225+
- description: "Whether to include suspended holds in hold queue length. 1 = yes, 0 or no parameter = no."
226+
in: query
227+
name: include_suspended_in_hold_queue
228+
required: false
229+
type: integer
220230
produces:
221231
- application/json
222232
responses:
@@ -358,6 +368,11 @@ paths:
358368
name: include_found_in_hold_queue
359369
required: false
360370
type: integer
371+
- description: "Whether to include suspended holds in hold queue length. 1 = yes, 0 or no parameter = no."
372+
in: query
373+
name: include_suspended_in_hold_queue
374+
required: false
375+
type: integer
361376
produces:
362377
- application/json
363378
responses:

Koha/Plugin/Fi/KohaSuomi/sample_requests.http

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ Authorization: Bearer {{token}}
4141
GET {{baseUrl}}/contrib/kohasuomi/availability/biblios/2/hold?patron_id=57&include_found_in_hold_queue=0 HTTP/1.1
4242
Authorization: Bearer {{token}}
4343

44+
###
45+
# @name hold_availability_suspended_included
46+
GET {{baseUrl}}/contrib/kohasuomi/availability/biblios/2/hold?patron_id=57&include_suspended_in_hold_queue=1 HTTP/1.1
47+
Authorization: Bearer {{token}}
48+
4449
###
4550
# @name item_hold_availability
46-
GET {{baseUrl}}/contrib/kohasuomi/availability/items/30/hold?patron_id=57&include_found_in_hold_queue=1 HTTP/1.1
51+
GET {{baseUrl}}/contrib/kohasuomi/availability/items/154/hold?patron_id=57&include_found_in_hold_queue=1 HTTP/1.1
52+
Authorization: Bearer {{token}}
53+
54+
###
55+
# @name item_hold_availability_suspended_included
56+
GET {{baseUrl}}/contrib/kohasuomi/availability/items/154/hold?patron_id=57&include_found_in_hold_queue=1&include_suspended_in_hold_queue=1 HTTP/1.1
4757
Authorization: Bearer {{token}}
4858

4959
###

0 commit comments

Comments
 (0)