| 1 |
<?php |
| 2 |
namespace FluentForm\App\Modules\Transfer; |
| 3 |
|
| 4 |
use Exception; |
| 5 |
use FluentForm\App\Services\Transfer\TransferService; |
| 6 |
use FluentForm\Framework\Foundation\App; |
| 7 |
|
| 8 |
class Transfer |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Request object |
| 13 |
* |
| 14 |
* @var \FluentForm\Framework\Request\Request $request |
| 15 |
*/ |
| 16 |
protected $request = null; |
| 17 |
|
| 18 |
|
| 19 |
public function __construct() |
| 20 |
{ |
| 21 |
$this->request = App::getInstance()->make('request'); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Export forms as JSON. |
| 27 |
*/ |
| 28 |
public function exportForms() |
| 29 |
{ |
| 30 |
try { |
| 31 |
$formIds = $this->request->get('forms'); |
| 32 |
TransferService::exportForms($formIds); |
| 33 |
} catch (Exception $exception) { |
| 34 |
wp_send_json([ |
| 35 |
'message' => $exception->getMessage() |
| 36 |
], 424); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Import forms from a previously exported JSON file. |
| 42 |
*/ |
| 43 |
public function importForms() |
| 44 |
{ |
| 45 |
try { |
| 46 |
$file = $this->request->file('file'); |
| 47 |
$applyDefaultStyle = $this->request->get('apply_default_style') === '1'; |
| 48 |
wp_send_json(TransferService::importForms($file, $applyDefaultStyle), 200); |
| 49 |
} catch (Exception $exception) { |
| 50 |
wp_send_json([ |
| 51 |
'message' => $exception->getMessage() |
| 52 |
], 424); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
public function exportEntries() { |
| 57 |
try { |
| 58 |
TransferService::exportEntries($this->request->get()); |
| 59 |
} catch (Exception $exception) { |
| 60 |
wp_send_json([ |
| 61 |
'message' => $exception->getMessage() |
| 62 |
], 424); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
} |