users weekly stats as bar-chart in dashboard (#847)
This commit is contained in:
42
src/Widget/Renderer/AbstractTwigRenderer.php
Normal file
42
src/Widget/Renderer/AbstractTwigRenderer.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Widget\Renderer;
|
||||
|
||||
use App\Widget\WidgetRendererInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
abstract class AbstractTwigRenderer implements WidgetRendererInterface
|
||||
{
|
||||
/**
|
||||
* @var Environment
|
||||
*/
|
||||
protected $twig;
|
||||
|
||||
/**
|
||||
* @param Environment $twig
|
||||
*/
|
||||
public function __construct(Environment $twig)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
* @param array $data
|
||||
* @return string
|
||||
* @throws \Twig\Error\LoaderError
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
*/
|
||||
protected function renderTemplate(string $template, array $data): string
|
||||
{
|
||||
return $this->twig->render($template, $data);
|
||||
}
|
||||
}
|
||||
29
src/Widget/Renderer/CompoundChartRenderer.php
Normal file
29
src/Widget/Renderer/CompoundChartRenderer.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Widget\Renderer;
|
||||
|
||||
use App\Widget\Type\CompoundChart;
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
class CompoundChartRenderer extends AbstractTwigRenderer
|
||||
{
|
||||
public function supports(WidgetInterface $widget): bool
|
||||
{
|
||||
return ($widget instanceof CompoundChart);
|
||||
}
|
||||
|
||||
public function render(WidgetInterface $widget, array $options = []): string
|
||||
{
|
||||
return $this->renderTemplate('widget/section-chart.html.twig', [
|
||||
'title' => $widget->getTitle(),
|
||||
'widgets' => $widget->getData(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
29
src/Widget/Renderer/CompoundRowRenderer.php
Normal file
29
src/Widget/Renderer/CompoundRowRenderer.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Widget\Renderer;
|
||||
|
||||
use App\Widget\Type\CompoundRow;
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
class CompoundRowRenderer extends AbstractTwigRenderer
|
||||
{
|
||||
public function supports(WidgetInterface $widget): bool
|
||||
{
|
||||
return ($widget instanceof CompoundRow);
|
||||
}
|
||||
|
||||
public function render(WidgetInterface $widget, array $options = []): string
|
||||
{
|
||||
return $this->renderTemplate('widget/section-simple.html.twig', [
|
||||
'title' => $widget->getTitle(),
|
||||
'widgets' => $widget->getData(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
33
src/Widget/Renderer/SimpleWidgetRenderer.php
Normal file
33
src/Widget/Renderer/SimpleWidgetRenderer.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Widget\Renderer;
|
||||
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
use App\Widget\WidgetInterface;
|
||||
use ReflectionClass;
|
||||
|
||||
class SimpleWidgetRenderer extends AbstractTwigRenderer
|
||||
{
|
||||
public function supports(WidgetInterface $widget): bool
|
||||
{
|
||||
return $widget instanceof SimpleWidget;
|
||||
}
|
||||
|
||||
public function render(WidgetInterface $widget, array $options = []): string
|
||||
{
|
||||
$name = (new ReflectionClass($widget))->getShortName();
|
||||
|
||||
return $this->renderTemplate(sprintf('widget/widget-%s.html.twig', strtolower($name)), [
|
||||
'data' => $widget->getData($options),
|
||||
'options' => $widget->getOptions($options),
|
||||
'title' => $widget->getTitle(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user