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-202
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 |
|
Lines 283-289
sub Search {
Link Here
|
283 |
} |
339 |
} |
284 |
$searchtype ||= "start_with"; |
340 |
$searchtype ||= "start_with"; |
285 |
|
341 |
|
286 |
return SearchInTable( "borrowers", $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ); |
342 |
my $cond = _get_cond_for_dbix({ |
|
|
343 |
filters => $filter, |
344 |
exact_search => ($searchtype eq 'exact') ? 1 : 0, |
345 |
search_on_fields => $search_on_fields, |
346 |
}); |
347 |
|
348 |
my $rs = Koha::Database->new()->schema->resultset('Borrower'); |
349 |
$rs = $rs->search( |
350 |
$cond, |
351 |
{ |
352 |
($columns_out) ? { columns => $columns_out } : {}, |
353 |
order_by => $orderby, |
354 |
rows => $limit, |
355 |
}, |
356 |
); |
357 |
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); |
358 |
return [ $rs->all ]; |
287 |
} |
359 |
} |
288 |
|
360 |
|
289 |
=head2 GetMemberDetails |
361 |
=head2 GetMemberDetails |
Lines 787-794
sub ModMember {
Link Here
|
787 |
} |
859 |
} |
788 |
} |
860 |
} |
789 |
my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} ); |
861 |
my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} ); |
790 |
my $execute_success=UpdateInTable("borrowers",\%data); |
862 |
|
791 |
if ($execute_success) { # only proceed if the update was a success |
863 |
# get only the columns of a borrower |
|
|
864 |
my $schema = Koha::Database->new()->schema; |
865 |
my @columns = $schema->source('Borrower')->columns; |
866 |
my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) }; |
867 |
delete $new_borrower->{flags}; |
868 |
|
869 |
my $rs = $schema->resultset('Borrower')->search({ |
870 |
borrowernumber => $new_borrower->{borrowernumber}, |
871 |
}); |
872 |
my $execute_success = $rs->update($new_borrower); |
873 |
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 |
874 |
# 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 |
875 |
# 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 |
876 |
# 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 { |
905 |
sub AddMember { |
824 |
my (%data) = @_; |
906 |
my (%data) = @_; |
825 |
my $dbh = C4::Context->dbh; |
907 |
my $dbh = C4::Context->dbh; |
|
|
908 |
my $schema = Koha::Database->new()->schema; |
826 |
|
909 |
|
827 |
# generate a proper login if none provided |
910 |
# generate a proper login if none provided |
828 |
$data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq ''; |
911 |
$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"); |
920 |
$data{'dateenrolled'} = C4::Dates->new()->output("iso"); |
838 |
} |
921 |
} |
839 |
|
922 |
|
840 |
my $patron_category = |
923 |
my $patron_category = $schema->resultset('Category')->find( $data{'categorycode'} ); |
841 |
Koha::Database->new()->schema()->resultset('Category') |
|
|
842 |
->find( $data{'categorycode'} ); |
843 |
$data{'privacy'} = |
924 |
$data{'privacy'} = |
844 |
$patron_category->default_privacy() eq 'default' ? 1 |
925 |
$patron_category->default_privacy() eq 'default' ? 1 |
845 |
: $patron_category->default_privacy() eq 'never' ? 2 |
926 |
: $patron_category->default_privacy() eq 'never' ? 2 |
Lines 848-861
sub AddMember {
Link Here
|
848 |
|
929 |
|
849 |
# create a disabled account if no password provided |
930 |
# create a disabled account if no password provided |
850 |
$data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!'; |
931 |
$data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!'; |
851 |
$data{'borrowernumber'}=InsertInTable("borrowers",\%data); |
932 |
$data{'dateofbirth'} = undef if( not $data{'dateofbirth'} ); |
|
|
933 |
|
934 |
# get only the columns of Borrower |
935 |
my @columns = $schema->source('Borrower')->columns; |
936 |
my $new_member = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) } ; |
937 |
delete $new_member->{borrowernumber}; |
938 |
|
939 |
my $rs = $schema->resultset('Borrower'); |
940 |
$data{borrowernumber} = $rs->create($new_member)->id; |
852 |
|
941 |
|
853 |
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. |
942 |
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. |
854 |
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); |
943 |
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); |
855 |
|
944 |
|
856 |
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} ); |
945 |
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} ); |
857 |
|
946 |
|
858 |
return $data{'borrowernumber'}; |
947 |
return $data{borrowernumber}; |
859 |
} |
948 |
} |
860 |
|
949 |
|
861 |
=head2 Check_Userid |
950 |
=head2 Check_Userid |