added team filter in timesheet search forms (#3590)

* added team filter in export and invoice search form
* added teams select to timesheet filter
* added team select to report filter
* hide user and team filter if count < 2
This commit is contained in:
Kevin Papst
2022-10-21 16:14:39 +02:00
committed by GitHub
parent 2022fa54d3
commit 14f4530de0
17 changed files with 235 additions and 17 deletions

View File

@@ -0,0 +1,88 @@
<?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\Form\Extension;
use App\Form\Toolbar\ExportToolbarForm;
use App\Form\Toolbar\InvoiceToolbarForm;
use App\Form\Toolbar\InvoiceToolbarSimpleForm;
use App\Form\Toolbar\TimesheetExportToolbarForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Form\Toolbar\UserToolbarForm;
use App\Reporting\MonthlyUserListForm;
use App\Reporting\WeeklyUserListForm;
use App\Reporting\YearlyUserListForm;
use App\User\TeamService;
use App\User\UserService;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
final class ToolbarFormExtension extends AbstractTypeExtension
{
private $userService;
private $teamService;
private $teamNames = ['team', 'teams', 'searchTeams'];
private $userNames = ['user', 'users'];
public function __construct(UserService $userService, TeamService $teamService)
{
$this->userService = $userService;
$this->teamService = $teamService;
}
public static function getExtendedTypes(): iterable
{
return [
InvoiceToolbarForm::class,
InvoiceToolbarSimpleForm::class,
ExportToolbarForm::class,
TimesheetToolbarForm::class,
TimesheetExportToolbarForm::class,
UserToolbarForm::class,
WeeklyUserListForm::class,
MonthlyUserListForm::class,
YearlyUserListForm::class,
];
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$deleteUser = false;
foreach ($this->userNames as $name) {
if ($builder->has($name) && $this->userService->countUser(true) < 2) {
$deleteUser = true;
break;
}
}
if ($deleteUser) {
foreach ($this->userNames as $name) {
if ($builder->has($name)) {
$builder->remove($name);
}
}
}
$deleteTeams = false;
foreach ($this->teamNames as $name) {
if ($builder->has($name) && !$this->teamService->hasTeams()) {
$deleteTeams = true;
break;
}
}
if ($deleteTeams) {
foreach ($this->teamNames as $name) {
if ($builder->has($name)) {
$builder->remove($name);
}
}
}
}
}