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

(-)a/svc/members/search (-22 / +48 lines)
Lines 26-32 use C4::Utils::DataTables qw( dt_get_params ); Link Here
26
use C4::Utils::DataTables::Members qw( search );
26
use C4::Utils::DataTables::Members qw( search );
27
use Koha::DateUtils qw( output_pref dt_from_string );
27
use Koha::DateUtils qw( output_pref dt_from_string );
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use Data::Dumper;
30
use Time::Piece;
29
use Time::Piece;
31
use JSON::XS qw( );
30
use JSON::XS qw( );
32
use HTML::Entities qw( encode_entities );
31
use HTML::Entities qw( encode_entities );
Lines 77-94 if ( $searchmember Link Here
77
    } if $member;
76
    } if $member;
78
}
77
}
79
78
80
# Perform the patrons search
79
my $filterable_results;
81
$results = C4::Utils::DataTables::Members::search(
80
if ($searchmember ne $first_query) {
82
  {
81
    # Perform the patrons search
83
     searchmember => $first_query,
82
    $results = C4::Utils::DataTables::Members::search(
84
     firstletter => $firstletter,
83
        {
85
     categorycode => $categorycode,
84
            searchmember => $first_query,
86
     branchcode => $branchcode,
85
            firstletter => $firstletter,
87
     searchtype => $searchtype,
86
            categorycode => $categorycode,
88
     searchfieldstype => $searchfieldstype,
87
            branchcode => $branchcode,
89
     dt_params => \%dt_params,
88
            searchtype => $searchtype,
90
  }
89
            searchfieldstype => $searchfieldstype,
91
) unless $results;
90
            dt_params => \%dt_params,
91
        }
92
    ) unless $results;
93
    my $value_to_display = $dt_params{'iDisplayLength'};
94
    $dt_params{'iDisplayLength'} = -1;
95
96
    # Retreive all patrons matching the $first_query value. These will be filtered
97
    $filterable_results = C4::Utils::DataTables::Members::search(
98
        {
99
            searchmember => $first_query,
100
            firstletter => $firstletter,
101
            categorycode => $categorycode,
102
            branchcode => $branchcode,
103
            searchtype => $searchtype,
104
            searchfieldstype => $searchfieldstype,
105
            dt_params => \%dt_params,
106
        }
107
    ) unless $filterable_results;
108
} else {
109
    # Perform the patrons search
110
    $results = C4::Utils::DataTables::Members::search(
111
        {
112
            searchmember => $first_query,
113
            firstletter => $firstletter,
114
            categorycode => $categorycode,
115
            branchcode => $branchcode,
116
            searchtype => $searchtype,
117
            searchfieldstype => $searchfieldstype,
118
            dt_params => \%dt_params,
119
        }
120
    ) unless $results;
121
}
92
122
93
    # It is not recommanded to use the has_permission param if you use the pagination
123
    # It is not recommanded to use the has_permission param if you use the pagination
94
    # The filter is done AFTER requested the data
124
    # The filter is done AFTER requested the data
Lines 115-127 $results = C4::Utils::DataTables::Members::search( Link Here
115
    }
145
    }
116
    my $date_format = C4::Context->preference("dateformat");
146
    my $date_format = C4::Context->preference("dateformat");
117
147
118
    if ($searchmember) {
148
    if ($searchmember ne $first_query) {
119
        my @filtered_patron_list;
149
        my @filtered_patron_list;
120
        my $count;
150
        my $count;
121
        for my $patron ( @{ $results->{patrons} } ) {
151
        for my $patron ( @{ $filterable_results->{patrons} } ) {
122
            my $match;
152
            my $match;
123
            for my $value (values $patron) {
153
            for my $value (values $patron) {
124
                warn $value;
125
                my $lc_patron_value = lc $value;
154
                my $lc_patron_value = lc $value;
126
                my $lc_searchmember = lc $searchmember;
155
                my $lc_searchmember = lc $searchmember;
127
156
Lines 138-151 $results = C4::Utils::DataTables::Members::search( Link Here
138
167
139
                    }
168
                    }
140
                }
169
                }
141
                warn $lc_patron_value;
142
                warn $lc_searchmember;
143
                if ($searchtype eq "start_with") {
170
                if ($searchtype eq "start_with") {
144
                    #Find a match starting with the start of a value in the patron record
171
                    #Find a match starting with the start of a value in the patron record
145
                    if (index($lc_patron_value, $lc_searchmember) == 0) {
172
                    if (index($lc_patron_value, $lc_searchmember) == 0) {
146
                        $match = 1;
173
                        $match = 1;
147
                        warn $lc_patron_value;
148
                        warn $lc_searchmember;
149
                    }
174
                    }
150
                } else {
175
                } else {
151
                    if (($lc_patron_value) =~ /($lc_searchmember)/) {
176
                    if (($lc_patron_value) =~ /($lc_searchmember)/) {
Lines 159-165 $results = C4::Utils::DataTables::Members::search( Link Here
159
            }
184
            }
160
        }
185
        }
161
        $results->{patrons} = \@filtered_patron_list;
186
        $results->{patrons} = \@filtered_patron_list;
162
        $results->{iTotalDisplayRecords} = scalar( @filtered_patron_list );
187
        if ($searchmember ne $first_query) {
188
            $results->{iTotalDisplayRecords} = scalar @{$results->{patrons}};
189
        }
163
    }
190
    }
164
191
165
    my $date_format = C4::Context->preference("dateformat");
192
    my $date_format = C4::Context->preference("dateformat");
166
- 

Return to bug 20346