| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentForm\App\Services\Integrations\FormIntegrationService; |
| 6 |
|
| 7 |
class FormIntegrationController extends Controller |
| 8 |
{ |
| 9 |
public function index(FormIntegrationService $integrationService, $formId) |
| 10 |
{ |
| 11 |
try { |
| 12 |
$formId = (int) $formId; |
| 13 |
return $this->sendSuccess( |
| 14 |
$integrationService->get($formId) |
| 15 |
); |
| 16 |
} catch (\Exception $e) { |
| 17 |
return $this->sendError([ |
| 18 |
'message' => $e->getMessage(), |
| 19 |
], 422); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public function find(FormIntegrationService $integrationService, $formId) |
| 24 |
{ |
| 25 |
try { |
| 26 |
$attributes = $this->request->all(); |
| 27 |
$attributes['form_id'] = (int) $formId; |
| 28 |
|
| 29 |
$integration = $integrationService->find($attributes); |
| 30 |
return $this->sendSuccess($integration); |
| 31 |
} catch (\Exception $e) { |
| 32 |
return $this->sendError([ |
| 33 |
'message' => $e->getMessage(), |
| 34 |
], 422); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
public function update(FormIntegrationService $integrationService, $formId) |
| 39 |
{ |
| 40 |
try { |
| 41 |
$attributes = $this->request->all(); |
| 42 |
$attributes['form_id'] = (int) $formId; |
| 43 |
|
| 44 |
$integration = $integrationService->update($attributes); |
| 45 |
return $this->sendSuccess($integration); |
| 46 |
} catch (\Exception $e) { |
| 47 |
return $this->sendError([ |
| 48 |
'message' => $e->getMessage() |
| 49 |
], 422); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
public function delete(FormIntegrationService $integrationService, $formId) |
| 54 |
{ |
| 55 |
try { |
| 56 |
$formId = (int) $formId; |
| 57 |
$id = intval($this->request->get('integration_id')); |
| 58 |
$integrationService->delete($id, $formId); |
| 59 |
return $this->sendSuccess([ |
| 60 |
'message' => __('Successfully deleted the Integration.', 'fluentform'), |
| 61 |
], 200); |
| 62 |
} catch (\Exception $e) { |
| 63 |
return $this->sendError([ |
| 64 |
'message' => $e->getMessage(), |
| 65 |
], 422); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public function integrationListComponent($formId) |
| 70 |
{ |
| 71 |
try { |
| 72 |
$attributes = $this->request->all(); |
| 73 |
$attributes['form_id'] = (int) $formId; |
| 74 |
|
| 75 |
$sanitizeMap = [ |
| 76 |
'integration_name' => 'sanitize_text_field', |
| 77 |
'list_id' => 'sanitize_text_field', |
| 78 |
]; |
| 79 |
$attributes = fluentform_backend_sanitizer($attributes, $sanitizeMap); |
| 80 |
|
| 81 |
$integrationName = $attributes['integration_name']; |
| 82 |
$formId = (int)$attributes['form_id']; |
| 83 |
$listId = $attributes['list_id']; |
| 84 |
$merge_fields = false; |
| 85 |
$merge_fields = apply_filters_deprecated( |
| 86 |
'fluentform_get_integration_merge_fields_' . $integrationName, |
| 87 |
[ |
| 88 |
$merge_fields, |
| 89 |
$listId, |
| 90 |
$formId |
| 91 |
], |
| 92 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 93 |
'fluentform/get_integration_merge_fields_' . $integrationName, |
| 94 |
'Use fluentform/get_integration_merge_fields_' . $integrationName . ' instead of fluentform_get_integration_merge_fields_' . $integrationName |
| 95 |
); |
| 96 |
|
| 97 |
$merge_fields = apply_filters('fluentform/get_integration_merge_fields_' . $integrationName, $merge_fields, $listId, $formId); |
| 98 |
|
| 99 |
return $this->sendSuccess([ |
| 100 |
'merge_fields' => $merge_fields, |
| 101 |
]); |
| 102 |
} catch (\Exception $e) { |
| 103 |
return $this->sendError([ |
| 104 |
'message' => $e->getMessage(), |
| 105 |
], 422); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
} |
| 110 |
|