Server IP : 172.67.158.161 / Your IP : 18.216.245.99 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/thread-self/root/proc/thread-self/root/home/giankuin/thietke365.net/wp-content/plugins/mailpoet/lib/API/JSON/v1/ |
Upload File : |
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\API\JSON\v1; if (!defined('ABSPATH')) exit; use MailPoet\API\JSON\Endpoint as APIEndpoint; use MailPoet\API\JSON\Error as APIError; use MailPoet\Config\AccessControl; use MailPoet\Entities\SubscriberEntity; use MailPoet\Newsletter\Statistics\WooCommerceRevenue; use MailPoet\Subscribers\Statistics\SubscriberStatisticsRepository; use MailPoet\Subscribers\SubscribersRepository; class SubscriberStats extends APIEndpoint { public $permissions = [ 'global' => AccessControl::PERMISSION_MANAGE_SUBSCRIBERS, ]; /** @var SubscribersRepository */ private $subscribersRepository; /** @var SubscriberStatisticsRepository */ private $subscribersStatisticsRepository; public function __construct( SubscribersRepository $subscribersRepository, SubscriberStatisticsRepository $subscribersStatisticsRepository ) { $this->subscribersRepository = $subscribersRepository; $this->subscribersStatisticsRepository = $subscribersStatisticsRepository; } public function get($data) { $subscriber = isset($data['subscriber_id']) ? $this->subscribersRepository->findOneById((int)$data['subscriber_id']) : null; if (!$subscriber instanceof SubscriberEntity) { return $this->errorResponse([ APIError::NOT_FOUND => __('This subscriber does not exist.', 'mailpoet'), ]); } $statistics = $this->subscribersStatisticsRepository->getStatistics($subscriber); $response = [ 'email' => $subscriber->getEmail(), 'total_sent' => $statistics->getTotalSentCount(), 'open' => $statistics->getOpenCount(), 'machine_open' => $statistics->getMachineOpenCount(), 'click' => $statistics->getClickCount(), 'engagement_score' => $subscriber->getEngagementScore(), ]; $dateFormat = 'Y-m-d H:i:s'; $lastEngagement = $subscriber->getLastEngagementAt(); if ($lastEngagement instanceof \DateTimeInterface) { $response['last_engagement'] = $lastEngagement->format($dateFormat); } $lastClick = $subscriber->getLastClickAt(); if ($lastClick instanceof \DateTimeInterface) { $response['last_click'] = $lastClick->format($dateFormat); } $lastOpen = $subscriber->getLastOpenAt(); if ($lastOpen instanceof \DateTimeInterface) { $response['last_open'] = $lastOpen->format($dateFormat); } $lastPageView = $subscriber->getLastPageViewAt(); if ($lastPageView instanceof \DateTimeInterface) { $response['last_page_view'] = $lastPageView->format($dateFormat); } $lastPurchase = $subscriber->getLastPurchaseAt(); if ($lastPurchase instanceof \DateTimeInterface) { $response['last_purchase'] = $lastPurchase->format($dateFormat); } $lastSending = $subscriber->getLastSendingAt(); if ($lastSending instanceof \DateTimeInterface) { $response['last_sending'] = $lastSending->format($dateFormat); } $woocommerce = $statistics->getWooCommerceRevenue(); if ($woocommerce instanceof WooCommerceRevenue) { $response['woocommerce'] = $woocommerce->asArray(); } return $this->successResponse($response); } }