apply users timezone to toolbar queries (#716)

This commit is contained in:
Kevin Papst
2019-04-22 16:21:22 +02:00
committed by GitHub
parent 46cb021260
commit 215d4fc8bf
11 changed files with 69 additions and 81 deletions

View File

@@ -13,6 +13,7 @@ use App\Calendar\Service;
use App\Calendar\TimesheetEntity;
use App\Entity\Timesheet;
use App\Repository\Query\TimesheetQuery;
use App\Repository\TimesheetRepository;
use App\Timesheet\UserDateTimeFactory;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -27,35 +28,16 @@ use Symfony\Component\Routing\Annotation\Route;
*/
class CalendarController extends AbstractController
{
/**
* @var Service
*/
protected $calendar;
/**
* @var UserDateTimeFactory
*/
protected $dateTime;
/**
* @param Service $calendar
* @param UserDateTimeFactory $dateTime
*/
public function __construct(Service $calendar, UserDateTimeFactory $dateTime)
{
$this->calendar = $calendar;
$this->dateTime = $dateTime;
}
/**
* @Route(path="/", name="calendar", methods={"GET"})
* @Cache(smaxage="10")
*/
public function userCalendar()
public function userCalendar(Service $calendar, UserDateTimeFactory $dateTime)
{
return $this->render('calendar/user.html.twig', [
'config' => $this->calendar->getConfig(),
'google' => $this->calendar->getGoogle(),
'now' => $this->dateTime->createDateTime(),
'config' => $calendar->getConfig(),
'google' => $calendar->getGoogle(),
'now' => $dateTime->createDateTime(),
]);
}
@@ -63,18 +45,18 @@ class CalendarController extends AbstractController
* @Route(path="/user", name="calendar_entries", methods={"GET"})
* @Cache(smaxage="10")
*/
public function calendarEntries(Request $request)
public function calendarEntries(Request $request, UserDateTimeFactory $dateTime, TimesheetRepository $repository)
{
$start = $request->get('start');
$end = $request->get('end');
$start = \DateTime::createFromFormat('Y-m-d', $start);
$start = $dateTime->createDateTimeFromFormat('Y-m-d', $start);
if ($start === false) {
$start = new \DateTime('first day of this month');
$start = $dateTime->createDateTime('first day of this month');
}
$start->setTime(0, 0, 0);
$end = \DateTime::createFromFormat('Y-m-d', $end);
$end = $dateTime->createDateTimeFromFormat('Y-m-d', $end);
if ($end === false) {
$end = clone $start;
$end = $end->modify('last day of this month');
@@ -90,8 +72,6 @@ class CalendarController extends AbstractController
->setEnd($end)
;
$repository = $this->getDoctrine()->getRepository(Timesheet::class);
/* @var $entries Timesheet[] */
$entries = $repository->findByQuery($query)->getQuery()->execute();
$result = [];