View | Details | Raw Unified | Return to bug 33080
Collapse All | Expand All

(-)a/Koha/REST/Plugin/Objects.pm (-13 / +33 lines)
Lines 114-120 shouldn't be called twice in it. Link Here
114
        'objects.search' => sub {
114
        'objects.search' => sub {
115
            my ( $c, $result_set ) = @_;
115
            my ( $c, $result_set ) = @_;
116
116
117
            return $c->objects->to_api( $c->objects->search_rs($result_set) );
117
            my $objects_rs = $c->objects->search_rs($result_set);
118
            $c->objects->generate_pagination_headers($objects_rs);
119
120
            return $c->objects->to_api( $objects_rs );
118
        }
121
        }
119
    );
122
    );
120
123
Lines 248-264 shouldn't be called twice in it. Link Here
248
            my $objects = $result_set->search( $filtered_params, $attributes );
251
            my $objects = $result_set->search( $filtered_params, $attributes );
249
            my $total   = $result_set->search->count;
252
            my $total   = $result_set->search->count;
250
253
251
            $c->add_pagination_headers(
254
            $c->stash('koha.pagination.base_total'   => $result_set->count);
252
                {
255
            $c->stash('koha.pagination.query_params' => $args);
253
                    total => (
254
                          $objects->is_paged
255
                        ? $objects->pager->total_entries
256
                        : $objects->count
257
                    ),
258
                    base_total => $total,
259
                    params     => $args,
260
                }
261
            );
262
256
263
            return $objects;
257
            return $objects;
264
        }
258
        }
Lines 293-298 Returns the API representation of the passed resultset. Link Here
293
            );
287
            );
294
        }
288
        }
295
    );
289
    );
290
291
=head3 objects.total_from_resultset
292
293
    my $objects_rs = $objects->search_rs( $rs );
294
    my $api_representation = $c->objects->generate_pagination_headers( $objects_rs );
295
296
Returns the API representation of the passed resultset.
297
298
=cut
299
300
    $app->helper(
301
        'objects.generate_pagination_headers' => sub {
302
            my ( $c, $result_set ) = @_;
303
304
            $c->add_pagination_headers(
305
                {
306
                    total      => $c->objects->total_from_resultset( $result_set ),
307
                    base_total => $c->stash('koha.pagination.base_total'),
308
                    params     => $c->stash('koha.pagination.query_params'),
309
                }
310
            );
311
312
            return $result_set->is_paged
313
                        ? $result_set->pager->total_entries
314
                        : $result_set->count
315
        }
316
    );
296
}
317
}
297
318
298
1;
319
1;
299
- 

Return to bug 33080