|
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 866-871
sub has_valid_userid {
Link Here
|
| 866 |
return $already_exists ? 0 : 1; |
867 |
return $already_exists ? 0 : 1; |
| 867 |
} |
868 |
} |
| 868 |
|
869 |
|
|
|
870 |
=head3 generate_userid |
| 871 |
|
| 872 |
my $patron = Koha::Patron->new( $params ); |
| 873 |
my $userid = $patron->generate_userid |
| 874 |
|
| 875 |
Generate a userid using the $surname and the $firstname (if there is a value in $firstname). |
| 876 |
|
| 877 |
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). |
| 878 |
|
| 879 |
# Note: Should we set $self->userid with the generated value? |
| 880 |
# Certainly yes, but we AddMember and ModMember will be rewritten |
| 881 |
|
| 882 |
=cut |
| 883 |
|
| 884 |
sub generate_userid { |
| 885 |
my ($self) = @_; |
| 886 |
my $userid; |
| 887 |
my $offset = 0; |
| 888 |
my $patron = Koha::Patron->new; |
| 889 |
my $firstname = $self->firstname; |
| 890 |
my $surname = $self->surname; |
| 891 |
#The script will "do" the following code and increment the $offset until the generated userid is unique |
| 892 |
do { |
| 893 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
| 894 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
| 895 |
$userid = lc(($firstname)? "$firstname.$surname" : $surname); |
| 896 |
$userid = unac_string('utf-8',$userid); |
| 897 |
$userid .= $offset unless $offset == 0; |
| 898 |
$patron->userid( $userid ); |
| 899 |
$offset++; |
| 900 |
} while (! $patron->has_valid_userid ); |
| 901 |
|
| 902 |
return $userid; |
| 903 |
|
| 904 |
} |
| 905 |
|
| 869 |
=head3 type |
906 |
=head3 type |
| 870 |
|
907 |
|
| 871 |
=cut |
908 |
=cut |
| 872 |
- |
|
|