From bde0cc3d5d35166a155aa43107eef9849432bdc5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 22 Apr 2024 16:16:52 +0200 Subject: [PATCH] Bug 36633: Add anti-the support --- Koha/REST/Plugin/Query.pm | 25 ++++++++----------- .../prog/en/modules/members/holdshistory.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/datatables.js | 11 +++++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index 7aa092fae25..30fb335a03d 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -333,30 +333,25 @@ according to the following rules: =cut sub _build_order_atom { - my ( $args ) = @_; + my ($args) = @_; my $string = $args->{string}; my $result_set = $args->{result_set}; my $param = $string; $param =~ s/^(\+|\-|\s)//; - if ( $result_set ) { - my $model_param = _from_api_param($param, $result_set); + + my $modifier; + ( $param, $modifier ) = split '/', $param; + if ($result_set) { + my $model_param = _from_api_param( $param, $result_set ); $param = $model_param if defined $model_param; } - if ( $string =~ m/^\+/ or - $string =~ m/^\s/ ) { - # asc order operator present - return { -asc => $param }; - } - elsif ( $string =~ m/^\-/ ) { - # desc order operator present - return { -desc => $param }; - } - else { - # no order operator present - return $param; + my $order = ( $string =~ m/^\+/ or $string =~ m/^\s/ ) ? 'asc' : ( $string =~ m/^\-/ ) ? 'desc' : ''; + if ( $modifier && $modifier eq 'anti-the' ) { + return \"REGEXP_REPLACE(LOWER($param), '^(a|an|the)', '') $order"; } + return $order ? { "-$order" => $param } : $param; } =head3 _parse_embed diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt index 289954ae798..8890ca2bcbb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt @@ -221,6 +221,7 @@ data: "biblio.title:biblio.subtitle:biblio.medium", searchable: true, orderable: true, + type: 'anti-the', render: function (data, type, row, meta) { return $biblio_to_html(row.biblio, { link: 1 }); } diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index be3f62aa5d7..ae6df81321f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -648,10 +648,15 @@ function _dt_default_ajax (params){ var orderArray = new Array(); order.forEach(function (e,i) { var order_col = e.column; - var order_by = options.columns[order_col].data; - order_by = order_by.split(':'); + var col = options.columns[order_col]; + var type = col.type; + var order_by_modifier = ''; + if ( type && type == 'anti-the' ) { + order_by_modifier = '/anti-the'; + } var order_dir = e.dir == 'asc' ? '+' : '-'; - Array.prototype.push.apply(orderArray,order_by.map(x => order_dir + (!x.includes('.')?'me.'+x:x))); + var order_by = col.data.split(':').map(x => order_dir + (!x.includes('.')?'me.'+x:x) + order_by_modifier); + Array.prototype.push.apply(orderArray, order_by); }); dataSet._order_by = orderArray.filter((v, i, a) => a.indexOf(v) === i).join(','); } -- 2.34.1