support custom fields in timesheet batch update (#2043)
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Form\Type\ActivityType;
|
||||
use App\Form\Type\CustomerType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\MetaFieldsCollectionType;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Form\Type\TagsType;
|
||||
use App\Form\Type\UserType;
|
||||
@@ -60,6 +61,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
$project = null;
|
||||
$customer = null;
|
||||
$currency = null;
|
||||
$entry = null;
|
||||
$customerCount = $this->customers->countCustomer(true);
|
||||
|
||||
if (isset($options['data'])) {
|
||||
@@ -119,6 +121,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
);
|
||||
|
||||
// replaces the project select after submission, to make sure only projects for the selected customer are displayed
|
||||
// TODO replace me with FormTrait
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SUBMIT,
|
||||
function (FormEvent $event) use ($builder, $project, $customer) {
|
||||
@@ -146,12 +149,14 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
'required' => false,
|
||||
'placeholder' => '',
|
||||
'query_builder' => function (ActivityRepository $repo) use ($activity, $project) {
|
||||
// TODO respect user (team permission)
|
||||
return $repo->getQueryBuilderForFormType(new ActivityFormTypeQuery($activity, $project));
|
||||
},
|
||||
])
|
||||
;
|
||||
|
||||
// replaces the activity select after submission, to make sure only activities for the selected project are displayed
|
||||
// TODO replace me with FormTrait
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SUBMIT,
|
||||
function (FormEvent $event) use ($activity) {
|
||||
@@ -164,6 +169,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
'required' => false,
|
||||
'placeholder' => '',
|
||||
'query_builder' => function (ActivityRepository $repo) use ($data, $activity) {
|
||||
// TODO respect user (team permission)
|
||||
return $repo->getQueryBuilderForFormType(new ActivityFormTypeQuery($activity, $data['project']));
|
||||
},
|
||||
]);
|
||||
@@ -215,6 +221,25 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
;
|
||||
}
|
||||
|
||||
// meta fields only if at least one exists
|
||||
if ($entry !== null && $entry->getMetaFields()->count() > 0) {
|
||||
$builder->add('metaFields', MetaFieldsCollectionType::class);
|
||||
|
||||
$choices = [];
|
||||
foreach ($entry->getMetaFields() as $field) {
|
||||
$name = $field->getName();
|
||||
$label = $entry->getMetaField($name)->getLabel();
|
||||
$choices[$label] = $name;
|
||||
}
|
||||
$builder->add('updateMeta', ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'label.batch_meta_fields',
|
||||
'help' => 'help.batch_meta_fields',
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add('entities', HiddenType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
@@ -11,15 +11,19 @@ namespace App\Form\MultiUpdate;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\EntityWithMetaFields;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @App\Validator\Constraints\TimesheetMultiUpdate
|
||||
*/
|
||||
class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO
|
||||
class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO implements EntityWithMetaFields
|
||||
{
|
||||
/**
|
||||
* @var Tag[]|ArrayCollection|iterable
|
||||
@@ -61,6 +65,19 @@ class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO
|
||||
* @var float|null
|
||||
*/
|
||||
private $hourlyRate = null;
|
||||
/**
|
||||
* @var TimesheetMeta[]|Collection
|
||||
*/
|
||||
private $meta;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $updateMeta = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->meta = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getCustomer(): ?Customer
|
||||
{
|
||||
@@ -184,4 +201,52 @@ class TimesheetMultiUpdateDTO extends MultiUpdateTableDTO
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TimesheetMeta[]|Collection
|
||||
*/
|
||||
public function getMetaFields(): Collection
|
||||
{
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
|
||||
{
|
||||
$this->updateMeta[$meta->getName()] = $meta->getName();
|
||||
if (null === ($current = $this->getMetaField($meta->getName()))) {
|
||||
$this->meta->add($meta);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$current->merge($meta);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUpdateMeta(array $names): EntityWithMetaFields
|
||||
{
|
||||
$this->updateMeta = $names;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUpdateMeta(): array
|
||||
{
|
||||
return $this->updateMeta;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user