Revision 420

Date:
2014/02/22 09:50:23
Author:
ahitrov
Revision Log:
users::Phone functions get_code & get_number
users::Keeper function phone_show for phone output formatting
users::UserProfile - create_credential for phone and e-mail modifies object adding credential to {phones}/{emails} and redifining phone/email fields
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/users/lib/users/Keeper.pm

     
    241 241 s/^\s+//;
    242 242 s/\s+$//;
    243 243 }
    244 if ( $phone =~ /^\+?(\d)+[\(\ ]+(\d+)[\)\ ]+([\d+\ ])$/ ) {
    244 if ( $phone =~ /^[\+]?(\d)+[\(\ ]+(\d+)[\)\ ]+([\d+\ ]+)$/ ) {
    245 245 my $cc = $1;
    246 246 my $code = $2;
    247 247 my $number = $3; $number =~ s/\D//g;
    248 $phone = $cc.'('.$code.')'.$phone;
    248 $cc = 7 if $phone !~ /^\+/ && $cc == 8;
    249 $phone = $cc.'('.$code.')'.$number;
    249 250 } elsif ( $phone =~ /^[\(]+(\d+)[\)\ ]+([\d+\ ])$/ ) {
    250 251 my $cc = '7';
    251 252 my $code = $1;
     
    258 259 }
    259 260 }
    260 261
    262 sub _phone_show {
    263 my $self = shift;
    264 my $phone = shift;
    265 if ( $phone ) {
    266 for ( $phone ) {
    267 s/-//g;
    268 s/\[/\(/g;
    269 s/\]/\)/g;
    270 s/^\s+//;
    271 s/\s+$//;
    272 }
    273 if ( $phone =~ /^[\+]?(\d)+[\(\ ]+(\d+)[\)\ ]+([\d+\ ]+)$/ ) {
    274 my $cc = $1;
    275 my $code = $2;
    276 my $number = $3; $number =~ s/\D//g;
    277 $cc = 7 if $phone !~ /^\+/ && $cc == 8;
    278 $number =~ s/^(\d{3})(\d+)/$1-$2/;
    279 $phone = $cc.' ('.$code.') '.$number;
    280 } elsif ( $phone =~ /^[\(]+(\d+)[\)\ ]+([\d+\ ])$/ ) {
    281 my $cc = '7';
    282 my $code = $1;
    283 my $number = $2; $number =~ s/\D//g;
    284 $number =~ s/^(\d{3})(\d+)/$1-$2/;
    285 $phone = $cc.' ('.$code.') '.$phone;
    286 } else {
    287 $phone =~ s/\D//g;
    288 }
    289 return $phone;
    290 }
    291 }
    292
    261 293 sub _phone_reduction {
    262 294 my $self = shift;
    263 295 my $phone = shift;
  • utf8/plugins/users/lib/users/Phone.pm

     
    21 21 )
    22 22 }
    23 23
    24 sub get_code {
    25 my $self = shift;
    26 if ( $self->name_format =~ /\((\d+)\)/ ) {
    27 return $1;
    28 }
    29 }
    30
    31 sub get_number {
    32 my $self = shift;
    33 my $number = $self->name_format;
    34 for ( $number ) {
    35 s/\+\d+//;
    36 s/\(\d+\)//;
    37 s/\D//g;
    38 }
    39 return $number;
    40 }
    41
    24 42 sub class_name
    25 43 {
    26 44 return 'Телефон';
  • utf8/plugins/users/lib/users/UserProfile.pm

     
    356 356 $object->store;
    357 357 }
    358 358 }
    359 if ( ref $object && $object->id ) {
    360 $self->{phones} = [] unless exists $self->{phones};
    361 if ( $opts{main} ) {
    362 my $sql = $keeper->SQL->prepare('update profile_credentials set main = 0 where class = ? and uid = ? and id != ?');
    363 $sql->execute( $object->class, $self->id, $object->id );
    364 $sql->finish;
    365 $self->{email} = $object;
    366 unshift @{$self->{emails}}, $object;
    367 } else {
    368 push @{$self->{emails}}, $object;
    369 }
    370 }
    359 371 if ( $opts{main} ) {
    360 my $sql = $keeper->SQL->prepare('update profile_credentials set main = 0 where class = ? and uid = ? and id != ?');
    361 $sql->execute( $object->class, $self->id, $object->id );
    362 $sql->finish;
    363 372 }
    364 373 } elsif ( $opts{phone} ) {
    365 374 ($object) = $self->keeper->get_documents(
     
    385 394 $object->store;
    386 395 }
    387 396 }
    388 if ( $opts{main} ) {
    389 my $sql = $keeper->SQL->prepare('update profile_credentials set main = 0 where class = ? and uid = ? and id != ?');
    390 $sql->execute( $object->class, $self->id, $object->id );
    391 $sql->finish;
    397 if ( ref $object && $object->id ) {
    398 $self->{phones} = [] unless exists $self->{phones};
    399 if ( $opts{main} ) {
    400 my $sql = $keeper->SQL->prepare('update profile_credentials set main = 0 where class = ? and uid = ? and id != ?');
    401 $sql->execute( $object->class, $self->id, $object->id );
    402 $sql->finish;
    403 $self->{phone} = $object;
    404 unshift @{$self->{phones}}, $object;
    405 } else {
    406 push @{$self->{phones}}, $object;
    407 }
    392 408 }
    393 409 }
    394 410 return $object;
     
    461 477 my $self = shift;
    462 478
    463 479 if ( $state->{users}->use_credentials && $self->email ) {
    464 $self->create_credential( email => $self->email, main => 1, $self->status == 1 ? (status => 1) : () );
    480 my $object = $self->create_credential( email => $self->email, main => 1, $self->status == 1 ? (status => 1) : () );
    481 if ( ref $object && $object->id ) {
    482 $self->{email} = $object;
    483 $self->{emails} = [] unless exists $self->{emails};
    484 unshift @{$self->{emails}}, $object;
    485 }
    465 486 }
    466 487
    467 488 1;