← All changes
|
app/Http/Controllers/CalendarIntegrationController.php
+79
-6
1.5.01
→
trunk
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,9 +90,15 @@ | ||
| 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 | - | |
| 94 | + | |
| 95 | + if (!$fromEventId || !PermissionManager::canUpdateCalendarEvent($fromEventId)) { | |
| 96 | + return $this->sendError([ | |
| 97 | + 'message' => __('You do not have permission to clone from the selected event.', 'fluent-booking') | |
| 98 | + ], 403); | |
| 99 | + } | |
| 100 | + | |
| 86 | 101 | $fromEventIntegrations = Meta::where('object_id', $fromEventId) |
| 87 | 102 | ->where('object_type', 'integration') |
| 88 | 103 | ->get(); |
| 89 | 104 | |
| @@ -88,9 +103,9 @@ | ||
| 88 | 103 | ->get(); |
| 89 | 104 | |
| 90 | 105 | if ($fromEventIntegrations->isEmpty()) { |
| 91 | 106 | return $this->sendError([ |
| 92 | - 'message' => __('Integrations not found', 'fluent-booking-pro') | |
| 107 | + 'message' => __('Integrations not found', 'fluent-booking') | |
| 93 | 108 | ], 422); |
| 94 | 109 | } |
| 95 | 110 | |
| 96 | 111 | foreach ($fromEventIntegrations as $feed) { |
| @@ -99,9 +114,9 @@ | ||
| 99 | 114 | $cloneIntegration->save(); |
| 100 | 115 | } |
| 101 | 116 | |
| 102 | 117 | return [ |
| 103 | - 'message' => __('Integrations has been successfully cloned.', 'fluent-booking-pro') | |
| 118 | + 'message' => __('Integrations have been successfully cloned.', 'fluent-booking') | |
| 104 | 119 | ]; |
| 105 | 120 | } |
| 106 | 121 | |
| 107 | 122 | public function integrationListComponent($calendarId, $slotId, $integrationId) |
| @@ -106,8 +121,9 @@ | ||
| 106 | 121 | |
| 107 | 122 | public function integrationListComponent($calendarId, $slotId, $integrationId) |
| 108 | 123 | { |
| 109 | 124 | try { |
| 125 | + $this->getCalendarEvent($calendarId, $slotId); | |
| 110 | 126 | $integrationName = $this->request->get('integration_name'); |
| 111 | 127 | $listId = $this->request->get('list_id'); |
| 112 | 128 | $merge_fields = false; |
| 113 | 129 | |
| @@ -125,8 +141,9 @@ | ||
| 125 | 141 | |
| 126 | 142 | public function getConfigFieldOptions($calendarId, $calendarEventId, $integrationId) |
| 127 | 143 | { |
| 128 | 144 | try { |
| 145 | + $this->getCalendarEvent($calendarId, $calendarEventId); | |
| 129 | 146 | $integrationName = $this->request->get('integration_name'); |
| 130 | 147 | $settings = $this->request->get('settings'); |
| 131 | 148 | |
| 132 | 149 | $fieldOptions = apply_filters('fluent_booking/get_integration_config_field_options_' . $integrationName, $settings, $calendarEventId); |
| @@ -138,6 +155,62 @@ | ||
| 138 | 155 | return $this->sendError([ |
| 139 | 156 | 'message' => $e->getMessage(), |
| 140 | 157 | ], 422); |
| 141 | 158 | } |
| 159 | + } | |
| 160 | + | |
| 161 | + public function createCrmTaxonomy($calendarId, $slotId, $integrationId) | |
| 162 | + { | |
| 163 | + try { | |
| 164 | + $this->getCalendarEvent($calendarId, $slotId); | |
| 165 | + | |
| 166 | + if (!CrmContactService::isActive()) { | |
| 167 | + return $this->sendError([ | |
| 168 | + 'message' => __('FluentCRM is not active.', 'fluent-booking'), | |
| 169 | + ], 422); | |
| 170 | + } | |
| 171 | + | |
| 172 | + if (!CrmPermissionManager::currentUserCan('fcrm_manage_contact_cats')) { | |
| 173 | + return $this->sendError([ | |
| 174 | + 'message' => __('You do not have permission to create FluentCRM tags or lists.', 'fluent-booking'), | |
| 175 | + ], 403); | |
| 176 | + } | |
| 177 | + | |
| 178 | + $type = $this->request->get('type'); | |
| 179 | + $title = trim((string) $this->request->get('title')); | |
| 180 | + | |
| 181 | + if (!in_array($type, ['tags', 'lists'], true)) { | |
| 182 | + return $this->sendError([ | |
| 183 | + 'message' => __('Invalid taxonomy type.', 'fluent-booking'), | |
| 184 | + ], 422); | |
| 185 | + } | |
| 186 | + | |
| 187 | + if ($title === '') { | |
| 188 | + return $this->sendError([ | |
| 189 | + 'message' => __('Please provide a name.', 'fluent-booking'), | |
| 190 | + ], 422); | |
| 191 | + } | |
| 192 | + | |
| 193 | + $item = CrmContactService::createTaxonomy($type, $title); | |
| 194 | + | |
| 195 | + if (!$item) { | |
| 196 | + return $this->sendError([ | |
| 197 | + 'message' => __('Please use a name that contains letters or numbers.', 'fluent-booking'), | |
| 198 | + ], 422); | |
| 199 | + } | |
| 200 | + | |
| 201 | + return $this->sendSuccess([ | |
| 202 | + 'item' => $item, | |
| 203 | + 'message' => __('Successfully created.', 'fluent-booking'), | |
| 204 | + ]); | |
| 205 | + } catch (Exception $e) { | |
| 206 | + return $this->sendError([ | |
| 207 | + 'message' => $e->getMessage(), | |
| 208 | + ], 422); | |
| 209 | + } | |
| 210 | + } | |
| 211 | + | |
| 212 | + private function getCalendarEvent($calendarId, $eventId) | |
| 213 | + { | |
| 214 | + return CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); | |
| 142 | 215 | } |
| 143 | 216 | } |