mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fix activity timeline using TimelineSingleQuery
This commit is contained in:
@@ -62,7 +62,7 @@ final class ActivityACLAwareRepository
|
||||
$metadataActivity = $this->em->getClassMetadata(Activity::class);
|
||||
|
||||
$from = $this->getFromClauseCenter($args);
|
||||
$where = $this->getWhereClause($context, $args);
|
||||
[$where, $parameters] = $this->getWhereClause($context, $args);
|
||||
|
||||
return [
|
||||
'id' => $metadataActivity->getTableName()
|
||||
@@ -71,7 +71,8 @@ final class ActivityACLAwareRepository
|
||||
'date' => $metadataActivity->getTableName()
|
||||
.'.'.$metadataActivity->getColumnName('date'),
|
||||
'FROM' => $from,
|
||||
'WHERE' => $where
|
||||
'WHERE' => $where,
|
||||
'parameters' => $parameters
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -29,13 +29,13 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
||||
|
||||
/**
|
||||
* Provide activity for inclusion in timeline
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
*/
|
||||
class TimelineActivityProvider implements TimelineProviderInterface
|
||||
{
|
||||
|
||||
@@ -93,63 +93,37 @@ class TimelineActivityProvider implements TimelineProviderInterface
|
||||
*/
|
||||
public function fetchQuery($context, array $args)
|
||||
{
|
||||
//$this->checkContext($context);
|
||||
//
|
||||
if ('center' === $context) {
|
||||
return $this->aclAwareRepository->queryTimelineIndexer($context, $args);
|
||||
return TimelineSingleQuery::fromArray($this->aclAwareRepository
|
||||
->queryTimelineIndexer($context, $args));
|
||||
}
|
||||
|
||||
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity');
|
||||
|
||||
return array(
|
||||
$metadataActivity = $this->em->getClassMetadata(Activity::class);
|
||||
|
||||
[$where, $parameters] = $this->getWhereClauseForPerson($args['person']);
|
||||
dump($where, $parameters);
|
||||
return TimelineSingleQuery::fromArray([
|
||||
'id' => $metadataActivity->getTableName()
|
||||
.'.'.$metadataActivity->getColumnName('id'),
|
||||
'type' => 'activity',
|
||||
'date' => $metadataActivity->getTableName()
|
||||
.'.'.$metadataActivity->getColumnName('date'),
|
||||
'FROM' => $this->getFromClause($metadataActivity, $metadataPerson),
|
||||
'WHERE' => $this->getWhereClause($metadataActivity, $metadataPerson,
|
||||
$args['person'])
|
||||
);
|
||||
}
|
||||
|
||||
private function getFromClause(string $context)
|
||||
{
|
||||
switch ($context) {
|
||||
case 'person':
|
||||
return $this->getFromClausePerson($metadataActivity, $metadataPerson);
|
||||
}
|
||||
}
|
||||
|
||||
private function getWhereClause(string $context, array $args)
|
||||
{
|
||||
switch ($context) {
|
||||
case 'person':
|
||||
return $this->getWhereClause($args['person']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var $centers array|Center[]
|
||||
*/
|
||||
private function getWhereClauseForCenter(array $centers)
|
||||
{
|
||||
$clause = "";
|
||||
$role = new Role('CHILL_ACTIVITY_SEE');
|
||||
|
||||
|
||||
'FROM' => $this->getFromClausePerson($args['person']),
|
||||
'WHERE' => $where,
|
||||
'parameters' => $parameters
|
||||
]);
|
||||
}
|
||||
|
||||
private function getWhereClauseForPerson(Person $person)
|
||||
{
|
||||
$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);
|
||||
$associationMapping = $metadataActivity->getAssociationMapping('person');
|
||||
|
||||
if (count($reachableCenters) === 0) {
|
||||
return 'FALSE = TRUE';
|
||||
@@ -157,31 +131,41 @@ class TimelineActivityProvider implements TimelineProviderInterface
|
||||
|
||||
// we start with activities having the person_id linked to person
|
||||
// (currently only context "person" is supported)
|
||||
$whereClause = sprintf('%s = %d',
|
||||
$associationMapping['joinColumns'][0]['name'],
|
||||
$person->getId());
|
||||
$whereClause = sprintf(' {activity.person_id} = ? ');
|
||||
$parameters[] = $person->getId();
|
||||
|
||||
// we add acl (reachable center and scopes)
|
||||
$centerAndScopeLines = array();
|
||||
$centerAndScopeClauses = [];
|
||||
foreach ($reachableCenters as $center) {
|
||||
$reachablesScopesId = array_map(
|
||||
function(Scope $scope) { return $scope->getId(); },
|
||||
$this->helper->getReachableScopes($this->user, $role,
|
||||
$person->getCenter())
|
||||
);
|
||||
|
||||
$centerAndScopeLines[] = sprintf('(%s = %d AND %s IN (%s))',
|
||||
$metadataPerson->getTableName().'.'.
|
||||
$metadataPerson->getAssociationMapping('center')['joinColumns'][0]['name'],
|
||||
$center->getId(),
|
||||
$metadataActivity->getTableName().'.'.
|
||||
$metadataActivity->getAssociationMapping('scope')['joinColumns'][0]['name'],
|
||||
implode(',', $reachablesScopesId));
|
||||
|
||||
$parameters[] = $center->getId();
|
||||
$scopes_ids = [];
|
||||
$reachableScopes = $this->helper->getReachableScopes($this->user, $role, $person->getCenter());
|
||||
foreach ($reachableScopes as $scope) {
|
||||
$scopes_ids[] = '?';
|
||||
$parameters[] = $scope->getId();
|
||||
}
|
||||
$centerAndScopeClauses[] = \strtr(
|
||||
'( {person.center_id} = ? AND {activity.scope_id} IN ({scopes_ids})) ',
|
||||
[
|
||||
'{scopes_ids}' => \implode(", ", $scopes_ids)
|
||||
]
|
||||
);
|
||||
}
|
||||
$whereClause .= ' AND ('.implode(' OR ', $centerAndScopeLines).')';
|
||||
|
||||
return $whereClause;
|
||||
$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'],
|
||||
]
|
||||
),
|
||||
$parameters
|
||||
];
|
||||
}
|
||||
|
||||
private function getFromClausePerson()
|
||||
@@ -199,21 +183,6 @@ class TimelineActivityProvider implements TimelineProviderInterface
|
||||
;
|
||||
}
|
||||
|
||||
private function getFromClauseCenter()
|
||||
{
|
||||
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity');
|
||||
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person');
|
||||
$associationMapping = $metadataActivity->getAssociationMapping('person');
|
||||
|
||||
return $metadataActivity->getTableName().' JOIN '
|
||||
.$metadataPerson->getTableName().' ON '
|
||||
.$metadataPerson->getTableName().'.'.
|
||||
$associationMapping['joinColumns'][0]['referencedColumnName']
|
||||
.' = '
|
||||
.$associationMapping['joinColumns'][0]['name']
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
|
Reference in New Issue
Block a user