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

(-)a/Koha/REST/Plugin/Query.pm (-1 / +54 lines)
Lines 65-70 Generates the DBIC query from the query parameters. Link Here
65
            return ( $filtered_params, $reserved_params );
65
            return ( $filtered_params, $reserved_params );
66
        }
66
        }
67
    );
67
    );
68
69
=head3 dbic_merge_sorting
70
71
    $attributes = $c->dbic_merge_sorting({ attributes => $attributes, params => $params });
72
73
Generates the DBIC order_by attributes based on I<$params>, and merges into I<$attributes>.
74
75
=cut
76
77
    $app->helper(
78
        'dbic_merge_sorting' => sub {
79
            my ( $c, $args ) = @_;
80
            my $attributes = $args->{attributes};
81
82
            my @order_by =
83
              map { _build_order_atom($_) }
84
              split( /\|/, $args->{params}->{_order_by} );
85
86
            $attributes->{order_by} = \@order_by;
87
            return $attributes;
88
        }
89
    );
68
}
90
}
69
91
70
=head2 Internal methods
92
=head2 Internal methods
Lines 81-84 sub _reserved_words { Link Here
81
    return \@reserved_words;
103
    return \@reserved_words;
82
}
104
}
83
105
106
=head3 _build_order_atom
107
108
    my $order_atom = _build_order_atom( $string );
109
110
Parses I<$string> and outputs data valid for using in SQL::Abstract order_by attribute
111
according to the following rules:
112
113
     string -> I<string>
114
    +string -> I<{ -asc => string }>
115
    -string -> I<{ -desc => string }>
116
117
=cut
118
119
sub _build_order_atom {
120
    my $string = shift;
121
122
    if ( $string =~ m/^\+/ ) {
123
        # asc order operator present
124
        $string =~ s/^\+//;
125
        return { -asc => $string };
126
    }
127
    elsif ( $string =~ m/^\-/ ) {
128
        # desc order operator present
129
        $string =~ s/^\-//;
130
        return { -desc => $string };
131
    }
132
    else {
133
        # no order operator present
134
        return $string;
135
    }
136
}
137
84
1;
138
1;
85
- 

Return to bug 19370