-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSubscriptionsEndingWithinPeriodWidget.php
63 lines (53 loc) · 2.54 KB
/
SubscriptionsEndingWithinPeriodWidget.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
<?php
namespace Crm\SubscriptionsModule\Components;
use Crm\ApplicationModule\Widget\BaseWidget;
use Crm\ApplicationModule\Widget\WidgetManager;
use Crm\SubscriptionsModule\Repository\SubscriptionsRepository;
use Nette\Localization\ITranslator;
use Nette\Utils\DateTime;
class SubscriptionsEndingWithinPeriodWidget extends BaseWidget implements IWidgetLegend
{
private $templateName = 'subscriptions_ending_within_period_widget.latte';
private $subscriptionsRepository;
private $translator;
public function __construct(
WidgetManager $widgetManager,
SubscriptionsRepository $subscriptionsRepository,
ITranslator $translator
) {
parent::__construct($widgetManager);
$this->subscriptionsRepository = $subscriptionsRepository;
$this->translator = $translator;
}
public function legend(): string
{
return sprintf('<span class="text-warning">%s</span>', $this->translator->translate('dashboard.subscriptions.ending.now.title'));
}
public function identifier()
{
return 'subscriptionsnedingwithinperiod';
}
public function render()
{
$this->template->subscriptionsEndToday = $this->subscriptionsRepository
->subscriptionsEndingBetween(DateTime::from('today 00:00'), DateTime::from('today 23:59:59'))
->count('*');
$this->template->subscriptionsEndTomorow = $this->subscriptionsRepository
->subscriptionsEndingBetween(DateTime::from('tomorrow 00:00'), DateTime::from('tomorrow 23:59:59'))
->count('*');
$this->template->subscriptionsEndAfterTomorow = $this->subscriptionsRepository
->subscriptionsEndingBetween(DateTime::from('+2 days 00:00'), DateTime::from('+2 days 23:59:59'))
->count('*');
$this->template->subscriptionsEndInOneWeek = $this->subscriptionsRepository
->subscriptionsEndingBetween(DateTime::from('today 00:00'), DateTime::from('+7 days 23:59:59'))
->count('*');
$this->template->subscriptionsEndInTwoWeeks = $this->subscriptionsRepository
->subscriptionsEndingBetween(DateTime::from('today 00:00'), DateTime::from('+14 days 23:59:59'))
->count('*');
$this->template->subscriptionsEndInOneMonth = $this->subscriptionsRepository
->subscriptionsEndingBetween(DateTime::from('today 00:00'), DateTime::from('+31 days 23:59:59'))
->count('*');
$this->template->setFile(__DIR__ . DIRECTORY_SEPARATOR . $this->templateName);
$this->template->render();
}
}