Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -13,17 +13,14 @@ use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class MultiUpdateTable extends AbstractType
|
||||
final class MultiUpdateTable extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var EntityRepository $repository */
|
||||
$repository = $options['repository'];
|
||||
@@ -36,7 +33,7 @@ class MultiUpdateTable extends AbstractType
|
||||
|
||||
$builder->get('entities')->addModelTransformer(
|
||||
new CallbackTransformer(
|
||||
function ($ids) {
|
||||
function ($ids): string {
|
||||
return implode(',', $ids);
|
||||
},
|
||||
function ($ids) use ($repository) {
|
||||
@@ -49,18 +46,22 @@ class MultiUpdateTable extends AbstractType
|
||||
)
|
||||
);
|
||||
|
||||
$builder->add('action', ChoiceType::class, [
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'choices' => $dto->getActions(),
|
||||
'search' => false,
|
||||
]);
|
||||
$i = 0;
|
||||
foreach ($dto->getActions() as $key => $value) {
|
||||
if (empty($key) || empty($value)) {
|
||||
continue;
|
||||
}
|
||||
$builder->add('action_' . $i++, ButtonType::class, [
|
||||
'label' => $key,
|
||||
'attr' => [
|
||||
'data-href' => $value,
|
||||
'class' => 'multi_update_table_action' . (stripos($key, 'delete') !== false ? ' btn-danger' : ''),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefined(['repository']);
|
||||
$resolver->setAllowedTypes('repository', EntityRepository::class);
|
||||
|
||||
@@ -9,34 +9,33 @@
|
||||
|
||||
namespace App\Form\MultiUpdate;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
class MultiUpdateTableDTO
|
||||
{
|
||||
/**
|
||||
* @var object[]
|
||||
* @var iterable<object>|Collection<object>
|
||||
*/
|
||||
private $entities = [];
|
||||
private iterable|Collection $entities = [];
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $actions = ['' => ''];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $action = null;
|
||||
private array $actions = ['' => ''];
|
||||
private ?string $action = null;
|
||||
|
||||
/**
|
||||
* @return object[]
|
||||
*/
|
||||
public function getEntities(): iterable
|
||||
public function getEntities(): iterable|Collection
|
||||
{
|
||||
return $this->entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object[] $entities
|
||||
* @param iterable<object>|Collection<object> $entities
|
||||
* @return MultiUpdateTableDTO
|
||||
*/
|
||||
public function setEntities(iterable $entities): MultiUpdateTableDTO
|
||||
public function setEntities(iterable|Collection $entities): MultiUpdateTableDTO
|
||||
{
|
||||
$this->entities = $entities;
|
||||
|
||||
@@ -65,7 +64,7 @@ class MultiUpdateTableDTO
|
||||
|
||||
public function addDelete(string $url): MultiUpdateTableDTO
|
||||
{
|
||||
$this->actions['action.delete'] = $url;
|
||||
$this->actions['delete'] = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -30,27 +30,13 @@ use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TimesheetMultiUpdate extends AbstractType
|
||||
final class TimesheetMultiUpdate extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var TimesheetRepository
|
||||
*/
|
||||
private $timesheet;
|
||||
/**
|
||||
* @var CustomerRepository
|
||||
*/
|
||||
private $customers;
|
||||
|
||||
public function __construct(TimesheetRepository $timesheet, CustomerRepository $customer)
|
||||
public function __construct(private TimesheetRepository $timesheet, private CustomerRepository $customers)
|
||||
{
|
||||
$this->timesheet = $timesheet;
|
||||
$this->customers = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$activity = null;
|
||||
$project = null;
|
||||
@@ -65,7 +51,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
|
||||
$activity = $entry->getActivity();
|
||||
$project = $entry->getProject();
|
||||
$customer = null === $project ? null : $project->getCustomer();
|
||||
$customer = $project?->getCustomer();
|
||||
|
||||
if (null === $project && null !== $activity) {
|
||||
$project = $activity->getProject();
|
||||
@@ -80,7 +66,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
->add('customer', CustomerType::class, [
|
||||
'query_builder_for_user' => true,
|
||||
'customers' => $customer,
|
||||
'data' => $customer ? $customer : '',
|
||||
'data' => $customer,
|
||||
'required' => false,
|
||||
'placeholder' => '',
|
||||
'mapped' => false,
|
||||
@@ -156,8 +142,8 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
'required' => true,
|
||||
'expanded' => true,
|
||||
'choices' => [
|
||||
'label.replaceTags' => true,
|
||||
'label.appendTags' => false,
|
||||
'replaceTags' => true,
|
||||
'appendTags' => false,
|
||||
]
|
||||
]);
|
||||
|
||||
@@ -173,7 +159,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
|
||||
if ($options['include_exported']) {
|
||||
$builder->add('exported', ChoiceType::class, [
|
||||
'label' => 'label.mark_as_exported',
|
||||
'label' => 'mark_as_exported',
|
||||
'required' => false,
|
||||
'choices' => [
|
||||
'entryState.exported' => true,
|
||||
@@ -184,7 +170,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
|
||||
if ($options['include_billable']) {
|
||||
$builder->add('billable', ChoiceType::class, [
|
||||
'label' => 'label.billable',
|
||||
'label' => 'billable',
|
||||
'choices' => [
|
||||
'' => null,
|
||||
'yes' => true,
|
||||
@@ -196,7 +182,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
if ($options['include_rate']) {
|
||||
$builder
|
||||
->add('recalculateRates', YesNoType::class, [
|
||||
'label' => 'label.recalculate_rates',
|
||||
'label' => 'recalculate_rates',
|
||||
])
|
||||
->add('fixedRate', FixedRateType::class, [
|
||||
'currency' => $currency,
|
||||
@@ -221,7 +207,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
'choices' => $choices,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'label.batch_meta_fields',
|
||||
'label' => 'batch_meta_fields',
|
||||
'help' => 'help.batch_meta_fields',
|
||||
]);
|
||||
}
|
||||
@@ -232,7 +218,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
|
||||
$builder->get('entities')->addModelTransformer(
|
||||
new CallbackTransformer(
|
||||
function ($timesheets) {
|
||||
function ($timesheets): string {
|
||||
$ids = [];
|
||||
/** @var \App\Entity\Timesheet $timesheet */
|
||||
foreach ($timesheets as $timesheet) {
|
||||
@@ -252,10 +238,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => TimesheetMultiUpdateDTO::class,
|
||||
|
||||
@@ -17,67 +17,38 @@ use App\Entity\Project;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use App\Validator\Constraints as Constraints;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @App\Validator\Constraints\TimesheetMultiUpdate
|
||||
* @internal
|
||||
*/
|
||||
class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO implements EntityWithMetaFields
|
||||
#[Constraints\TimesheetMultiUpdate]
|
||||
final class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO implements EntityWithMetaFields
|
||||
{
|
||||
/**
|
||||
* @var Tag[]|ArrayCollection|iterable
|
||||
* @var iterable<Tag>
|
||||
*/
|
||||
private $tags = [];
|
||||
private iterable $tags = [];
|
||||
private bool $replaceTags = false;
|
||||
private bool $recalculateRates = false;
|
||||
private ?Customer $customer = null;
|
||||
private ?Project $project = null;
|
||||
private ?Activity $activity = null;
|
||||
private ?User $user = null;
|
||||
private ?bool $exported = null;
|
||||
private ?bool $billable = null;
|
||||
private ?float $fixedRate = null;
|
||||
private ?float $hourlyRate = null;
|
||||
/**
|
||||
* @var bool
|
||||
* @var Collection<TimesheetMeta>
|
||||
*/
|
||||
private $replaceTags = false;
|
||||
private Collection $meta;
|
||||
/**
|
||||
* @var bool
|
||||
* @var array<string>
|
||||
*/
|
||||
private $recalculateRates = false;
|
||||
/**
|
||||
* @var Customer|null
|
||||
*/
|
||||
private $customer;
|
||||
/**
|
||||
* @var Project|null
|
||||
*/
|
||||
private $project;
|
||||
/**
|
||||
* @var Activity|null
|
||||
*/
|
||||
private $activity;
|
||||
/**
|
||||
* @var User|null
|
||||
*/
|
||||
private $user;
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private $exported = null;
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private $billable = null;
|
||||
/**
|
||||
* @var float|null
|
||||
*/
|
||||
private $fixedRate = null;
|
||||
/**
|
||||
* @var float|null
|
||||
*/
|
||||
private $hourlyRate = null;
|
||||
/**
|
||||
* @var TimesheetMeta[]|Collection
|
||||
*/
|
||||
private $meta;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $updateMeta = [];
|
||||
private array $updateMeta = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -115,7 +86,7 @@ class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO implements EntityWithM
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tag[]|ArrayCollection|iterable
|
||||
* @return iterable<Tag>
|
||||
*/
|
||||
public function getTags(): iterable
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user