Ignore:
Timestamp:
12/22/15 12:59:06 (9 years ago)
Author:
nanardon
Message:

Add endStrictEmployment user's attribute and doc

File:
1 edited

Legend:

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

    r1511 r1514  
    236236                            } 
    237237                            if ($tend->ymd lt $nextstart->ymd) { 
     238                                last; 
     239                            } 
     240                        } 
     241                        $end = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
     242                        $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     243                        $end->add(hours => 23, minutes => 59, seconds => 59); 
     244                    } 
     245                    $list_empl->finish; 
     246 
     247                    if (!$end) { 
     248                        my $listold = $self->base->db->prepare_cached(q{ 
     249                            SELECT max(lastday) as lastday FROM employment WHERE "user" = ? and 
     250                            lastday IS NOT NULL and lastday <= now() - '1 days'::interval 
     251                        }); 
     252                        $listold->execute($self->id); 
     253                        my $res = $listold->fetchrow_hashref; 
     254                        if ($res && $res->{lastday}) { 
     255                            $end = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
     256                            $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     257                            $end->add(hours => 23, minutes => 59, seconds => 59); 
     258                        } 
     259                        $listold->finish; 
     260                    } 
     261                    return $end ? $end->iso8601 : undef 
     262                }, 
     263            }, 
     264            endStrictEmployment => { 
     265                formtype => 'DATETIME', 
     266                managed => 1, 
     267                ro => 1, 
     268                get => sub { 
     269                    my ($attr) = @_; 
     270                    my $self = $attr->object; 
     271 
     272                    my $list_empl = $self->base->db->prepare_cached(q{ 
     273                        SELECT * FROM employment WHERE "user" = ? and 
     274                            (lastday is null or lastday >= now() - '1 days'::interval)  
     275                            order by firstday asc 
     276                    }); 
     277                    $list_empl->execute($self->id); 
     278                    my $end; 
     279                    while (my $res = $list_empl->fetchrow_hashref) { 
     280                        if (!$res->{lastday}) { 
     281                            # Ultimate employment. 
     282                            $list_empl->finish; 
     283                            return undef; 
     284                        } 
     285                        if ($end) { 
     286                            my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday})); 
     287                            if ($end->ymd lt $nextstart->ymd) { 
    238288                                last; 
    239289                            } 
Note: See TracChangeset for help on using the changeset viewer.