Lines 30-38
Koha::REST::Plugin::Objects
Link Here
|
30 |
=head3 objects.search |
30 |
=head3 objects.search |
31 |
|
31 |
|
32 |
my $patrons_set = Koha::Patrons->new; |
32 |
my $patrons_set = Koha::Patrons->new; |
33 |
my $patrons = $c->objects->search($patrons_set); |
33 |
my $patrons = $c->objects->search( $patrons_set, [\&to_model] ); |
34 |
|
34 |
|
35 |
Performs a database search using given Koha::Objects object and query parameters |
35 |
Performs a database search using given Koha::Objects object and query parameters. |
|
|
36 |
Optionally, it applies the I<$to_model> function reference before building the |
37 |
query itself. |
38 |
|
39 |
Note: Make sure I<$to_model> doesn't autovivify keys. |
36 |
|
40 |
|
37 |
Returns a Koha::Objects object |
41 |
Returns a Koha::Objects object |
38 |
|
42 |
|
Lines 43-49
sub register {
Link Here
|
43 |
|
47 |
|
44 |
$app->helper( |
48 |
$app->helper( |
45 |
'objects.search' => sub { |
49 |
'objects.search' => sub { |
46 |
my ( $c, $objects_set ) = @_; |
50 |
my ( $c, $objects_set, $to_model ) = @_; |
47 |
|
51 |
|
48 |
my $args = $c->validation->output; |
52 |
my $args = $c->validation->output; |
49 |
my $attributes = {}; |
53 |
my $attributes = {}; |
Lines 67-73
sub register {
Link Here
|
67 |
} |
71 |
} |
68 |
); |
72 |
); |
69 |
|
73 |
|
70 |
$filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); |
74 |
# Call the to_model function by reference, if defined |
|
|
75 |
if ( defined $filtered_params ) { |
76 |
|
77 |
# Apply the mapping function to the passed params |
78 |
$filtered_params = $to_model->($filtered_params) |
79 |
if defined $to_model; |
80 |
$filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); |
81 |
} |
82 |
|
71 |
# Perform search |
83 |
# Perform search |
72 |
my $objects = $objects_set->search( $filtered_params, $attributes ); |
84 |
my $objects = $objects_set->search( $filtered_params, $attributes ); |
73 |
|
85 |
|
74 |
- |
|
|