Lines 32-38
use C4::Reserves;
Link Here
|
32 |
use C4::Accounts; |
32 |
use C4::Accounts; |
33 |
use C4::Biblio; |
33 |
use C4::Biblio; |
34 |
use C4::Letters; |
34 |
use C4::Letters; |
35 |
use C4::SQLHelper qw(InsertInTable UpdateInTable SearchInTable); |
|
|
36 |
use C4::Members::Attributes qw(SearchIdMatchingAttribute); |
35 |
use C4::Members::Attributes qw(SearchIdMatchingAttribute); |
37 |
use C4::NewsChannels; #get slip news |
36 |
use C4::NewsChannels; #get slip news |
38 |
use DateTime; |
37 |
use DateTime; |
Lines 197-205
sub _express_member_find {
Link Here
|
197 |
return (undef, $search_on_fields, $searchtype); |
196 |
return (undef, $search_on_fields, $searchtype); |
198 |
} |
197 |
} |
199 |
|
198 |
|
|
|
199 |
sub _get_cond_for_dbix { |
200 |
my ($params) = @_; |
201 |
my $filters = $params->{filters}; |
202 |
my $exact_search = $params->{exact_search}; |
203 |
my $search_on_fields = $params->{search_on_fields}; |
204 |
|
205 |
my $cond; |
206 |
if( ref($filters) eq 'ARRAY' ) { |
207 |
$cond = []; |
208 |
foreach my $filter (@$filters) { |
209 |
push @$cond, _get_cond_for_dbix({ |
210 |
filters => $filter, |
211 |
exact_search => $exact_search, |
212 |
search_on_fields => $search_on_fields, |
213 |
}); |
214 |
}; |
215 |
} |
216 |
elsif( ref($filters) eq 'HASH' ) { |
217 |
$cond = { %$filters }; |
218 |
$cond->{'-or'} = _get_columns_cond({ |
219 |
string => $filters->{''}, |
220 |
search_on_fields => $search_on_fields, |
221 |
exact_search => $exact_search, |
222 |
}) if( exists( $filters->{''} ) ); |
223 |
delete $cond->{''}; |
224 |
} |
225 |
elsif( not ref($filters) ) { |
226 |
$cond = _get_columns_cond({ |
227 |
string => $filters, |
228 |
search_on_fields => $search_on_fields, |
229 |
exact_search => $exact_search, |
230 |
}); |
231 |
} |
232 |
return $cond; |
233 |
} |
234 |
|
235 |
sub _get_columns_cond { |
236 |
my ($params) = @_; |
237 |
my $string = $params->{string}; |
238 |
my $exact_search = $params->{exact_search} || 1; |
239 |
my $search_on_fields = $params->{search_on_fields} || undef; |
240 |
|
241 |
my $source = Koha::Database->new()->schema->source('Borrower'); |
242 |
my @columns = $search_on_fields ? @$search_on_fields : $source->columns; |
243 |
|
244 |
my $cond = []; |
245 |
foreach my $column (@columns) { |
246 |
if( $exact_search ) { |
247 |
push @$cond, { $column => [ map { $_ } split(' ', $string) ] }; |
248 |
} |
249 |
else { |
250 |
push @$cond, { $column => { like => [ map { $_.'%' } split(' ', $string) ] } }; |
251 |
} |
252 |
} |
253 |
return $cond; |
254 |
} |
255 |
|
200 |
sub Search { |
256 |
sub Search { |
201 |
my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_; |
257 |
my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_; |
202 |
|
258 |
use Data::Dumper; |
|
|
259 |
#die Dumper($filter); |
203 |
my $search_string; |
260 |
my $search_string; |
204 |
my $found_borrower; |
261 |
my $found_borrower; |
205 |
|
262 |
|
Lines 283-289
sub Search {
Link Here
|
283 |
} |
340 |
} |
284 |
$searchtype ||= "start_with"; |
341 |
$searchtype ||= "start_with"; |
285 |
|
342 |
|
286 |
return SearchInTable( "borrowers", $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ); |
343 |
my $cond = _get_cond_for_dbix({ |
|
|
344 |
filters => $filter, |
345 |
exact_search => ($searchtype eq 'exact') ? 1 : 0, |
346 |
search_on_fields => $search_on_fields, |
347 |
}); |
348 |
#die Dumper($filter); |
349 |
use Data::Dumper; |
350 |
#die Dumper($cond); |
351 |
my $rs = Koha::Database->new()->schema->resultset('Borrower'); |
352 |
$rs = $rs->search( |
353 |
$cond, |
354 |
{ |
355 |
($columns_out) ? { columns => $columns_out } : {}, |
356 |
order_by => $orderby, |
357 |
rows => $limit, |
358 |
}, |
359 |
); |
360 |
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); |
361 |
return [ $rs->all ]; |
287 |
} |
362 |
} |
288 |
|
363 |
|
289 |
=head2 GetMemberDetails |
364 |
=head2 GetMemberDetails |
Lines 787-794
sub ModMember {
Link Here
|
787 |
} |
862 |
} |
788 |
} |
863 |
} |
789 |
my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} ); |
864 |
my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} ); |
790 |
my $execute_success=UpdateInTable("borrowers",\%data); |
865 |
|
791 |
if ($execute_success) { # only proceed if the update was a success |
866 |
# get only the columns of a borrower |
|
|
867 |
my $schema = Koha::Database->new()->schema; |
868 |
my @columns = $schema->source('Borrower')->columns; |
869 |
my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) }; |
870 |
delete $new_borrower->{flags}; |
871 |
|
872 |
my $rs = $schema->resultset('Borrower')->search({ |
873 |
borrowernumber => $new_borrower->{borrowernumber}, |
874 |
}); |
875 |
my $execute_success = $rs->update($new_borrower); |
876 |
if ($execute_success ne '0E0') { # only proceed if the update was a success |
792 |
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor |
877 |
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor |
793 |
# so when we update information for an adult we should check for guarantees and update the relevant part |
878 |
# so when we update information for an adult we should check for guarantees and update the relevant part |
794 |
# of their records, ie addresses and phone numbers |
879 |
# of their records, ie addresses and phone numbers |
Lines 823-828
Returns as undef upon any db error without further processing
Link Here
|
823 |
sub AddMember { |
908 |
sub AddMember { |
824 |
my (%data) = @_; |
909 |
my (%data) = @_; |
825 |
my $dbh = C4::Context->dbh; |
910 |
my $dbh = C4::Context->dbh; |
|
|
911 |
my $schema = Koha::Database->new()->schema; |
826 |
|
912 |
|
827 |
# generate a proper login if none provided |
913 |
# generate a proper login if none provided |
828 |
$data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq ''; |
914 |
$data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq ''; |
Lines 837-845
sub AddMember {
Link Here
|
837 |
$data{'dateenrolled'} = C4::Dates->new()->output("iso"); |
923 |
$data{'dateenrolled'} = C4::Dates->new()->output("iso"); |
838 |
} |
924 |
} |
839 |
|
925 |
|
840 |
my $patron_category = |
926 |
my $patron_category = $schema->resultset('Category')->find( $data{'categorycode'} ); |
841 |
Koha::Database->new()->schema()->resultset('Category') |
|
|
842 |
->find( $data{'categorycode'} ); |
843 |
$data{'privacy'} = |
927 |
$data{'privacy'} = |
844 |
$patron_category->default_privacy() eq 'default' ? 1 |
928 |
$patron_category->default_privacy() eq 'default' ? 1 |
845 |
: $patron_category->default_privacy() eq 'never' ? 2 |
929 |
: $patron_category->default_privacy() eq 'never' ? 2 |
Lines 848-861
sub AddMember {
Link Here
|
848 |
|
932 |
|
849 |
# create a disabled account if no password provided |
933 |
# create a disabled account if no password provided |
850 |
$data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!'; |
934 |
$data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!'; |
851 |
$data{'borrowernumber'}=InsertInTable("borrowers",\%data); |
935 |
$data{'dateofbirth'} = undef if( not $data{'dateofbirth'} ); |
|
|
936 |
|
937 |
# get only the columns of Borrower |
938 |
my @columns = $schema->source('Borrower')->columns; |
939 |
my $new_member = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) } ; |
940 |
delete $new_member->{borrowernumber}; |
941 |
|
942 |
my $rs = $schema->resultset('Borrower'); |
943 |
$data{borrowernumber} = $rs->create($new_member)->id; |
852 |
|
944 |
|
853 |
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. |
945 |
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. |
854 |
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); |
946 |
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); |
855 |
|
947 |
|
856 |
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} ); |
948 |
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} ); |
857 |
|
949 |
|
858 |
return $data{'borrowernumber'}; |
950 |
return $data{borrowernumber}; |
859 |
} |
951 |
} |
860 |
|
952 |
|
861 |
=head2 Check_Userid |
953 |
=head2 Check_Userid |