本文整理汇总了PHP中TTDate::isTimeOverLap方法的典型用法代码示例。如果您正苦于以下问题:PHP TTDate::isTimeOverLap方法的具体用法?PHP TTDate::isTimeOverLap怎么用?PHP TTDate::isTimeOverLap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTDate
的用法示例。
在下文中一共展示了TTDate::isTimeOverLap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getShifts
function getShifts($start_date, $end_date, &$holiday_data = array(), &$branch_options = array(), &$department_options = array(), &$n, &$shifts = array(), &$shifts_index = array(), $open_shift_conflict_index = array(), $permission_children_ids = NULL)
{
//Debug::text('Start Date: '. TTDate::getDate('DATE+TIME', $start_date) .' End Date: '. TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
$recurring_schedule_control_start_date = TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date'));
//Debug::text('Recurring Schedule Control Start Date: '. TTDate::getDate('DATE+TIME', $recurring_schedule_control_start_date),__FILE__, __LINE__, __METHOD__, 10);
$current_template_week = $this->getColumn('remapped_week');
$max_week = $this->getColumn('max_week');
//Debug::text('Template Week: '. $current_template_week .' Max Week: '. $this->getColumn('max_week') .' ReMapped Week: '. $this->getColumn('remapped_week') ,__FILE__, __LINE__, __METHOD__, 10);
if ($recurring_schedule_control_start_date == '') {
return FALSE;
}
//Get week of start_date
$start_date_week = TTDate::getBeginWeekEpoch($recurring_schedule_control_start_date, 0);
//Start week on Sunday to match Recurring Schedule.
//Debug::text('Week of Start Date: '. $start_date_week ,__FILE__, __LINE__, __METHOD__, 10);
$apf = TTnew('AbsencePolicyFactory');
$absence_policy_paid_type_options = $apf->getOptions('paid_type');
for ($i = $start_date; $i <= $end_date; $i += 86400 + 43200) {
//Handle DST by adding 12hrs to the date to get the mid-day epoch, then forcing it back to the beginning of the day.
$i = TTDate::getBeginDayEpoch($i);
if ($this->getColumn('hire_date') != '' and $i < $this->getColumn('hire_date') or $this->getColumn('termination_date') != '' and $i > $this->getColumn('termination_date')) {
//Debug::text('Skipping due to Hire/Termination date: User ID: '. $this->getColumn('user_id') .' I: '. $i .' Hire Date: '. $this->getColumn('hire_date') .' Termination Date: '. $this->getColumn('termination_date') ,__FILE__, __LINE__, __METHOD__, 10);
continue;
}
//This needs to take into account weeks spanning January 1st of each year. Where the week goes from 53 to 1.
//Rather then use the week of the year, calculate the weeks between the recurring schedule start date and now.
$current_week = round((TTDate::getBeginWeekEpoch($i, 0) - $start_date_week) / 604800);
//Find out which week we are on based on the recurring schedule start date. Use round due to DST the week might be 6.9 or 7.1, so we need to round to the nearest full week.
//Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Week: '. $start_date_week,__FILE__, __LINE__, __METHOD__, 10);
$template_week = $current_week % $max_week + 1;
//Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
if ($template_week == $current_template_week) {
//Debug::text('Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week,__FILE__, __LINE__, __METHOD__, 10);
//Debug::text(' Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
if ($this->isActiveShiftDay($i)) {
//Debug::text(' Active Shift on this day...',__FILE__, __LINE__, __METHOD__, 10);
$start_time = TTDate::getTimeLockedDate($this->getStartTime(), $i);
$end_time = TTDate::getTimeLockedDate($this->getEndTime(), $i);
if ($end_time < $start_time) {
//Spans the day boundary, add 86400 to end_time
$end_time = $end_time + 86400;
//Debug::text(' Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10);
}
$iso_date_stamp = TTDate::getISODateStamp(PayPeriodScheduleFactory::getShiftAssignedDate($start_time, $end_time, $this->getColumn('shift_assigned_day_id')));
//$iso_date_stamp = TTDate::getISODateStamp( $i );
$open_shift_multiplier = $this->getColumn('user_id') == 0 ? $this->getOpenShiftMultiplier() : 1;
//Debug::text('Open Shift Multiplier: '. $open_shift_multiplier,__FILE__, __LINE__, __METHOD__, 10);
for ($x = 0; $x < $open_shift_multiplier; $x++) {
//Check all non-OPEN shifts for conflicts.
if ($this->getColumn('user_id') > 0 and isset($shifts_index[$iso_date_stamp][$this->getColumn('user_id')])) {
//User has previous recurring schedule shifts, check for overlap.
//Loop over each employees shift for this day and check for conflicts
foreach ($shifts_index[$iso_date_stamp][$this->getColumn('user_id')] as $shift_key) {
if (isset($shifts[$iso_date_stamp][$shift_key])) {
//Must use parseDateTime() when called from the API due to date formats that strtotime() fails on.
if (TTDate::isTimeOverLap(defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['start_date']) : $shifts[$iso_date_stamp][$shift_key]['start_date'], defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['end_date']) : $shifts[$iso_date_stamp][$shift_key]['end_date'], $start_time, $end_time) == TRUE) {
//Debug::text(' Found overlapping recurring schedules! User ID: '. $this->getColumn('user_id') .' Start Time: '. $start_time,__FILE__, __LINE__, __METHOD__, 10);
continue 2;
}
}
}
unset($shift_key);
} elseif ($this->getColumn('user_id') == 0 and isset($shifts_index[$iso_date_stamp])) {
//Debug::text(' Checking OPEN shift conflicts... Date: '. $iso_date_stamp,__FILE__, __LINE__, __METHOD__, 10);
//Check all OPEN shifts for conflicts.
//This is special, since there can be multiple open shifts for the same branch,department,job,task, so we need to check if are conflicts with *any* employee.
//Do we allow conflicting shifts between committed and recurring OPEN shifts? For example what if there are two open shifts on the same day
//6AM-3PM (x2) and they want to override one of those shifts to 7AM-4PM? If we use this check:
// ( $shifts[$iso_date_stamp][$shift_key]['user_id'] > 0 OR ( isset($shifts[$iso_date_stamp][$shift_key]['id']) AND $shifts[$iso_date_stamp][$shift_key]['id'] > 0 ) )
//That allows committed OPEN shifts to override recurring open shifts, which is great, but it prevents adding additional open shifts that may
//also overlap unless they override all recurring shifts first. I think this is the trade-off we have to make as its more likely that they
//will adjust an open shift time rather than add/remove specific shifts. Removing recurring OPEN shifts can be done by making them ABSENT.
//This will also affect when recurring OPEN shifts are committed by preventing the shifts from doubling up.
foreach ($shifts_index[$iso_date_stamp] as $tmp_index_user_id => $tmp_index_arr) {
foreach ($tmp_index_arr as $shift_key) {
$tmp_start_date = defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['start_date']) : $shifts[$iso_date_stamp][$shift_key]['start_date'];
$tmp_end_date = defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['end_date']) : $shifts[$iso_date_stamp][$shift_key]['end_date'];
if (($shifts[$iso_date_stamp][$shift_key]['user_id'] > 0 or isset($shifts[$iso_date_stamp][$shift_key]['id']) and $shifts[$iso_date_stamp][$shift_key]['id'] > 0) and (!isset($open_shift_conflict_index['open'][$this->getID()][$shift_key]) and (isset($shifts[$iso_date_stamp][$shift_key]['id']) and !isset($open_shift_conflict_index['scheduled'][$shifts[$iso_date_stamp][$shift_key]['id']]))) and $this->getColumn('schedule_branch_id') == $shifts[$iso_date_stamp][$shift_key]['branch_id'] and $this->getColumn('schedule_department_id') == $shifts[$iso_date_stamp][$shift_key]['department_id'] and $this->getColumn('job_id') == $shifts[$iso_date_stamp][$shift_key]['job_id'] and $this->getColumn('job_item_id') == $shifts[$iso_date_stamp][$shift_key]['job_item_id'] and ($tmp_start_date == $start_time and $tmp_end_date == $end_time)) {
//Debug::text(' Found OPEN shift conflict... Skipping...! Shift Key: '. $shift_key,__FILE__, __LINE__, __METHOD__, 10);
//We need to track each shift_key that caused a conflict so it can't cause another conflict later on.
// Make sure we just track it on a per template basis though, otherwise the same $shift_key from a previous template can affect other templates.
// The above issue would show up as OPEN shifts not being overridden.
//We also need to track which scheduled shift that caused a conflict so it can't cause another one later on.
// This prevents a single scheduled shift from overriding multiple OPEN shifts of different times.
//However we need to be smarter about which shifts override which OPEN shifts...
// So if there are two open shifts, 10AM-4PM and 3:50PM-9PM, a 10AM-4PM scheduled shift overrides the OPEN shift that best fits it (10AM to 4PM, *not* 3:50-9PM)
// For now require an exact match to override an OPEN shift, if we start using partial schedules it gets much more complicated.
// Or we could introduce a hardcoded "fudge factor" setting (ie: 5 mins) that is always used instead.
$open_shift_conflict_index['open'][$this->getID()][$shift_key] = TRUE;
$open_shift_conflict_index['scheduled'][$shifts[$iso_date_stamp][$shift_key]['id']] = TRUE;
continue 3;
}
unset($tmp_start_date, $tmp_end_date);
}
}
unset($tmp_index_user_id, $tmp_index_arr);
}
//This check has to occurr after the committed schedule check, otherwise no committed schedules will appear.
if ($this->getColumn('recurring_schedule_control_start_date') != '' and $i < TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date')) or $this->getColumn('recurring_schedule_control_end_date') != '' and $i > TTDate::strtotime($this->getColumn('recurring_schedule_control_end_date'))) {
//Debug::text('Skipping due to Recurring Schedule Start/End date: ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' I: '. $i .' Start Date: '. $this->getColumn('recurring_schedule_control_start_date') .' ('. TTDate::strtotime( $this->getColumn('recurring_schedule_control_start_date') ) .') End Date: '. $this->getColumn('recurring_schedule_control_end_date') ,__FILE__, __LINE__, __METHOD__, 10);
//.........这里部分代码省略.........
示例2: mergeScheduleArray
function mergeScheduleArray($schedule_shifts, $recurring_schedule_shifts)
{
//Debug::text('Merging Schedule, and Recurring Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10);
$ret_arr = $schedule_shifts;
//Debug::Arr($schedule_shifts, '(c) Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10);
if (is_array($recurring_schedule_shifts) and count($recurring_schedule_shifts) > 0) {
foreach ($recurring_schedule_shifts as $date_stamp => $day_shifts_arr) {
//Debug::text('----------------------------------', __FILE__, __LINE__, __METHOD__, 10);
//Debug::text('Date Stamp: '. TTDate::getDate('DATE+TIME', $date_stamp). ' Epoch: '. $date_stamp , __FILE__, __LINE__, __METHOD__, 10);
//Debug::Arr($schedule_shifts[$date_stamp], 'Date Arr: ', __FILE__, __LINE__, __METHOD__, 10);
foreach ($day_shifts_arr as $key => $shift_arr) {
if (isset($ret_arr[$date_stamp])) {
//Debug::text('Already Schedule Shift on this day: '. TTDate::getDate('DATE', $date_stamp) , __FILE__, __LINE__, __METHOD__, 10);
//Loop through each shift on this day, and check for overlaps
//Only include the recurring shift if ALL times DO NOT overlap
$overlap = 0;
foreach ($ret_arr[$date_stamp] as $tmp_shift_arr) {
if (TTDate::isTimeOverLap($shift_arr['start_time'], $shift_arr['end_time'], $tmp_shift_arr['start_time'], $tmp_shift_arr['end_time'])) {
//Debug::text('Times OverLap: '. TTDate::getDate('DATE+TIME', $shift_arr['start_time']) , __FILE__, __LINE__, __METHOD__, 10);
$overlap++;
} else {
//Debug::text('Times DO NOT OverLap: '. TTDate::getDate('DATE+TIME', $shift_arr['start_time']) , __FILE__, __LINE__, __METHOD__, 10);
}
}
if ($overlap == 0) {
//Debug::text('NO Times OverLap, using recurring schedule: '. TTDate::getDate('DATE+TIME', $shift_arr['start_time']) , __FILE__, __LINE__, __METHOD__, 10);
$ret_arr[$date_stamp][] = $shift_arr;
}
} else {
//Debug::text('No Schedule Shift on this day: '. TTDate::getDate('DATE', $date_stamp) , __FILE__, __LINE__, __METHOD__, 10);
$ret_arr[$date_stamp][] = $shift_arr;
}
}
}
}
return $ret_arr;
}
示例3: getShiftData
//.........这里部分代码省略.........
}
if (!isset($shift_data[$shift]['total_time'])) {
$shift_data[$shift]['total_time'] = 0;
}
$punch_day_epoch = TTDate::getBeginDayEpoch($p_obj->getTimeStamp());
if (!isset($shift_data[$shift]['total_time_per_day'][$punch_day_epoch])) {
$shift_data[$shift]['total_time_per_day'][$punch_day_epoch] = 0;
}
//Determine which shift is closest to the given epoch.
$punch_difference_from_epoch = abs($epoch - $p_obj->getTimeStamp());
if ($nearest_punch_difference === FALSE or $punch_difference_from_epoch < $nearest_punch_difference) {
Debug::text('Nearest Shift Determined to be: ' . $shift . ' Nearest Punch Diff: ' . (int) $nearest_punch_difference . ' Punch Diff: ' . $punch_difference_from_epoch, __FILE__, __LINE__, __METHOD__, 10);
$nearest_shift_id = $shift;
$nearest_punch_difference = $punch_difference_from_epoch;
}
$punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType());
$shift_data[$shift]['punches'][] = $punch_arr;
$shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId();
if ($punch_control_obj->getUserDateID() != FALSE) {
$shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID();
}
$shift_data[$shift]['span_midnight'] = FALSE;
if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) {
//Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['first_in'] = $punch_arr;
} elseif ($p_obj->getStatus() == 20) {
//Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['last_out'] = $punch_arr;
//Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['total_time'] += $total_time;
//Check to see if the previous punch was on a different day then the current punch.
if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) {
Debug::text('Punch pair DOES span midnight', __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['span_midnight'] = TRUE;
$total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp());
if (is_array($total_time_for_each_day_arr)) {
foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) {
if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) {
$shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0;
}
$shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time;
}
}
unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time);
} else {
$shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time;
}
}
$prev_punch_arr = $punch_arr;
$i++;
}
//Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10);
if (isset($shift_data)) {
//Loop through each shift to determine the day with the most time.
foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) {
krsort($shift_data[$tmp_shift_key]['total_time_per_day']);
//Sort by day first
arsort($shift_data[$tmp_shift_key]['total_time_per_day']);
//Sort by total time per day.
reset($shift_data[$tmp_shift_key]['total_time_per_day']);
$shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']);
$shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']);
if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) {
$shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']);
}
}
unset($tmp_shift_key, $tmp_shift_data);
if ($filter == 'first_shift') {
//Only return first shift.
$shift_data = $shift_data[0];
} elseif ($filter == 'last_shift') {
//Only return last shift.
$shift_data = $shift_data[$shift];
} elseif ($filter == 'nearest_shift') {
$shift_data = $shift_data[$nearest_shift_id];
//Check to make sure the nearest shift is within the new shift trigger time of EPOCH.
if (isset($shift_data['first_in']['time_stamp'])) {
$first_in = $shift_data['first_in']['time_stamp'];
} elseif (isset($shift_data['last_out']['time_stamp'])) {
$first_in = $shift_data['last_out']['time_stamp'];
}
if (isset($shift_data['last_out']['time_stamp'])) {
$last_out = $shift_data['last_out']['time_stamp'];
} elseif (isset($shift_data['first_in']['time_stamp'])) {
$last_out = $shift_data['first_in']['time_stamp'];
}
if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) {
Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
return FALSE;
}
unset($first_in, $last_out);
}
$profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
//Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10);
return $shift_data;
}
}
$profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
return FALSE;
}
示例4: getShiftData
//.........这里部分代码省略.........
//This is for splitting shifts at exactly midnight.
if ($punch_difference_from_epoch != $nearest_punch_difference or $punch_difference_from_epoch == $nearest_punch_difference and (is_object($tmp_punch_control_obj) and $tmp_punch_control_obj->getId() == $p_obj->getPunchControlID())) {
//Debug::text('Found two punches with the same timestamp... Tmp Punch Control: '.$tmp_punch_control_obj->getId() .' Punch Control: '. $p_obj->getPunchControlID() , __FILE__, __LINE__, __METHOD__, 10);
$nearest_shift_id = $shift;
$nearest_punch_difference = $punch_difference_from_epoch;
}
}
$punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType());
$shift_data[$shift]['punches'][] = $punch_arr;
$shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId();
if ($punch_control_obj->getUserDateID() != FALSE) {
$shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID();
}
if (!isset($shift_data[$shift]['span_midnight'])) {
$shift_data[$shift]['span_midnight'] = FALSE;
}
if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) {
//Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['first_in'] = $punch_arr;
} elseif ($p_obj->getStatus() == 20) {
//Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['last_out'] = $punch_arr;
//Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['total_time'] += $total_time;
//Check to see if the previous punch was on a different day then the current punch.
if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) {
Debug::text('Punch PAIR DOES span midnight', __FILE__, __LINE__, __METHOD__, 10);
$shift_data[$shift]['span_midnight'] = TRUE;
$total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp());
if (is_array($total_time_for_each_day_arr)) {
foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) {
if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) {
$shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0;
}
$shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time;
}
}
unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time);
} else {
$shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time;
}
}
$prev_punch_arr = $punch_arr;
$i++;
}
//Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10);
if (isset($shift_data)) {
//Loop through each shift to determine the day with the most time.
foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) {
krsort($shift_data[$tmp_shift_key]['total_time_per_day']);
//Sort by day first
arsort($shift_data[$tmp_shift_key]['total_time_per_day']);
//Sort by total time per day.
reset($shift_data[$tmp_shift_key]['total_time_per_day']);
$shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']);
$shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']);
if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) {
$shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']);
}
}
unset($tmp_shift_key, $tmp_shift_data);
if ($filter == 'first_shift') {
//Only return first shift.
$shift_data = $shift_data[0];
} elseif ($filter == 'last_shift') {
//Only return last shift.
$shift_data = $shift_data[$shift];
} elseif ($filter == 'nearest_shift') {
$shift_data = $shift_data[$nearest_shift_id];
//Check to make sure the nearest shift is within the new shift trigger time of EPOCH.
if (isset($shift_data['first_in']['time_stamp'])) {
$first_in = $shift_data['first_in']['time_stamp'];
} elseif (isset($shift_data['last_out']['time_stamp'])) {
$first_in = $shift_data['last_out']['time_stamp'];
}
if (isset($shift_data['last_out']['time_stamp'])) {
$last_out = $shift_data['last_out']['time_stamp'];
} elseif (isset($shift_data['first_in']['time_stamp'])) {
$last_out = $shift_data['first_in']['time_stamp'];
}
//The check below must occur so if the user attempts to add an In punch that occurs AFTER the Out punch, this function
//still returns the shift data, so the validation checks can occur in PunchControl factory.
if ($first_in > $last_out) {
//It appears that the first in punch has occurred after the OUT punch, so swap first_in and last_out, so we don't return FALSE in this case.
list($first_in, $last_out) = array($last_out, $first_in);
}
if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) {
Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
return FALSE;
}
unset($first_in, $last_out);
}
$profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
//Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10);
return $shift_data;
}
}
$profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
return FALSE;
}
示例5: getInCompletePunchControlIdByUserIdAndEpoch
function getInCompletePunchControlIdByUserIdAndEpoch($user_id, $epoch, $status_id)
{
Debug::text(' Epoch: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
if ($user_id == '') {
return FALSE;
}
if ($epoch == '') {
return FALSE;
}
$plf = new PunchListFactory();
$plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch);
if ($plf->getRecordCount() > 0) {
//Check for gaps.
$prev_time_stamp = 0;
foreach ($plf as $p_obj) {
if ($p_obj->getStatus() == 10) {
$punch_arr[$p_obj->getPunchControlId()]['in'] = $p_obj->getTimeStamp();
} else {
$punch_arr[$p_obj->getPunchControlId()]['out'] = $p_obj->getTimeStamp();
}
if ($prev_time_stamp != 0) {
$prev_punch_arr[$p_obj->getTimeStamp()] = $prev_time_stamp;
}
$prev_time_stamp = $p_obj->getTimeStamp();
}
unset($prev_time_stamp);
if (isset($prev_punch_arr)) {
$next_punch_arr = array_flip($prev_punch_arr);
}
//Debug::Arr( $punch_arr, ' Punch Array: ', __FILE__, __LINE__, __METHOD__,10);
//Debug::Arr( $next_punch_arr, ' Next Punch Array: ', __FILE__, __LINE__, __METHOD__,10);
if (isset($punch_arr)) {
$i = 0;
foreach ($punch_arr as $punch_control_id => $data) {
$found_gap = FALSE;
Debug::text(' Iteration: ' . $i, __FILE__, __LINE__, __METHOD__, 10);
//Skip complete punch control rows.
if (isset($data['in']) and isset($data['out'])) {
Debug::text(' Punch Control ID is Complete: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10);
} else {
//Make sure we don't assign a In punch that comes AFTER an Out punch to the same pair.
//As well the opposite, an Out punch that comes BEFORE an In punch to the same pair.
if ($status_id == 10 and !isset($data['in']) and (isset($data['out']) and $epoch <= $data['out'])) {
Debug::text(' aFound Valid Gap...', __FILE__, __LINE__, __METHOD__, 10);
$found_gap = TRUE;
} elseif ($status_id == 20 and !isset($data['out']) and (isset($data['in']) and $epoch >= $data['in'])) {
Debug::text(' bFound Valid Gap...', __FILE__, __LINE__, __METHOD__, 10);
$found_gap = TRUE;
} else {
Debug::text(' No Valid Gap Found...', __FILE__, __LINE__, __METHOD__, 10);
}
}
if ($found_gap == TRUE) {
if ($status_id == 10) {
//In Gap
Debug::text(' In Gap...', __FILE__, __LINE__, __METHOD__, 10);
if (isset($prev_punch_arr[$data['out']])) {
Debug::text(' Punch Before In Gap... Range Start: ' . TTDate::getDate('DATE+TIME', $prev_punch_arr[$data['out']]) . ' End: ' . TTDate::getDate('DATE+TIME', $data['out']), __FILE__, __LINE__, __METHOD__, 10);
if ($prev_punch_arr[$data['out']] == $data['out'] or TTDate::isTimeOverLap($epoch, $epoch, $prev_punch_arr[$data['out']], $data['out'])) {
Debug::text(' Epoch OverLaps, THIS IS GOOD!', __FILE__, __LINE__, __METHOD__, 10);
Debug::text(' aReturning Punch Control ID: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10);
$retval = $punch_control_id;
break;
//Without this adding mass punches fails in some basic circumstances because it loops and attaches to a later punch control
} else {
Debug::text(' Epoch does not OverLaps, Cant attached to this punch_control!', __FILE__, __LINE__, __METHOD__, 10);
}
} else {
//No Punch After
Debug::text(' NO Punch Before In Gap...', __FILE__, __LINE__, __METHOD__, 10);
$retval = $punch_control_id;
break;
}
} else {
//Out Gap
Debug::text(' Out Gap...', __FILE__, __LINE__, __METHOD__, 10);
//Start: $data['in']
//End: $data['in']
if (isset($next_punch_arr[$data['in']])) {
Debug::text(' Punch After Out Gap... Range Start: ' . TTDate::getDate('DATE+TIME', $data['in']) . ' End: ' . TTDate::getDate('DATE+TIME', $next_punch_arr[$data['in']]), __FILE__, __LINE__, __METHOD__, 10);
if ($data['in'] == $next_punch_arr[$data['in']] or TTDate::isTimeOverLap($epoch, $epoch, $data['in'], $next_punch_arr[$data['in']])) {
Debug::text(' Epoch OverLaps, THIS IS GOOD!', __FILE__, __LINE__, __METHOD__, 10);
Debug::text(' bReturning Punch Control ID: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10);
$retval = $punch_control_id;
break;
//Without this adding mass punches fails in some basic circumstances because it loops and attaches to a later punch control
} else {
Debug::text(' Epoch does not OverLaps, Cant attached to this punch_control!', __FILE__, __LINE__, __METHOD__, 10);
}
} else {
//No Punch After
Debug::text(' NO Punch After Out Gap...', __FILE__, __LINE__, __METHOD__, 10);
$retval = $punch_control_id;
break;
}
}
}
$i++;
}
}
//.........这里部分代码省略.........
示例6: isActiveTime
function isActiveTime($in_epoch, $out_epoch)
{
Debug::text(' Checking for Active Time with: In: ' . TTDate::getDate('DATE+TIME', $in_epoch) . ' Out: ' . TTDate::getDate('DATE+TIME', $out_epoch), __FILE__, __LINE__, __METHOD__, 10);
Debug::text(' Raw Start TimeStamp(' . $this->getStartTime(TRUE) . '): ' . TTDate::getDate('DATE+TIME', $this->getStartTime()) . ' Raw End TimeStamp: ' . TTDate::getDate('DATE+TIME', $this->getEndTime()), __FILE__, __LINE__, __METHOD__, 10);
$start_time_stamp = TTDate::getTimeLockedDate($this->getStartTime(), $in_epoch);
$end_time_stamp = TTDate::getTimeLockedDate($this->getEndTime(), $in_epoch);
//Check if end timestamp is before start, if it is, move end timestamp to next day.
if ($end_time_stamp < $start_time_stamp) {
Debug::text(' Moving End TimeStamp to next day.', __FILE__, __LINE__, __METHOD__, 10);
$end_time_stamp = $end_time_stamp + 86400;
}
Debug::text(' Start TimeStamp: ' . TTDate::getDate('DATE+TIME', $start_time_stamp) . ' End TimeStamp: ' . TTDate::getDate('DATE+TIME', $end_time_stamp), __FILE__, __LINE__, __METHOD__, 10);
//Check to see if start/end time stamps are not set or are equal, we always return TRUE if they are.
if ($start_time_stamp == '' or $end_time_stamp == '' or $start_time_stamp == $end_time_stamp) {
Debug::text(' Start/End time not set, assume it always matches.', __FILE__, __LINE__, __METHOD__, 10);
return TRUE;
} else {
//If the premium policy start/end time spans midnight, there could be multiple windows to check
//where the premium policy applies, make sure we check all windows.
for ($i = $start_time_stamp - 86400; $i <= $end_time_stamp + 86400; $i += 86400) {
$tmp_start_time_stamp = $i;
$tmp_end_time_stamp = $tmp_start_time_stamp + ($end_time_stamp - $start_time_stamp);
if ($this->isActive($tmp_start_time_stamp, $tmp_end_time_stamp) == TRUE) {
//Debug::text(' Checking against Start TimeStamp: '. TTDate::getDate('DATE+TIME', $tmp_start_time_stamp) .' End TimeStamp: '. TTDate::getDate('DATE+TIME', $tmp_end_time_stamp) , __FILE__, __LINE__, __METHOD__, 10);
if ($this->getIncludePartialPunch() == TRUE and TTDate::isTimeOverLap($in_epoch, $out_epoch, $tmp_start_time_stamp, $tmp_end_time_stamp) == TRUE) {
//When dealing with partial punches, any overlap whatsoever activates the policy.
Debug::text(' Partial Punch Within Active Time!', __FILE__, __LINE__, __METHOD__, 10);
return TRUE;
} elseif ($in_epoch >= $tmp_start_time_stamp and $in_epoch <= $tmp_end_time_stamp) {
//Non partial punches, they must punch in within the time window.
Debug::text(' Within Active Time!', __FILE__, __LINE__, __METHOD__, 10);
return TRUE;
}
} else {
Debug::text(' Not Active on this day: ' . TTDate::getDate('DATE+TIME', $i), __FILE__, __LINE__, __METHOD__, 10);
}
}
}
Debug::text(' NOT Within Active Time!', __FILE__, __LINE__, __METHOD__, 10);
return FALSE;
}
示例7: getShifts
function getShifts($start_date, $end_date, &$holiday_data = array(), &$branch_options = array(), &$department_options = array(), &$shifts = array(), &$shifts_index = array())
{
//Debug::text('Start Date: '. TTDate::getDate('DATE+TIME', $start_date) .' End Date: '. TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
$recurring_schedule_control_start_date = TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date'));
//Debug::text('Recurring Schedule Control Start Date: '. TTDate::getDate('DATE+TIME', $recurring_schedule_control_start_date),__FILE__, __LINE__, __METHOD__, 10);
$current_template_week = $this->getColumn('remapped_week');
$max_week = $this->getColumn('max_week');
//Debug::text('Template Week: '. $current_template_week .' Max Week: '. $this->getColumn('max_week') .' ReMapped Week: '. $this->getColumn('remapped_week') ,__FILE__, __LINE__, __METHOD__, 10);
if ($recurring_schedule_control_start_date == '') {
return FALSE;
}
//Get week of start_date
$start_date_week = TTDate::getWeek($recurring_schedule_control_start_date, 0);
//Start week on Sunday to match Recurring Schedule.
//Debug::text('Week of Start Date: '. $start_date_week ,__FILE__, __LINE__, __METHOD__, 10);
for ($i = $start_date; $i <= $end_date; $i += 86400 + 43200) {
//Handle DST by adding 12hrs to the date to get the mid-day epoch, then forcing it back to the beginning of the day.
$i = TTDate::getBeginDayEpoch($i);
if ($this->getColumn('hire_date') != '' and $i <= $this->getColumn('hire_date') or $this->getColumn('termination_date') != '' and $i > $this->getColumn('termination_date')) {
//Debug::text('Skipping due to Hire/Termination date: User ID: '. $this->getColumn('user_id') .' I: '. $i .' Hire Date: '. $this->getColumn('hire_date') .' Termination Date: '. $this->getColumn('termination_date') ,__FILE__, __LINE__, __METHOD__, 10);
continue;
}
$current_week = TTDate::getWeek($i, 0);
//Start week on Sunday to match Recurring Schedule.
//Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week,__FILE__, __LINE__, __METHOD__, 10);
$template_week = abs($current_week - $start_date_week) % $max_week + 1;
//Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
if ($template_week == $current_template_week) {
//Debug::text('Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week,__FILE__, __LINE__, __METHOD__, 10);
//Debug::text(' Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
if ($this->isActiveShiftDay($i)) {
//Debug::text(' Active Shift on this day...',__FILE__, __LINE__, __METHOD__, 10);
$iso_date_stamp = TTDate::getISODateStamp($i);
$start_time = TTDate::getTimeLockedDate($this->getStartTime(), $i);
$end_time = TTDate::getTimeLockedDate($this->getEndTime(), $i);
if ($end_time < $start_time) {
//Spans the day boundary, add 86400 to end_time
$end_time = $end_time + 86400;
//Debug::text(' Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10);
}
if (isset($shifts_index[$iso_date_stamp][$this->getColumn('user_id')])) {
//User has previous recurring schedule shifts, check for overlap.
//Loop over each employees shift for this day and check for conflicts
foreach ($shifts_index[$iso_date_stamp][$this->getColumn('user_id')] as $shift_key) {
if (isset($shifts[$iso_date_stamp][$shift_key])) {
if (TTDate::isTimeOverLap($shifts[$iso_date_stamp][$shift_key]['start_time'], $shifts[$iso_date_stamp][$shift_key]['end_time'], $start_time, $end_time) == TRUE) {
//Debug::text(' Found overlapping recurring schedules! User ID: '. $this->getColumn('user_id') .' Start Time: '. $start_time,__FILE__, __LINE__, __METHOD__, 10);
continue 2;
}
}
}
unset($shift_key);
}
//This check has to occurr after the committed schedule check, otherwise no committed schedules will appear.
if ($this->getColumn('recurring_schedule_control_start_date') != '' and $i < TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date')) or $this->getColumn('recurring_schedule_control_end_date') != '' and $i > TTDate::strtotime($this->getColumn('recurring_schedule_control_end_date'))) {
//Debug::text('Skipping due to Recurring Schedule Start/End date: ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' I: '. $i .' Start Date: '. $this->getColumn('recurring_schedule_control_start_date') .' ('. TTDate::strtotime( $this->getColumn('recurring_schedule_control_start_date') ) .') End Date: '. $this->getColumn('recurring_schedule_control_end_date') ,__FILE__, __LINE__, __METHOD__, 10);
continue;
}
//Debug::text(' Start Date: '. TTDate::getDate('DATE+TIME', $start_time) .' End Date: '. TTDate::getDate('DATE+TIME', $end_time),__FILE__, __LINE__, __METHOD__, 10);
$status_id = 10;
//Working
$absence_policy_id = FALSE;
$absence_policy = NULL;
if (isset($holiday_data[$iso_date_stamp])) {
//We have to assume they are eligible, because we really won't know
//if they will have worked enough days or not. We could assume they
//work whatever their schedule is, but chances are they will be eligible then anyways.
Debug::text(' Found Holiday on this day...', __FILE__, __LINE__, __METHOD__, 10);
$status_id = $holiday_data[$iso_date_stamp]['status_id'];
if (isset($holiday_data[$iso_date_stamp]['absence_policy_id'])) {
$absence_policy_id = $holiday_data[$iso_date_stamp]['absence_policy_id'];
$absence_policy = $holiday_data[$iso_date_stamp]['absence_policy'];
}
}
//Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Time: '. TTDate::getDate('DATE+TIME', $start_time ),__FILE__, __LINE__, __METHOD__, 10);
$shifts[$iso_date_stamp][$this->getColumn('user_id') . $start_time] = array('user_id' => $this->getColumn('user_id'), 'user_full_name' => Misc::getFullName($this->getColumn('first_name'), NULL, $this->getColumn('last_name'), FALSE, FALSE), 'user_created_by' => $this->getColumn('user_created_by'), 'status_id' => $status_id, 'date_stamp' => TTDate::getAPIDate('DATE', $start_time), 'start_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $start_time) : $start_time, 'end_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $end_time) : $end_time, 'start_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $start_time) : $start_time, 'end_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $end_time) : $end_time, 'total_time' => $this->getTotalTime(), 'schedule_policy_id' => $this->getSchedulePolicyID(), 'absence_policy_id' => $absence_policy_id, 'absence_policy' => $absence_policy, 'branch_id' => $this->getColumn('schedule_branch_id'), 'branch' => Option::getByKey($this->getColumn('schedule_branch_id'), $branch_options, NULL), 'department_id' => $this->getColumn('schedule_department_id'), 'department' => Option::getByKey($this->getColumn('schedule_department_id'), $department_options, NULL), 'job_id' => $this->getJob(), 'job_item_id' => $this->getJobItem());
$shifts_index[$iso_date_stamp][$this->getColumn('user_id')][] = $this->getColumn('user_id') . $start_time;
unset($start_time, $end_time);
} else {
//Debug::text(' NOT active shift on this day... ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' Start Time: '. TTDate::getDate('DATE+TIME', $i),__FILE__, __LINE__, __METHOD__, 10);
}
}
}
if (isset($shifts)) {
//Debug::Arr($shifts, 'Template Shifts: ',__FILE__, __LINE__, __METHOD__, 10);
return $shifts;
}
return FALSE;
}