Display meta-fields in datatables (#1116)
This commit is contained in:
@@ -177,7 +177,7 @@ class ActivityController extends BaseApiController
|
||||
$activity = new Activity();
|
||||
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ActivityApiEditForm::class, $activity);
|
||||
|
||||
@@ -242,7 +242,7 @@ class ActivityController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ActivityApiEditForm::class, $activity);
|
||||
|
||||
@@ -301,7 +301,7 @@ class ActivityController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -156,7 +156,7 @@ class CustomerController extends BaseApiController
|
||||
$customer = new Customer();
|
||||
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(CustomerApiEditForm::class, $customer);
|
||||
|
||||
@@ -221,7 +221,7 @@ class CustomerController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(CustomerApiEditForm::class, $customer);
|
||||
|
||||
@@ -280,7 +280,7 @@ class CustomerController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -162,7 +162,7 @@ class ProjectController extends BaseApiController
|
||||
$project = new Project();
|
||||
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project);
|
||||
|
||||
@@ -227,7 +227,7 @@ class ProjectController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project);
|
||||
|
||||
@@ -286,7 +286,7 @@ class ProjectController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -291,7 +291,7 @@ class TimesheetController extends BaseApiController
|
||||
$timesheet->setBegin($this->dateTime->createDateTime());
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$mode = $this->getTrackingMode();
|
||||
|
||||
@@ -372,7 +372,7 @@ class TimesheetController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$mode = $this->getTrackingMode();
|
||||
|
||||
@@ -732,7 +732,7 @@ class TimesheetController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Event\ActivityMetaDefinitionEvent;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Form\ActivityEditForm;
|
||||
use App\Form\Toolbar\ActivityToolbarForm;
|
||||
use App\Form\Type\ActivityType;
|
||||
@@ -92,9 +94,22 @@ class ActivityController extends AbstractController
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'metaColumns' => $this->findMetaColumns($query),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActivityQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(ActivityQuery $query): array
|
||||
{
|
||||
$event = new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::ACTIVITY);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/create", name="admin_activity_create", methods={"GET", "POST"})
|
||||
* @Route(path="/create/{project}", name="admin_activity_create_with_project", methods={"GET", "POST"})
|
||||
@@ -123,9 +138,13 @@ class ActivityController extends AbstractController
|
||||
*/
|
||||
public function budgetAction(Activity $activity)
|
||||
{
|
||||
$stats = $this->getRepository()->getActivityStatistics($activity);
|
||||
|
||||
// TODO sent event with stats
|
||||
|
||||
return $this->render('activity/budget.html.twig', [
|
||||
'activity' => $activity,
|
||||
'stats' => $this->getRepository()->getActivityStatistics($activity)
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -207,7 +226,7 @@ class ActivityController extends AbstractController
|
||||
protected function renderActivityForm(Activity $activity, Request $request)
|
||||
{
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($activity);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Event\CustomerMetaDefinitionEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Form\CustomerEditForm;
|
||||
use App\Form\CustomerTeamPermissionForm;
|
||||
use App\Form\Toolbar\CustomerToolbarForm;
|
||||
@@ -49,10 +51,6 @@ class CustomerController extends AbstractController
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param CustomerRepository $repository
|
||||
* @param FormConfiguration $configuration
|
||||
*/
|
||||
public function __construct(CustomerRepository $repository, FormConfiguration $configuration, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
@@ -93,9 +91,22 @@ class CustomerController extends AbstractController
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'metaColumns' => $this->findMetaColumns($query),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CustomerQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(CustomerQuery $query): array
|
||||
{
|
||||
$event = new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::CUSTOMER);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/create", name="admin_customer_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_customer')")
|
||||
@@ -151,9 +162,13 @@ class CustomerController extends AbstractController
|
||||
*/
|
||||
public function budgetAction(Customer $customer)
|
||||
{
|
||||
$stats = $this->getRepository()->getCustomerStatistics($customer);
|
||||
|
||||
// TODO sent event with stats
|
||||
|
||||
return $this->render('customer/budget.html.twig', [
|
||||
'customer' => $customer,
|
||||
'stats' => $this->getRepository()->getCustomerStatistics($customer)
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -224,7 +239,7 @@ class CustomerController extends AbstractController
|
||||
protected function renderCustomerForm(Customer $customer, Request $request)
|
||||
{
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($customer);
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ class ExportController extends AbstractController
|
||||
$query->getBegin()->setTime(0, 0, 0);
|
||||
$query->getEnd()->setTime(23, 59, 59);
|
||||
|
||||
return $this->timesheetRepository->getTimesheetsForQuery($query);
|
||||
return $this->timesheetRepository->getTimesheetsForQuery($query, true);
|
||||
}
|
||||
|
||||
protected function getToolbarForm(ExportQuery $query, string $method): FormInterface
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Event\ProjectMetaDefinitionEvent;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Form\ProjectEditForm;
|
||||
use App\Form\ProjectTeamPermissionForm;
|
||||
use App\Form\Toolbar\ProjectToolbarForm;
|
||||
@@ -89,9 +91,22 @@ class ProjectController extends AbstractController
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'metaColumns' => $this->findMetaColumns($query),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProjectQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(ProjectQuery $query): array
|
||||
{
|
||||
$event = new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::PROJECT);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/permissions", name="admin_project_permissions", methods={"GET", "POST"})
|
||||
* @Security("is_granted('permissions', project)")
|
||||
@@ -144,9 +159,13 @@ class ProjectController extends AbstractController
|
||||
*/
|
||||
public function budgetAction(Project $project)
|
||||
{
|
||||
$stats = $this->getRepository()->getProjectStatistics($project);
|
||||
|
||||
// TODO sent event with stats
|
||||
|
||||
return $this->render('project/budget.html.twig', [
|
||||
'project' => $project,
|
||||
'stats' => $this->getRepository()->getProjectStatistics($project)
|
||||
'stats' => $stats
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -218,7 +237,7 @@ class ProjectController extends AbstractController
|
||||
protected function renderProjectForm(Project $project, Request $request)
|
||||
{
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($project);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Configuration\TimesheetConfiguration;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDefinitionEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\Toolbar\TimesheetToolbarForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
@@ -81,7 +83,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
protected function index($page, Request $request, string $renderTemplate)
|
||||
protected function index($page, Request $request, string $renderTemplate, string $location): Response
|
||||
{
|
||||
$query = new TimesheetQuery();
|
||||
$query->setPage($page);
|
||||
@@ -122,20 +124,28 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'showSummary' => $this->includeSummary(),
|
||||
'showStartEndTime' => $this->canSeeStartEndTime()
|
||||
'showStartEndTime' => $this->canSeeStartEndTime(),
|
||||
'metaColumns' => $this->findMetaColumns($query, $location),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param Request $request
|
||||
* @param string $renderTemplate
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @param TimesheetQuery $query
|
||||
* @param string $location
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function edit(Timesheet $entry, Request $request, string $renderTemplate)
|
||||
protected function findMetaColumns(TimesheetQuery $query, string $location): array
|
||||
{
|
||||
$event = new TimesheetMetaDisplayEvent($query, $location);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
protected function edit(Timesheet $entry, Request $request, string $renderTemplate): Response
|
||||
{
|
||||
$event = new TimesheetMetaDefinitionEvent($entry);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->getEditForm($entry, $request->get('page'));
|
||||
$editForm->handleRequest($request);
|
||||
@@ -157,14 +167,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $renderTemplate
|
||||
* @param ProjectRepository $projectRepository
|
||||
* @param ActivityRepository $activityRepository
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository)
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository): Response
|
||||
{
|
||||
$entry = new Timesheet();
|
||||
$entry->setUser($this->getUser());
|
||||
@@ -183,7 +186,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
if ($request->query->get('tags')) {
|
||||
$tagNames = explode(',', $request->query->get('tags'));
|
||||
foreach ($tagNames as $tagName) {
|
||||
$tag = $tagRepository->findOneByName($tagName);
|
||||
$tag = $tagRepository->findTagByName($tagName);
|
||||
if (!$tag) {
|
||||
$tag = new Tag();
|
||||
$tag->setName($tagName);
|
||||
@@ -193,7 +196,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($entry);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$mode = $this->getTrackingMode();
|
||||
$mode->create($entry, $request);
|
||||
@@ -224,12 +227,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $renderTemplate
|
||||
* @return Response
|
||||
*/
|
||||
protected function export(Request $request, string $renderTemplate)
|
||||
protected function export(Request $request, string $renderTemplate, string $location): Response
|
||||
{
|
||||
$query = new TimesheetQuery();
|
||||
|
||||
@@ -257,6 +255,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
return $this->render($renderTemplate, [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'metaColumns' => $this->findMetaColumns($query, $location),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TagRepository;
|
||||
@@ -34,7 +35,7 @@ class TimesheetController extends TimesheetAbstractController
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
return $this->index($page, $request, 'timesheet/index.html.twig');
|
||||
return $this->index($page, $request, 'timesheet/index.html.twig', TimesheetMetaDisplayEvent::TIMESHEET);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,7 @@ class TimesheetController extends TimesheetAbstractController
|
||||
*/
|
||||
public function exportAction(Request $request)
|
||||
{
|
||||
return $this->export($request, 'timesheet/export.html.twig');
|
||||
return $this->export($request, 'timesheet/export.html.twig', TimesheetMetaDisplayEvent::TIMESHEET_EXPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Form\TimesheetAdminEditForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
@@ -36,7 +37,7 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
return $this->index($page, $request, 'timesheet-team/index.html.twig');
|
||||
return $this->index($page, $request, 'timesheet-team/index.html.twig', TimesheetMetaDisplayEvent::TEAM_TIMESHEET);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +48,7 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
*/
|
||||
public function exportAction(Request $request)
|
||||
{
|
||||
return $this->export($request, 'timesheet-team/export.html.twig');
|
||||
return $this->export($request, 'timesheet-team/export.html.twig', TimesheetMetaDisplayEvent::TEAM_TIMESHEET_EXPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use App\Form\Toolbar\UserToolbarForm;
|
||||
use App\Form\UserCreateType;
|
||||
use App\Repository\Query\UserQuery;
|
||||
@@ -18,6 +19,7 @@ use App\Repository\UserRepository;
|
||||
use App\Security\RolePermissionManager;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
@@ -38,11 +40,16 @@ class UserController extends AbstractController
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $repository;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(UserPasswordEncoderInterface $encoder, UserRepository $repository)
|
||||
public function __construct(UserPasswordEncoderInterface $encoder, UserRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->encoder = $encoder;
|
||||
$this->repository = $repository;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,10 +85,14 @@ class UserController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
$event = new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::USERS);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $this->render('user/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'preferences' => $event->getPreferences(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ class Activity implements EntityWithMetaFields
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ class Customer implements EntityWithMetaFields
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,4 +148,19 @@ interface MetaTableTypeInterface
|
||||
* @return MetaTableTypeInterface
|
||||
*/
|
||||
public function setLabel(string $label): MetaTableTypeInterface;
|
||||
|
||||
/**
|
||||
* Set an array of options for the FormType.
|
||||
*
|
||||
* @param array $options
|
||||
* @return MetaTableTypeInterface
|
||||
*/
|
||||
public function setOptions(array $options): MetaTableTypeInterface;
|
||||
|
||||
/**
|
||||
* Returns an array with options for the FormType.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,12 @@ trait MetaTableTypeTrait
|
||||
*/
|
||||
private $constraints = [];
|
||||
|
||||
/**
|
||||
* An array of options for the form element
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
if (null === $this->name) {
|
||||
@@ -183,7 +189,10 @@ trait MetaTableTypeTrait
|
||||
->setType($meta->getType())
|
||||
->setConstraints($meta->getConstraints())
|
||||
->setIsRequired($meta->isRequired())
|
||||
->setIsVisible($meta->isVisible());
|
||||
->setIsVisible($meta->isVisible())
|
||||
->setLabel($meta->getLabel())
|
||||
->setOptions($meta->getOptions())
|
||||
;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -203,4 +212,16 @@ trait MetaTableTypeTrait
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptions(array $options): MetaTableTypeInterface
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class Project implements EntityWithMetaFields
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ class Timesheet implements EntityWithMetaFields, InvoiceItemInterface
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Form\Type\YesNoType;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
@@ -96,18 +97,11 @@ class UserPreference
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setUser(User $user): UserPreference
|
||||
{
|
||||
$this->user = $user;
|
||||
@@ -115,18 +109,11 @@ class UserPreference
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setName(string $name): UserPreference
|
||||
{
|
||||
$this->name = $name;
|
||||
@@ -140,6 +127,7 @@ class UserPreference
|
||||
public function getValue()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case YesNoType::class:
|
||||
case CheckboxType::class:
|
||||
return (bool) $this->value;
|
||||
case IntegerType::class:
|
||||
@@ -169,34 +157,24 @@ class UserPreference
|
||||
* @param string $type
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setType(string $type)
|
||||
public function setType(string $type): UserPreference
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setEnabled(bool $enabled)
|
||||
public function setEnabled(bool $enabled): UserPreference
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
@@ -259,4 +237,13 @@ class UserPreference
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
if (isset($this->options['label'])) {
|
||||
return $this->options['label'];
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ final class ActivityMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Activity
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Activity $entity)
|
||||
{
|
||||
|
||||
76
src/Event/ActivityMetaDisplayEvent.php
Normal file
76
src/Event/ActivityMetaDisplayEvent.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a activity query.
|
||||
*/
|
||||
final class ActivityMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const ACTIVITY = 'activity';
|
||||
|
||||
/**
|
||||
* @var ActivityQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(ActivityQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return ActivityQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class CustomerMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Customer
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Customer $entity)
|
||||
{
|
||||
|
||||
76
src/Event/CustomerMetaDisplayEvent.php
Normal file
76
src/Event/CustomerMetaDisplayEvent.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a customer query.
|
||||
*/
|
||||
final class CustomerMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const CUSTOMER = 'customer';
|
||||
|
||||
/**
|
||||
* @var CustomerQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(CustomerQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return CustomerQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
42
src/Event/MetaDisplayEventInterface.php
Normal file
42
src/Event/MetaDisplayEventInterface.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
|
||||
interface MetaDisplayEventInterface
|
||||
{
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return BaseQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery;
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string;
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array;
|
||||
|
||||
/**
|
||||
* Adds a field that should be displayed.
|
||||
*
|
||||
* @param MetaTableTypeInterface $meta
|
||||
*/
|
||||
public function addField(MetaTableTypeInterface $meta);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class ProjectMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Project
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Project $entity)
|
||||
{
|
||||
|
||||
76
src/Event/ProjectMetaDisplayEvent.php
Normal file
76
src/Event/ProjectMetaDisplayEvent.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a project query.
|
||||
*/
|
||||
final class ProjectMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const PROJECT = 'project';
|
||||
|
||||
/**
|
||||
* @var ProjectQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(ProjectQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return ProjectQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class TimesheetMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Timesheet
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Timesheet $entity)
|
||||
{
|
||||
|
||||
79
src/Event/TimesheetMetaDisplayEvent.php
Normal file
79
src/Event/TimesheetMetaDisplayEvent.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a timesheet query.
|
||||
*/
|
||||
final class TimesheetMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const TIMESHEET = 'timesheet';
|
||||
public const TEAM_TIMESHEET = 'team-timesheet';
|
||||
public const TIMESHEET_EXPORT = 'timesheet-export';
|
||||
public const TEAM_TIMESHEET_EXPORT = 'team-timesheet-export';
|
||||
|
||||
/**
|
||||
* @var TimesheetQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(TimesheetQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return TimesheetQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
59
src/Event/UserPreferenceDisplayEvent.php
Normal file
59
src/Event/UserPreferenceDisplayEvent.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Event;
|
||||
|
||||
use App\Entity\UserPreference;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible user preferences to display.
|
||||
*/
|
||||
final class UserPreferenceDisplayEvent extends Event
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const USERS = 'users';
|
||||
|
||||
/**
|
||||
* @var UserPreference[]
|
||||
*/
|
||||
protected $preferences = [];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
|
||||
public function __construct(string $location)
|
||||
{
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserPreference[]
|
||||
*/
|
||||
public function getPreferences(): array
|
||||
{
|
||||
return $this->preferences;
|
||||
}
|
||||
|
||||
public function addPreference(UserPreference $preference)
|
||||
{
|
||||
$this->preferences[] = $preference;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where the preference will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ final class UserPreferenceEvent extends Event
|
||||
public function addUserPreference(UserPreference $preference)
|
||||
{
|
||||
foreach ($this->preferences as $pref) {
|
||||
if ($pref->getName() == $preference->getName()) {
|
||||
if (strtolower($pref->getName()) === strtolower($preference->getName())) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Cannot add preference, one with the name "' . $preference->getName() . '" is already existing'
|
||||
);
|
||||
|
||||
@@ -9,7 +9,14 @@
|
||||
|
||||
namespace App\Export\Renderer;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Twig\DateExtensions;
|
||||
use DateTime;
|
||||
@@ -18,6 +25,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
@@ -40,11 +48,16 @@ abstract class AbstractSpreadsheetRenderer
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, DateExtensions $dateExtension)
|
||||
public function __construct(TranslatorInterface $translator, DateExtensions $dateExtension, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->dateExtension = $dateExtension;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
protected function setFormattedDateTime(Worksheet $sheet, $column, $row, ?DateTime $date)
|
||||
@@ -109,6 +122,17 @@ abstract class AbstractSpreadsheetRenderer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MetaDisplayEventInterface $event
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(MetaDisplayEventInterface $event): array
|
||||
{
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet[] $timesheets
|
||||
* @param TimesheetQuery $query
|
||||
@@ -117,14 +141,14 @@ abstract class AbstractSpreadsheetRenderer
|
||||
*/
|
||||
protected function fromArrayToSpreadsheet(array $timesheets, TimesheetQuery $query): Spreadsheet
|
||||
{
|
||||
$publicMetaFields = [];
|
||||
foreach ($timesheets as $timesheet) {
|
||||
foreach ($timesheet->getVisibleMetaFields() as $metaField) {
|
||||
$publicMetaFields[] = $metaField->getName();
|
||||
}
|
||||
}
|
||||
$timesheetMetaFields = $this->findMetaColumns(new TimesheetMetaDisplayEvent($query, TimesheetMetaDisplayEvent::EXPORT));
|
||||
$customerMetaFields = $this->findMetaColumns(new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::EXPORT));
|
||||
$projectMetaFields = $this->findMetaColumns(new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::EXPORT));
|
||||
$activityMetaFields = $this->findMetaColumns(new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::EXPORT));
|
||||
|
||||
$publicMetaFields = array_unique($publicMetaFields);
|
||||
$event = new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::EXPORT);
|
||||
$this->dispatcher->dispatch($event);
|
||||
$userPreferences = $event->getPreferences();
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
@@ -146,8 +170,20 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.tags'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.hourlyRate'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.fixedRate'));
|
||||
foreach ($publicMetaFields as $metaFieldName) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaFieldName));
|
||||
foreach ($timesheetMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($customerMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($projectMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($activityMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($userPreferences as $preference) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($preference->getLabel()));
|
||||
}
|
||||
|
||||
$entryHeaderRow = $recordsHeaderRow + 1;
|
||||
@@ -205,10 +241,42 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$this->setRate($sheet, $entryHeaderColumn, $entryHeaderRow, $timesheet->getFixedRate(), $customerCurrency);
|
||||
$entryHeaderColumn++;
|
||||
|
||||
foreach ($publicMetaFields as $metaFieldName) {
|
||||
$metaField = $timesheet->getMetaField($metaFieldName);
|
||||
foreach ($timesheetMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField && $metaField->isVisible()) {
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($customerMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getProject()->getCustomer()->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($projectMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getProject()->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($activityMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getActivity()->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($userPreferences as $preference) {
|
||||
$metaField = $timesheet->getUser()->getPreference($preference->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
|
||||
@@ -9,9 +9,17 @@
|
||||
|
||||
namespace App\Export\Renderer;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use App\Export\RendererInterface;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Twig\Environment;
|
||||
|
||||
@@ -23,10 +31,26 @@ final class HtmlRenderer implements RendererInterface
|
||||
* @var Environment
|
||||
*/
|
||||
protected $twig;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(Environment $twig)
|
||||
public function __construct(Environment $twig, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MetaDisplayEventInterface $event
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(MetaDisplayEventInterface $event): array
|
||||
{
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,18 +63,24 @@ final class HtmlRenderer implements RendererInterface
|
||||
*/
|
||||
public function render(array $timesheets, TimesheetQuery $query): Response
|
||||
{
|
||||
$publicMetaFields = [];
|
||||
foreach ($timesheets as $timesheet) {
|
||||
foreach ($timesheet->getVisibleMetaFields() as $metaField) {
|
||||
$publicMetaFields[] = $metaField->getName();
|
||||
}
|
||||
}
|
||||
$timesheetMetaFields = $this->findMetaColumns(new TimesheetMetaDisplayEvent($query, TimesheetMetaDisplayEvent::EXPORT));
|
||||
$customerMetaFields = $this->findMetaColumns(new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::EXPORT));
|
||||
$projectMetaFields = $this->findMetaColumns(new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::EXPORT));
|
||||
$activityMetaFields = $this->findMetaColumns(new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::EXPORT));
|
||||
|
||||
$event = new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::EXPORT);
|
||||
$this->dispatcher->dispatch($event);
|
||||
$userPreferences = $event->getPreferences();
|
||||
|
||||
$content = $this->twig->render('export/renderer/default.html.twig', [
|
||||
'entries' => $timesheets,
|
||||
'query' => $query,
|
||||
'metaFields' => array_unique($publicMetaFields),
|
||||
'summaries' => $this->calculateSummary($timesheets),
|
||||
'timesheetMetaFields' => $timesheetMetaFields,
|
||||
'customerMetaFields' => $customerMetaFields,
|
||||
'projectMetaFields' => $projectMetaFields,
|
||||
'activityMetaFields' => $activityMetaFields,
|
||||
'userPreferences' => $userPreferences,
|
||||
]);
|
||||
|
||||
$response = new Response();
|
||||
|
||||
@@ -42,11 +42,11 @@ class EntityMetaDefinitionType extends AbstractType
|
||||
return;
|
||||
}
|
||||
|
||||
$event->getForm()->add('value', $definition->getType(), [
|
||||
$event->getForm()->add('value', $definition->getType(), array_merge([
|
||||
'label' => $definition->getLabel(),
|
||||
'constraints' => $definition->getConstraints(),
|
||||
'required' => $definition->isRequired(),
|
||||
]);
|
||||
], $definition->getOptions()));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -19,10 +21,15 @@ final class TimesheetIdLoader implements LoaderInterface
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $fullyHydrated = false;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $hydrateFullTree = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $hydrateFullTree;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,23 +44,45 @@ final class TimesheetIdLoader implements LoaderInterface
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$projects = $qb->select('PARTIAL t.{id}', 'project')
|
||||
$timesheets = $qb->select('PARTIAL t.{id}', 'project')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.project', 'project')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if (!empty($projects)) {
|
||||
$projectIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
$projectIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL p.{id}', 'meta')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$projects = $qb->select('PARTIAL p.{id}', 'customer')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$customerIds = array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL p.{id}', 'customer')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
$qb->select('PARTIAL c.{id}', 'meta')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('c.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
@@ -66,6 +95,20 @@ final class TimesheetIdLoader implements LoaderInterface
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$activityIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getActivity()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'meta')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('a.id', $activityIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'user')
|
||||
->from(Timesheet::class, 't')
|
||||
|
||||
@@ -19,9 +19,9 @@ final class TimesheetLoader implements LoaderInterface
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $hydrateFullTree = false)
|
||||
{
|
||||
$this->loader = new TimesheetIdLoader($entityManager);
|
||||
$this->loader = new TimesheetIdLoader($entityManager, $hydrateFullTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,11 @@ class TagRepository extends EntityRepository
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function findTagByName(string $tagName): ?Tag
|
||||
{
|
||||
return $this->findOneBy(['name' => $tagName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find ids of the given tagNames separated by comma
|
||||
* @param string $tagNames
|
||||
|
||||
@@ -432,12 +432,7 @@ class TimesheetRepository extends EntityRepository
|
||||
$qb->setParameter('user', $user);
|
||||
}
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$loader = new TimesheetLoader($qb->getEntityManager());
|
||||
$loader->loadResults($results);
|
||||
|
||||
return $results;
|
||||
return $this->getHydratedResultsByQuery($qb, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -530,16 +525,33 @@ class TimesheetRepository extends EntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* When switching $fullyHydrated to true, the call gets even more expensive.
|
||||
* You normally don't need this, unless you want to access deeply nested attributes for many entries!
|
||||
*
|
||||
* @param TimesheetQuery $query
|
||||
* @param bool $fullyHydrated
|
||||
* @return Timesheet[]
|
||||
*/
|
||||
public function getTimesheetsForQuery(TimesheetQuery $query): iterable
|
||||
public function getTimesheetsForQuery(TimesheetQuery $query, bool $fullyHydrated = false): iterable
|
||||
{
|
||||
// this is using the paginator internally, as it will load all joined entities into the working unit
|
||||
// do not "optimize" to use the query directly, as it would results in hundreds of additional lazy queries
|
||||
$paginator = $this->getPaginatorForQuery($query);
|
||||
$qb = $this->getQueryBuilderForQuery($query);
|
||||
|
||||
return $paginator->getAll();
|
||||
return $this->getHydratedResultsByQuery($qb, $fullyHydrated);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $qb
|
||||
* @param bool $fullyHydrated
|
||||
* @return Timesheet[]
|
||||
*/
|
||||
protected function getHydratedResultsByQuery(QueryBuilder $qb, bool $fullyHydrated = false): iterable
|
||||
{
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$loader = new TimesheetLoader($qb->getEntityManager(), $fullyHydrated);
|
||||
$loader->loadResults($results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function getQueryBuilderForQuery(TimesheetQuery $query): QueryBuilder
|
||||
@@ -738,12 +750,7 @@ class TimesheetRepository extends EntityRepository
|
||||
->orderBy('t.end', 'DESC')
|
||||
;
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$loader = new TimesheetLoader($qb->getEntityManager());
|
||||
$loader->loadResults($results);
|
||||
|
||||
return $results;
|
||||
return $this->getHydratedResultsByQuery($qb, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,41 +80,53 @@ class DateExtensions extends AbstractExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateShort(DateTime $date)
|
||||
public function dateShort($date)
|
||||
{
|
||||
if (null === $this->dateFormat) {
|
||||
$this->dateFormat = $this->localeSettings->getDateFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateTime(DateTime $date)
|
||||
public function dateTime($date)
|
||||
{
|
||||
if (null === $this->dateTimeFormat) {
|
||||
$this->dateTimeFormat = $this->localeSettings->getDateTimeFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->dateTimeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateTimeFull(DateTime $date)
|
||||
public function dateTimeFull($date)
|
||||
{
|
||||
if (null === $this->dateTimeTypeFormat) {
|
||||
$this->dateTimeTypeFormat = $this->localeSettings->getDateTimeTypeFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
$formatter = new \IntlDateFormatter(
|
||||
$this->localeSettings->getLocale(),
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
@@ -128,25 +140,33 @@ class DateExtensions extends AbstractExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @param string $format
|
||||
* @return false|string
|
||||
*/
|
||||
public function dateFormat(DateTime $date, string $format)
|
||||
public function dateFormat($date, string $format)
|
||||
{
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function time(DateTime $date)
|
||||
public function time($date)
|
||||
{
|
||||
if (null === $this->timeFormat) {
|
||||
$this->timeFormat = $this->localeSettings->getTimeFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->timeFormat);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use App\Utils\LocaleSettings;
|
||||
use NumberFormatter;
|
||||
use Symfony\Component\Intl\Countries;
|
||||
use Symfony\Component\Intl\Currencies;
|
||||
use Symfony\Component\Intl\Languages;
|
||||
use Symfony\Component\Intl\Locales;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
@@ -67,6 +68,7 @@ class Extensions extends AbstractExtension
|
||||
new TwigFilter('money', [$this, 'money']),
|
||||
new TwigFilter('currency', [$this, 'currency']),
|
||||
new TwigFilter('country', [$this, 'country']),
|
||||
new TwigFilter('language', [$this, 'language']),
|
||||
new TwigFilter('docu_link', [$this, 'documentationLink']),
|
||||
];
|
||||
}
|
||||
@@ -162,6 +164,15 @@ class Extensions extends AbstractExtension
|
||||
return Currencies::getSymbol($currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $language
|
||||
* @return string
|
||||
*/
|
||||
public function language($language)
|
||||
{
|
||||
return Languages::getName($language, $this->locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $country
|
||||
* @return string
|
||||
|
||||
Reference in New Issue
Block a user