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:
43
src/User/TeamService.php
Normal file
43
src/User/TeamService.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\User;
|
||||
|
||||
use App\Repository\TeamRepository;
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class TeamService
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
private $cache = [];
|
||||
private $repository;
|
||||
|
||||
public function __construct(TeamRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function countTeams(): int
|
||||
{
|
||||
if (!\array_key_exists('count', $this->cache)) {
|
||||
$this->cache['count'] = $this->repository->count([]);
|
||||
}
|
||||
|
||||
return $this->cache['count'];
|
||||
}
|
||||
|
||||
public function hasTeams(): bool
|
||||
{
|
||||
return $this->countTeams() > 0;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,11 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
*/
|
||||
class UserService
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
private $cache = [];
|
||||
|
||||
private $repository;
|
||||
private $dispatcher;
|
||||
private $validator;
|
||||
@@ -44,6 +49,17 @@ class UserService
|
||||
$this->encoderFactory = $encoderFactory;
|
||||
}
|
||||
|
||||
public function countUser(?bool $enabled = null): int
|
||||
{
|
||||
$key = 'count' . ($enabled === null ? '_all' : ($enabled ? '_visible' : '_invisible'));
|
||||
|
||||
if (!\array_key_exists($key, $this->cache)) {
|
||||
$this->cache[$key] = $this->repository->countUser($enabled);
|
||||
}
|
||||
|
||||
return $this->cache[$key];
|
||||
}
|
||||
|
||||
public function createNewUser(): User
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
Reference in New Issue
Block a user