diff --git a/.github/lock.yml b/.github/lock.yml index aa70e6e8..a9888ed5 100644 --- a/.github/lock.yml +++ b/.github/lock.yml @@ -14,6 +14,8 @@ lockComment: > This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. + If you use Kimai on a daily basis, please [consider donating](https://www.kimai.org/donate/) to + support further development of Kimai. # Assign `resolved` as the reason for locking. Set to `false` to disable setLockReason: false diff --git a/src/Form/TimesheetEditForm.php b/src/Form/TimesheetEditForm.php index 94d20158..554ac2aa 100644 --- a/src/Form/TimesheetEditForm.php +++ b/src/Form/TimesheetEditForm.php @@ -32,6 +32,26 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ class TimesheetEditForm extends AbstractType { + + /** + * @var CustomerRepository + */ + private $customers; + /** + * @var ProjectRepository + */ + private $projects; + + /** + * @param CustomerRepository $customer + * @param ProjectRepository $project + */ + public function __construct(CustomerRepository $customer, ProjectRepository $project) + { + $this->customers = $customer; + $this->projects = $project; + } + /** * {@inheritdoc} */ @@ -82,34 +102,45 @@ class TimesheetEditForm extends AbstractType ]); } + $projectOptions = []; + + if ($this->customers->countCustomer(true) > 1) { + $builder + ->add('customer', CustomerType::class, [ + // documentation is for NelmioApiDocBundle + 'documentation' => [ + 'type' => 'integer', + 'description' => 'Customer ID', + ], + 'query_builder' => function (CustomerRepository $repo) use ($customer) { + return $repo->builderForEntityType($customer); + }, + 'data' => $customer ? $customer : '', + 'required' => false, + 'mapped' => false, + 'attr' => [ + 'data-related-select' => $this->getBlockPrefix() . '_project', + 'data-api-url' => ['get_projects', ['customer' => '-s-']], + ], + ]); + } else { + $projectOptions['group_by'] = null; + } + + if ($this->projects->countProject(true) > 1) { + $projectOptions['placeholder'] = null; + } else { + $projectOptions['group_by'] = null; + } + $builder - ->add('customer', CustomerType::class, [ - // documentation is for NelmioApiDocBundle - 'documentation' => [ - 'type' => 'integer', - 'description' => 'Customer ID', - ], - 'label' => 'label.customer', - 'query_builder' => function (CustomerRepository $repo) use ($customer) { - return $repo->builderForEntityType($customer); - }, - 'data' => $customer ? $customer : '', - 'required' => false, - 'mapped' => false, - 'attr' => [ - 'data-related-select' => $this->getBlockPrefix() . '_project', - 'data-api-url' => ['get_projects', ['customer' => '-s-']], - ], - ]) - ->add('project', ProjectType::class, [ + ->add('project', ProjectType::class, array_merge($projectOptions, [ // documentation is for NelmioApiDocBundle 'documentation' => [ 'type' => 'integer', 'description' => 'Project ID', ], 'required' => true, - 'placeholder' => '', - 'label' => 'label.project', 'query_builder' => function (ProjectRepository $repo) use ($project) { return $repo->builderForEntityType($project); }, @@ -117,14 +148,15 @@ class TimesheetEditForm extends AbstractType 'data-related-select' => $this->getBlockPrefix() . '_activity', 'data-api-url' => ['get_activities', ['project' => '-s-']], ], - ]) + ])); + + $builder ->add('activity', ActivityType::class, [ // documentation is for NelmioApiDocBundle 'documentation' => [ 'type' => 'integer', 'description' => 'Activity ID', ], - 'label' => 'label.activity', 'query_builder' => function (ActivityRepository $repo) use ($activity) { return $repo->builderForEntityType($activity); }, diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php index b9c88322..cb252e84 100644 --- a/src/Repository/CustomerRepository.php +++ b/src/Repository/CustomerRepository.php @@ -35,10 +35,15 @@ class CustomerRepository extends AbstractRepository } /** + * @param null|bool $visible * @return int */ - public function countCustomer() + public function countCustomer($visible = null) { + if (null !== $visible) { + return $this->count(['visible' => (int) $visible]); + } + return $this->count([]); } diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index 9d5a1ae8..053efe85 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -35,10 +35,15 @@ class ProjectRepository extends AbstractRepository } /** + * @param null|bool $visible * @return int */ - public function countProject() + public function countProject($visible = null) { + if (null !== $visible) { + return $this->count(['visible' => (int) $visible]); + } + return $this->count([]); }