1 | <?php |
||
2 | |||
3 | namespace IproSync\Jobs\Settings; |
||
4 | |||
5 | use Illuminate\Bus\Queueable; |
||
6 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
7 | use Illuminate\Foundation\Bus\Dispatchable; |
||
8 | use Illuminate\Queue\InteractsWithQueue; |
||
9 | use Illuminate\Queue\SerializesModels; |
||
10 | use Illuminate\Support\Arr; |
||
11 | use IproSync\Models\BookingRule; |
||
12 | use LaravelIproSoftwareApi\IproSoftwareFacade; |
||
13 | |||
14 | class BookingRulesPull implements ShouldQueue |
||
15 | { |
||
16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
17 | |||
18 | public function handle() |
||
19 | { |
||
20 | $response = IproSoftwareFacade::getBookingRulesList()->onlySuccessful(); |
||
21 | |||
22 | $groups = $response->json(); |
||
23 | if (is_array($groups) && !empty($groups)) { |
||
24 | foreach ($groups as $groupType => $items) { |
||
25 | foreach ($items as $item) { |
||
26 | if (!isset($item['Id'])) { |
||
27 | continue; |
||
28 | } |
||
29 | BookingRule::firstOrNew(['id' => $item['Id']], ) |
||
30 | ->fill([ |
||
31 | 'name' => $item['Name'], |
||
32 | 'type' => $groupType, |
||
33 | 'rules' => Arr::except($item, ['Id', 'Name']), |
||
34 | ]) |
||
35 | ->fillPulled() |
||
36 | ->save(); |
||
37 | } |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 |