refactored repositories and DB queries (#5026)
* removed unused teams from export order * added new paginator for query instead of querybuilder * added field hydrate enums * hide PARTIAL deprecation * never log deprecations in production * replaced InvoiceLoader with native Doctrine feature * prevent excessive permission queries * support loading customers of team * improved findByIds * internalized API * fix null string deprecations
This commit is contained in:
@@ -9,17 +9,17 @@
|
||||
|
||||
namespace App\Widget\Type;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Team;
|
||||
use App\Project\ProjectStatisticService;
|
||||
use App\Repository\Loader\ProjectLoader;
|
||||
use App\Repository\Loader\TeamLoader;
|
||||
use App\Widget\WidgetInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class UserTeamProjects extends AbstractWidget
|
||||
{
|
||||
public function __construct(private ProjectStatisticService $statisticService, private EntityManagerInterface $entityManager)
|
||||
public function __construct(
|
||||
private readonly ProjectStatisticService $statisticService,
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -65,34 +65,23 @@ final class UserTeamProjects extends AbstractWidget
|
||||
public function getData(array $options = []): mixed
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$teams = $user->getTeams();
|
||||
$now = new \DateTime('now', new \DateTimeZone($user->getTimezone()));
|
||||
|
||||
$loader = new TeamLoader($this->entityManager);
|
||||
$loader->loadResults($user->getTeams());
|
||||
$loader = new TeamLoader($this->entityManager, true);
|
||||
$loader->loadResults($teams);
|
||||
|
||||
$teamProjects = [];
|
||||
$projects = [];
|
||||
|
||||
/** @var Team $team */
|
||||
foreach ($user->getTeams() as $team) {
|
||||
/** @var Project $project */
|
||||
foreach ($teams as $team) {
|
||||
foreach ($team->getProjects() as $project) {
|
||||
if (!isset($teamProjects[$project->getId()])) {
|
||||
$teamProjects[$project->getId()] = $project;
|
||||
if (!$project->isVisibleAtDate($now) || !$project->hasBudgets()) {
|
||||
continue;
|
||||
}
|
||||
$projects[$project->getId()] = $project;
|
||||
}
|
||||
}
|
||||
|
||||
$loader = new ProjectLoader($this->entityManager, false, false, false);
|
||||
$loader->loadResults($teamProjects);
|
||||
|
||||
foreach ($teamProjects as $id => $project) {
|
||||
if (!$project->isVisibleAtDate($now) || !$project->hasBudgets()) {
|
||||
continue;
|
||||
}
|
||||
$projects[$project->getId()] = $project;
|
||||
}
|
||||
|
||||
return $this->statisticService->getBudgetStatisticModelForProjects($projects, $now);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,10 @@
|
||||
|
||||
namespace App\Widget\Type;
|
||||
|
||||
use App\Repository\Loader\UserLoader;
|
||||
use App\Widget\WidgetInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class UserTeams extends AbstractWidget
|
||||
{
|
||||
public function __construct(private EntityManagerInterface $entityManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function getWidth(): int
|
||||
{
|
||||
return WidgetInterface::WIDTH_HALF;
|
||||
@@ -57,12 +51,6 @@ final class UserTeams extends AbstractWidget
|
||||
*/
|
||||
public function getData(array $options = []): mixed
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
// without this, every user would be lazy loaded
|
||||
$loader = new UserLoader($this->entityManager, true);
|
||||
$loader->loadResults([$user->getId()]);
|
||||
|
||||
return $user->getTeams();
|
||||
return $this->getUser()->getTeams();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user