support custom fields for timesheets, customers, projects and activities (#871)

This commit is contained in:
Kevin Papst
2019-06-26 00:39:05 +02:00
committed by GitHub
parent 994c671fd8
commit d8621f0b7a
103 changed files with 2567 additions and 238 deletions

View File

@@ -12,7 +12,8 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\Customer;
use App\Form\CustomerEditForm;
use App\Event\CustomerMetaDefinitionEvent;
use App\Form\API\CustomerApiEditForm;
use App\Repository\CustomerRepository;
use App\Repository\Query\CustomerQuery;
use FOS\RestBundle\Controller\Annotations as Rest;
@@ -22,6 +23,7 @@ use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -37,20 +39,20 @@ class CustomerController extends BaseApiController
* @var CustomerRepository
*/
protected $repository;
/**
* @var ViewHandlerInterface
*/
protected $viewHandler;
/**
* @param ViewHandlerInterface $viewHandler
* @param CustomerRepository $repository
* @var EventDispatcherInterface
*/
public function __construct(ViewHandlerInterface $viewHandler, CustomerRepository $repository)
protected $dispatcher;
public function __construct(ViewHandlerInterface $viewHandler, CustomerRepository $repository, EventDispatcherInterface $dispatcher)
{
$this->viewHandler = $viewHandler;
$this->repository = $repository;
$this->dispatcher = $dispatcher;
}
/**
@@ -111,12 +113,18 @@ class CustomerController extends BaseApiController
*/
public function getAction($id)
{
/** @var Customer $data */
$data = $this->repository->find($id);
if (null === $data) {
throw new NotFoundException();
}
// make sure the fields are properly setup and we know, which meta fields
// should be exposed and which not
$event = new CustomerMetaDefinitionEvent($data);
$this->dispatcher->dispatch(CustomerMetaDefinitionEvent::class, $event);
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
@@ -155,9 +163,7 @@ class CustomerController extends BaseApiController
$customer = new Customer();
$form = $this->createForm(CustomerEditForm::class, $customer, [
'csrf_protection' => false,
]);
$form = $this->createForm(CustomerApiEditForm::class, $customer);
$form->submit($request->request->all());
@@ -219,9 +225,7 @@ class CustomerController extends BaseApiController
throw new AccessDeniedHttpException('User cannot update customer');
}
$form = $this->createForm(CustomerEditForm::class, $customer, [
'csrf_protection' => false,
]);
$form = $this->createForm(CustomerApiEditForm::class, $customer);
$form->setData($customer);
$form->submit($request->request->all(), false);