35 خطوط
1.2 KiB
PHP
35 خطوط
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\Setting;
|
|
use Carbon\Carbon;
|
|
|
|
class WorkingHours
|
|
{
|
|
public static function followUpAllowed(string $dateTime): bool
|
|
{
|
|
if (Setting::where('key', 'prevent_follow_up_outside_working_hours')->value('value') !== 'true') {
|
|
return true;
|
|
}
|
|
|
|
$at = Carbon::parse($dateTime);
|
|
$dayMap = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
$workingDays = array_filter(array_map('trim', explode(',', Setting::where('key', 'working_days')->value('value') ?: 'sat,sun,mon,tue,wed')));
|
|
if (!in_array($dayMap[$at->dayOfWeek], $workingDays, true)) {
|
|
return false;
|
|
}
|
|
|
|
$holidays = array_filter(array_map('trim', explode(',', Setting::where('key', 'custom_holidays')->value('value') ?: '')));
|
|
if (in_array($at->toDateString(), $holidays, true)) {
|
|
return false;
|
|
}
|
|
|
|
$start = Setting::where('key', 'working_hours_start')->value('value') ?: '09:00';
|
|
$end = Setting::where('key', 'working_hours_end')->value('value') ?: '18:00';
|
|
$time = $at->format('H:i');
|
|
|
|
return $time >= $start && $time <= $end;
|
|
}
|
|
}
|