Merge branch '111_exports_suite' into calendar/finalization

This commit is contained in:
2022-09-08 10:19:53 +02:00
72 changed files with 579 additions and 282 deletions

View File

@@ -40,11 +40,11 @@ class BySocialActionAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('socialaction', $qb->getAllAliases(), true)) {
$qb->join('activity.socialActions', 'socialaction');
if (!in_array('actsocialaction', $qb->getAllAliases(), true)) {
$qb->join('activity.socialActions', 'actsocialaction');
}
$qb->addSelect('socialaction.id AS socialaction_aggregator');
$qb->addSelect('actsocialaction.id AS socialaction_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -40,11 +40,11 @@ class BySocialIssueAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('socialissue', $qb->getAllAliases(), true)) {
$qb->join('activity.socialIssues', 'socialissue');
if (!in_array('actsocialissue', $qb->getAllAliases(), true)) {
$qb->join('activity.socialIssues', 'actsocialissue');
}
$qb->addSelect('socialissue.id AS socialissue_aggregator');
$qb->addSelect('actsocialissue.id AS socialissue_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -40,11 +40,11 @@ class ByThirdpartyAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('thirdparty', $qb->getAllAliases(), true)) {
$qb->join('activity.thirdParties', 'thirdparty');
if (!in_array('acttparty', $qb->getAllAliases(), true)) {
$qb->join('activity.thirdParties', 'acttparty');
}
$qb->addSelect('thirdparty.id AS thirdparty_aggregator');
$qb->addSelect('acttparty.id AS thirdparty_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -40,11 +40,11 @@ class ByUserAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('user', $qb->getAllAliases(), true)) {
$qb->join('activity.users', 'user');
if (!in_array('actusers', $qb->getAllAliases(), true)) {
$qb->join('activity.users', 'actusers');
}
$qb->addSelect('user.id AS users_aggregator');
$qb->addSelect('actusers.id AS users_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -40,11 +40,11 @@ class LocationTypeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('location', $qb->getAllAliases(), true)) {
$qb->join('activity.location', 'location');
if (!in_array('actloc', $qb->getAllAliases(), true)) {
$qb->join('activity.location', 'actloc');
}
$qb->addSelect('IDENTITY(location.locationType) AS locationtype_aggregator');
$qb->addSelect('IDENTITY(actloc.locationType) AS locationtype_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -40,11 +40,11 @@ class UserScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('user', $qb->getAllAliases(), true)) {
$qb->join('activity.user', 'user');
if (!in_array('actuser', $qb->getAllAliases(), true)) {
$qb->join('activity.user', 'actuser');
}
$qb->addSelect('IDENTITY(user.mainScope) AS userscope_aggregator');
$qb->addSelect('IDENTITY(actuser.mainScope) AS userscope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');

View File

@@ -44,8 +44,8 @@ class ActivityTypeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('type', $qb->getAllAliases(), true)) {
$qb->join('activity.activityType', 'type');
if (!in_array('acttype', $qb->getAllAliases(), true)) {
$qb->join('activity.activityType', 'acttype');
}
$qb->addSelect(sprintf('IDENTITY(activity.activityType) AS %s', self::KEY));
@@ -94,23 +94,4 @@ class ActivityTypeAggregator implements AggregatorInterface
{
return 'Aggregate by activity type';
}
/**
* Check if a join between Activity and another alias.
*
* @param Join[] $joins
* @param string $alias the alias to search for
*
* @return bool
*/
private function checkJoinAlreadyDefined(array $joins, $alias)
{
foreach ($joins as $join) {
if ($join->getAlias() === $alias) {
return true;
}
}
return false;
}
}

View File

@@ -67,29 +67,15 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali
$qb->addSelect($elem . ' as ' . $alias);
// make a jointure only if needed
$join = $qb->getDQLPart('join');
if (
(
array_key_exists('activity', $join)
&& !$this->checkJoinAlreadyDefined($join['activity'], 'reasons')
)
|| (!array_key_exists('activity', $join))
) {
$qb->add(
'join',
[
'activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons'),
],
true
);
if (!in_array( 'actreasons', $qb->getAllAliases(), true)) {
$qb->innerJoin('activity.reasons', 'actreasons');
}
// join category if necessary
if ('activity_categories_id' === $alias) {
// add join only if needed
if (!$this->checkJoinAlreadyDefined($qb->getDQLPart('join')['activity'], 'category')) {
$qb->join('reasons.category', 'category');
if (!in_array('actreasoncat', $qb->getAllAliases(), true)) {
$qb->join('actreasons.category', 'actreasoncat');
}
}
@@ -193,23 +179,4 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali
->addViolation();
}
}
/**
* Check if a join between Activity and another alias.
*
* @param Join[] $joins
* @param string $alias the alias to search for
*
* @return bool
*/
private function checkJoinAlreadyDefined(array $joins, $alias)
{
foreach ($joins as $join) {
if ($join->getAlias() === $alias) {
return true;
}
}
return false;
}
}

View File

@@ -84,7 +84,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->repository->createQueryBuilder('activity')
->join('activity.accompanyingPeriod', 'acp');
->join('activity.accompanyingPeriod', 'actacp');
$qb->select('AVG(activity.durationTime) as export_avg_activity_duration');

View File

@@ -84,7 +84,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->repository->createQueryBuilder('activity')
->join('activity.accompanyingPeriod', 'acp');
->join('activity.accompanyingPeriod', 'actacp');
$qb->select('AVG(activity.travelTime) as export_avg_activity_visit_duration');

View File

@@ -84,8 +84,11 @@ class CountActivity implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->repository->createQueryBuilder('activity')
->join('activity.accompanyingPeriod', 'acp');
$qb = $this->repository->createQueryBuilder('activity');
if (!in_array('actacp', $qb->getAllAliases(), true)) {
$qb->join('activity.accompanyingPeriod', 'actacp');
}
$qb->select('COUNT(activity.id) as export_count_activity');

View File

@@ -83,8 +83,11 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->repository->createQueryBuilder('activity')
->join('activity.accompanyingPeriod', 'acp');
$qb = $this->repository->createQueryBuilder('activity');
if (!in_array('actacp', $qb->getAllAliases(), true)) {
$qb->join('activity.accompanyingPeriod', 'actacp');
}
$qb->select('SUM(activity.durationTime) as export_sum_activity_duration');

View File

@@ -83,8 +83,11 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->repository->createQueryBuilder('activity')
->join('activity.accompanyingPeriod', 'acp');
$qb = $this->repository->createQueryBuilder('activity');
if (!in_array('actacp', $qb->getAllAliases(), true)) {
$qb->join('activity.accompanyingPeriod', 'actacp');
}
$qb->select('SUM(activity.travelTime) as export_sum_activity_visit_duration');

View File

@@ -84,8 +84,11 @@ class CountActivity implements ExportInterface, GroupedExportInterface
{
$centers = array_map(static fn ($el) => $el['center'], $acl);
$qb = $this->activityRepository->createQueryBuilder('activity')
->join('activity.person', 'person');
$qb = $this->activityRepository->createQueryBuilder('activity');
if (!in_array('actperson', $qb->getAllAliases(), true)) {
$qb->join('activity.person', 'actperson');
}
$qb->select('COUNT(activity.id) as export_count_activity');

View File

@@ -210,9 +210,9 @@ class ListActivity implements ListInterface, GroupedExportInterface
$qb
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.person', 'person')
->join('person.center', 'center')
->andWhere('center IN (:authorized_centers)')
->join('activity.person', 'actperson')
->join('actperson.center', 'actcenter')
->andWhere('actcenter IN (:authorized_centers)')
->setParameter('authorized_centers', $centers);
foreach ($this->fields as $f) {
@@ -239,8 +239,8 @@ class ListActivity implements ListInterface, GroupedExportInterface
break;
case 'user_username':
$qb->join('activity.user', 'user');
$qb->addSelect('user.username AS user_username');
$qb->join('activity.user', 'actuser');
$qb->addSelect('actuser.username AS user_username');
break;

View File

@@ -120,9 +120,9 @@ class StatActivityDuration implements ExportInterface, GroupedExportInterface
}
return $qb->select($select)
->join('activity.person', 'person')
->join('person.center', 'center')
->where($qb->expr()->in('center', ':centers'))
->join('activity.person', 'actperson')
->join('actperson.center', 'actcenter')
->where($qb->expr()->in('actcenter', ':centers'))
->setParameter(':centers', $centers);
}

View File

@@ -39,11 +39,11 @@ class BySocialActionFilter implements FilterInterface
{
$where = $qb->getDQLPart('where');
if (!in_array('socialaction', $qb->getAllAliases(), true)) {
$qb->join('activity.socialActions', 'socialaction');
if (!in_array('actsocialaction', $qb->getAllAliases(), true)) {
$qb->join('activity.socialActions', 'actsocialaction');
}
$clause = $qb->expr()->in('socialaction.id', ':socialactions');
$clause = $qb->expr()->in('actsocialaction.id', ':socialactions');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -39,11 +39,11 @@ class BySocialIssueFilter implements FilterInterface
{
$where = $qb->getDQLPart('where');
if (!in_array('socialissue', $qb->getAllAliases(), true)) {
$qb->join('activity.socialIssues', 'socialissue');
if (!in_array('actsocialissue', $qb->getAllAliases(), true)) {
$qb->join('activity.socialIssues', 'actsocialissue');
}
$clause = $qb->expr()->in('socialissue.id', ':socialissues');
$clause = $qb->expr()->in('actsocialissue.id', ':socialissues');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -39,11 +39,11 @@ class ByUserFilter implements FilterInterface
{
$where = $qb->getDQLPart('where');
if (!in_array('user', $qb->getAllAliases(), true)) {
$qb->join('activity.users', 'user');
if (!in_array('actusers', $qb->getAllAliases(), true)) {
$qb->join('activity.users', 'actusers');
}
$clause = $qb->expr()->in('user.id', ':users');
$clause = $qb->expr()->in('actusers.id', ':users');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -37,12 +37,12 @@ class LocationTypeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('location', $qb->getAllAliases(), true)) {
$qb->join('activity.location', 'location');
if (!in_array('actloc', $qb->getAllAliases(), true)) {
$qb->join('activity.location', 'actloc');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('location.locationType', ':locationtype');
$clause = $qb->expr()->in('actloc.locationType', ':locationtype');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -37,13 +37,13 @@ class UserScopeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('user', $qb->getAllAliases(), true)) {
$qb->join('activity.user', 'user');
if (!in_array('actuser', $qb->getAllAliases(), true)) {
$qb->join('activity.user', 'actuser');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('user.mainScope', ':userscope');
$clause = $qb->expr()->in('actuser.mainScope', ':userscope');
if ($where instanceof Andx) {
$where->add($clause);

View File

@@ -102,23 +102,4 @@ class ActivityTypeFilter implements ExportElementValidatedInterface, FilterInter
->addViolation();
}
}
/**
* Check if a join between Activity and Reason is already defined.
*
* @param Join[] $joins
* @param mixed $alias
*
* @return bool
*/
private function checkJoinAlreadyDefined(array $joins, $alias)
{
foreach ($joins as $join) {
if ($join->getAlias() === $alias) {
return true;
}
}
return false;
}
}

View File

@@ -52,20 +52,9 @@ class ActivityReasonFilter implements ExportElementValidatedInterface, FilterInt
$where = $qb->getDQLPart('where');
$join = $qb->getDQLPart('join');
$clause = $qb->expr()->in('reasons', ':selected_activity_reasons');
//dump($join);
// add a join to reasons only if needed
if (
(
array_key_exists('activity', $join)
&& !$this->checkJoinAlreadyDefined($join['activity'], 'reasons')
)
|| (!array_key_exists('activity', $join))
) {
$qb->add(
'join',
['activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')],
true
);
if (!in_array('actreasons', $qb->getAllAliases(), true)) {
$qb->join('activity.reasons', 'actreasons');
}
if ($where instanceof Expr\Andx) {
@@ -123,21 +112,4 @@ class ActivityReasonFilter implements ExportElementValidatedInterface, FilterInt
->addViolation();
}
}
/**
* Check if a join between Activity and Reason is already defined.
*
* @param Join[] $joins
* @param mixed $alias
*/
private function checkJoinAlreadyDefined(array $joins, $alias): bool
{
foreach ($joins as $join) {
if ($join->getAlias() === $alias) {
return true;
}
}
return false;
}
}