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 841-846
sub has_valid_userid {
Link Here
|
841 |
return $already_exists ? 0 : 1; |
842 |
return $already_exists ? 0 : 1; |
842 |
} |
843 |
} |
843 |
|
844 |
|
|
|
845 |
=head3 generate_userid |
846 |
|
847 |
my $patron = Koha::Patron->new( $params ); |
848 |
my $userid = $patron->generate_userid |
849 |
|
850 |
Generate a userid using the $surname and the $firstname (if there is a value in $firstname). |
851 |
|
852 |
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). |
853 |
|
854 |
# Note: Should we set $self->userid with the generated value? |
855 |
# Certainly yes, but we AddMember and ModMember will be rewritten |
856 |
|
857 |
=cut |
858 |
|
859 |
sub generate_userid { |
860 |
my ($self) = @_; |
861 |
my $userid; |
862 |
my $offset = 0; |
863 |
my $patron = Koha::Patron->new; |
864 |
my $firstname = $self->firstname; |
865 |
my $surname = $self->surname; |
866 |
#The script will "do" the following code and increment the $offset until the generated userid is unique |
867 |
do { |
868 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
869 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
870 |
$userid = lc(($firstname)? "$firstname.$surname" : $surname); |
871 |
$userid = unac_string('utf-8',$userid); |
872 |
$userid .= $offset unless $offset == 0; |
873 |
$patron->userid( $userid ); |
874 |
$offset++; |
875 |
} while (! $patron->has_valid_userid ); |
876 |
|
877 |
return $userid; |
878 |
|
879 |
} |
880 |
|
844 |
=head3 type |
881 |
=head3 type |
845 |
|
882 |
|
846 |
=cut |
883 |
=cut |
847 |
- |
|
|