mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add tasks to global timeline
This commit is contained in:
parent
5350a09951
commit
2cb9dfc250
@ -7,6 +7,9 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<span class="statement">{{ '%user% has created the task'|trans({ '%user%': event.author.username }) }}</span>
|
<span class="statement">{{ '%user% has created the task'|trans({ '%user%': event.author.username }) }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if 'person' != context %}
|
||||||
|
/ {{ task.person|chill_entity_render_box({'addLink': true}) }}
|
||||||
|
{% endif %}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div class="statement">
|
<div class="statement">
|
||||||
@ -29,5 +32,17 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ chill_path_add_return_path('chill_task_single_task_show', { 'id' : task.id }, false, 'Back to the timeline'|trans ) }}" class="sc-button bt-show">
|
||||||
|
{{ "View the task"|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ chill_path_add_return_path('chill_task_single_task_edit', { 'id' : task.id }, false, 'Back to the timeline'|trans) }}" class="sc-button bt-update">
|
||||||
|
{{ "Edit task"|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
@ -18,6 +18,7 @@
|
|||||||
namespace Chill\TaskBundle\Timeline;
|
namespace Chill\TaskBundle\Timeline;
|
||||||
|
|
||||||
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
||||||
|
use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent;
|
use Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent;
|
||||||
use Chill\TaskBundle\Entity\SingleTask;
|
use Chill\TaskBundle\Entity\SingleTask;
|
||||||
@ -25,9 +26,8 @@ use Symfony\Component\Workflow\Registry;
|
|||||||
use Symfony\Component\Workflow\Workflow;
|
use Symfony\Component\Workflow\Workflow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Provide timeline elements related to tasks, in tasks context
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
||||||
*/
|
*/
|
||||||
class SingleTaskTaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
class SingleTaskTaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||||
{
|
{
|
||||||
@ -63,7 +63,7 @@ class SingleTaskTaskLifeCycleEventTimelineProvider implements TimelineProviderIn
|
|||||||
$singleTaskMetadata = $this->em
|
$singleTaskMetadata = $this->em
|
||||||
->getClassMetadata(SingleTask::class);
|
->getClassMetadata(SingleTask::class);
|
||||||
|
|
||||||
return [
|
return TimelineSingleQuery::fromArray([
|
||||||
'id' => sprintf('%s.%s.%s', $metadata->getSchemaName(), $metadata->getTableName(), $metadata->getColumnName('id')),
|
'id' => sprintf('%s.%s.%s', $metadata->getSchemaName(), $metadata->getTableName(), $metadata->getColumnName('id')),
|
||||||
'type' => self::TYPE,
|
'type' => self::TYPE,
|
||||||
'date' => $metadata->getColumnName('datetime'),
|
'date' => $metadata->getColumnName('datetime'),
|
||||||
@ -77,8 +77,9 @@ class SingleTaskTaskLifeCycleEventTimelineProvider implements TimelineProviderIn
|
|||||||
sprintf('%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName()),
|
sprintf('%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName()),
|
||||||
$singleTaskMetadata->getColumnName('id'),
|
$singleTaskMetadata->getColumnName('id'),
|
||||||
$args['task']->getId()
|
$args['task']->getId()
|
||||||
)
|
),
|
||||||
];
|
'parameters' => [],
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,43 +21,30 @@ use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent;
|
use Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent;
|
||||||
use Chill\TaskBundle\Entity\SingleTask;
|
use Chill\TaskBundle\Entity\SingleTask;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
use Symfony\Component\Workflow\Workflow;
|
use Symfony\Component\Workflow\Workflow;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Provide element for timeline for 'person' and 'center' context
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
||||||
*/
|
*/
|
||||||
class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||||
{
|
{
|
||||||
/**
|
protected EntityManagerInterface $em;
|
||||||
*
|
|
||||||
* @var EntityManagerInterface
|
|
||||||
*/
|
|
||||||
protected $em;
|
|
||||||
|
|
||||||
/**
|
protected Registry $registry;
|
||||||
*
|
|
||||||
* @var Registry
|
|
||||||
*/
|
|
||||||
protected $registry;
|
|
||||||
|
|
||||||
/**
|
protected AuthorizationHelper $authorizationHelper;
|
||||||
*
|
|
||||||
* @var AuthorizationHelper
|
protected Security $security;
|
||||||
*/
|
|
||||||
protected $authorizationHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var TokenStorageInterface
|
|
||||||
*/
|
|
||||||
protected $tokenStorage;
|
|
||||||
|
|
||||||
const TYPE = 'chill_task.transition';
|
const TYPE = 'chill_task.transition';
|
||||||
|
|
||||||
@ -65,60 +52,172 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
EntityManagerInterface $em,
|
EntityManagerInterface $em,
|
||||||
Registry $registry,
|
Registry $registry,
|
||||||
AuthorizationHelper $authorizationHelper,
|
AuthorizationHelper $authorizationHelper,
|
||||||
TokenStorageInterface $tokenStorage
|
Security $security
|
||||||
) {
|
) {
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
$this->tokenStorage = $tokenStorage;
|
$this->security = $security;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchQuery($context, $args)
|
public function fetchQuery($context, $args)
|
||||||
{
|
{
|
||||||
if ($context !== 'person') {
|
|
||||||
throw new \LogicException(sprintf('%s is not able '
|
|
||||||
. 'to render context %s', self::class, $context));
|
|
||||||
}
|
|
||||||
|
|
||||||
$metadata = $this->em
|
$metadata = $this->em
|
||||||
->getClassMetadata(SingleTaskPlaceEvent::class);
|
->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||||
$singleTaskMetadata = $this->em
|
|
||||||
->getClassMetadata(SingleTask::class);
|
|
||||||
$user = $this->tokenStorage->getToken()->getUser();
|
|
||||||
$circles = $this->authorizationHelper->getReachableCircles(
|
|
||||||
$user, new Role(ActivityVoter::SEE_DETAILS), $args['person']->getCenter());
|
|
||||||
|
|
||||||
|
switch ($context) {
|
||||||
if (count($circles) > 0) {
|
case 'person':
|
||||||
$circlesId = \array_map(function($c) { return $c->getId(); }, $circles);
|
[ $where, $parameters ] = $this->getWhereClauseForPerson($args['person']);
|
||||||
$circleRestriction = sprintf('%s.%s.%s IN (%s)',
|
break;
|
||||||
$singleTaskMetadata->getSchemaName(), // chill_task schema
|
case 'center':
|
||||||
$singleTaskMetadata->getTableName(), // single_task table name
|
[ $where, $parameters ] = $this->getWhereClauseForCenter($args['centers']);
|
||||||
$singleTaskMetadata->getAssociationMapping('circle')['joinColumns'][0]['name'],
|
break;
|
||||||
\implode(', ', $circlesId)
|
default:
|
||||||
);
|
throw new \UnexpectedValueException("context {$context} is not supported");
|
||||||
} else {
|
|
||||||
$circleRestriction = 'FALSE = TRUE';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TimelineSingleQuery::fromArray([
|
||||||
return [
|
|
||||||
'id' => sprintf('%s.%s.%s', $metadata->getSchemaName(), $metadata->getTableName(), $metadata->getColumnName('id')),
|
'id' => sprintf('%s.%s.%s', $metadata->getSchemaName(), $metadata->getTableName(), $metadata->getColumnName('id')),
|
||||||
'type' => self::TYPE,
|
'type' => self::TYPE,
|
||||||
'date' => $metadata->getColumnName('datetime'),
|
'date' => $metadata->getColumnName('datetime'),
|
||||||
'FROM' => sprintf('%s JOIN %s ON %s = %s',
|
'FROM' => $this->getFromClause($context),
|
||||||
sprintf('%s.%s', $metadata->getSchemaName(), $metadata->getTableName()),
|
'WHERE' => $where,
|
||||||
sprintf('%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName()),
|
'parameters' => $parameters
|
||||||
$metadata->getAssociationMapping('task')['joinColumns'][0]['name'],
|
]);
|
||||||
sprintf('%s.%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName(), $singleTaskMetadata->getColumnName('id'))
|
}
|
||||||
),
|
|
||||||
'WHERE' => sprintf('%s.%s = %d and %s',
|
private function getWhereClauseForCenter(array $centers): array
|
||||||
sprintf('%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName()),
|
{
|
||||||
$singleTaskMetadata->getAssociationMapping('person')['joinColumns'][0]['name'],
|
$taskEvent = $this->em->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||||
$args['person']->getId(),
|
$singleTask = $this->em->getClassMetadata(SingleTask::class);
|
||||||
$circleRestriction
|
$person = $this->em->getClassMetadata(Person::class);
|
||||||
)
|
$personFkCenter = $person->getAssociationMapping('center')['joinColumns'][0]['name'];
|
||||||
|
$taskFkCircle = $singleTask->getAssociationMapping('circle')['joinColumns'][0]['name'];
|
||||||
|
|
||||||
|
// the parameters
|
||||||
|
$parameters = [];
|
||||||
|
|
||||||
|
// the clause that we will repeat for each center, joined by 'OR'
|
||||||
|
$clause = "{person}.{center_id} = ? AND {task}.{circle} IN ({circle_ids})";
|
||||||
|
|
||||||
|
// array to gather clauses
|
||||||
|
$clauses = [];
|
||||||
|
|
||||||
|
// loop over centers
|
||||||
|
foreach ($this->authorizationHelper->getReachableCenters(
|
||||||
|
$this->security->getUser(), new Role(ActivityVoter::SEE_DETAILS)) as $center) {
|
||||||
|
|
||||||
|
if (FALSE === \in_array($center, $centers)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill center parameter
|
||||||
|
$parameters[] = $center->getId();
|
||||||
|
|
||||||
|
// we loop over circles
|
||||||
|
$circles = $this->authorizationHelper->getReachableCircles(
|
||||||
|
$this->security->getUser(), new Role(ActivityVoter::SEE_DETAILS), $center);
|
||||||
|
$circleIds = [];
|
||||||
|
|
||||||
|
foreach ($circles as $circle) {
|
||||||
|
$parameters[] = $circleIds[] = $circle->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
$clauses[] = \strtr(
|
||||||
|
$clause,
|
||||||
|
[
|
||||||
|
'{person}' => $person->getTableName(),
|
||||||
|
'{center_id}' => $personFkCenter,
|
||||||
|
'{task}' => $singleTask->getSchemaName().".".$singleTask->getTableName(),
|
||||||
|
'{circle}' => $taskFkCircle,
|
||||||
|
'{circle_ids}' => \implode(', ', \array_fill(0, count($circleIds), '?'))
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === \count($clauses)) {
|
||||||
|
return [ 'FALSE = TRUE' , [] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
\implode(' OR ', $clauses),
|
||||||
|
$parameters
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getWhereClauseForPerson(Person $personArg): array
|
||||||
|
{
|
||||||
|
$taskEvent = $this->em->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||||
|
$singleTask = $this->em->getClassMetadata(SingleTask::class);
|
||||||
|
$person = $this->em->getClassMetadata(Person::class);
|
||||||
|
$eventFkTask = $taskEvent->getAssociationMapping('task')['joinColumns'][0]['name'];
|
||||||
|
$taskFkPerson = $singleTask->getAssociationMapping('person')['joinColumns'][0]['name'];
|
||||||
|
$personPk = $singleTask->getAssociationMapping('person')['joinColumns'][0]['referencedColumnName'];
|
||||||
|
$taskFkCircle = $singleTask->getAssociationMapping('circle')['joinColumns'][0]['name'];
|
||||||
|
|
||||||
|
|
||||||
|
// the parameters
|
||||||
|
$parameters = [];
|
||||||
|
|
||||||
|
// the clause that we will fill
|
||||||
|
$clause = "{person}.{person_id} = ? AND {task}.{circle} IN ({circle_ids})";
|
||||||
|
|
||||||
|
// person is the first parameter
|
||||||
|
$parameters[] = $personArg->getId();
|
||||||
|
|
||||||
|
// we loop over circles
|
||||||
|
$circles = $this->authorizationHelper->getReachableCircles(
|
||||||
|
$this->security->getUser(), new Role(ActivityVoter::SEE_DETAILS), $personArg->getCenter());
|
||||||
|
|
||||||
|
if (0 === count($circles)) {
|
||||||
|
// go fast to block access to every tasks
|
||||||
|
return [ "FALSE = TRUE", [] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($circles as $circle) {
|
||||||
|
$parameters[] = $circleIds[] = $circle->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
\strtr(
|
||||||
|
$clause,
|
||||||
|
[
|
||||||
|
'{person}' => $person->getTableName(),
|
||||||
|
'{person_id}' => $person->getColumnName('id'),
|
||||||
|
'{task}' => $singleTask->getSchemaName().".".$singleTask->getTableName(),
|
||||||
|
'{circle}' => $taskFkCircle,
|
||||||
|
'{circle_ids}' => \implode(', ', \array_fill(0, count($circleIds), '?'))
|
||||||
|
]
|
||||||
|
),
|
||||||
|
$parameters
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFromClause(string $context)
|
||||||
|
{
|
||||||
|
$taskEvent = $this->em->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||||
|
$singleTask = $this->em->getClassMetadata(SingleTask::class);
|
||||||
|
$person = $this->em->getClassMetadata(Person::class);
|
||||||
|
$eventFkTask = $taskEvent->getAssociationMapping('task')['joinColumns'][0]['name'];
|
||||||
|
$taskFkPerson = $singleTask->getAssociationMapping('person')['joinColumns'][0]['name'];
|
||||||
|
$personPk = $singleTask->getAssociationMapping('person')['joinColumns'][0]['referencedColumnName'];
|
||||||
|
|
||||||
|
$from = "{single_task_event} ".
|
||||||
|
"JOIN {single_task} ON {single_task}.{task_pk} = {single_task_event}.{event_fk_task} ".
|
||||||
|
"JOIN {person} ON {single_task}.{task_person_fk} = {person}.{person_pk}";
|
||||||
|
|
||||||
|
return \strtr(
|
||||||
|
$from,
|
||||||
|
[
|
||||||
|
'{single_task}' => sprintf('%s.%s', $singleTask->getSchemaName(), $singleTask->getTableName()),
|
||||||
|
'{single_task_event}' => sprintf('%s.%s', $taskEvent->getSchemaName(), $taskEvent->getTableName()),
|
||||||
|
'{task_pk}' => $singleTask->getColumnName('id'),
|
||||||
|
'{event_fk_task}' => $eventFkTask,
|
||||||
|
'{person}' => $person->getTableName(),
|
||||||
|
'{task_person_fk}' => $taskFkPerson,
|
||||||
|
'{person_pk}' => $personPk
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEntities(array $ids)
|
public function getEntities(array $ids)
|
||||||
@ -147,10 +246,11 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
$transition = $this->getTransitionByName($entity->getTransition(), $workflow);
|
$transition = $this->getTransitionByName($entity->getTransition(), $workflow);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'template' => 'ChillTaskBundle:Timeline:single_task_transition_person_context.html.twig',
|
'template' => 'ChillTaskBundle:Timeline:single_task_transition.html.twig',
|
||||||
'template_data' => [
|
'template_data' => [
|
||||||
'person' => $args['person'],
|
'context' => $context,
|
||||||
'event' => $entity,
|
'event' => $entity,
|
||||||
|
'task' => $entity->getTask(),
|
||||||
'transition' => $transition
|
'transition' => $transition
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
@ -4,14 +4,15 @@ services:
|
|||||||
$em: '@Doctrine\ORM\EntityManagerInterface'
|
$em: '@Doctrine\ORM\EntityManagerInterface'
|
||||||
$registry: '@Symfony\Component\Workflow\Registry'
|
$registry: '@Symfony\Component\Workflow\Registry'
|
||||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||||
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
|
$security: '@Symfony\Component\Security\Core\Security'
|
||||||
public: true
|
public: true
|
||||||
# tags:
|
tags:
|
||||||
# - { name: 'chill.timeline', context: 'person' }
|
- { name: 'chill.timeline', context: 'person' }
|
||||||
|
- { name: 'chill.timeline', context: 'center' }
|
||||||
|
|
||||||
Chill\TaskBundle\Timeline\SingleTaskTaskLifeCycleEventTimelineProvider:
|
Chill\TaskBundle\Timeline\SingleTaskTaskLifeCycleEventTimelineProvider:
|
||||||
arguments:
|
arguments:
|
||||||
$em: '@Doctrine\ORM\EntityManagerInterface'
|
$em: '@Doctrine\ORM\EntityManagerInterface'
|
||||||
$registry: '@Symfony\Component\Workflow\Registry'
|
$registry: '@Symfony\Component\Workflow\Registry'
|
||||||
# tags:
|
tags:
|
||||||
#- { name: 'chill.timeline', context: 'task' }
|
- { name: 'chill.timeline', context: 'task' }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user