Display nps statis meter

[MAILPOET-2549]
This commit is contained in:
Pavel Dohnal
2020-01-21 12:57:22 +01:00
committed by Jack Kitterhing
parent be0c9a726c
commit a37d8888d9
4 changed files with 62 additions and 3 deletions

View File

@ -5,7 +5,11 @@ namespace MailPoet\AdminPages\Pages;
use MailPoet\AdminPages\PageRenderer;
use MailPoet\Listing\PageLimit;
use MailPoet\Models\Segment;
use MailPoet\Settings\SettingsController;
use MailPoet\Settings\UserFlagsController;
use MailPoet\Util\Installation;
use MailPoet\Util\License\License;
use MailPoet\WP\Functions as WPFunctions;
class Forms {
/** @var PageRenderer */
@ -17,14 +21,29 @@ class Forms {
/** @var Installation */
private $installation;
/** @var UserFlagsController */
private $userFlags;
/** @var WPFunctions */
private $wp;
/** @var SettingsController */
private $settings;
public function __construct(
PageRenderer $pageRenderer,
PageLimit $listingPageLimit,
Installation $installation
Installation $installation,
SettingsController $settings,
UserFlagsController $userFlags,
WPFunctions $wp
) {
$this->pageRenderer = $pageRenderer;
$this->listingPageLimit = $listingPageLimit;
$this->installation = $installation;
$this->userFlags = $userFlags;
$this->wp = $wp;
$this->settings = $settings;
}
public function render() {
@ -33,6 +52,24 @@ class Forms {
$data['segments'] = Segment::findArray();
$data['is_new_user'] = $this->installation->isNewInstallation();
$data = $this->getNPSSurveyData($data);
$this->pageRenderer->displayPage('forms.html', $data);
}
public function getNPSSurveyData($data) {
$data['display_nps_survey'] = false;
if ($this->userFlags->get('display_new_form_editor_nps_survey')) {
$data['current_wp_user'] = $this->wp->wpGetCurrentUser()->to_array();
$data['site_url'] = $this->wp->siteUrl();
$data['premium_plugin_active'] = License::getLicense();
$data['current_wp_user_firstname'] = $this->wp->wpGetCurrentUser()->user_firstname;
$installedAtDateTime = new \DateTime($this->settings->get('installed_at'));
$data['installed_days_ago'] = (int)$installedAtDateTime->diff(new \DateTime())->format('%a');
$data['display_nps_survey'] = true;
$this->userFlags->set('display_new_form_editor_nps_survey', false);
}
return $data;
}
}