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/paths.json (+3 lines)
Lines 11-16 Link Here
11
  "/holds/{reserve_id}": {
11
  "/holds/{reserve_id}": {
12
    "$ref": "paths/holds.json#/~1holds~1{reserve_id}"
12
    "$ref": "paths/holds.json#/~1holds~1{reserve_id}"
13
  },
13
  },
14
  "/meta/advanced-search-types": {
15
    "$ref": "paths/meta.json#/~1meta~1advanced-search-types"
16
  },
14
  "/patrons": {
17
  "/patrons": {
15
    "$ref": "paths/patrons.json#/~1patrons"
18
    "$ref": "paths/patrons.json#/~1patrons"
16
  },
19
  },
(-)a/api/v1/swagger/paths/meta.json (+52 lines)
Line 0 Link Here
1
{
2
  "/meta/advanced-search-types": {
3
    "get": {
4
      "x-mojo-controller": "Koha::REST::V1::Meta",
5
      "operationId": "advanced_search_types",
6
      "tags": ["meta"],
7
      "produces": [
8
        "application/json"
9
      ],
10
      "responses": {
11
        "200": {
12
          "description": "Advanced search types list",
13
          "schema": {
14
            "type": "object",
15
            "required": [
16
              "ccl",
17
              "types"
18
            ],
19
            "properties": {
20
              "ccl": {
21
                "type": "string"
22
              },
23
              "types": {
24
                "type": "array",
25
                "items": {
26
                  "type": "object",
27
                  "required": [
28
                    "code",
29
                    "description",
30
                    "imageurl"
31
                  ],
32
                  "properties": {
33
                    "code": {
34
                      "type": "string"
35
                    },
36
                    "description": {
37
                      "type": "string"
38
                    },
39
                    "imageurl": {
40
                      "type": "string",
41
                      "format": "uri"
42
                    }
43
                  }
44
                }
45
              }
46
            }
47
          }
48
        }
49
      }
50
    }
51
  }
52
}
(-)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