← All changes
|
app/Http/Controllers/CalendarIntegrationController.php
+63
-2
2.2.0
→
2.5.0
View file →
| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | use FluentBooking\App\Models\CalendarSlot; |
| 8 | 8 | use FluentBooking\App\Services\Helper; |
| 9 | 9 | use FluentBooking\App\Services\PermissionManager; |
| 10 | 10 | use FluentBooking\App\Services\Integrations\CalendarIntegrationService; |
| 11 | +use FluentBooking\App\Services\Integrations\FluentCRM\CrmContactService; | |
| 12 | +use FluentCrm\App\Services\PermissionManager as CrmPermissionManager; | |
| 11 | 13 | |
| 12 | 14 | class CalendarIntegrationController extends Controller |
| 13 | 15 | { |
| 14 | 16 | public function index(CalendarIntegrationService $integrationService, $calendarId, $eventId) |
| @@ -89,15 +91,23 @@ | ||
| 89 | 91 | $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId); |
| 90 | 92 | |
| 91 | 93 | $fromEventId = intval($this->request->get('from_event_id')); |
| 92 | 94 | |
| 93 | - if (!$fromEventId || !PermissionManager::canUpdateCalendarEvent($fromEventId)) { | |
| 95 | + $fromEvent = CalendarSlot::find($fromEventId); | |
| 96 | + | |
| 97 | + if (!$fromEvent) { | |
| 94 | 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([ | |
| 95 | 105 | 'message' => __('You do not have permission to clone from the selected event.', 'fluent-booking') |
| 96 | 106 | ], 403); |
| 97 | 107 | } |
| 98 | 108 | |
| 99 | - $fromEventIntegrations = Meta::where('object_id', $fromEventId) | |
| 109 | + $fromEventIntegrations = Meta::where('object_id', $fromEvent->id) | |
| 100 | 110 | ->where('object_type', 'integration') |
| 101 | 111 | ->get(); |
| 102 | 112 | |
| 103 | 113 | if ($fromEventIntegrations->isEmpty()) { |
| @@ -147,8 +157,59 @@ | ||
| 147 | 157 | $fieldOptions = apply_filters('fluent_booking/get_integration_config_field_options_' . $integrationName, $settings, $calendarEventId); |
| 148 | 158 | |
| 149 | 159 | return $this->sendSuccess([ |
| 150 | 160 | 'field_options' => $fieldOptions, |
| 161 | + ]); | |
| 162 | + } catch (Exception $e) { | |
| 163 | + return $this->sendError([ | |
| 164 | + 'message' => $e->getMessage(), | |
| 165 | + ], 422); | |
| 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'), | |
| 151 | 212 | ]); |
| 152 | 213 | } catch (Exception $e) { |
| 153 | 214 | return $this->sendError([ |
| 154 | 215 | 'message' => $e->getMessage(), |