detail pages for customers and projects (#1371)

This commit is contained in:
Kevin Papst
2020-01-16 16:25:28 +01:00
committed by GitHub
parent 28c5357f11
commit 6a44dbfe83
131 changed files with 3055 additions and 1742 deletions

View File

@@ -294,12 +294,15 @@ class ActivityRepository extends EntityRepository
if ($query->isGlobalsOnly()) {
$where->add($qb->expr()->isNull('a.project'));
} elseif (null !== $query->getProject()) {
$where->add(
$qb->expr()->orX(
$qb->expr()->eq('a.project', ':project'),
$qb->expr()->isNull('a.project')
)
$orX = $qb->expr()->orX(
$qb->expr()->eq('a.project', ':project')
);
if (!$query->isExcludeGlobals()) {
$orX->add($qb->expr()->isNull('a.project'));
}
$where->add($orX);
$qb->setParameter('project', $query->getProject());
} elseif (null !== $query->getCustomer()) {
$where->add('p.customer = :customer');
@@ -343,6 +346,11 @@ class ActivityRepository extends EntityRepository
}
}
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('a.id')->addGroupBy($orderBy);
return $qb;
}
@@ -352,6 +360,7 @@ class ActivityRepository extends EntityRepository
$qb
->resetDQLPart('select')
->resetDQLPart('orderBy')
->resetDQLPart('groupBy')
->select($qb->expr()->countDistinct('a.id'))
;

View File

@@ -11,6 +11,7 @@ namespace App\Repository;
use App\Entity\Activity;
use App\Entity\Customer;
use App\Entity\CustomerComment;
use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
@@ -208,9 +209,13 @@ class CustomerRepository extends EntityRepository
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('c')
$qb
->select('c')
->from(Customer::class, 'c')
->orderBy('c.' . $query->getOrderBy(), $query->getOrder());
;
$orderBy = 'c.' . $query->getOrderBy();
$qb->orderBy($orderBy, $query->getOrder());
if (CustomerQuery::SHOW_VISIBLE == $query->getVisibility()) {
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
@@ -260,6 +265,11 @@ class CustomerRepository extends EntityRepository
}
}
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('c.id')->addGroupBy($orderBy);
return $qb;
}
@@ -278,6 +288,7 @@ class CustomerRepository extends EntityRepository
$qb
->resetDQLPart('select')
->resetDQLPart('orderBy')
->resetDQLPart('groupBy')
->select($qb->expr()->countDistinct('c.id'))
;
@@ -336,4 +347,33 @@ class CustomerRepository extends EntityRepository
throw $ex;
}
}
public function getComments(Customer $customer): array
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->select('comments')
->from(CustomerComment::class, 'comments')
->andWhere($qb->expr()->eq('comments.customer', ':customer'))
->addOrderBy('comments.pinned', 'DESC')
->addOrderBy('comments.createdAt', 'DESC')
->setParameter('customer', $customer)
;
return $qb->getQuery()->getResult();
}
public function saveComment(CustomerComment $comment)
{
$entityManager = $this->getEntityManager();
$entityManager->persist($comment);
$entityManager->flush();
}
public function deleteComment(CustomerComment $comment)
{
$entityManager = $this->getEntityManager();
$entityManager->remove($comment);
$entityManager->flush();
}
}

View File

@@ -11,6 +11,7 @@ namespace App\Repository;
use App\Entity\Activity;
use App\Entity\Project;
use App\Entity\ProjectComment;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Model\ProjectStatistic;
@@ -351,6 +352,11 @@ class ProjectRepository extends EntityRepository
}
}
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('p.id')->addGroupBy($orderBy);
return $qb;
}
@@ -360,6 +366,7 @@ class ProjectRepository extends EntityRepository
$qb
->resetDQLPart('select')
->resetDQLPart('orderBy')
->resetDQLPart('groupBy')
->select($qb->expr()->countDistinct('p.id'))
;
@@ -438,4 +445,33 @@ class ProjectRepository extends EntityRepository
throw $ex;
}
}
public function getComments(Project $project): array
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->select('comments')
->from(ProjectComment::class, 'comments')
->andWhere($qb->expr()->eq('comments.project', ':project'))
->addOrderBy('comments.pinned', 'DESC')
->addOrderBy('comments.createdAt', 'DESC')
->setParameter('project', $project)
;
return $qb->getQuery()->getResult();
}
public function saveComment(ProjectComment $comment)
{
$entityManager = $this->getEntityManager();
$entityManager->persist($comment);
$entityManager->flush();
}
public function deleteComment(ProjectComment $comment)
{
$entityManager = $this->getEntityManager();
$entityManager->remove($comment);
$entityManager->flush();
}
}

View File

@@ -26,6 +26,10 @@ class ActivityQuery extends ProjectQuery
* @var bool
*/
private $globalsOnly = false;
/**
* @var bool
*/
private $excludeGlobals = false;
public function __construct()
{
@@ -54,6 +58,18 @@ class ActivityQuery extends ProjectQuery
return $this;
}
public function isExcludeGlobals(): bool
{
return (bool) $this->excludeGlobals;
}
public function setExcludeGlobals(bool $excludeGlobals): self
{
$this->excludeGlobals = (bool) $excludeGlobals;
return $this;
}
/**
* @return Project|int|null
*/