PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 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 All 34 releases
← All changes | app/Http/Controllers/CalendarIntegrationController.php +88 -7 1.6.0 → 2.5.0 View file →
@@ -5,9 +5,12 @@
5 5 use Exception;
6 6 use FluentBooking\App\Models\Meta;
7 7 use FluentBooking\App\Models\CalendarSlot;
8 8 use FluentBooking\App\Services\Helper;
9 +use FluentBooking\App\Services\PermissionManager;
9 10 use FluentBooking\App\Services\Integrations\CalendarIntegrationService;
11 +use FluentBooking\App\Services\Integrations\FluentCRM\CrmContactService;
12 +use FluentCrm\App\Services\PermissionManager as CrmPermissionManager;
10 13
11 14 class CalendarIntegrationController extends Controller
12 15 {
13 16 public function index(CalendarIntegrationService $integrationService, $calendarId, $eventId)
@@ -12,9 +15,9 @@
12 15 {
13 16 public function index(CalendarIntegrationService $integrationService, $calendarId, $eventId)
14 17 {
15 18 try {
16 - $calendarEvent = CalendarSlot::findOrFail($eventId);
19 + $calendarEvent = $this->getCalendarEvent($calendarId, $eventId);
17 20 $settings = $integrationService->get($eventId);
18 21
19 22 $settings['smart_codes'] = [
20 23 'texts' => Helper::getEditorShortCodes($calendarEvent),
@@ -31,8 +34,9 @@
31 34
32 35 public function find(CalendarIntegrationService $integrationService, $calendarId, $slotId, $integrationId)
33 36 {
34 37 try {
38 + $this->getCalendarEvent($calendarId, $slotId);
35 39 $data = $this->request->all();
36 40 $data['slot_id'] = $slotId;
37 41 $integration = $integrationService->find($data);
38 42 return $this->sendSuccess($integration);
@@ -63,11 +67,16 @@
63 67
64 68 public function delete(CalendarIntegrationService $integrationService, $calendarId, $slotId, $integrationId)
65 69 {
66 70 try {
67 - $id = $this->request->get('integration_id');
68 - $integrationService->delete($id);
71 + $deleted = $integrationService->delete($integrationId, $slotId);
69 72
73 + if (!$deleted) {
74 + return $this->sendError([
75 + 'message' => __('Integration not found for this event.', 'fluent-booking'),
76 + ], 404);
77 + }
78 +
70 79 return $this->sendSuccess([
71 80 'message' => __('Successfully deleted the Integration.', 'fluent-booking'),
72 81 ]);
73 82 } catch (Exception $e) {
@@ -81,16 +90,30 @@
81 90 {
82 91 $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId);
83 92
84 93 $fromEventId = intval($this->request->get('from_event_id'));
85 -
86 - $fromEventIntegrations = Meta::where('object_id', $fromEventId)
94 +
95 + $fromEvent = CalendarSlot::find($fromEventId);
96 +
97 + if (!$fromEvent) {
98 + return $this->sendError([
99 + 'message' => __('Source event not found', 'fluent-booking')
100 + ], 422);
101 + }
102 +
103 + if (!PermissionManager::canUpdateCalendarEvent($fromEvent->id)) {
104 + return $this->sendError([
105 + 'message' => __('You do not have permission to clone from the selected event.', 'fluent-booking')
106 + ], 403);
107 + }
108 +
109 + $fromEventIntegrations = Meta::where('object_id', $fromEvent->id)
87 110 ->where('object_type', 'integration')
88 111 ->get();
89 112
90 113 if ($fromEventIntegrations->isEmpty()) {
91 114 return $this->sendError([
92 - 'message' => __('Integrations not found', 'fluent-booking-pro')
115 + 'message' => __('Integrations not found', 'fluent-booking')
93 116 ], 422);
94 117 }
95 118
96 119 foreach ($fromEventIntegrations as $feed) {
@@ -99,9 +122,9 @@
99 122 $cloneIntegration->save();
100 123 }
101 124
102 125 return [
103 - 'message' => __('Integrations has been successfully cloned.', 'fluent-booking-pro')
126 + 'message' => __('Integrations have been successfully cloned.', 'fluent-booking')
104 127 ];
105 128 }
106 129
107 130 public function integrationListComponent($calendarId, $slotId, $integrationId)
@@ -106,8 +129,9 @@
106 129
107 130 public function integrationListComponent($calendarId, $slotId, $integrationId)
108 131 {
109 132 try {
133 + $this->getCalendarEvent($calendarId, $slotId);
110 134 $integrationName = $this->request->get('integration_name');
111 135 $listId = $this->request->get('list_id');
112 136 $merge_fields = false;
113 137
@@ -125,8 +149,9 @@
125 149
126 150 public function getConfigFieldOptions($calendarId, $calendarEventId, $integrationId)
127 151 {
128 152 try {
153 + $this->getCalendarEvent($calendarId, $calendarEventId);
129 154 $integrationName = $this->request->get('integration_name');
130 155 $settings = $this->request->get('settings');
131 156
132 157 $fieldOptions = apply_filters('fluent_booking/get_integration_config_field_options_' . $integrationName, $settings, $calendarEventId);
@@ -138,6 +163,62 @@
138 163 return $this->sendError([
139 164 'message' => $e->getMessage(),
140 165 ], 422);
141 166 }
167 + }
168 +
169 + public function createCrmTaxonomy($calendarId, $slotId, $integrationId)
170 + {
171 + try {
172 + $this->getCalendarEvent($calendarId, $slotId);
173 +
174 + if (!CrmContactService::isActive()) {
175 + return $this->sendError([
176 + 'message' => __('FluentCRM is not active.', 'fluent-booking'),
177 + ], 422);
178 + }
179 +
180 + if (!CrmPermissionManager::currentUserCan('fcrm_manage_contact_cats')) {
181 + return $this->sendError([
182 + 'message' => __('You do not have permission to create FluentCRM tags or lists.', 'fluent-booking'),
183 + ], 403);
184 + }
185 +
186 + $type = $this->request->get('type');
187 + $title = trim((string) $this->request->get('title'));
188 +
189 + if (!in_array($type, ['tags', 'lists'], true)) {
190 + return $this->sendError([
191 + 'message' => __('Invalid taxonomy type.', 'fluent-booking'),
192 + ], 422);
193 + }
194 +
195 + if ($title === '') {
196 + return $this->sendError([
197 + 'message' => __('Please provide a name.', 'fluent-booking'),
198 + ], 422);
199 + }
200 +
201 + $item = CrmContactService::createTaxonomy($type, $title);
202 +
203 + if (!$item) {
204 + return $this->sendError([
205 + 'message' => __('Please use a name that contains letters or numbers.', 'fluent-booking'),
206 + ], 422);
207 + }
208 +
209 + return $this->sendSuccess([
210 + 'item' => $item,
211 + 'message' => __('Successfully created.', 'fluent-booking'),
212 + ]);
213 + } catch (Exception $e) {
214 + return $this->sendError([
215 + 'message' => $e->getMessage(),
216 + ], 422);
217 + }
218 + }
219 +
220 + private function getCalendarEvent($calendarId, $eventId)
221 + {
222 + return CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId);
142 223 }
143 224 }