View | Details | Raw Unified | Return to bug 19936
Collapse All | Expand All

(-)a/Koha/Patron.pm (-1 / +37 lines)
Lines 21-26 package Koha::Patron; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use Carp;
23
use Carp;
24
use Text::Unaccent qw( unac_string );
24
25
25
use C4::Context;
26
use C4::Context;
26
use C4::Log;
27
use C4::Log;
Lines 744-749 sub has_valid_userid { Link Here
744
    return $already_exists ? 0 : 1;
745
    return $already_exists ? 0 : 1;
745
}
746
}
746
747
748
=head3 generate_userid
749
750
my $patron = Koha::Patron->new( $params );
751
my $userid = $patron->generate_userid
752
753
Generate a userid using the $surname and the $firstname (if there is a value in $firstname).
754
755
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).
756
757
# Note: Should we set $self->userid with the generated value?
758
# Certainly yes, but we AddMember and ModMember will be rewritten
759
760
=cut
761
762
sub generate_userid {
763
    my ($self) = @_;
764
    my $userid;
765
    my $offset = 0;
766
    my $patron = Koha::Patron->new;
767
    my $firstname = $self->firstname;
768
    my $surname = $self->surname;
769
    #The script will "do" the following code and increment the $offset until the generated userid is unique
770
    do {
771
      $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
772
      $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
773
      $userid = lc(($firstname)? "$firstname.$surname" : $surname);
774
      $userid = unac_string('utf-8',$userid);
775
      $userid .= $offset unless $offset == 0;
776
      $patron->userid( $userid );
777
      $offset++;
778
     } while (! $patron->has_valid_userid );
779
780
     return $userid;
781
782
}
783
747
=head3 type
784
=head3 type
748
785
749
=cut
786
=cut
750
- 

Return to bug 19936