added begin, end and export filter for API timesheets (#639)
This commit is contained in:
75
src/API/ConfigurationController.php
Normal file
75
src/API/ConfigurationController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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\API;
|
||||
|
||||
use App\API\Model\I18n;
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\User;
|
||||
use FOS\RestBundle\Controller\Annotations as Rest;
|
||||
use FOS\RestBundle\View\View;
|
||||
use FOS\RestBundle\View\ViewHandlerInterface;
|
||||
use Swagger\Annotations as SWG;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
class ConfigurationController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var ViewHandlerInterface
|
||||
*/
|
||||
protected $viewHandler;
|
||||
/**
|
||||
* @var LanguageFormattings
|
||||
*/
|
||||
protected $formats;
|
||||
|
||||
/**
|
||||
* @param ViewHandlerInterface $viewHandler
|
||||
* @param LanguageFormattings $formats
|
||||
*/
|
||||
public function __construct(ViewHandlerInterface $viewHandler, LanguageFormattings $formats)
|
||||
{
|
||||
$this->viewHandler = $viewHandler;
|
||||
$this->formats = $formats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns the locale specific configurations for this user",
|
||||
* @SWG\Schema(ref="#/definitions/I18nConfig")
|
||||
* )
|
||||
*
|
||||
* @Rest\Get(path="/config/i18n")
|
||||
*/
|
||||
public function i18nAction()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$locale = $user->getLocale();
|
||||
|
||||
$model = new I18n();
|
||||
$model
|
||||
->setFormDateTime($this->formats->getDateTimeTypeFormat($locale))
|
||||
->setFormDate($this->formats->getDateTypeFormat($locale))
|
||||
->setDateTime($this->formats->getDateTimeFormat($locale))
|
||||
->setDate($this->formats->getDateFormat($locale))
|
||||
->setDuration($this->formats->getDurationFormat($locale))
|
||||
->setTime($this->formats->getTimeFormat($locale))
|
||||
->setIs24hours($this->formats->isTwentyFourHours($locale))
|
||||
;
|
||||
|
||||
$view = new View($model, 200);
|
||||
$view->getContext()->setGroups(['Default', 'Config']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
}
|
||||
190
src/API/Model/I18n.php
Normal file
190
src/API/Model/I18n.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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\API\Model;
|
||||
|
||||
class I18n
|
||||
{
|
||||
/**
|
||||
* Format used for 'begin' and 'end' in TimesheetEditForm: POST, PATCH
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $formDateTime = '';
|
||||
/**
|
||||
* Format used for Timesheet queries in: GET
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $formDate = '';
|
||||
/**
|
||||
* Format used to display date-time values (see PHP function date_format)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $dateTime = '';
|
||||
/**
|
||||
* Format used to display date values (see PHP function date_format)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $date = '';
|
||||
/**
|
||||
* Format used to display times (see PHP function date_format)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $time = '';
|
||||
/**
|
||||
* Format used to display durations (replace: %h with hours, %m with minutes, %s with seconds)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $duration = '';
|
||||
/**
|
||||
* Whether a twenty-four hour format is used (true) or 12-hours AM/PM format (false)
|
||||
* @var bool
|
||||
*/
|
||||
protected $is24hours = true;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFormDateTime(): string
|
||||
{
|
||||
return $this->formDateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formDateTime
|
||||
* @return I18n
|
||||
*/
|
||||
public function setFormDateTime(string $formDateTime)
|
||||
{
|
||||
$this->formDateTime = $formDateTime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFormDate(): string
|
||||
{
|
||||
return $this->formDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formDate
|
||||
* @return I18n
|
||||
*/
|
||||
public function setFormDate(string $formDate)
|
||||
{
|
||||
$this->formDate = $formDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDateTime(): string
|
||||
{
|
||||
return $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dateTime
|
||||
* @return I18n
|
||||
*/
|
||||
public function setDateTime(string $dateTime)
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDate(): string
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $date
|
||||
* @return I18n
|
||||
*/
|
||||
public function setDate(string $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDuration(): string
|
||||
{
|
||||
return $this->duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $duration
|
||||
* @return I18n
|
||||
*/
|
||||
public function setDuration(string $duration)
|
||||
{
|
||||
$this->duration = $duration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTime(): string
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $time
|
||||
* @return I18n
|
||||
*/
|
||||
public function setTime(string $time)
|
||||
{
|
||||
$this->time = $time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isIs24hours(): bool
|
||||
{
|
||||
return $this->is24hours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is24hours
|
||||
* @return I18n
|
||||
*/
|
||||
public function setIs24hours(bool $is24hours)
|
||||
{
|
||||
$this->is24hours = $is24hours;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Swagger\Annotations as SWG;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
|
||||
/**
|
||||
* @RouteResource("Timesheet")
|
||||
@@ -84,6 +85,9 @@ class TimesheetController extends BaseApiController
|
||||
* @Rest\QueryParam(name="size", requirements="\d+", strict=true, nullable=true, description="The amount of entries for each page (default: 25)")
|
||||
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order (allowed values: 'ASC', 'DESC')")
|
||||
* @Rest\QueryParam(name="orderBy", requirements="id|begin|end|rate", strict=true, nullable=true, description="The field by which results will be ordered (allowed values: 'id', 'begin', 'end', 'rate')")
|
||||
* @Rest\QueryParam(name="begin", requirements=@Constraints\DateTime, strict=true, nullable=true, description="Only records after this date will be included (format: Y-m-d H:i:s)")
|
||||
* @Rest\QueryParam(name="end", requirements=@Constraints\DateTime, strict=true, nullable=true, description="Only records before this date will be included (format: Y-m-d H:i:s)")
|
||||
* @Rest\QueryParam(name="exported", requirements="0|1", strict=true, nullable=true, description="Use this flag if you want to filter for export state (0=not exported, 1=exported, null=all")
|
||||
*
|
||||
* @Security("is_granted('view_own_timesheet') or is_granted('view_other_timesheet')")
|
||||
*
|
||||
@@ -130,6 +134,23 @@ class TimesheetController extends BaseApiController
|
||||
$query->setOrderBy($orderBy);
|
||||
}
|
||||
|
||||
if (null !== ($begin = $paramFetcher->get('begin'))) {
|
||||
$query->setBegin(new \DateTime($begin));
|
||||
}
|
||||
|
||||
if (null !== ($end = $paramFetcher->get('end'))) {
|
||||
$query->setEnd(new \DateTime($end));
|
||||
}
|
||||
|
||||
if (null !== ($exported = $paramFetcher->get('exported'))) {
|
||||
$exported = (int) $exported;
|
||||
if ($exported === 1) {
|
||||
$query->setExported(TimesheetQuery::STATE_EXPORTED);
|
||||
} elseif ($exported === 0) {
|
||||
$query->setExported(TimesheetQuery::STATE_NOT_EXPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var Pagerfanta $data */
|
||||
$data = $this->repository->findByQuery($query);
|
||||
$data = (array) $data->getCurrentPageResults();
|
||||
|
||||
Reference in New Issue
Block a user