-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMonthSubscriptionsStatWidget.php
42 lines (35 loc) · 1.32 KB
/
MonthSubscriptionsStatWidget.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
<?php
namespace Crm\SubscriptionsModule\Components;
use Crm\ApplicationModule\Widget\BaseWidget;
use Crm\ApplicationModule\Widget\WidgetManager;
use Crm\SubscriptionsModule\Repository\SubscriptionsRepository;
use Nette\Utils\DateTime;
class MonthSubscriptionsStatWidget extends BaseWidget
{
private $templateName = 'month_subscriptions_stat_widget.latte';
private $subscriptionsRepository;
public function __construct(
WidgetManager $widgetManager,
SubscriptionsRepository $subscriptionsRepository
) {
parent::__construct($widgetManager);
$this->subscriptionsRepository = $subscriptionsRepository;
}
public function identifier()
{
return 'monthsubscriptionsstatwidget';
}
public function render()
{
$this->template->thisMonthSubscriptions = $this->subscriptionsRepository->subscriptionsCreatedBetween(
DateTime::from(date('Y-m')),
new DateTime()
)->count('*');
$this->template->lastMonthSubscriptions = $this->subscriptionsRepository->subscriptionsCreatedBetween(
DateTime::from('first day of -1 month 00:00'),
DateTime::from(date('Y-m'))
)->count('*');
$this->template->setFile(__DIR__ . DIRECTORY_SEPARATOR . $this->templateName);
$this->template->render();
}
}