PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.1.2
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.1.2
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Http / Controllers / CalendarIntegrationController.php

CalendarIntegrationController.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.1.2, at app/Http/Controllers/CalendarIntegrationController.php

164 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Http\Controllers;
4
5 use Exception;
6 use FluentBooking\App\Models\Meta;
7 use FluentBooking\App\Models\CalendarSlot;
8 use FluentBooking\App\Services\Helper;
9 use FluentBooking\App\Services\PermissionManager;
10 use FluentBooking\App\Services\Integrations\CalendarIntegrationService;
11
12 class CalendarIntegrationController extends Controller
13 {
14 public function index(CalendarIntegrationService $integrationService, $calendarId, $eventId)
15 {
16 try {
17 $calendarEvent = $this->getCalendarEvent($calendarId, $eventId);
18 $settings = $integrationService->get($eventId);
19
20 $settings['smart_codes'] = [
21 'texts' => Helper::getEditorShortCodes($calendarEvent),
22 'html' => Helper::getEditorShortCodes($calendarEvent, true)
23 ];
24
25 return $this->sendSuccess($settings);
26 } catch (Exception $e) {
27 return $this->sendError([
28 'message' => $e->getMessage(),
29 ], 422);
30 }
31 }
32
33 public function find(CalendarIntegrationService $integrationService, $calendarId, $slotId, $integrationId)
34 {
35 try {
36 $this->getCalendarEvent($calendarId, $slotId);
37 $data = $this->request->all();
38 $data['slot_id'] = $slotId;
39 $integration = $integrationService->find($data);
40 return $this->sendSuccess($integration);
41 } catch (Exception $e) {
42 return $this->sendError([
43 'message' => $e->getMessage(),
44 ], 422);
45 }
46 }
47
48 public function update(CalendarIntegrationService $integrationService, $calendarId, $slotId, $integrationId)
49 {
50
51 $data = $this->request->all();
52 $data['slot_id'] = $slotId;
53 $data['integration_id'] = $integrationId;
54
55 try {
56 $integration = $integrationService->update($data);
57 return $this->sendSuccess($integration);
58 } catch (Exception $e) {
59 return $this->sendError([
60 'message' => $e->getMessage(),
61 'errors' => $e->errors(),
62 ], 422);
63 }
64 }
65
66 public function delete(CalendarIntegrationService $integrationService, $calendarId, $slotId, $integrationId)
67 {
68 try {
69 $deleted = $integrationService->delete($integrationId, $slotId);
70
71 if (!$deleted) {
72 return $this->sendError([
73 'message' => __('Integration not found for this event.', 'fluent-booking'),
74 ], 404);
75 }
76
77 return $this->sendSuccess([
78 'message' => __('Successfully deleted the Integration.', 'fluent-booking'),
79 ]);
80 } catch (Exception $e) {
81 return $this->sendError([
82 'message' => $e->getMessage(),
83 ], 422);
84 }
85 }
86
87 public function cloneIntegrations(CalendarIntegrationService $integrationService, $calendarId, $slotId)
88 {
89 $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId);
90
91 $fromEventId = intval($this->request->get('from_event_id'));
92
93 if (!$fromEventId || !PermissionManager::canUpdateCalendarEvent($fromEventId)) {
94 return $this->sendError([
95 'message' => __('You do not have permission to clone from the selected event.', 'fluent-booking')
96 ], 403);
97 }
98
99 $fromEventIntegrations = Meta::where('object_id', $fromEventId)
100 ->where('object_type', 'integration')
101 ->get();
102
103 if ($fromEventIntegrations->isEmpty()) {
104 return $this->sendError([
105 'message' => __('Integrations not found', 'fluent-booking')
106 ], 422);
107 }
108
109 foreach ($fromEventIntegrations as $feed) {
110 $cloneIntegration = $feed->replicate();
111 $cloneIntegration->object_id = $calendarEvent->id;
112 $cloneIntegration->save();
113 }
114
115 return [
116 'message' => __('Integrations have been successfully cloned.', 'fluent-booking')
117 ];
118 }
119
120 public function integrationListComponent($calendarId, $slotId, $integrationId)
121 {
122 try {
123 $this->getCalendarEvent($calendarId, $slotId);
124 $integrationName = $this->request->get('integration_name');
125 $listId = $this->request->get('list_id');
126 $merge_fields = false;
127
128 $merge_fields = apply_filters('fluent_booking/get_integration_merge_fields_' . $integrationName, $merge_fields, $listId, $slotId);
129
130 return $this->sendSuccess([
131 'merge_fields' => $merge_fields,
132 ]);
133 } catch (Exception $e) {
134 return $this->sendError([
135 'message' => $e->getMessage(),
136 ], 422);
137 }
138 }
139
140 public function getConfigFieldOptions($calendarId, $calendarEventId, $integrationId)
141 {
142 try {
143 $this->getCalendarEvent($calendarId, $calendarEventId);
144 $integrationName = $this->request->get('integration_name');
145 $settings = $this->request->get('settings');
146
147 $fieldOptions = apply_filters('fluent_booking/get_integration_config_field_options_' . $integrationName, $settings, $calendarEventId);
148
149 return $this->sendSuccess([
150 'field_options' => $fieldOptions,
151 ]);
152 } catch (Exception $e) {
153 return $this->sendError([
154 'message' => $e->getMessage(),
155 ], 422);
156 }
157 }
158
159 private function getCalendarEvent($calendarId, $eventId)
160 {
161 return CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId);
162 }
163 }
164