App-Dochazka-REST
view release on metacpan or search on metacpan
lib/App/Dochazka/REST/Fillup.pm view on Meta::CPAN
$status = tsrange_to_dates_and_times( $this->intvl );
return unless $status->ok;
$pl = $status->payload;
my $this_end = "\"" . $pl->{end}->[0] . " " . $pl->{end}->[1] . "\"";
$status = tsrange_to_dates_and_times( $next->intvl );
return unless $status->ok;
$pl = $status->payload;
my $next_end = "\"" . $pl->{end}->[0] . " " . $pl->{end}->[1] . "\"";
$t = "[ " . $this_end . ", " . $next_end . " )";
$status = canonicalize_tsrange( $self->context->{dbix_conn}, $t );
return unless $status->ok;
push @$result_set, $self->_gen_int( $status->payload );
}
# Given a tempintvl object (which represents a single scheduled interval), find
# and return reference to array of existing attendance intervals that conflict
# with it.
sub _conflicting_intervals {
my ( $self, $tempintvl ) = @_;
my @conflicting_intervals = ();
my $status = fetch_intervals_by_eid_and_tsrange_inclusive(
$self->context->{'dbix_conn'},
$self->emp_obj->eid,
$tempintvl->intvl,
);
if ( $status->ok and $status->code eq 'DISPATCH_RECORDS_FOUND' ) {
foreach my $int ( @{ $status->payload } ) {
push @conflicting_intervals, $int;
}
} elsif ( $status->level eq 'NOTICE' and $status->code eq 'DISPATCH_NO_RECORDS_FOUND' ) {
$log->debug( "Scheduled interval " . $tempintvl->intvl .
" does not overlap with any existing intervals" );
} else {
$log->crit( "IN FILLUP, FAILED TO FETCH CONFLICTING INTERVALS: " . $status->text );
}
return \@conflicting_intervals;
}
=head2 DESTROY
Instance destructor. Once we are done with the scratch intervals, they can be deleted.
Returns a status object.
=cut
sub DESTROY {
my $self = shift;
$log->debug( "Entering " . __PACKAGE__ . "::DESTROY with arguments " . join( ' ', @_ ) );
$log->notice( "GLOBAL DESTRUCTION" ) if ${^GLOBAL_PHASE} eq 'DESTRUCT';
my $status;
try {
$dbix_conn->run( fixup => sub {
my $sth = $_->prepare( $site->SQL_TEMPINTVLS_DELETE_MULTIPLE );
$sth->bind_param( 1, $self->tiid );
$sth->execute;
my $rows = $sth->rows;
if ( $rows > 0 ) {
$status = $CELL->status_ok( 'DOCHAZKA_RECORDS_DELETED', args => [ $rows ], count => $rows );
} elsif ( $rows == 0 ) {
$status = $CELL->status_warn( 'DOCHAZKA_RECORDS_DELETED', args => [ $rows ], count => $rows );
} else {
die( "\$sth->rows returned a weird value $rows" );
}
} );
} catch {
$status = $CELL->status_err( 'DOCHAZKA_DBI_ERR', args => [ $_ ] );
};
$log->notice( "Fillup destructor says " . $status->level . ": " . $status->text );
return $status if $status;
return $CELL->status_ok;
}
=head1 FUNCTIONS
=head2 _next_tiid
Get next value from the temp_intvl_seq sequence
=cut
sub _next_tiid {
my $val;
my $status;
try {
$dbix_conn->run( fixup => sub {
( $val ) = $_->selectrow_array( $site->SQL_NEXT_TIID );
} );
} catch {
$status = $CELL->status_err( 'DOCHAZKA_DBI_ERR', args => [ $_ ] );
};
if ( $status ) {
$log->crit( $status->text );
return;
}
return $val;
}
=head2 Days_to_Date
Missing function in L<Date::Calc>
=cut
sub Days_to_Date {
my $canonical = shift;
my ( $year, $month, $day ) = Add_Delta_Days(1,1,1, $canonical - 1);
return ( $year, $month, $day );
}
=head2 _init_lower_sched_hash
( run in 1.062 second using v1.01-cache-2.11-cpan-2398b32b56e )