weekly quick-entry form (#2793)
This commit is contained in:
@@ -24,6 +24,7 @@ use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
|
||||
@@ -160,16 +161,26 @@ class ActivityRepository extends EntityRepository
|
||||
return $stats;
|
||||
}
|
||||
|
||||
private function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = [], bool $globalsOnly = false)
|
||||
private function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = [], bool $globalsOnly = false): void
|
||||
{
|
||||
$permissions = $this->getPermissionCriteria($qb, $user, $teams, $globalsOnly);
|
||||
if ($permissions->count() > 0) {
|
||||
$qb->andWhere($permissions);
|
||||
}
|
||||
}
|
||||
|
||||
private function getPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = [], bool $globalsOnly = false): Andx
|
||||
{
|
||||
$andX = $qb->expr()->andX();
|
||||
|
||||
// make sure that all queries without a user see all projects
|
||||
if (null === $user && empty($teams)) {
|
||||
return;
|
||||
return $andX;
|
||||
}
|
||||
|
||||
// make sure that admins see all activities
|
||||
if (null !== $user && $user->canSeeAllData()) {
|
||||
return;
|
||||
return $andX;
|
||||
}
|
||||
|
||||
if (null !== $user) {
|
||||
@@ -177,33 +188,33 @@ class ActivityRepository extends EntityRepository
|
||||
}
|
||||
|
||||
if (empty($teams)) {
|
||||
$qb->andWhere('SIZE(a.teams) = 0');
|
||||
$andX->add('SIZE(a.teams) = 0');
|
||||
if (!$globalsOnly) {
|
||||
$qb->andWhere('SIZE(p.teams) = 0');
|
||||
$qb->andWhere('SIZE(c.teams) = 0');
|
||||
$andX->add('SIZE(p.teams) = 0');
|
||||
$andX->add('SIZE(c.teams) = 0');
|
||||
}
|
||||
|
||||
return;
|
||||
return $andX;
|
||||
}
|
||||
|
||||
$orActivity = $qb->expr()->orX(
|
||||
'SIZE(a.teams) = 0',
|
||||
$qb->expr()->isMemberOf(':teams', 'a.teams')
|
||||
);
|
||||
$qb->andWhere($orActivity);
|
||||
$andX->add($orActivity);
|
||||
|
||||
if (!$globalsOnly) {
|
||||
$orProject = $qb->expr()->orX(
|
||||
'SIZE(p.teams) = 0',
|
||||
$qb->expr()->isMemberOf(':teams', 'p.teams')
|
||||
);
|
||||
$qb->andWhere($orProject);
|
||||
$andX->add($orProject);
|
||||
|
||||
$orCustomer = $qb->expr()->orX(
|
||||
'SIZE(c.teams) = 0',
|
||||
$qb->expr()->isMemberOf(':teams', 'c.teams')
|
||||
);
|
||||
$qb->andWhere($orCustomer);
|
||||
$andX->add($orCustomer);
|
||||
}
|
||||
|
||||
$ids = array_values(array_unique(array_map(function (Team $team) {
|
||||
@@ -211,6 +222,8 @@ class ActivityRepository extends EntityRepository
|
||||
}, $teams)));
|
||||
|
||||
$qb->setParameter('teams', $ids);
|
||||
|
||||
return $andX;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,9 +255,9 @@ class ActivityRepository extends EntityRepository
|
||||
->addOrderBy('a.name', 'ASC')
|
||||
;
|
||||
|
||||
$where = $qb->expr()->andX();
|
||||
$mainQuery = $qb->expr()->andX();
|
||||
|
||||
$where->add($qb->expr()->eq('a.visible', ':visible'));
|
||||
$mainQuery->add($qb->expr()->eq('a.visible', ':visible'));
|
||||
$qb->setParameter('visible', true, \PDO::PARAM_BOOL);
|
||||
|
||||
if (!$query->isGlobalsOnly()) {
|
||||
@@ -254,7 +267,7 @@ class ActivityRepository extends EntityRepository
|
||||
->leftJoin('a.project', 'p')
|
||||
->leftJoin('p.customer', 'c');
|
||||
|
||||
$where->add(
|
||||
$mainQuery->add(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('a.project'),
|
||||
$qb->expr()->andX(
|
||||
@@ -268,9 +281,9 @@ class ActivityRepository extends EntityRepository
|
||||
}
|
||||
|
||||
if ($query->isGlobalsOnly()) {
|
||||
$where->add($qb->expr()->isNull('a.project'));
|
||||
$mainQuery->add($qb->expr()->isNull('a.project'));
|
||||
} elseif ($query->hasProjects()) {
|
||||
$where->add(
|
||||
$mainQuery->add(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('a.project'),
|
||||
$qb->expr()->in('a.project', ':project')
|
||||
@@ -279,28 +292,30 @@ class ActivityRepository extends EntityRepository
|
||||
$qb->setParameter('project', $query->getProjects());
|
||||
}
|
||||
|
||||
if (null !== $query->getActivityToIgnore()) {
|
||||
$qb->andWhere($qb->expr()->neq('a.id', ':ignored'));
|
||||
$qb->setParameter('ignored', $query->getActivityToIgnore());
|
||||
$permissions = $this->getPermissionCriteria($qb, $query->getUser(), $query->getTeams(), $query->isGlobalsOnly());
|
||||
if ($permissions->count() > 0) {
|
||||
$mainQuery->add($permissions);
|
||||
}
|
||||
|
||||
$this->addPermissionCriteria($qb, $query->getUser(), $query->getTeams(), $query->isGlobalsOnly());
|
||||
$outerQuery = $qb->expr()->orX();
|
||||
|
||||
$or = $qb->expr()->orX();
|
||||
|
||||
// this must always be the last part before the or
|
||||
$or->add($where);
|
||||
|
||||
// this must always be the last part of the query
|
||||
if ($query->hasActivities()) {
|
||||
$or->add($qb->expr()->in('a.id', ':activity'));
|
||||
$outerQuery->add($qb->expr()->in('a.id', ':activity'));
|
||||
$qb->setParameter('activity', $query->getActivities());
|
||||
}
|
||||
|
||||
if ($or->count() > 0) {
|
||||
$qb->andWhere($or);
|
||||
if (null !== $query->getActivityToIgnore()) {
|
||||
$mainQuery = $qb->expr()->andX(
|
||||
$mainQuery,
|
||||
$qb->expr()->neq('a.id', ':ignored')
|
||||
);
|
||||
$qb->setParameter('ignored', $query->getActivityToIgnore());
|
||||
}
|
||||
|
||||
$outerQuery->add($mainQuery);
|
||||
|
||||
$qb->andWhere($outerQuery);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user