| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Services\Integrations; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Meta; |
| 6 |
use FluentBooking\Framework\Support\Arr; |
| 7 |
use FluentBooking\App\Services\ConditionAssesor; |
| 8 |
|
| 9 |
class GlobalNotificationService |
| 10 |
{ |
| 11 |
public function checkCondition($parsedValue, $booking) |
| 12 |
{ |
| 13 |
return true; |
| 14 |
|
| 15 |
$conditionSettings = Arr::get($parsedValue, 'conditionals'); |
| 16 |
if ( |
| 17 |
!$conditionSettings || |
| 18 |
!Arr::isTrue($conditionSettings, 'status') || |
| 19 |
!count(Arr::get($conditionSettings, 'conditions')) |
| 20 |
) { |
| 21 |
return true; |
| 22 |
} |
| 23 |
|
| 24 |
return ConditionAssesor::evaluate($parsedValue, $booking); |
| 25 |
} |
| 26 |
|
| 27 |
public function getEntry($id, $form) |
| 28 |
{ |
| 29 |
// $submission = Submission::find($id); |
| 30 |
// $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']); |
| 31 |
// return bookingParser::parseFormEntry($submission, $form, $formInputs); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @param $feeds |
| 36 |
* @param $booking |
| 37 |
* @param $insertId |
| 38 |
* |
| 39 |
* @return array |
| 40 |
*/ |
| 41 |
public function getEnabledFeeds($feeds, $booking) |
| 42 |
{ |
| 43 |
$enabledFeeds = []; |
| 44 |
foreach ($feeds as $feed) { |
| 45 |
$parsedValue = $feed->value; |
| 46 |
if (!$parsedValue || !Arr::isTrue($parsedValue, 'enabled')) { |
| 47 |
continue; |
| 48 |
} |
| 49 |
|
| 50 |
// Now check if conditions matched or not |
| 51 |
$isConditionMatched = $this->checkCondition($parsedValue, $booking); |
| 52 |
if ($isConditionMatched) { |
| 53 |
$item = [ |
| 54 |
'id' => $feed->id, |
| 55 |
'key' => $feed->key, |
| 56 |
'settings' => $parsedValue, |
| 57 |
]; |
| 58 |
$enabledFeeds[] = $item; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
return $enabledFeeds; |
| 63 |
} |
| 64 |
|
| 65 |
public function getNotificationFeeds($slotId, $feedMetaKeys) |
| 66 |
{ |
| 67 |
return Meta::where('object_id', $slotId)->whereIn('key', $feedMetaKeys)->orderBy('id', 'ASC')->get(); |
| 68 |
} |
| 69 |
} |
| 70 |
|