mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fix query in timeline in activity and person bundle
This commit is contained in:
@@ -101,7 +101,7 @@ class TimelineActivityProvider implements TimelineProviderInterface
|
||||
$metadataActivity = $this->em->getClassMetadata(Activity::class);
|
||||
|
||||
[$where, $parameters] = $this->getWhereClauseForPerson($args['person']);
|
||||
dump($where, $parameters);
|
||||
|
||||
return TimelineSingleQuery::fromArray([
|
||||
'id' => $metadataActivity->getTableName()
|
||||
.'.'.$metadataActivity->getColumnName('id'),
|
||||
@@ -119,49 +119,33 @@ class TimelineActivityProvider implements TimelineProviderInterface
|
||||
$parameters = [];
|
||||
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity');
|
||||
$associationMapping = $metadataActivity->getAssociationMapping('person');
|
||||
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person');
|
||||
|
||||
$role = new Role('CHILL_ACTIVITY_SEE');
|
||||
$reachableCenters = $this->helper->getReachableCenters($this->user,
|
||||
$role);
|
||||
|
||||
if (count($reachableCenters) === 0) {
|
||||
return 'FALSE = TRUE';
|
||||
}
|
||||
|
||||
// we start with activities having the person_id linked to person
|
||||
// (currently only context "person" is supported)
|
||||
$whereClause = sprintf(' {activity.person_id} = ? ');
|
||||
$reachableScopes = $this->helper->getReachableScopes($this->user,
|
||||
$role, $person->getCenter());
|
||||
$whereClause = sprintf(' {activity.person_id} = ? AND {activity.scope_id} IN ({scopes_ids}) ');
|
||||
$scopes_ids = [];
|
||||
|
||||
// first parameter: activity.person_id
|
||||
$parameters[] = $person->getId();
|
||||
|
||||
// we add acl (reachable center and scopes)
|
||||
$centerAndScopeClauses = [];
|
||||
foreach ($reachableCenters as $center) {
|
||||
$parameters[] = $center->getId();
|
||||
$scopes_ids = [];
|
||||
$reachableScopes = $this->helper->getReachableScopes($this->user, $role, $person->getCenter());
|
||||
foreach ($reachableScopes as $scope) {
|
||||
$scopes_ids[] = '?';
|
||||
$parameters[] = $scope->getId();
|
||||
|
||||
// loop on reachable scopes
|
||||
foreach ($reachableScopes as $scope) {
|
||||
if (\in_array($scope->getId(), $scopes_ids)) {
|
||||
continue;
|
||||
}
|
||||
$centerAndScopeClauses[] = \strtr(
|
||||
'( {person.center_id} = ? AND {activity.scope_id} IN ({scopes_ids})) ',
|
||||
[
|
||||
'{scopes_ids}' => \implode(", ", $scopes_ids)
|
||||
]
|
||||
);
|
||||
$scopes_ids[] = '?';
|
||||
$parameters[] = $scope->getId();
|
||||
}
|
||||
$whereClause .= ' AND ('.\implode(' OR ', $centerAndScopeClauses).' ) ';
|
||||
|
||||
return [
|
||||
\strtr(
|
||||
$whereClause,
|
||||
[
|
||||
'{activity.person_id}' => $associationMapping['joinColumns'][0]['name'],
|
||||
'{person.center_id}' => $metadataPerson->getTableName().'.'.
|
||||
$metadataPerson->getAssociationMapping('center')['joinColumns'][0]['name'],
|
||||
'{activity.scope_id}' => $metadataActivity->getTableName().'.'.
|
||||
$metadataActivity->getAssociationMapping('scope')['joinColumns'][0]['name'],
|
||||
'{scopes_ids}' => \implode(", ", $scopes_ids)
|
||||
,
|
||||
]
|
||||
),
|
||||
$parameters
|
||||
|
Reference in New Issue
Block a user