-
Notifications
You must be signed in to change notification settings - Fork 611
/
NewUsers.php
111 lines (96 loc) · 2.44 KB
/
NewUsers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\widgets;
use Craft;
use craft\base\Widget;
use craft\elements\User;
use craft\enums\CmsEdition;
use craft\helpers\Json;
use craft\web\assets\newusers\NewUsersAsset;
/**
* NewUsers represents a New Users dashboard widget.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0.0
*/
class NewUsers extends Widget
{
/**
* @inheritdoc
*/
public static function displayName(): string
{
return Craft::t('app', 'New {type}', [
'type' => User::pluralDisplayName(),
]);
}
/**
* @inheritdoc
*/
public static function isSelectable(): bool
{
// This widget is only available for Craft Pro
return Craft::$app->edition === CmsEdition::Pro;
}
/**
* @inheritdoc
*/
public static function icon(): ?string
{
return 'user-group';
}
/**
* @var int|null The ID of the user group
*/
public ?int $userGroupId = null;
/**
* @var string|null The date range
*/
public ?string $dateRange = null;
/**
* @inheritdoc
*/
public function getTitle(): ?string
{
if ($groupId = $this->userGroupId) {
$userGroup = Craft::$app->getUserGroups()->getGroupById($groupId);
if ($userGroup) {
return sprintf(
'%s – %s',
parent::getTitle(),
Craft::t('site', $userGroup->name)
);
}
}
return parent::getTitle();
}
/**
* @inheritdoc
*/
public function getBodyHtml(): ?string
{
if (Craft::$app->edition !== CmsEdition::Pro) {
return null;
}
$options = $this->getSettings();
$options['orientation'] = Craft::$app->getLocale()->getOrientation();
$view = Craft::$app->getView();
$view->registerAssetBundle(NewUsersAsset::class);
$view->registerJs('new Craft.NewUsersWidget(' . $this->id . ', ' . Json::encode($options) . ');');
return '';
}
/**
* @inheritdoc
*/
public function getSettingsHtml(): ?string
{
return Craft::$app->getView()->renderTemplate('_components/widgets/NewUsers/settings.twig',
[
'widget' => $this,
]);
}
}