Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -1,135 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ActivityIdLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function loadResults(array $ids): void
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Activity[] $activities */
|
||||
$activities = $qb->select('PARTIAL a.{id}', 'project')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.project', 'project')
|
||||
->andWhere($qb->expr()->isNotNull('a.project'))
|
||||
->andWhere($qb->expr()->in('a.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'meta')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('a.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// global activities don't have projects
|
||||
if (!empty($activities)) {
|
||||
$projectIds = array_unique(array_map(function (Activity $activity) {
|
||||
if (null === $activity->getProject()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $activity->getProject()->getId();
|
||||
}, $activities));
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'customer')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('project.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$customerIds = array_unique(array_map(function (Activity $activity) {
|
||||
if (null === $activity->getProject()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $activity->getProject()->getCustomer()->getId();
|
||||
}, $activities));
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'teams')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('project.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL customer.{id}', 'teams')
|
||||
->from(Customer::class, 'customer')
|
||||
->leftJoin('customer.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('customer.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'teams')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('a.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($activities as $activity) {
|
||||
foreach ($activity->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,29 +10,126 @@
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class ActivityLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
public function __construct(private EntityManagerInterface $entityManager, private bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity[] $activities
|
||||
* @param array<int|Activity> $results
|
||||
*/
|
||||
public function loadResults(array $activities): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (Activity $activity) {
|
||||
return $activity->getId();
|
||||
}, $activities);
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader = new ActivityIdLoader($this->entityManager, $this->fullyHydrated);
|
||||
$loader->loadResults($ids);
|
||||
$ids = array_map(function ($activity) {
|
||||
if ($activity instanceof Activity) {
|
||||
return $activity->getId();
|
||||
}
|
||||
|
||||
return $activity;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Activity[] $activities */
|
||||
$activities = $qb->select('PARTIAL a.{id}', 'project')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.project', 'project')
|
||||
->andWhere($qb->expr()->isNotNull('a.project'))
|
||||
->andWhere($qb->expr()->in('a.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'meta')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('a.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// global activities don't have projects
|
||||
if (!empty($activities)) {
|
||||
$projectIds = array_unique(array_map(function (Activity $activity) {
|
||||
if (null === $activity->getProject()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $activity->getProject()->getId();
|
||||
}, $activities));
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'customer')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('project.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$customerIds = array_unique(array_map(function (Activity $activity) {
|
||||
if (null === $activity->getProject()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $activity->getProject()->getCustomer()->getId();
|
||||
}, $activities));
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'teams')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('project.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL customer.{id}', 'teams')
|
||||
->from(Customer::class, 'customer')
|
||||
->leftJoin('customer.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('customer.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'teams')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('a.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($activities as $activity) {
|
||||
foreach ($activity->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CustomerIdLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function loadResults(array $ids): void
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Customer[] $customers */
|
||||
$customers = $qb->select('PARTIAL c.{id}', 'meta')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('c.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL c.{id}', 'teams')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('c.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($customers as $customer) {
|
||||
foreach ($customer->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,29 +10,72 @@
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class CustomerLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
public function __construct(private EntityManagerInterface $entityManager, private bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer[] $customers
|
||||
* @param array<int|Customer> $results
|
||||
*/
|
||||
public function loadResults(array $customers): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (Customer $customer) {
|
||||
return $customer->getId();
|
||||
}, $customers);
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader = new CustomerIdLoader($this->entityManager, $this->fullyHydrated);
|
||||
$loader->loadResults($ids);
|
||||
$ids = array_map(function ($customer) {
|
||||
if ($customer instanceof Customer) {
|
||||
return $customer->getId();
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Customer[] $customers */
|
||||
$customers = $qb->select('PARTIAL c.{id}', 'meta')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('c.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL c.{id}', 'teams')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('c.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($customers as $customer) {
|
||||
foreach ($customer->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ namespace App\Repository\Loader;
|
||||
|
||||
final class DefaultLoader implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* @param array $results
|
||||
*/
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
// nothing to do here, the results are already fully populated
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Invoice;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvoiceIdLoader implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function loadResults(array $ids): void
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL i.{id}', 'customer')
|
||||
->from(Invoice::class, 'i')
|
||||
->leftJoin('i.customer', 'customer')
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL i.{id}', 'user')
|
||||
->from(Invoice::class, 'i')
|
||||
->leftJoin('i.user', 'user')
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL i.{id}', 'meta')
|
||||
->from(Invoice::class, 'i')
|
||||
->leftJoin('i.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('i.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
@@ -14,23 +14,49 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class InvoiceLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(private EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice[] $invoices
|
||||
* @param array<int|Invoice> $results
|
||||
*/
|
||||
public function loadResults(array $invoices): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (Invoice $invoice) {
|
||||
return $invoice->getId();
|
||||
}, $invoices);
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader = new InvoiceIdLoader($this->entityManager);
|
||||
$loader->loadResults($ids);
|
||||
$ids = array_map(function ($invoice) {
|
||||
if ($invoice instanceof Invoice) {
|
||||
return $invoice->getId();
|
||||
}
|
||||
|
||||
return $invoice;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL i.{id}', 'customer')
|
||||
->from(Invoice::class, 'i')
|
||||
->leftJoin('i.customer', 'customer')
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL i.{id}', 'user')
|
||||
->from(Invoice::class, 'i')
|
||||
->leftJoin('i.user', 'user')
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL i.{id}', 'meta')
|
||||
->from(Invoice::class, 'i')
|
||||
->leftJoin('i.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('i.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace App\Repository\Loader;
|
||||
interface LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Prepares the given database results, so no lazy loading will be performed.
|
||||
* Prepares the given database results, to prevent lazy loading.
|
||||
*
|
||||
* @param array $results
|
||||
*/
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ProjectIdLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function loadResults(array $ids): void
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Project[] $projects */
|
||||
$projects = $qb->select('PARTIAL project.{id}', 'customer')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('project.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'meta')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('project.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'teams')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('project.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$customerIds = array_unique(array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects));
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL customer.{id}', 'teams')
|
||||
->from(Customer::class, 'customer')
|
||||
->leftJoin('customer.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('customer.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($projects as $project) {
|
||||
foreach ($project->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,30 +9,98 @@
|
||||
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class ProjectLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
public function __construct(private EntityManagerInterface $entityManager, private bool $hydrateTeamMembers = false, private bool $hydrateTeams = true, private bool $hydrateMeta = true)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project[] $projects
|
||||
* @param array<int|Project> $results
|
||||
*/
|
||||
public function loadResults(array $projects): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (Project $project) {
|
||||
return $project->getId();
|
||||
}, $projects);
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader = new ProjectIdLoader($this->entityManager, $this->fullyHydrated);
|
||||
$loader->loadResults($ids);
|
||||
$ids = array_map(function ($project) {
|
||||
if ($project instanceof Project) {
|
||||
return $project->getId();
|
||||
}
|
||||
|
||||
return $project;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Project[] $projects */
|
||||
$projects = $qb->select('PARTIAL project.{id}', 'customer')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('project.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$customerIds = array_unique(array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects));
|
||||
|
||||
if ($this->hydrateMeta) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'meta')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('project.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
if ($this->hydrateTeams) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL project.{id}', 'teams')
|
||||
->from(Project::class, 'project')
|
||||
->leftJoin('project.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('project.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL customer.{id}', 'teams')
|
||||
->from(Customer::class, 'customer')
|
||||
->leftJoin('customer.teams', 'teams')
|
||||
->andWhere($qb->expr()->in('customer.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->hydrateTeamMembers) {
|
||||
$teamIds = [];
|
||||
foreach ($projects as $project) {
|
||||
foreach ($project->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Team;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TeamIdLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $teamIds
|
||||
*/
|
||||
public function loadResults(array $teamIds): void
|
||||
{
|
||||
if (empty($teamIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'projects')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.projects', 'projects')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
@@ -14,23 +14,44 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class TeamLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(private EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Team[] $teams
|
||||
* @param array<int|Team> $results
|
||||
*/
|
||||
public function loadResults(array $teams): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (Team $team) {
|
||||
return $team->getId();
|
||||
}, $teams);
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader = new TeamIdLoader($this->entityManager);
|
||||
$loader->loadResults($ids);
|
||||
$ids = array_map(function ($team) {
|
||||
if ($team instanceof Team) {
|
||||
return $team->getId();
|
||||
}
|
||||
|
||||
return $team;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL team.{id}', 'projects')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.projects', 'projects')
|
||||
->andWhere($qb->expr()->in('team.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TimesheetIdLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function loadResults(array $ids): void
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$timesheets = $qb->select('PARTIAL t.{id}', 'project')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.project', 'project')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$projectIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL p.{id}', 'meta')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$projects = $qb->select('PARTIAL p.{id}', 'customer')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$customerIds = array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL c.{id}', 'meta')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('c.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'activity')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.activity', 'activity')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$activityIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getActivity()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'meta')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('a.id', $activityIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'user')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.user', 'user')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'tags')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.tags', 'tags')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'meta')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
@@ -9,30 +9,129 @@
|
||||
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class TimesheetLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
public function __construct(private EntityManagerInterface $entityManager, private bool $fullyHydrated = false, private bool $basicHydrated = true)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet[] $timesheets
|
||||
* @param array<int|Timesheet> $results
|
||||
*/
|
||||
public function loadResults(array $timesheets): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getId();
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ids = array_map(function ($timesheet) {
|
||||
if ($timesheet instanceof Timesheet) {
|
||||
return $timesheet->getId();
|
||||
}
|
||||
|
||||
return $timesheet;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$timesheets = $qb->select('PARTIAL t.{id}', 'project')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.project', 'project')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$projectIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
$loader = new TimesheetIdLoader($this->entityManager, $this->fullyHydrated);
|
||||
$loader->loadResults($ids);
|
||||
if ($this->fullyHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL p.{id}', 'meta')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$projects = $qb->select('PARTIAL p.{id}', 'customer')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$customerIds = array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL c.{id}', 'meta')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('c.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'activity')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.activity', 'activity')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$activityIds = array_filter(array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getActivity()?->getId();
|
||||
}, $timesheets), function ($id): bool {
|
||||
return $id !== null;
|
||||
});
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'meta')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('a.id', $activityIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
if ($this->basicHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'user')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.user', 'user')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'tags')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.tags', 'tags')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'meta')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
<?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\Repository\Loader;
|
||||
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class UserIdLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function loadResults(array $ids): void
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var User[] $users */
|
||||
$users = $qb->select('PARTIAL user.{id}', 'memberships', 'team')
|
||||
->from(User::class, 'user')
|
||||
->leftJoin('user.memberships', 'memberships')
|
||||
->leftJoin('memberships.team', 'team')
|
||||
->andWhere($qb->expr()->in('user.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL user.{id}', 'preferences')
|
||||
->from(User::class, 'user')
|
||||
->leftJoin('user.preferences', 'preferences')
|
||||
->andWhere($qb->expr()->in('user.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($users as $user) {
|
||||
foreach ($user->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Team[] $teams */
|
||||
$teams = $qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,30 +9,75 @@
|
||||
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class UserLoader implements LoaderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
private $fullyHydrated;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $fullyHydrated = false)
|
||||
public function __construct(private EntityManagerInterface $entityManager, private bool $fullyHydrated = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $fullyHydrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User[] $users
|
||||
* @param array<int|User> $results
|
||||
*/
|
||||
public function loadResults(array $users): void
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
$ids = array_map(function (User $user) {
|
||||
return $user->getId();
|
||||
}, $users);
|
||||
if (empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader = new UserIdLoader($this->entityManager, $this->fullyHydrated);
|
||||
$loader->loadResults($ids);
|
||||
$ids = array_map(function ($user) {
|
||||
if ($user instanceof User) {
|
||||
return $user->getId();
|
||||
}
|
||||
|
||||
return $user;
|
||||
}, $results);
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var User[] $users */
|
||||
$users = $qb->select('PARTIAL user.{id}', 'memberships', 'team')
|
||||
->from(User::class, 'user')
|
||||
->leftJoin('user.memberships', 'memberships')
|
||||
->leftJoin('memberships.team', 'team')
|
||||
->andWhere($qb->expr()->in('user.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL user.{id}', 'preferences')
|
||||
->from(User::class, 'user')
|
||||
->leftJoin('user.preferences', 'preferences')
|
||||
->andWhere($qb->expr()->in('user.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
// do not load team members or leads by default, because they will only be used on detail pages
|
||||
// and there is no benefit in adding multiple queries for most requests when they are only needed in one place
|
||||
if ($this->fullyHydrated) {
|
||||
$teamIds = [];
|
||||
foreach ($users as $user) {
|
||||
foreach ($user->getTeams() as $team) {
|
||||
$teamIds[] = $team->getId();
|
||||
}
|
||||
}
|
||||
$teamIds = array_unique($teamIds);
|
||||
|
||||
if (\count($teamIds) > 0) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var Team[] $teams */
|
||||
$teams = $qb->select('PARTIAL team.{id}', 'members', 'user')
|
||||
->from(Team::class, 'team')
|
||||
->leftJoin('team.members', 'members')
|
||||
->leftJoin('members.user', 'user')
|
||||
->andWhere($qb->expr()->in('team.id', $teamIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user