-
Notifications
You must be signed in to change notification settings - Fork 7
/
SingleStatWidget.php
44 lines (35 loc) · 1.25 KB
/
SingleStatWidget.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
<?php
namespace Crm\ApplicationModule\Components\Widgets\SingleStatWidget;
use Crm\ApplicationModule\Models\Widget\BaseLazyWidget;
use Crm\ApplicationModule\Models\Widget\LazyWidgetManager;
use Nette\Localization\Translator;
/**
* Widget used for rendering simple single stat widgets in groups.
*
* @package Crm\ApplicationModule\Components
*/
class SingleStatWidget extends BaseLazyWidget
{
private $templateName = 'single_stat_widget.latte';
private $translator;
public function __construct(
Translator $translator,
LazyWidgetManager $lazyWidgetManager
) {
parent::__construct($lazyWidgetManager);
$this->translator = $translator;
}
public function render($path, $params = [])
{
$widgets = $this->widgetManager->getWidgets($path);
foreach ($widgets as $sorting => $widget) {
if (!$this->getComponent($widget->identifier())) {
$this->addComponent($widget, $widget->identifier());
}
}
$this->template->widgets = $widgets;
$this->template->title = $this->translator->translate($params['title']);
$this->template->setFile(__DIR__ . DIRECTORY_SEPARATOR . $this->templateName);
$this->template->render();
}
}