users weekly stats as bar-chart in dashboard (#847)

This commit is contained in:
Kevin Papst
2019-06-13 18:38:49 +02:00
committed by GitHub
parent e1f862507e
commit 3311f17bbb
96 changed files with 2754 additions and 846 deletions

View File

@@ -1,106 +0,0 @@
<?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\Model;
class DashboardSection
{
public const TYPE_SIMPLE = 'simple';
public const TYPE_CHART = 'chart';
/**
* @var null|string
*/
protected $title;
/**
* @var Widget[]
*/
protected $widgets = [];
/**
* @var int
*/
protected $order = 0;
/**
* @var string
*/
protected $type = self::TYPE_SIMPLE;
/**
* @param null|string $title
*/
public function __construct(?string $title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
* @return DashboardSection
*/
public function setType(string $type)
{
$this->type = $type;
return $this;
}
/**
* @return int
*/
public function getOrder(): int
{
return $this->order;
}
/**
* @param int $order
* @return DashboardSection
*/
public function setOrder(int $order)
{
$this->order = $order;
return $this;
}
/**
* @return string
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return Widget[]
*/
public function getWidgets(): array
{
return $this->widgets;
}
/**
* @param Widget $widget
* @return DashboardSection
*/
public function addWidget(Widget $widget)
{
$this->widgets[] = $widget;
return $this;
}
}

View File

@@ -0,0 +1,64 @@
<?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\Model\Statistic;
use DateTime;
class Day
{
/**
* @var int
*/
protected $totalDuration = 0;
/**
* @var float
*/
protected $totalRate = 0.00;
/**
* @var DateTime
*/
protected $day;
public function __construct(DateTime $day, int $duration, float $rate)
{
$this->day = $day;
$this->totalDuration = $duration;
$this->totalRate = $rate;
}
public function getDay(): DateTime
{
return $this->day;
}
public function getTotalDuration(): int
{
return $this->totalDuration;
}
public function setTotalDuration(int $seconds): Day
{
$this->totalDuration = $seconds;
return $this;
}
public function getTotalRate(): float
{
return $this->totalRate;
}
public function setTotalRate(float $totalRate): Day
{
$this->totalRate = $totalRate;
return $this;
}
}

View File

@@ -9,6 +9,8 @@
namespace App\Model\Statistic;
use InvalidArgumentException;
/**
* Monthly statistics
*/
@@ -23,9 +25,9 @@ class Month
*/
protected $totalDuration = 0;
/**
* @var int
* @var float
*/
protected $totalRate = 0;
protected $totalRate = 0.00;
/**
* @param string $month
@@ -34,7 +36,9 @@ class Month
{
$monthNumber = (int) $month;
if ($monthNumber < 1 || $monthNumber > 12) {
throw new \InvalidArgumentException('Invalid month given, expected 01-12 but given: ' . $monthNumber);
throw new InvalidArgumentException(
sprintf('Invalid month given. Expected 1-12, received "%s".', $monthNumber)
);
}
$this->month = $month;
}
@@ -47,38 +51,24 @@ class Month
return $this->month;
}
/**
* @return int
*/
public function getTotalDuration()
public function getTotalDuration(): int
{
return $this->totalDuration;
}
/**
* @param int $totalDuration
* @return $this
*/
public function setTotalDuration($totalDuration)
public function setTotalDuration(int $seconds): Month
{
$this->totalDuration = $totalDuration;
$this->totalDuration = $seconds;
return $this;
}
/**
* @return int
*/
public function getTotalRate()
public function getTotalRate(): float
{
return $this->totalRate;
}
/**
* @param int $totalRate
* @return $this
*/
public function setTotalRate($totalRate)
public function setTotalRate(float $totalRate): Month
{
$this->totalRate = $totalRate;

View File

@@ -24,7 +24,6 @@ class Year
protected $months = [];
/**
* Year constructor.
* @param string $year
*/
public function __construct($year)
@@ -40,22 +39,14 @@ class Year
return $this->year;
}
/**
* @param Month $month
* @return $this
*/
public function setMonth(Month $month)
public function setMonth(Month $month): Year
{
$this->months[(int) $month->getMonth()] = $month;
return $this;
}
/**
* @param int $month
* @return null|Month
*/
public function getMonth(int $month)
public function getMonth(int $month): ?Month
{
if (isset($this->months[$month])) {
return $this->months[$month];
@@ -67,7 +58,7 @@ class Year
/**
* @return Month[]
*/
public function getMonths()
public function getMonths(): array
{
return array_values($this->months);
}

View File

@@ -1,219 +0,0 @@
<?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\Model;
class Widget
{
public const TYPE_COUNTER = 'counter';
public const TYPE_MORE = 'more';
public const DATA_TYPE_INT = 'int';
public const DATA_TYPE_MONEY = 'money';
public const DATA_TYPE_DURATION = 'duration';
/**
* @var string|null
*/
protected $title;
/**
* @var string
*/
protected $icon = '';
/**
* @var string
*/
protected $color = '';
/**
* @var string
*/
protected $type = self::TYPE_COUNTER;
/**
* @var string
*/
protected $range;
/**
* @var string|null
*/
protected $route;
/**
* @var array
*/
protected $routeOptions = [];
/**
* @var mixed
*/
protected $data;
/**
* @var string
*/
protected $dataType = self::DATA_TYPE_INT;
/**
* @param string $title
* @param mixed $data
*/
public function __construct(string $title, $data)
{
$this->title = $title;
$this->data = $data;
}
/**
* @return string
*/
public function getDataType(): string
{
return $this->dataType;
}
/**
* @param string $dataType
* @return Widget
*/
public function setDataType(string $dataType)
{
$this->dataType = $dataType;
return $this;
}
/**
* @return array
*/
public function getRouteOptions(): array
{
return $this->routeOptions;
}
/**
* @param array $routeOptions
* @return Widget
*/
public function setRouteOptions(array $routeOptions)
{
$this->routeOptions = $routeOptions;
return $this;
}
/**
* @return string|null
*/
public function getRoute(): ?string
{
return $this->route;
}
/**
* @param string $route
* @return Widget
*/
public function setRoute(string $route)
{
$this->route = $route;
return $this;
}
/**
* @return mixed
*/
public function getData()
{
return $this->data;
}
/**
* @param mixed $data
* @return Widget
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @param string $title
* @return Widget
*/
public function setTitle(string $title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getIcon(): string
{
return $this->icon;
}
/**
* @param string $icon
* @return Widget
*/
public function setIcon(string $icon)
{
$this->icon = $icon;
return $this;
}
/**
* @return string
*/
public function getColor(): string
{
return $this->color;
}
/**
* @param string $color
* @return Widget
*/
public function setColor(string $color)
{
$this->color = $color;
return $this;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
* @return Widget
*/
public function setType(string $type)
{
$this->type = $type;
return $this;
}
}