|
Lines 22-27
use Modern::Perl;
Link Here
|
| 22 |
|
22 |
|
| 23 |
use Carp; |
23 |
use Carp; |
| 24 |
use List::MoreUtils qw( uniq ); |
24 |
use List::MoreUtils qw( uniq ); |
|
|
25 |
use Text::Unaccent qw( unac_string ); |
| 25 |
|
26 |
|
| 26 |
use C4::Context; |
27 |
use C4::Context; |
| 27 |
use C4::Log; |
28 |
use C4::Log; |
|
Lines 897-902
sub has_valid_userid {
Link Here
|
| 897 |
return $already_exists ? 0 : 1; |
898 |
return $already_exists ? 0 : 1; |
| 898 |
} |
899 |
} |
| 899 |
|
900 |
|
|
|
901 |
=head3 generate_userid |
| 902 |
|
| 903 |
my $patron = Koha::Patron->new( $params ); |
| 904 |
my $userid = $patron->generate_userid |
| 905 |
|
| 906 |
Generate a userid using the $surname and the $firstname (if there is a value in $firstname). |
| 907 |
|
| 908 |
Return the generate userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $userid is unique, or a higher numeric value if not unique). |
| 909 |
|
| 910 |
# Note: Should we set $self->userid with the generated value? |
| 911 |
# Certainly yes, but we AddMember and ModMember will be rewritten |
| 912 |
|
| 913 |
=cut |
| 914 |
|
| 915 |
sub generate_userid { |
| 916 |
my ($self) = @_; |
| 917 |
my $userid; |
| 918 |
my $offset = 0; |
| 919 |
my $patron = Koha::Patron->new; |
| 920 |
my $firstname = $self->firstname; |
| 921 |
my $surname = $self->surname; |
| 922 |
#The script will "do" the following code and increment the $offset until the generated userid is unique |
| 923 |
do { |
| 924 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
| 925 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
| 926 |
$userid = lc(($firstname)? "$firstname.$surname" : $surname); |
| 927 |
$userid = unac_string('utf-8',$userid); |
| 928 |
$userid .= $offset unless $offset == 0; |
| 929 |
$patron->userid( $userid ); |
| 930 |
$offset++; |
| 931 |
} while (! $patron->has_valid_userid ); |
| 932 |
|
| 933 |
return $userid; |
| 934 |
|
| 935 |
} |
| 936 |
|
| 900 |
=head2 Internal methods |
937 |
=head2 Internal methods |
| 901 |
|
938 |
|
| 902 |
=head3 _type |
939 |
=head3 _type |
| 903 |
- |
|
|