Ignore:
Timestamp:
10/03/19 01:22:25 (5 years ago)
Author:
nanardon
Message:

Add EmploymentSummary?() feature

File:
1 edited

Legend:

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

    r2275 r2288  
    1212use DateTime; 
    1313use DateTime::TimeZone; 
     14use DateTime::Format::Pg; 
    1415use base qw(LATMOS::Accounts::Bases::Sql::objects); 
    1516use LATMOS::Accounts::I18N; 
     
    20922093} 
    20932094 
     2095=head2 EmploymentSummary 
     2096 
     2097Return an array of employment information group by successive contratType 
     2098 
     2099=cut 
     2100 
     2101sub EmploymentSummary { 
     2102    my ( $self ) = @_; 
     2103 
     2104    my $sth = $self->db->prepare_cached(q{ 
     2105        select employment.name from employment 
     2106        where "user" = ? order by employment.firstday asc 
     2107    }); 
     2108    $sth->execute($self->id); 
     2109    my @values; 
     2110    my $prevContrat = ':'; 
     2111    my $prevEnd = undef; 
     2112    while (my $res = $sth->fetchrow_hashref) { 
     2113        my $Emp = $self->base->get_object('employment', $res->{name}); 
     2114 
     2115        my $new = 0; 
     2116 
     2117        my $curContrat  = $Emp->get_attributes('contratType') || ''; 
     2118        my $DTfirstday  = DateTime::Format::Pg->parse_datetime( $Emp->get_attributes('firstday') ); 
     2119 
     2120        if ($curContrat ne $prevContrat) { 
     2121            $new = 1; 
     2122        } 
     2123        if ($prevEnd) { 
     2124            if ($DTfirstday->epoch - $prevEnd->epoch > 86400 * 2) { 
     2125                $new = 1; 
     2126            } 
     2127        } 
     2128        if (!@values) { 
     2129            $new = 1; 
     2130        } 
     2131 
     2132        if ( my $lastday = $Emp->get_attributes('lastday') ) { 
     2133            $prevEnd = DateTime::Format::Pg->parse_datetime( $lastday ); 
     2134        } 
     2135 
     2136        if ( $new ) { 
     2137            $prevContrat = $curContrat; 
     2138            push( 
     2139                @values, 
     2140                { 
     2141                    firstday => $DTfirstday->ymd('-'), 
     2142                    lastday  => $prevEnd ? $prevEnd->ymd('-') : undef, 
     2143                    contratType => $curContrat, 
     2144                } 
     2145            ); 
     2146        } else { 
     2147            $values[-1]->{lastday} = $prevEnd ? $prevEnd->ymd('-') : undef; 
     2148        } 
     2149    } 
     2150 
     2151    @values 
     2152} 
     2153 
    20942154=head2 storeBannedPassword($epassword) 
    20952155 
Note: See TracChangeset for help on using the changeset viewer.