- Модуль: report
- Путь к файлу: ~/bitrix/modules/report/classes/general/report_helper.php
- Класс: CReportHelper
- Вызов: CReportHelper::formatResultValue
static function formatResultValue($k, &$v, &$row, &$cInfo, $total, &$customChartValue = null)
{
/** @var EntityField $field */
$field = $cInfo['field'];
$dataType = self::getFieldDataType($field);
$isUF = false;
$ufInfo = null;
if (isset($cInfo['isUF']) && $cInfo['isUF'])
{
$isUF = true;
$ufInfo = $cInfo['ufInfo'];
}
if ($isUF && $dataType == 'float' && (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$precision = $defaultPrecision = 1;
if (is_array($ufInfo) && is_array($ufInfo['SETTINGS']) && isset($ufInfo['SETTINGS']['PRECISION']))
$precision = (int)$ufInfo['SETTINGS']['PRECISION'];
if ($precision < 0)
$precision = $defaultPrecision;
$v = round($v, $precision);
}
elseif ($isUF && $dataType === 'enum' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$v = htmlspecialcharsbx(static::getUserFieldEnumerationValue($v, $ufInfo));
}
elseif ($isUF && $dataType === 'file' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldFileValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldFileValueForChart($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'disk_file' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldDiskFileValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldDiskFileValueForChart($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'employee' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldEmployeeValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldEmployeeValueForChart($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'crm' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldCrmValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldCrmValueForChart($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'crm_status' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldCrmStatusValue($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'iblock_element' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldIblockElementValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldIblockElementValueForChart($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'iblock_section' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldIblockSectionValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldIblockSectionValueForChart($valueKey, $ufInfo);
}
elseif ($isUF && $dataType === 'money' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt']))
{
$valueKey = $v;
$v = static::getUserFieldMoneyValue($valueKey, $ufInfo);
// unformatted value for charts
$customChartValue['exist'] = true;
$customChartValue['type'] = 'string';
$customChartValue['value'] = static::getUserFieldMoneyValueForChart($valueKey, $ufInfo);
}
elseif ($dataType == 'datetime' && !empty($v)
&& (empty($cInfo['aggr']) || $cInfo['aggr'] !== 'COUNT_DISTINCT')
&& !mb_strlen($cInfo['prcnt'])
)
{
$v = ($v instanceof BitrixMainTypeDateTime || $v instanceof BitrixMainTypeDate) ? ConvertTimeStamp($v->getTimestamp(), 'SHORT') : '';
}
elseif ($dataType == 'float' && !empty($v) && !$isUF && !mb_strlen($cInfo['prcnt']))
{
$v = round($v, 1);
}
elseif (mb_substr($k, -11) == '_SHORT_NAME' && (empty($cInfo['aggr']) || $cInfo['aggr'] == 'GROUP_CONCAT'))
{
$v = str_replace(
array('#NOBR#', '#/NOBR#'),
array('', ''),
htmlspecialcharsbx($v));
}
elseif (mb_substr($k, -6) == '_PRCNT' && !mb_strlen($cInfo['prcnt']))
{
$v = round($v, 2). '%';
}
elseif ($dataType == 'boolean' && empty($cInfo['aggr']))
{
if ($isUF && empty($v))
$v = 0;
if($v <> '')
{
// get bool value "yes/no"
/** @var EntityBooleanField $field */
$boolValues = ($isUF? array(0, 1) : $field->GetValues());
$fValues = array_flip($boolValues);
$fValue = (bool)$fValues[$v];
$mess = 'REPORT_BOOLEAN_VALUE_'.($fValue? 'TRUE' : 'FALSE');
$v = htmlspecialcharsbx(GetMessage($mess));
}
}
elseif($cInfo['prcnt'] <> '')
{
if($cInfo['prcnt'] == 'self_column')
{
if(array_key_exists('TOTAL_'.$k, $total) && $total['TOTAL_'.$k] > 0)
{
$v = round($v / $total['TOTAL_'.$k] * 100, 2);
}
else
{
$v = '--';
}
}
else
{
$v = round($v, 2);
}
$v = $v.'%';
}
else
{
$v = htmlspecialcharsbx($v);
}
}