id = $id; $this->calendar = $calendar; $this->start = $start; $this->end = $end; $this->breakStart = $breakStart; $this->breakEnd = $breakEnd; $this->employee = $employee; $this->status = $status; } public function getGroupingId() { $ret = array(); $ret[] = $this->getStart(); $ret[] = $this->getEnd(); $ret[] = $this->getCalendar()->getId(); $ret[] = $this->isPublished() ? 1 : 0; $moreKeys = $this->getRawDataKeys(); $moreKeys = array_filter( $moreKeys, function($e){ return ('meta_' === substr($e, 0, strlen('meta_'))); } ); foreach( $moreKeys as $k ){ $v = $this->getRawData( $k ); if( is_string($v) ){ $ret[] = $v; } } $ret = join( '-', $ret ); return $ret; } public function setRawData( $data ) { $this->raw = $data; return $this; } public function setRawDataByKey( $key, $value ) { $this->raw[$key] = $value; return $this; } public function getRawData( $key ) { $return = array_key_exists( $key, $this->raw ) ? $this->raw[$key] : NULL; return $return; } public function getRawDataKeys() { return array_keys( $this->raw ); } public function getId() { return $this->id; } public function setId( $id ) { $this->id = $id; return $this; } public function getStatus() { return $this->status; } public function isPublished() { return ($this->status == self::STATUS_PUBLISH); } public function isDraft() { return ($this->status == self::STATUS_DRAFT); } public function getTitle() { $return = array(); $return[] = $this->getStart(); $return[] = $this->getEnd(); $return = join('-', $return); return $return; } public function getCalendar() { return $this->calendar; } public function getEmployee() { return $this->employee; } public function isOpen() { $employee = $this->getEmployee(); $employeeId = $employee->getId(); $return = ( $employeeId == 0 ) ? TRUE : FALSE; return $return; } public function getStart() { return $this->start; } public function getEnd() { return $this->end; } public function setStart( $start ) { $this->start = $start; return $this; } public function setEnd( $end ) { $this->end = $end; return $this; } public function getBreakStart() { return $this->breakStart; } public function getBreakEnd() { return $this->breakEnd; } public function getStartInDay() { $full = $this->getStart(); $hour = substr( $full, 8, 2 ); $minute = substr( $full, 10, 2 ); $return = $hour * 60 * 60 + $minute * 60; return $return; } public function getEndInDay() { $start = $this->getStart(); $end = $this->getEnd(); $full = $this->getEnd(); $hour = substr( $full, 8, 2 ); $minute = substr( $full, 10, 2 ); $return = $hour * 60 * 60 + $minute * 60; if( $return ){ $d1 = substr( $start, 0, 8 ); $d2 = substr( $end, 0, 8 ); // overnight shifts if( $d2 > $d1 ){ if (function_exists('gregoriantojd')) { $days = gregoriantojd((int) substr($end, 4, 2), (int) substr($end, 6, 2), (int) substr($end, 0, 4)) - gregoriantojd((int) substr($start, 4, 2), (int) substr($start, 6, 2), (int) substr($start, 0, 4)); $return = $return + $days * 24*60*60; } else { $string1 = substr($start, 0, 4) . '-' . substr($start, 4, 2) . '-' . substr($start, 6, 2) . ' ' . '00:00:00'; $string2 = substr($end, 0, 4) . '-' . substr($end, 4, 2) . '-' . substr($end, 6, 2) . ' ' . substr($end, 8, 2) . ':' . substr($end, 10, 2) . ':00'; $date = new DateTime( $string1 ); $date2 = new DateTime( $string2 ); $return = $date2->getTimestamp() - $date->getTimestamp(); } } // overnight shifts /* $startInDay = $this->getStartInDay(); if( $return <= $startInDay ){ $return = 24*60*60 + $return; } */ } if( 0 == $return ){ $return = 24*60*60; } return $return; } public function getBreakStartInDay() { $ret = null; $full = (string) $this->getBreakStart(); if( ! $full ){ return $ret; } $hour = (int) substr( $full, 8, 2 ); $minute = (int) substr( $full, 10, 2 ); $ret = $hour * 60 * 60 + $minute * 60; return $ret; } public function getBreakEndInDay() { $ret = null; $full = (string) $this->getBreakEnd(); if( ! $full ){ return $ret; } $hour = (int) substr( $full, 8, 2 ); $minute = (int) substr( $full, 10, 2 ); $ret = $hour * 60 * 60 + $minute * 60; if( 0 == $ret ){ $ret = 24*60*60; } return $ret; } public function getDateStart() { $full = $this->getStart(); $return = substr( $full, 0, 8 ); return $return; } public function getDateEnd() { $full = $this->getEnd(); $return = substr( $full, 0, 8 ); return $return; } public function isMultiDay() { $startInDay = $this->getStartInDay(); $endInDay = $this->getEndInDay(); $return = FALSE; if( (0 == $startInDay) && ((24*60*60 == $endInDay) OR (0 == $endInDay)) ){ $return = TRUE; } return $return; } }