| 1 |
<?php |
| 2 |
namespace Depicter\Controllers\Ajax; |
| 3 |
|
| 4 |
use Depicter\Utility\Sanitize; |
| 5 |
use WPEmerge\Requests\RequestInterface; |
| 6 |
|
| 7 |
class ReportIssueAjaxController |
| 8 |
{ |
| 9 |
|
| 10 |
public function sendIssue( RequestInterface $request, $view ) { |
| 11 |
|
| 12 |
$bodyParams = [ |
| 13 |
'issueType' => Sanitize::textfield( $request->body('issueType') ), |
| 14 |
'issueRelatesTo' => Sanitize::textfield( $request->body('issueRelatesTo') ), |
| 15 |
'userDescription' => Sanitize::editor( $request->body('userDescription') ), |
| 16 |
'userEmail' => Sanitize::email( $request->body('userEmail') ) |
| 17 |
]; |
| 18 |
|
| 19 |
try { |
| 20 |
if ( \Depicter::client()->reportIssue( $bodyParams ) ) { |
| 21 |
return \Depicter::json([ |
| 22 |
"hits" => 1, |
| 23 |
'message' => "Feedback has been sent successfully" |
| 24 |
])->withStatus(200 ); |
| 25 |
} else { |
| 26 |
return \Depicter::json([ |
| 27 |
'errors' => "Error while sending feedback, please try again later" |
| 28 |
])->withStatus(400 ); |
| 29 |
} |
| 30 |
} catch ( \Exception $exception ){ |
| 31 |
return \Depicter::json([ |
| 32 |
'errors' => [ $exception->getMessage() ] |
| 33 |
]); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
public function sendError( RequestInterface $request, $view ) { |
| 38 |
$bodyParams = [ |
| 39 |
'crashReport' => Sanitize::textarea( $request->body('crashReport') ), |
| 40 |
'userComment' => Sanitize::editor( $request->body('userComment') ), |
| 41 |
'envInfo' => Sanitize::textarea( $request->body('envInfo') ), |
| 42 |
'userEmail' => Sanitize::email( $request->body('userEmail') ), |
| 43 |
'userDocumentData' => Sanitize::textarea( $request->body('userDocumentData') ) |
| 44 |
]; |
| 45 |
|
| 46 |
try { |
| 47 |
if ( \Depicter::client()->reportError( $bodyParams ) ) { |
| 48 |
return \Depicter::json([ |
| 49 |
"hits" => 1, |
| 50 |
'message' => "Error report has been sent successfully" |
| 51 |
])->withStatus(200 ); |
| 52 |
} else { |
| 53 |
return \Depicter::json([ |
| 54 |
'errors' => "Error while sending report, please try again later" |
| 55 |
])->withStatus(400 ); |
| 56 |
} |
| 57 |
} catch ( \Exception $exception ){ |
| 58 |
return \Depicter::json([ |
| 59 |
'errors' => [ $exception->getMessage() ] |
| 60 |
]); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|