added begin, end and export filter for API timesheets (#639)

This commit is contained in:
Kevin Papst
2019-03-14 03:34:54 +01:00
committed by GitHub
parent 2e6f3ed864
commit bde791fa55
28 changed files with 993 additions and 86 deletions

View File

@@ -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();