| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Http\Controllers; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use FluentForm\App\Services\Logger\Logger; |
| 7 |
|
| 8 |
class SubmissionLogController extends Controller |
| 9 |
{ |
| 10 |
public function get(Logger $logger, $submissionId) |
| 11 |
{ |
| 12 |
try { |
| 13 |
$attributes = $this->request->all(); |
| 14 |
|
| 15 |
$sanitizeMap = [ |
| 16 |
'page' => 'intval', |
| 17 |
'per_page' => 'intval', |
| 18 |
]; |
| 19 |
$attributes = fluentform_backend_sanitizer($attributes, $sanitizeMap); |
| 20 |
|
| 21 |
return $this->sendSuccess( |
| 22 |
$logger->getSubmissionLogs($submissionId, $attributes) |
| 23 |
); |
| 24 |
} catch (Exception $e) { |
| 25 |
return $this->sendError([ |
| 26 |
'message' => $e->getMessage(), |
| 27 |
]); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function remove(Logger $logger, $submissionId) |
| 32 |
{ |
| 33 |
try { |
| 34 |
$attributes = $this->request->all(); |
| 35 |
|
| 36 |
$sanitizeMap = [ |
| 37 |
'log_ids' => function ($value) { |
| 38 |
if (is_array($value)) { |
| 39 |
return array_map('intval', $value); |
| 40 |
} |
| 41 |
|
| 42 |
return []; |
| 43 |
}, |
| 44 |
'type' => 'sanitize_text_field', |
| 45 |
]; |
| 46 |
$attributes = fluentform_backend_sanitizer($attributes, $sanitizeMap); |
| 47 |
$attributes['entry_id'] = intval($submissionId); |
| 48 |
|
| 49 |
return $this->sendSuccess( |
| 50 |
$logger->remove($attributes) |
| 51 |
); |
| 52 |
} catch (Exception $e) { |
| 53 |
return $this->sendError([ |
| 54 |
'message' => $e->getMessage(), |
| 55 |
]); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|