Commit 4372a472 authored by Julien Fastré's avatar Julien Fastré
Browse files

Merge branch 'master' into 1.0

parents 1c5c38b0 e939a809
Pipeline #334 failed with stage
......@@ -21,6 +21,8 @@ services:
- '@doctrine.orm.entity_manager'
- '@chill.main.security.authorization.helper'
- '@security.token_storage'
- '@chill.custom_field.helper'
- '%chill_custom_fields.show_empty_values%'
tags:
- { name: chill.timeline, context: 'person' }
......
......@@ -9,12 +9,15 @@
'Report list': 'Liste des rapports'
Details: Détails
Person: Personne
Scope: Scope
Scope: Cercle
Date: Date
User: Utilisateur
'Report type': 'Type de rapport'
'View the report': "Voir le rapport"
'Update the report': "Mettre à jour le rapport"
Report data: Données du rapport
'Report view : %name%': 'Rapport : %name%'
Report: Rapport
#Flash messages
'Success : report created!': "Succès : le rapport a bien été créé !"
......
......@@ -21,6 +21,8 @@
{% block title %}{{ 'Report view' |trans() }}{% endblock title %}
{% block personcontent %}
<h1>{{ 'Report view : %name%' | trans({ '%name%' : entity.cFGroup.getName|localize_translatable_string } ) }}</h1>
<h2 class="chill-red">{{ 'Details'|trans }}</h2>
......@@ -33,12 +35,14 @@
<dd>{{ entity.date|localizeddate('long', 'none') }}</dd>
<dt>{{ 'User'|trans }}&nbsp;:</dt>
<dd>{{ entity.user }}</dd>
<dt>{{ 'Report type'|trans }}&nbsp;:</dt>
<dd>{{ entity.cFGroup.getName(app.request.locale) }}</dd>
{{ chill_custom_fields_group_widget(entity.cFData, entity.cFGroup) }}
</dl>
<h2 class="chill-red">{{ 'Report data'|trans }}</h2>
<dl class="chill_report_view_data">
{{ chill_custom_fields_group_widget(entity.cFData, entity.cFGroup) }}
</dl>
{% if is_granted('CHILL_REPORT_UPDATE', entity) %}
<a class="sc-button bt-update" href="{{ path('report_edit', { 'person_id': entity.person.id, 'report_id': entity.id }) }}"><i class="fa fa-pencil"></i> {{ 'Update the report' | trans }}</a>
{% endif %}
......
......@@ -12,7 +12,7 @@
{% if custom_fields_in_summary|length > 0 %}
<div class="summary">
<hr/>
<dl>
<dl class="chill_report_view_data timeline">
{% for field in custom_fields_in_summary %}
{% if field.type == 'title' %}
{{ chill_custom_field_widget(report.cFData, field) }}
......
......@@ -28,6 +28,8 @@ use Symfony\Component\Security\Core\Role\Role;
use Doctrine\ORM\Mapping\ClassMetadata;
use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Entity\Scope;
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
use Chill\ReportBundle\Entity\Report;
/**
* Provide report for inclusion in timeline
......@@ -56,8 +58,17 @@ class TimelineReportProvider implements TimelineProviderInterface
*/
protected $user;
/**
*
* @var CustomFieldsHelper
*/
protected $customFieldsHelper;
protected $showEmptyValues;
public function __construct(EntityManager $em, AuthorizationHelper $helper,
TokenStorage $storage)
TokenStorage $storage, CustomFieldsHelper $customFieldsHelper,
$showEmptyValues)
{
$this->em = $em;
$this->helper = $helper;
......@@ -68,6 +79,8 @@ class TimelineReportProvider implements TimelineProviderInterface
}
$this->user = $storage->getToken()->getUser();
$this->customFieldsHelper = $customFieldsHelper;
$this->showEmptyValues = $showEmptyValues;
}
/**
......@@ -169,29 +182,61 @@ class TimelineReportProvider implements TimelineProviderInterface
{
$this->checkContext($context);
return array(
'template' => 'ChillReportBundle:Timeline:report_person_context.html.twig',
'template_data' => array(
'report' => $entity,
'custom_fields_in_summary' => $this->getFieldsToRender($entity, $context),
'person' => $args['person'],
'user' => $entity->getUser()
)
);
}
protected function getFieldsToRender(Report $entity, $context, array $args = array())
{
//gather all custom fields which should appears in summary
$customFieldsInSummary = array();
$gatheredFields = array();
if (array_key_exists('summary_fields', $entity->getCFGroup()->getOptions())) {
// keep in memory title
$title = null;
$subtitle = null;
foreach ($entity->getCFGroup()->getCustomFields() as $customField) {
if (in_array($customField->getSlug(),
$entity->getCFGroup()->getOptions()['summary_fields'])) {
$customFieldsInSummary[] = $customField;
// if we do not want to show empty values
if ($this->showEmptyValues === false) {
if ($customField->getType() === 'title') {
$options = $customField->getOptions();
switch($options['type']) {
case 'title': $title = $customField; break;
case 'subtitle': $subtitle = $customField; break;
}
} else {
if ($this->customFieldsHelper->isEmptyValue($entity->getCFData(), $customField)
=== false) {
if ($title !== NULL) {
$gatheredFields[] = $title;
$title = null;
}
if ($subtitle !== NULL) {
$gatheredFields[] = $subtitle;
$subtitle = null;
}
$gatheredFields[] = $customField;
}
}
} else {
$gatheredFields[] = $customField;
}
}
}
}
return $gatheredFields;
return array(
'template' => 'ChillReportBundle:Timeline:report_person_context.html.twig',
'template_data' => array(
'report' => $entity,
'custom_fields_in_summary' => $customFieldsInSummary,
'person' => $args['person'],
'user' => $entity->getUser()
)
);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment