@@ -10,17 +10,16 @@
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Controller\TimesheetControllerTrait;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\Toolbar\TimesheetAdminToolbarForm;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Controller\TimesheetControllerTrait;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Timesheet;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use App\Form\TimesheetAdminForm;
|
||||
|
||||
/**
|
||||
* Controller used for manage timesheet entries in the admin part of the site.
|
||||
@@ -33,6 +32,15 @@ class TimesheetController extends AbstractController
|
||||
{
|
||||
use TimesheetControllerTrait;
|
||||
|
||||
/**
|
||||
* TimesheetController constructor.
|
||||
* @param bool $durationOnly
|
||||
*/
|
||||
public function __construct(bool $durationOnly)
|
||||
{
|
||||
$this->setDurationMode($durationOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* This route shows all users timesheet entries.
|
||||
*
|
||||
@@ -138,10 +146,11 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
protected function getCreateForm(Timesheet $entry)
|
||||
{
|
||||
return $this->createForm(TimesheetAdminForm::class, $entry, [
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('admin_timesheet_create'),
|
||||
'method' => 'POST',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
'duration_only' => $this->isDurationOnlyMode(),
|
||||
'include_user' => true
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -152,13 +161,14 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
protected function getEditForm(Timesheet $entry, $page)
|
||||
{
|
||||
return $this->createForm(TimesheetAdminForm::class, $entry, [
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('admin_timesheet_edit', [
|
||||
'id' => $entry->getId(),
|
||||
'page' => $page
|
||||
]),
|
||||
'method' => 'POST',
|
||||
'currency' => $entry->getActivity()->getProject()->getCustomer()->getCurrency(),
|
||||
'duration_only' => $this->isDurationOnlyMode(),
|
||||
'include_user' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,17 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\Toolbar\TimesheetToolbarForm;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Timesheet;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Form\TimesheetEditForm;
|
||||
|
||||
/**
|
||||
* Controller used to manage timesheet contents in the public part of the site.
|
||||
@@ -32,6 +31,15 @@ class TimesheetController extends AbstractController
|
||||
{
|
||||
use TimesheetControllerTrait;
|
||||
|
||||
/**
|
||||
* TimesheetController constructor.
|
||||
* @param bool $durationOnly
|
||||
*/
|
||||
public function __construct(bool $durationOnly)
|
||||
{
|
||||
$this->setDurationMode($durationOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="timesheet")
|
||||
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="timesheet_paginated")
|
||||
@@ -175,15 +183,11 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
protected function getCreateForm(Timesheet $entry)
|
||||
{
|
||||
return $this->createForm(
|
||||
TimesheetEditForm::class,
|
||||
$entry,
|
||||
[
|
||||
'action' => $this->generateUrl('timesheet_create'),
|
||||
'method' => 'POST',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
]
|
||||
);
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('timesheet_create'),
|
||||
'method' => 'POST',
|
||||
'duration_only' => $this->isDurationOnlyMode(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,18 +197,14 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
protected function getEditForm(Timesheet $entry, $page)
|
||||
{
|
||||
return $this->createForm(
|
||||
TimesheetEditForm::class,
|
||||
$entry,
|
||||
[
|
||||
'action' => $this->generateUrl('timesheet_edit', [
|
||||
'id' => $entry->getId(),
|
||||
'page' => $page
|
||||
]),
|
||||
'method' => 'POST',
|
||||
'currency' => $entry->getActivity()->getProject()->getCustomer()->getCurrency(),
|
||||
]
|
||||
);
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('timesheet_edit', [
|
||||
'id' => $entry->getId(),
|
||||
'page' => $page
|
||||
]),
|
||||
'method' => 'POST',
|
||||
'duration_only' => $this->isDurationOnlyMode(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,28 @@ use App\Repository\TimesheetRepository;
|
||||
*/
|
||||
trait TimesheetControllerTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $durationOnly = false;
|
||||
|
||||
/**
|
||||
* @param bool $durationOnly
|
||||
*/
|
||||
protected function setDurationMode(bool $durationOnly)
|
||||
{
|
||||
$this->durationOnly = $durationOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDurationOnlyMode()
|
||||
{
|
||||
return $this->durationOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TimesheetRepository
|
||||
*/
|
||||
@@ -56,6 +78,18 @@ trait TimesheetControllerTrait
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
if ($editForm->has('duration')) {
|
||||
/** @var Timesheet $record */
|
||||
$record = $editForm->getData();
|
||||
$duration = $editForm->get('duration')->getData();
|
||||
$end = null;
|
||||
if ($duration > 0) {
|
||||
$end = clone $record->getBegin();
|
||||
$end->modify('+ ' . $duration . 'seconds');
|
||||
}
|
||||
$record->setEnd($end);
|
||||
}
|
||||
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($entry);
|
||||
$entityManager->flush();
|
||||
@@ -65,13 +99,10 @@ trait TimesheetControllerTrait
|
||||
return $this->redirectToRoute($redirectRoute, ['page' => $request->get('page')]);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
$renderTemplate,
|
||||
[
|
||||
'entry' => $entry,
|
||||
'form' => $editForm->createView(),
|
||||
]
|
||||
);
|
||||
return $this->render($renderTemplate, [
|
||||
'entry' => $entry,
|
||||
'form' => $editForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,10 +118,20 @@ trait TimesheetControllerTrait
|
||||
$entry->setBegin(new \DateTime());
|
||||
|
||||
$createForm = $this->getCreateForm($entry);
|
||||
|
||||
$createForm->handleRequest($request);
|
||||
|
||||
if ($createForm->isSubmitted() && $createForm->isValid()) {
|
||||
if ($createForm->has('duration')) {
|
||||
$duration = $createForm->get('duration')->getData();
|
||||
if ($duration > 0) {
|
||||
/** @var Timesheet $record */
|
||||
$record = $createForm->getData();
|
||||
$end = clone $record->getBegin();
|
||||
$end->modify('+ ' . $duration . 'seconds');
|
||||
$record->setEnd($end);
|
||||
}
|
||||
}
|
||||
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($entry);
|
||||
|
||||
@@ -101,13 +142,10 @@ trait TimesheetControllerTrait
|
||||
return $this->redirectToRoute($redirectRoute);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
$renderTemplate,
|
||||
[
|
||||
'entry' => $entry,
|
||||
'form' => $createForm->createView(),
|
||||
]
|
||||
);
|
||||
return $this->render($renderTemplate, [
|
||||
'entry' => $entry,
|
||||
'form' => $createForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user