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

(-)a/Koha/REST/V1/Meta.pm (+52 lines)
Line 0 Link Here
1
package Koha::REST::V1::Meta;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::ItemTypes;
23
use C4::Koha;
24
25
sub advanced_search_types {
26
    my ($self, $args, $cb) = @_;
27
28
    my $advanced_search_types = $self->syspref("AdvancedSearchTypes");
29
    my ($ccl, @typesloop);
30
    if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
31
        my $itemtypes = Koha::ItemTypes->unblessed;
32
        my $itype_or_itemtype = ($self->syspref("item-level_itypes"))?'itype':'itemtype';
33
        @typesloop = map {
34
            code        => $_->{itemtype},
35
            description => $_->{description},
36
            imageurl    => getitemtypeimagelocation( 'opac', $_->{imageurl} ),
37
        }, sort {$a->{description} cmp $b->{description} } @$itemtypes;
38
        $ccl = "$itype_or_itemtype,phr";
39
    } else {
40
        my $advsearchtypes = GetAuthorisedValues($advanced_search_types, 'OPAC');
41
        @typesloop = map {
42
            code        => $_->{authorised_value},
43
            description => $_->{lib},
44
            imageurl    => getitemtypeimagelocation( 'opac', $_->{imageurl} ),
45
        }, @$advsearchtypes;
46
        $ccl = $advanced_search_types;
47
    }
48
49
    return $self->$cb({ ccl => $ccl, types => \@typesloop }, 200);
50
}
51
52
1;
(-)a/api/v1/swagger.json (+49 lines)
Lines 332-337 Link Here
332
          }
332
          }
333
        }
333
        }
334
      }
334
      }
335
    },
336
    "/meta/advanced-search-types": {
337
      "get": {
338
        "operationId": "advanced_search_typesMeta",
339
        "tags": ["meta"],
340
        "produces": [
341
          "application/json"
342
        ],
343
        "responses": {
344
          "200": {
345
            "description": "Advanced search types list",
346
            "schema": {
347
              "type": "object",
348
              "required": [
349
                "ccl",
350
                "types"
351
              ],
352
              "properties": {
353
                "ccl": {
354
                  "type": "string"
355
                },
356
                "types": {
357
                  "type": "array",
358
                  "items": {
359
                    "type": "object",
360
                    "required": [
361
                      "code",
362
                      "description",
363
                      "imageurl"
364
                    ],
365
                    "properties": {
366
                      "code": {
367
                        "type": "string"
368
                      },
369
                      "description": {
370
                        "type": "string"
371
                      },
372
                      "imageurl": {
373
                        "type": "string",
374
                        "format": "uri"
375
                      }
376
                    }
377
                  }
378
                }
379
              }
380
            }
381
          }
382
        }
383
      }
335
    }
384
    }
336
  },
385
  },
337
  "definitions": {
386
  "definitions": {
(-)a/t/db_dependent/api/v1/meta.t (-1 / +82 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More;
21
use Test::Mojo;
22
use t::lib::TestBuilder;
23
use t::lib::Mocks;
24
25
use C4::Auth;
26
use C4::Context;
27
28
use Koha::Database;
29
use Koha::Patron;
30
use Koha::AuthorisedValues;
31
32
my $builder = t::lib::TestBuilder->new();
33
34
my $dbh = C4::Context->dbh;
35
$dbh->{AutoCommit} = 0;
36
$dbh->{RaiseError} = 1;
37
38
my $t = Test::Mojo->new('Koha::REST::V1');
39
40
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode();
41
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
42
43
my $borrower = $builder->build({ source => 'Borrower' });
44
45
my $session = C4::Auth::get_session('');
46
$session->param('number', $borrower->{borrowernumber});
47
$session->param('id', $borrower->{userid});
48
$session->param('ip', '127.0.0.1');
49
$session->param('lasttime', time());
50
$session->flush;
51
52
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
53
54
my %cat = map { $_ => 1 } Koha::AuthorisedValues->categories;
55
foreach (qw/CCODE LOC/) {
56
    next unless $cat{$_};
57
58
    t::lib::Mocks::mock_preference('AdvancedSearchTypes', $_);
59
    my $tx = $t->ua->build_tx(GET => '/api/v1/meta/advanced-search-types');
60
    $tx->req->cookies({name => 'CGISESSID', value => $session->id});
61
    $tx->req->env({REMOTE_ADDR => '127.0.0.1'});
62
    $t->request_ok($tx)
63
      ->status_is(200)
64
      ->json_is('/ccl' => $_)
65
      ->json_has('/types/0/code')
66
      ->json_has('/types/0/description')
67
      ->json_has('/types/0/imageurl');
68
}
69
70
t::lib::Mocks::mock_preference('AdvancedSearchTypes', 'itemtypes');
71
my $tx = $t->ua->build_tx(GET => '/api/v1/meta/advanced-search-types');
72
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
73
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
74
$t->request_ok($tx)
75
  ->status_is(200)
76
  ->json_like('/ccl' => qr/\w+/)
77
  ->json_has('/types/0/code')
78
  ->json_has('/types/0/description')
79
  ->json_has('/types/0/imageurl');
80
81
$dbh->rollback;
82
done_testing();

Return to bug 7520