forked from remp2020/crm-application-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleWidget.php
49 lines (39 loc) · 1.35 KB
/
SimpleWidget.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
<?php
namespace Crm\ApplicationModule\Components;
use Crm\ApplicationModule\Widget\BaseWidget;
/**
* Widget used for rendering other widgets in groups.
*
* @package Crm\ApplicationModule\Components
*/
class SimpleWidget extends BaseWidget
{
private $templateName = 'simple_widget.latte';
private static $counters;
private function getNextIdentifier(string $key)
{
if (!isset(self::$counters[$key])) {
self::$counters[$key] = 0;
}
return $key . '_' . ++self::$counters[$key];
}
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());
}
}
foreach ($this->widgetManager->getWidgetFactories($path) as $sorting => $factory) {
$widget = $factory->create();
$widgets[$sorting] = $widget;
$this->addComponent($widget, $this->getNextIdentifier($widget->identifier()));
}
ksort($widgets);
$this->template->widgets = $widgets;
$this->template->params = $params;
$this->template->setFile(__DIR__ . '/' . $this->templateName);
$this->template->render();
}
}