| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of SurveyModalController |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
* |
| 8 |
* @autoload: a2wl_admin_init |
| 9 |
* @ajax: true |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace AliNext_Lite;; |
| 13 |
|
| 14 |
use Pages; |
| 15 |
|
| 16 |
class SurveyModalController extends AbstractController |
| 17 |
{ |
| 18 |
protected ExitSurveyService $ExitSurveyService; |
| 19 |
protected AssetService $AssetService; |
| 20 |
|
| 21 |
public function __construct(ExitSurveyService $ExitSurveyService, AssetService $AssetService) |
| 22 |
{ |
| 23 |
parent::__construct(A2WL()->plugin_path() . '/view/'); |
| 24 |
|
| 25 |
$this->ExitSurveyService = $ExitSurveyService; |
| 26 |
$this->AssetService = $AssetService; |
| 27 |
|
| 28 |
add_action('admin_enqueue_scripts', [$this, 'assets']); |
| 29 |
add_action('wp_ajax_a2wl_exit_survey_submit', [$this, 'ajaxExitSurveySubmit']); |
| 30 |
} |
| 31 |
|
| 32 |
public function assets(): void |
| 33 |
{ |
| 34 |
if (user_can(get_current_user_id(), 'manage_options') === false) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
$currentScreen = get_current_screen(); |
| 39 |
if (isset($currentScreen->id) && 'plugins' === $currentScreen->id) { |
| 40 |
wp_enqueue_style( |
| 41 |
'a2wl-exit-survey', |
| 42 |
A2WL()->plugin_url() . '/assets/css/exit-survey.css', |
| 43 |
[], |
| 44 |
A2WL()->version |
| 45 |
); |
| 46 |
|
| 47 |
wp_register_script( |
| 48 |
'a2wl-exit-survey', |
| 49 |
A2WL()->plugin_url() . '/assets/js/exit-survey.js', |
| 50 |
['jquery'], |
| 51 |
A2WL()->version, |
| 52 |
true |
| 53 |
); |
| 54 |
|
| 55 |
wp_localize_script( |
| 56 |
'a2wl-exit-survey', |
| 57 |
'a2wl_data', |
| 58 |
[ |
| 59 |
'nonce' => wp_create_nonce(self::AJAX_NONCE_ACTION), |
| 60 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 61 |
'logo' => $this->AssetService->getLogoUrl('logo-155.png'), |
| 62 |
'deactivateLinkId' => $this->ExitSurveyService->getDeactivateLinkId(), |
| 63 |
'lang' => [ |
| 64 |
'title' => _x('We\'re sorry to see you go!', 'survey modal', 'ali2woo'), |
| 65 |
'subtitle' => _x( |
| 66 |
'Before you deactivate AliNext (Lite version), please take a moment to share your reason. ' . |
| 67 |
'Your feedback helps us improve and make AliNext (Lite version) better for everyone.', |
| 68 |
'survey modal', |
| 69 |
'ali2woo' |
| 70 |
), |
| 71 |
'reason_complex' => _x( |
| 72 |
'Hard to set up / use', |
| 73 |
'survey modal', |
| 74 |
'ali2woo' |
| 75 |
), |
| 76 |
'reason_conflict' => _x( |
| 77 |
'Conflict with other plugins', |
| 78 |
'survey modal', |
| 79 |
'ali2woo' |
| 80 |
), |
| 81 |
'reason_upgrade' => _x( |
| 82 |
'Upgraded to paid version', |
| 83 |
'survey modal', |
| 84 |
'ali2woo' |
| 85 |
), |
| 86 |
'reason_other' => _x('Other (please provide details)', 'survey modal', 'ali2woo'), |
| 87 |
'other_placeholder' => _x( |
| 88 |
'Please provide details...', |
| 89 |
'survey modal', |
| 90 |
'ali2woo' |
| 91 |
), |
| 92 |
'other_empty_error' => _x('Please specify a reason', 'survey modal', 'ali2woo'), |
| 93 |
'contact_title' => _x('May we contact you?', 'survey modal', 'ali2woo'), |
| 94 |
'contact_text' => _x( |
| 95 |
'We’re improving AliNext (Lite version) and sometimes ask users for extra feedback. ' . |
| 96 |
'Would you be open to us reaching out? If so, please leave your email below.', |
| 97 |
'survey modal', |
| 98 |
'ali2woo' |
| 99 |
), |
| 100 |
'email_placeholder' => _x('Email address...', 'survey modal', 'ali2woo'), |
| 101 |
'submit_btn' => _x('Submit & Deactivate', 'survey modal', 'ali2woo'), |
| 102 |
'skip_btn' => _x('Skip & Deactivate', 'survey modal', 'ali2woo'), |
| 103 |
] |
| 104 |
] |
| 105 |
); |
| 106 |
|
| 107 |
wp_enqueue_script('a2wl-exit-survey'); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
public function ajaxExitSurveySubmit(): void |
| 112 |
{ |
| 113 |
check_admin_referer(self::AJAX_NONCE_ACTION, self::NONCE); |
| 114 |
|
| 115 |
if (!PageGuardHelper::canAccessPage(Pages::ORDER_MANAGEMENT)) { |
| 116 |
$result = ResultBuilder::buildError($this->getErrorTextNoPermissions()); |
| 117 |
echo wp_json_encode($result); |
| 118 |
wp_die(); |
| 119 |
} |
| 120 |
|
| 121 |
$reason = sanitize_text_field($_POST['reason'] ?? ''); |
| 122 |
$other = sanitize_text_field($_POST['other'] ?? ''); |
| 123 |
$contact_email = sanitize_email($_POST['contact_email'] ?? ''); |
| 124 |
|
| 125 |
$dto = ExitSurveyDTO::build($reason, $other, $contact_email); |
| 126 |
$this->ExitSurveyService->send($dto); |
| 127 |
|
| 128 |
echo wp_json_encode(ResultBuilder::buildOk()); |
| 129 |
wp_die(); |
| 130 |
} |
| 131 |
} |
| 132 |
|