Ignore:
Timestamp:
08/15/09 03:34:34 (15 years ago)
Author:
nanardon
Message:
  • don't use anymore address attributes on user object itself: o user has one or several address containing this info o address can have a 'site' attribute making global address fetch from site object o one and only one of this address can be set as main (attribute isMainAddress, setting it delete it from other object for this user)

o in case no main address is found and user has a 'site' attribute, global address is fetch from it
o user have now an attribute 'mainaddress' to get the name of the address object for main address

File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r342 r347  
    7474        department => 'department', 
    7575        otheraddress => 'otheraddress', 
     76        mainaddress => 'mainaddress', 
    7677        ) : ()), 
    7778    ) 
     
    184185        } 
    185186        return \@values; 
    186     } elsif ((grep { $field eq $_ } __PACKAGE__->_address_fields()) 
    187         && (my $fsite = $self->get_c_field('site'))) { 
    188         my $site = $self->base->get_object('site', $fsite); 
    189         if ($site) { 
    190             return $site->get_c_field($field); 
     187    } elsif ($field eq 'mainaddress') { 
     188        my $sth = $self->db->prepare_cached(q{ 
     189            select name from address join address_attributes on ikey = okey 
     190            where "user" = ? and attr = 'isMainAddress' 
     191            }); 
     192        $sth->execute($self->id); 
     193        my $res = $sth->fetchrow_hashref; 
     194        $sth->finish; 
     195        return $res->{name}; 
     196    } elsif (grep { $field eq $_ } qw(telephoneNumber physicalDeliveryOfficeName)) { 
     197        if (my $fmainaddress = $self->get_c_field('mainaddress')) { 
     198            my $address = $self->base->get_object('address', $fmainaddress); 
     199            if ($address) { 
     200                return $address->get_c_field($field); 
     201            } else { # can't happend 
     202                return; 
     203            } 
     204        } else { 
     205            return $self->SUPER::get_field($field); 
     206        } 
     207    } elsif (grep { $field eq $_ } __PACKAGE__->_address_fields()) { 
     208        if (my $fmainaddress = $self->get_c_field('mainaddress')) { 
     209            my $address = $self->base->get_object('address', $fmainaddress); 
     210            if ($address) { 
     211                return $address->get_c_field($field); 
     212            } else { # can't happend 
     213                return; 
     214            } 
     215        } elsif (my $fsite = $self->get_c_field('site')) { 
     216            my $site = $self->base->get_object('site', $fsite); 
     217            if ($site) { 
     218                return $site->get_c_field($field); 
     219            } else { # can't happend 
     220                return; 
     221            } 
     222        } else { 
     223            return; 
    191224        } 
    192225    } else { 
Note: See TracChangeset for help on using the changeset viewer.