settings = $settings; $this->t = $t; } public function getShifts() { return $this->shifts; } public function reset() { $this->qty = 0; $this->duration = 0; $this->qtyTimeoff = 0; $this->durationTimeoff = 0; $this->shifts = array(); return $this; } public function add( SH4_Shifts_Model $model ) { $id = $model->getId(); if( isset($this->shifts[$id]) ){ return $this; } $this->shifts[$id] = $model; $start = $model->getStart(); $end = $model->getEnd(); $this->t->setDateTimeDb( $start ); $startTs = $this->t->getTimestamp(); $startDayStart = $this->t->setStartDay()->getTimestamp(); $startDate = $this->t->formatDateDb(); $startDayTs = $startTs - $startDayStart; $this->t->setDateTimeDb( $end ); $endTs = $this->t->getTimestamp(); $endDayStart = $this->t->setStartDay()->getTimestamp(); $endDate = $this->t->formatDateDb(); $endDayTs = $endTs - $endDayStart; $duration = abs( $endTs - $startTs ); if( ($startDayTs == 0) && ($endDayTs == 0) ){ $fullDayCountAs = $this->settings->get('full_day_count_as'); // $durationDays = $duration / (24 * 60 * 60); $durationDays = 0; $rexDate = $startDate; $this->t->setDateDb( $rexDate ); while( $rexDate < $endDate ){ $durationDays++; $rexDate = $this->t ->modify( '+1 day' ) ->formatDateDb() ; } $duration = $durationDays * $fullDayCountAs; // echo "DD = '$durationDays'
"; } $noBreak = $this->settings->get( 'shifttypes_nobreak' ); if( ! $noBreak ){ $breakStart = (string) $model->getBreakStart(); $breakEnd = (string) $model->getBreakEnd(); if( $breakStart OR $breakEnd ){ // if( $breakStart < $start ) $breakStart = $start; // if( $breakEnd > $end ) $breakEnd = $end; if( ($breakStart >= $start) && ($breakEnd <= $end) ){ $this->t->setDateTimeDb( $breakStart ); $breakStartTs = $this->t->getTimestamp(); $this->t->setDateTimeDb( $breakEnd ); $breakEndTs = $this->t->getTimestamp(); $breakDuration = abs( $breakEndTs - $breakStartTs ); $duration = $duration - $breakDuration; } } } $this->qty++; $this->duration += $duration; // is timeoff $calendar = $model->getCalendar(); if( $calendar->isTimeoff() ){ $this->qtyTimeoff++; $this->durationTimeoff += $duration; } return $this; } public function getDuration() { return $this->duration; } public function getDurationTimeoff() { return $this->durationTimeoff; } public function getDurationHours() { $return = $this->getDuration(); $return = $return / (60 * 60); $return = sprintf( '%0.2f', $return ); return $return; } public function formatDuration( $duration = NULL ) { if( NULL === $duration ){ $duration = $this->getDuration(); } $hours = floor( $duration / (60 * 60) ); $remain = $duration - $hours * (60 * 60); $minutes = floor( $remain / 60 ); $hoursView = $hours; $minutesView = sprintf( '%02d', $minutes ); $return = $hoursView . ':' . $minutesView; // $return = gmdate( "H:i", $this->getDuration() ); return $return; } public function getQty() { return $this->qty; } public function getQtyTimeoff() { return $this->qtyTimeoff; } }