uawdijnntqw1x1x1
IP : 216.73.216.107
Hostname : toronto-dev2
Kernel : Linux toronto-dev2 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
srv
/
users
/
craft4
/
apps
/
craft4-newsite-space
/
vendor
/
craftcms
/
.
/
commerce
/
src
/
widgets
/
TopCustomers.php
/
/
<?php /** * @link https://craftcms.com/ * @copyright Copyright (c) Pixel & Tonic, Inc. * @license https://craftcms.github.io/license/ */ namespace craft\commerce\widgets; use Craft; use craft\base\Widget; use craft\commerce\base\StatWidgetTrait; use craft\commerce\stats\TopCustomers as TopCustomersStat; use craft\commerce\web\assets\statwidgets\StatWidgetsAsset; use craft\helpers\DateTimeHelper; use craft\helpers\Html; use craft\helpers\StringHelper; use craft\web\assets\admintable\AdminTableAsset; /** * Top Customers widget * * @property string|false $bodyHtml the widget's body HTML * @property string $settingsHtml the component’s settings HTML * @property string $title the widget’s title * @author Pixel & Tonic, Inc. <support@pixelandtonic.com> * @since 3.0 */ class TopCustomers extends Widget { use StatWidgetTrait; /** * @var string|null Options 'total', 'average'. */ public ?string $type = null; /** * @var TopCustomersStat */ private TopCustomersStat $_stat; /** * @var string */ private string $_title; /** * @var array */ private array $_typeOptions; /** * @inheritDoc */ public function init(): void { $this->_typeOptions = [ 'total' => Craft::t('commerce', 'Total'), 'average' => Craft::t('commerce', 'Average'), ]; $this->_title = match ($this->type) { 'average' => Craft::t('commerce', 'Top Customers by Average Order'), 'total' => Craft::t('commerce', 'Top Customers by Total Revenue'), default => Craft::t('commerce', 'Top Customers'), }; $this->dateRange = !isset($this->dateRange) || !$this->dateRange ? TopCustomersStat::DATE_RANGE_TODAY : $this->dateRange; $this->_stat = new TopCustomersStat( $this->dateRange, $this->type, DateTimeHelper::toDateTime($this->startDate, true), DateTimeHelper::toDateTime($this->endDate, true) ); if (!empty($this->orderStatuses)) { $this->_stat->setOrderStatuses($this->orderStatuses); } parent::init(); } /** * @inheritdoc */ public static function isSelectable(): bool { return Craft::$app->getUser()->checkPermission('commerce-manageOrders') && Craft::$app->getUser()->checkPermission('commerce-manageCustomers'); } /** * @inheritdoc */ public static function displayName(): string { return Craft::t('commerce', 'Top Customers'); } /** * @inheritdoc */ public static function icon(): ?string { return Craft::getAlias('@craft/commerce/icon-mask.svg'); } /** * @inheritdoc */ public function getTitle(): ?string { return $this->_title; } /** * @inheritDoc */ public function getSubtitle(): ?string { return $this->_stat->getDateRangeWording(); } /** * @inheritdoc */ public function getBodyHtml(): ?string { $stats = $this->_stat->get(); if (empty($stats)) { return Html::tag('p', Craft::t('commerce', 'No stats available.'), ['class' => 'zilch']); } $view = Craft::$app->getView(); $view->registerAssetBundle(StatWidgetsAsset::class); $view->registerAssetBundle(AdminTableAsset::class); return $view->renderTemplate('commerce/_components/widgets/customers/top/body', [ 'stats' => $stats, 'type' => $this->type, 'typeLabel' => $this->_typeOptions[$this->type] ?? '', 'id' => 'top-products' . StringHelper::randomString(), ]); } /** * @inheritdoc */ public function getSettingsHtml(): ?string { $id = 'top-products' . StringHelper::randomString(); $namespaceId = Craft::$app->getView()->namespaceInputId($id); return Craft::$app->getView()->renderTemplate('commerce/_components/widgets/customers/top/settings', [ 'id' => $id, 'namespaceId' => $namespaceId, 'orderStatuses' => $this->getOrderStatusOptions(), 'widget' => $this, 'typeOptions' => $this->_typeOptions, ]); } }
/srv/users/craft4/apps/craft4-newsite-space/vendor/craftcms/./commerce/src/widgets/TopCustomers.php