mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
fix show empty values in timeline
This commit is contained in:
parent
b672074823
commit
e939a809b1
@ -21,6 +21,8 @@ services:
|
|||||||
- '@doctrine.orm.entity_manager'
|
- '@doctrine.orm.entity_manager'
|
||||||
- '@chill.main.security.authorization.helper'
|
- '@chill.main.security.authorization.helper'
|
||||||
- '@security.token_storage'
|
- '@security.token_storage'
|
||||||
|
- '@chill.custom_field.helper'
|
||||||
|
- '%chill_custom_fields.show_empty_values%'
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.timeline, context: 'person' }
|
- { name: chill.timeline, context: 'person' }
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ use Symfony\Component\Security\Core\Role\Role;
|
|||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
|
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
|
||||||
|
use Chill\ReportBundle\Entity\Report;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide report for inclusion in timeline
|
* Provide report for inclusion in timeline
|
||||||
@ -56,8 +58,17 @@ class TimelineReportProvider implements TimelineProviderInterface
|
|||||||
*/
|
*/
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var CustomFieldsHelper
|
||||||
|
*/
|
||||||
|
protected $customFieldsHelper;
|
||||||
|
|
||||||
|
protected $showEmptyValues;
|
||||||
|
|
||||||
public function __construct(EntityManager $em, AuthorizationHelper $helper,
|
public function __construct(EntityManager $em, AuthorizationHelper $helper,
|
||||||
TokenStorage $storage)
|
TokenStorage $storage, CustomFieldsHelper $customFieldsHelper,
|
||||||
|
$showEmptyValues)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->helper = $helper;
|
$this->helper = $helper;
|
||||||
@ -68,6 +79,8 @@ class TimelineReportProvider implements TimelineProviderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->user = $storage->getToken()->getUser();
|
$this->user = $storage->getToken()->getUser();
|
||||||
|
$this->customFieldsHelper = $customFieldsHelper;
|
||||||
|
$this->showEmptyValues = $showEmptyValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,30 +182,62 @@ class TimelineReportProvider implements TimelineProviderInterface
|
|||||||
{
|
{
|
||||||
$this->checkContext($context);
|
$this->checkContext($context);
|
||||||
|
|
||||||
//gather all custom fields which should appears in summary
|
|
||||||
$customFieldsInSummary = array();
|
|
||||||
if (array_key_exists('summary_fields', $entity->getCFGroup()->getOptions())) {
|
|
||||||
|
|
||||||
foreach ($entity->getCFGroup()->getCustomFields() as $customField) {
|
|
||||||
if (in_array($customField->getSlug(),
|
|
||||||
$entity->getCFGroup()->getOptions()['summary_fields'])) {
|
|
||||||
$customFieldsInSummary[] = $customField;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'template' => 'ChillReportBundle:Timeline:report_person_context.html.twig',
|
'template' => 'ChillReportBundle:Timeline:report_person_context.html.twig',
|
||||||
'template_data' => array(
|
'template_data' => array(
|
||||||
'report' => $entity,
|
'report' => $entity,
|
||||||
'custom_fields_in_summary' => $customFieldsInSummary,
|
'custom_fields_in_summary' => $this->getFieldsToRender($entity, $context),
|
||||||
'person' => $args['person'],
|
'person' => $args['person'],
|
||||||
'user' => $entity->getUser()
|
'user' => $entity->getUser()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getFieldsToRender(Report $entity, $context, array $args = array())
|
||||||
|
{
|
||||||
|
//gather all custom fields which should appears in summary
|
||||||
|
$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'])) {
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user