Skip to content

Instantly share code, notes, and snippets.

@cygeorgel
Created September 16, 2021 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cygeorgel/7c65052719efe057cd46acbb857f2895 to your computer and use it in GitHub Desktop.
Save cygeorgel/7c65052719efe057cd46acbb857f2895 to your computer and use it in GitHub Desktop.
Check cconflicts for time spans
private function checkConflicts(array $daysOfWeek, array $timeSpan, $callQueueId, $callQueueTimeSpanId = null)
{
$conflicts = 0;
if ($callQueueTimeSpanId) {
foreach ($daysOfWeek as $dayOfWeek) {
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('id', '!=', $callQueueTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['end'])
->count();
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('id', '!=', $callQueueTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '>=', $timeSpan['start'])
->where('end', '<=', $timeSpan['end'])
->count();
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('id', '!=', $callQueueTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['start'])
->count();
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('id', '!=', $callQueueTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('end', '>=', $timeSpan['end'])
->where('start', '<=', $timeSpan['end'])
->count();
}
} else {
foreach ($daysOfWeek as $dayOfWeek) {
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['end'])
->count();
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '>=', $timeSpan['start'])
->where('end', '<=', $timeSpan['end'])
->count();
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['start'])
->count();
$conflicts += CallQueueTimeSpan::where('call_group_id', $callQueueId)
->where('dayOfWeek', $dayOfWeek)
->where('end', '>=', $timeSpan['end'])
->where('start', '<=', $timeSpan['end'])
->count();
}
}
return $conflicts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment