mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-18 08:14:24 +00:00
add and display events in history timeline
This commit is contained in:
parent
8bf4621911
commit
2ff22a73fa
@ -33,6 +33,7 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface
|
||||
$loader->load('fixtures.yml');
|
||||
$loader->load('menu.yml');
|
||||
$loader->load('controller.yml');
|
||||
$loader->load('timeline.yml');
|
||||
}
|
||||
|
||||
/* (non-PHPdoc)
|
||||
|
9
Resources/config/services/timeline.yml
Normal file
9
Resources/config/services/timeline.yml
Normal file
@ -0,0 +1,9 @@
|
||||
services:
|
||||
chill.event.timeline:
|
||||
class: Chill\EventBundle\Timeline\TimelineEventProvider
|
||||
arguments:
|
||||
- '@doctrine.orm.entity_manager'
|
||||
- '@chill.main.security.authorization.helper'
|
||||
- '@security.token_storage'
|
||||
tags:
|
||||
- { name: chill.timeline, context: 'person' }
|
3
Resources/views/EventReason/macro.html.twig
Normal file
3
Resources/views/EventReason/macro.html.twig
Normal file
@ -0,0 +1,3 @@
|
||||
{%- macro reason(r) -%}
|
||||
<span class="entity entity-event event-reason"><i class="fa fa-question-circle"></i> {{ r.name | localize_translatable_string }}</span>
|
||||
{%- endmacro -%}
|
61
Resources/views/Timeline/event_person_context.html.twig
Normal file
61
Resources/views/Timeline/event_person_context.html.twig
Normal file
@ -0,0 +1,61 @@
|
||||
{% import 'ChillEventBundle:EventReason:macro.html.twig' as m %}
|
||||
|
||||
{{ dump() }}
|
||||
{% for participation in event.participations %}
|
||||
{{ participation.id }} --->
|
||||
{{ participation.lastupdate|localizeddate('long', 'none') }}
|
||||
<br>
|
||||
{% endfor %}
|
||||
|
||||
{#
|
||||
TODO
|
||||
- user a inscrit la personne à l'événement machin
|
||||
- user a modifié le statut de la personne inscrite à l'événement machin. nouveau statut :
|
||||
- user a modifié le rôle de la personne inscrite à l'événement machin. nouveau rôle :
|
||||
- participation de la personne à l'événement machin
|
||||
#}
|
||||
|
||||
<div>
|
||||
<h3>{{ event.date|localizeddate('long', 'none') }}<span class="event"> / {{ 'Event'|trans }}</span></h3>
|
||||
<div class="statement">
|
||||
<span class="statement">{{ '%user% has done an %event_type%'|trans(
|
||||
{
|
||||
'%user%' : user,
|
||||
'%event_type%': event.type.name|localize_translatable_string,
|
||||
'%date%' : event.date|localizeddate('long', 'none') }
|
||||
) }}</span>
|
||||
|
||||
|
||||
{% if is_granted(constant('Chill\\ActivityBundle\\Security\\Authorization\\ActivityVoter::SEE_DETAILS'), event) %}
|
||||
<dl class="chill_view_data">
|
||||
<dt class="inline">{{ 'Remark'|trans }}</dt>
|
||||
<dd>{% if event.remark is empty %}{{ 'No remarks'|trans }}{% else %}<blockquote class="chill-user-quote">{{ event.remark|nl2br }}</blockquote>{% endif %}</dd>
|
||||
|
||||
<dt class="inline">{{ 'Reasons'|trans }}</dt>
|
||||
{%- if event.reasons is empty -%}
|
||||
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
|
||||
{%- else -%}
|
||||
<dd>{% for r in event.reasons %}{{ m.reason(r) }} {% endfor %}</dd>
|
||||
{%- endif -%}
|
||||
|
||||
</dl>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('chill_event__event_show', { 'event_id': event.id} ) }}" class="sc-button bt-view">
|
||||
{{ 'Show the event'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% if is_granted('CHILL_EVENT_UPDATE', event) %}
|
||||
<li>
|
||||
<a href="{{ path('chill_event__event_edit', { 'event_id': event.id} ) }}" class="sc-button bt-edit">
|
||||
{{ 'Edit the event'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
</ul>
|
||||
</div>
|
242
Timeline/TimelineEventProvider.php
Normal file
242
Timeline/TimelineEventProvider.php
Normal file
@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2019 Champs Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\EventBundle\Timeline;
|
||||
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Class TimelineEventProvider
|
||||
*
|
||||
* @package Chill\EventBundle\Timeline
|
||||
* @author Mathieu Jaumotte jaum_mathieu@collectifs.net
|
||||
*/
|
||||
class TimelineEventProvider implements TimelineProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $helper;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* TimelineEventProvider constructor.
|
||||
*
|
||||
* @param EntityManager $em
|
||||
* @param AuthorizationHelper $helper
|
||||
* @param TokenStorage $storage
|
||||
*/
|
||||
public function __construct(
|
||||
EntityManager $em,
|
||||
AuthorizationHelper $helper,
|
||||
TokenStorage $storage
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->helper = $helper;
|
||||
if (!$storage->getToken()->getUser() instanceof User) {
|
||||
throw new \RuntimeException('A user should be authenticated !');
|
||||
}
|
||||
$this->user = $storage->getToken()->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $context
|
||||
* @param array $args
|
||||
* @return array|string[]
|
||||
* @throws \Doctrine\ORM\Mapping\MappingException
|
||||
*/
|
||||
public function fetchQuery($context, array $args)
|
||||
{
|
||||
$this->checkContext($context);
|
||||
|
||||
$metadataEvent = $this->em->getClassMetadata('ChillEventBundle:Event');
|
||||
$metadataParticipation = $this->em->getClassMetadata('ChillEventBundle:Participation');
|
||||
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person');
|
||||
|
||||
$query = array(
|
||||
'id' => $metadataEvent->getTableName().'.'.$metadataEvent->getColumnName('id'),
|
||||
'type' => 'event',
|
||||
'date' => $metadataEvent->getTableName().'.'.$metadataEvent->getColumnName('date'),
|
||||
'FROM' => $this->getFromClause($metadataEvent, $metadataParticipation, $metadataPerson),
|
||||
'WHERE' => $this->getWhereClause($metadataEvent, $metadataParticipation, $metadataPerson, $args['person'])
|
||||
);
|
||||
|
||||
dump($query);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadata $metadataEvent
|
||||
* @param ClassMetadata $metadataParticipation
|
||||
* @param ClassMetadata $metadataPerson
|
||||
* @return string
|
||||
* @throws \Doctrine\ORM\Mapping\MappingException
|
||||
*/
|
||||
private function getFromClause(
|
||||
ClassMetadata $metadataEvent,
|
||||
ClassMetadata $metadataParticipation,
|
||||
ClassMetadata $metadataPerson
|
||||
) {
|
||||
$eventParticipationMapping = $metadataParticipation->getAssociationMapping('event');
|
||||
$participationPersonMapping = $metadataParticipation->getAssociationMapping('person');
|
||||
|
||||
return $metadataEvent->getTableName()
|
||||
|
||||
.' JOIN '.$metadataParticipation->getTableName()
|
||||
.' ON ' .$metadataParticipation->getTableName()
|
||||
.'.' .$eventParticipationMapping['joinColumns'][0]['name']
|
||||
.' = ' .$metadataEvent->getTableName()
|
||||
.'.' .$eventParticipationMapping['joinColumns'][0]['referencedColumnName']
|
||||
|
||||
.' JOIN '.$metadataPerson->getTableName()
|
||||
.' ON ' .$metadataPerson->getTableName()
|
||||
.'.' .$participationPersonMapping['joinColumns'][0]['referencedColumnName']
|
||||
.' = ' .$metadataParticipation->getTableName()
|
||||
.'.' .$participationPersonMapping['joinColumns'][0]['name']
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadata $metadataEvent
|
||||
* @param ClassMetadata $metadataParticipation
|
||||
* @param ClassMetadata $metadataPerson
|
||||
* @param Person $person
|
||||
* @return string
|
||||
* @throws \Doctrine\ORM\Mapping\MappingException
|
||||
*/
|
||||
private function getWhereClause(
|
||||
ClassMetadata $metadataEvent,
|
||||
ClassMetadata $metadataParticipation,
|
||||
ClassMetadata $metadataPerson,
|
||||
Person $person
|
||||
) {
|
||||
$role = new Role('CHILL_EVENT_SEE');
|
||||
|
||||
$reachableCenters = $this->helper->getReachableCenters($this->user, $role);
|
||||
$associationMapping = $metadataParticipation->getAssociationMapping('person');
|
||||
|
||||
if (count($reachableCenters) === 0) {
|
||||
return 'FALSE = TRUE';
|
||||
}
|
||||
|
||||
$whereClause = sprintf( '%s = %d',
|
||||
$associationMapping['joinColumns'][0]['name'],
|
||||
$person->getId());
|
||||
|
||||
// and
|
||||
$centerAndScopeLines = array();
|
||||
foreach ($reachableCenters as $center) {
|
||||
$reachableCircleId = array_map(
|
||||
function (Scope $scope) { return $scope->getId(); },
|
||||
$this->helper->getReachableCircles($this->user, $role, $person->getCenter())
|
||||
);
|
||||
$centerAndScopeLines[] = sprintf(
|
||||
'(%s = %d AND %s IN (%s))',
|
||||
$metadataPerson->getTableName() . '.' .
|
||||
$metadataPerson->getAssociationMapping('center')['joinColumns'][0]['name'],
|
||||
$center->getId(),
|
||||
$metadataEvent->getTableName() . '.' .
|
||||
$metadataEvent->getAssociationMapping('circle')['joinColumns'][0]['name'],
|
||||
implode(',', $reachableCircleId)
|
||||
);
|
||||
}
|
||||
$whereClause .= ' AND ('. implode(' OR ', $centerAndScopeLines) .')';
|
||||
|
||||
return $whereClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the context is supported
|
||||
*
|
||||
* @param string $context
|
||||
* @throws \LogicException if the context is not supported
|
||||
*/
|
||||
private function checkContext($context)
|
||||
{
|
||||
if ($context !== 'person') {
|
||||
throw new \LogicException("The context '$context' is not "
|
||||
. "supported. Currently only 'person' is supported");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsType($type)
|
||||
{
|
||||
return $type === 'event';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return array|mixed[]
|
||||
*/
|
||||
public function getEntities(array $ids) {
|
||||
|
||||
$events = $this->em->getRepository(Event::class)
|
||||
->findBy(array('id' => $ids));
|
||||
|
||||
$result = array();
|
||||
foreach ($events as $event) {
|
||||
$result[$event->getId()] = $event;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $entity
|
||||
* @param string $context
|
||||
* @param array $args
|
||||
* @return array|mixed[]
|
||||
*/
|
||||
public function getEntityTemplate($entity, $context, array $args) {
|
||||
|
||||
$this->checkContext($context);
|
||||
|
||||
return array(
|
||||
'template' => 'ChillEventBundle:Timeline:event_person_context.html.twig',
|
||||
'template_data' => array(
|
||||
'event' => $entity,
|
||||
'person' => $args['person'],
|
||||
'user' => $this->user
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user