Skip to content

Instantly share code, notes, and snippets.

@cygeorgel
Created September 16, 2021 10:06
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/38b37d7520426a9b98647e7923210646 to your computer and use it in GitHub Desktop.
Save cygeorgel/38b37d7520426a9b98647e7923210646 to your computer and use it in GitHub Desktop.
Check conflicts for time span groups
private function checkConflicts(array $daysOfWeek, array $timeSpan, $callQueueGroupId, $callQueueGroupTimeSpanId = null)
{
$conflicts = 0;
if ($callQueueGroupTimeSpanId) {
foreach ($daysOfWeek as $dayOfWeek) {
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('id', '!=', $callQueueGroupeTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['end'])
->count();
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('id', '!=', $callQueueGroupeTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '>=', $timeSpan['start'])
->where('end', '<=', $timeSpan['end'])
->count();
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('id', '!=', $callQueueGroupeTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['start'])
->count();
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('id', '!=', $callQueueGroupeTimeSpanId)
->where('dayOfWeek', $dayOfWeek)
->where('end', '>=', $timeSpan['end'])
->where('start', '<=', $timeSpan['end'])
->count();
}
} else {
foreach ($daysOfWeek as $dayOfWeek) {
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['end'])
->count();
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '>=', $timeSpan['start'])
->where('end', '<=', $timeSpan['end'])
->count();
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->where('dayOfWeek', $dayOfWeek)
->where('start', '<=', $timeSpan['start'])
->where('end', '>=', $timeSpan['start'])
->count();
$conflicts += CallQueueGroupTimeSpan::where('call_queue_group_id', $callQueueGroupId)
->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