first impl for global timeline: apply on activities

This commit is contained in:
2021-05-14 16:25:56 +02:00
parent 8c98f2cf6e
commit c3ef8d112c
18 changed files with 604 additions and 98 deletions

View File

@@ -21,6 +21,7 @@
namespace Chill\ActivityBundle\Timeline;
use Chill\MainBundle\Timeline\TimelineProviderInterface;
use Chill\ActivityBundle\Repository\ActivityACLAwareRepository;
use Doctrine\ORM\EntityManager;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -55,6 +56,10 @@ class TimelineActivityProvider implements TimelineProviderInterface
* @var \Chill\MainBundle\Entity\User
*/
protected $user;
protected ActivityACLAwareRepository $aclAwareRepository;
private const SUPPORTED_CONTEXTS = [ 'center', 'person'];
/**
* TimelineActivityProvider constructor.
@@ -66,11 +71,13 @@ class TimelineActivityProvider implements TimelineProviderInterface
public function __construct(
EntityManager $em,
AuthorizationHelper $helper,
TokenStorageInterface $storage
TokenStorageInterface $storage,
ActivityACLAwareRepository $aclAwareRepository
)
{
$this->em = $em;
$this->helper = $helper;
$this->aclAwareRepository = $aclAwareRepository;
if (!$storage->getToken()->getUser() instanceof \Chill\MainBundle\Entity\User)
{
@@ -86,10 +93,13 @@ class TimelineActivityProvider implements TimelineProviderInterface
*/
public function fetchQuery($context, array $args)
{
$this->checkContext($context);
//$this->checkContext($context);
//
if ('center' === $context) {
return $this->aclAwareRepository->queryTimelineIndexer($context, $args);
}
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity');
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person');
return array(
'id' => $metadataActivity->getTableName()
@@ -102,10 +112,40 @@ class TimelineActivityProvider implements TimelineProviderInterface
$args['person'])
);
}
private function getWhereClause(ClassMetadata $metadataActivity,
ClassMetadata $metadataPerson, Person $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');
}
private function getWhereClauseForPerson(Person $person)
{
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity');
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person');
$role = new Role('CHILL_ACTIVITY_SEE');
$reachableCenters = $this->helper->getReachableCenters($this->user,
$role);
@@ -144,9 +184,25 @@ class TimelineActivityProvider implements TimelineProviderInterface
return $whereClause;
}
private function getFromClause(ClassMetadata $metadataActivity,
ClassMetadata $metadataPerson)
private function getFromClausePerson()
{
$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']
;
}
private function getFromClauseCenter()
{
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity');
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person');
$associationMapping = $metadataActivity->getAssociationMapping('person');
return $metadataActivity->getTableName().' JOIN '
@@ -183,14 +239,13 @@ class TimelineActivityProvider implements TimelineProviderInterface
{
$this->checkContext($context);
return array(
return [
'template' => 'ChillActivityBundle:Timeline:activity_person_context.html.twig',
'template_data' => array(
'template_data' => [
'activity' => $entity,
'person' => $args['person'],
'user' => $entity->getUser()
)
);
'context' => $context
]
];
}
/**
@@ -210,7 +265,7 @@ class TimelineActivityProvider implements TimelineProviderInterface
*/
private function checkContext($context)
{
if ($context !== 'person') {
if (FALSE === \in_array($context, self::SUPPORTED_CONTEXTS)) {
throw new \LogicException("The context '$context' is not "
. "supported. Currently only 'person' is supported");
}