added explicit classes for widgets (#3170)
This commit is contained in:
59
src/Widget/Type/AbstractAmountPeriod.php
Normal file
59
src/Widget/Type/AbstractAmountPeriod.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Event\RevenueStatisticEvent;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
abstract class AbstractAmountPeriod extends SimpleStatisticChart
|
||||
{
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(TimesheetRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
parent::__construct($repository);
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'stats.' . $this->getId();
|
||||
}
|
||||
|
||||
public function getTemplateName(): string
|
||||
{
|
||||
return 'widget/widget-counter.html.twig';
|
||||
}
|
||||
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'icon' => 'money',
|
||||
'dataType' => 'money',
|
||||
], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
|
||||
$this->setQueryWithUser(false);
|
||||
|
||||
$data = parent::getData($options);
|
||||
|
||||
$event = new RevenueStatisticEvent($this->begin, $this->end);
|
||||
if ($data !== null) {
|
||||
$event->addRevenue($data);
|
||||
}
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getRevenue();
|
||||
}
|
||||
}
|
||||
59
src/Widget/Type/AbstractUserAmountPeriod.php
Normal file
59
src/Widget/Type/AbstractUserAmountPeriod.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Event\UserRevenueStatisticEvent;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
abstract class AbstractUserAmountPeriod extends SimpleStatisticChart
|
||||
{
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(TimesheetRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
parent::__construct($repository);
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'stats.' . str_replace('userA', 'a', $this->getId());
|
||||
}
|
||||
|
||||
public function getTemplateName(): string
|
||||
{
|
||||
return 'widget/widget-counter.html.twig';
|
||||
}
|
||||
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'icon' => 'money',
|
||||
'dataType' => 'money',
|
||||
], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
|
||||
$this->setQueryWithUser(true);
|
||||
|
||||
$data = parent::getData($options);
|
||||
|
||||
$event = new UserRevenueStatisticEvent($this->user, $this->begin, $this->end);
|
||||
if ($data !== null) {
|
||||
$event->addRevenue($data);
|
||||
}
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getRevenue();
|
||||
}
|
||||
}
|
||||
33
src/Widget/Type/AmountMonth.php
Normal file
33
src/Widget/Type/AmountMonth.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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class AmountMonth extends AbstractAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_MONTH], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'amountMonth';
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setBegin('first day of this month 00:00:00');
|
||||
$this->setEnd('last day of this month 23:59:59');
|
||||
|
||||
return parent::getData($options);
|
||||
}
|
||||
}
|
||||
33
src/Widget/Type/AmountToday.php
Normal file
33
src/Widget/Type/AmountToday.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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class AmountToday extends AbstractAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_TODAY], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'amountToday';
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setBegin('00:00:00');
|
||||
$this->setEnd('23:59:59');
|
||||
|
||||
return parent::getData($options);
|
||||
}
|
||||
}
|
||||
25
src/Widget/Type/AmountTotal.php
Normal file
25
src/Widget/Type/AmountTotal.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class AmountTotal extends AbstractAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_TOTAL], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'amountTotal';
|
||||
}
|
||||
}
|
||||
33
src/Widget/Type/AmountWeek.php
Normal file
33
src/Widget/Type/AmountWeek.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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class AmountWeek extends AbstractAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_WEEK], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'amountWeek';
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setBegin('monday this week 00:00:00');
|
||||
$this->setEnd('sunday this week 23:59:59');
|
||||
|
||||
return parent::getData($options);
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,23 @@
|
||||
namespace App\Widget\Type;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Event\RevenueStatisticEvent;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\WidgetInterface;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class AmountYear extends CounterYear
|
||||
{
|
||||
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
parent::__construct($repository, $systemConfiguration);
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->setId('amountYear');
|
||||
$this->setOption('dataType', 'money');
|
||||
$this->setOption('icon', 'money');
|
||||
$this->setOption('color', 'yellow');
|
||||
$this->setOption('color', WidgetInterface::COLOR_YEAR);
|
||||
$this->setTitle('stats.amountYear');
|
||||
}
|
||||
|
||||
@@ -30,6 +36,14 @@ final class AmountYear extends CounterYear
|
||||
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
|
||||
$this->setQueryWithUser(false);
|
||||
|
||||
return parent::getData($options);
|
||||
$data = parent::getData($options);
|
||||
|
||||
$event = new RevenueStatisticEvent($this->begin, $this->end);
|
||||
if ($data !== null) {
|
||||
$event->addRevenue($data);
|
||||
}
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getRevenue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
|
||||
/**
|
||||
* @var User|null
|
||||
*/
|
||||
private $user;
|
||||
protected $user;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
@@ -106,11 +106,11 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
|
||||
$end = $this->end;
|
||||
|
||||
if (!empty($begin) && \is_string($begin)) {
|
||||
$begin = new \DateTime($begin, $timezone);
|
||||
$this->begin = new \DateTime($begin, $timezone);
|
||||
}
|
||||
|
||||
if (!empty($end) && \is_string($end)) {
|
||||
$end = new \DateTime($end, $timezone);
|
||||
$this->end = new \DateTime($end, $timezone);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -119,7 +119,7 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
|
||||
$user = $this->user;
|
||||
}
|
||||
|
||||
return $this->repository->getStatistic($this->query, $begin, $end, $user);
|
||||
return $this->repository->getStatistic($this->query, $this->begin, $this->end, $user);
|
||||
} catch (\Exception $ex) {
|
||||
throw new WidgetException(
|
||||
'Failed loading widget data: ' . $ex->getMessage()
|
||||
|
||||
33
src/Widget/Type/UserAmountMonth.php
Normal file
33
src/Widget/Type/UserAmountMonth.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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class UserAmountMonth extends AbstractUserAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_MONTH], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'userAmountMonth';
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setBegin('first day of this month 00:00:00');
|
||||
$this->setEnd('last day of this month 23:59:59');
|
||||
|
||||
return parent::getData($options);
|
||||
}
|
||||
}
|
||||
33
src/Widget/Type/UserAmountToday.php
Normal file
33
src/Widget/Type/UserAmountToday.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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class UserAmountToday extends AbstractUserAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_TODAY], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'userAmountToday';
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setBegin('00:00:00');
|
||||
$this->setEnd('23:59:59');
|
||||
|
||||
return parent::getData($options);
|
||||
}
|
||||
}
|
||||
25
src/Widget/Type/UserAmountTotal.php
Normal file
25
src/Widget/Type/UserAmountTotal.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class UserAmountTotal extends AbstractUserAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_TOTAL], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'userAmountTotal';
|
||||
}
|
||||
}
|
||||
33
src/Widget/Type/UserAmountWeek.php
Normal file
33
src/Widget/Type/UserAmountWeek.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\Type;
|
||||
|
||||
use App\Widget\WidgetInterface;
|
||||
|
||||
final class UserAmountWeek extends AbstractUserAmountPeriod
|
||||
{
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge(['color' => WidgetInterface::COLOR_WEEK], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'userAmountWeek';
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$this->setBegin('monday this week 00:00:00');
|
||||
$this->setEnd('sunday this week 23:59:59');
|
||||
|
||||
return parent::getData($options);
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,23 @@
|
||||
namespace App\Widget\Type;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Event\UserRevenueStatisticEvent;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\WidgetInterface;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class UserAmountYear extends CounterYear
|
||||
{
|
||||
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
parent::__construct($repository, $systemConfiguration);
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->setId('userAmountYear');
|
||||
$this->setOption('dataType', 'money');
|
||||
$this->setOption('icon', 'money');
|
||||
$this->setOption('color', 'yellow');
|
||||
$this->setOption('color', WidgetInterface::COLOR_YEAR);
|
||||
$this->setTitle('stats.amountYear');
|
||||
}
|
||||
|
||||
@@ -30,6 +36,14 @@ final class UserAmountYear extends CounterYear
|
||||
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
|
||||
$this->setQueryWithUser(true);
|
||||
|
||||
return parent::getData($options);
|
||||
$data = parent::getData($options);
|
||||
|
||||
$event = new UserRevenueStatisticEvent($this->user, $this->begin, $this->end);
|
||||
if ($data !== null) {
|
||||
$event->addRevenue($data);
|
||||
}
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getRevenue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,12 @@ namespace App\Widget;
|
||||
|
||||
interface WidgetInterface
|
||||
{
|
||||
public const COLOR_TODAY = 'green';
|
||||
public const COLOR_WEEK = 'blue';
|
||||
public const COLOR_MONTH = 'purple';
|
||||
public const COLOR_YEAR = 'yellow';
|
||||
public const COLOR_TOTAL = 'red';
|
||||
|
||||
/**
|
||||
* Returns a unique ID for this widget.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user