- Модуль: report
- Путь к файлу: ~/bitrix/modules/report/classes/general/report.php
- Класс: CReport
- Вызов: CReport::getFormattedNameExpr
static function getFormattedNameExpr($format, $defPrefix)
{
global $DB;
$values = array(
'#NAME#' => array($DB->IsNull('%s', '' ''), 'NAME'),
'#NAME_SHORT#' => array($DB->Concat("UPPER(".$DB->Substr($DB->IsNull('%s', '' ''), 1, 1).")", "'.'"), 'NAME'),
'#SECOND_NAME#' => array($DB->IsNull('%s', '' ''), 'SECOND_NAME'),
'#SECOND_NAME_SHORT#' => array($DB->Concat("UPPER(".$DB->Substr($DB->IsNull('%s', '' ''), 1, 1).")", "'.'"), 'SECOND_NAME'),
'#LAST_NAME#' => array($DB->IsNull('%s', '' ''), 'LAST_NAME'),
'#LAST_NAME_SHORT#' => array($DB->Concat("UPPER(".$DB->Substr($DB->IsNull('%s', '' ''), 1, 1).")", "'.'"), 'LAST_NAME')
);
if (empty($format))
{
$format = '#LAST_NAME# #NAME_SHORT#';
}
$sql_fields = array(null);
$matches = preg_split(
'/('.join('|', array_keys($values)).')/',
str_replace('%', '%%', $format),
-1, PREG_SPLIT_DELIM_CAPTURE
);
$expression = array();
foreach ($matches as $match)
{
if (array_key_exists($match, $values))
{
$expression[] = $values[$match][0];
$sql_fields[] = (empty($defPrefix) ? '' : $defPrefix.'.').$values[$match][1];
}
elseif ($match !== '')
{
$expression[] = "'".$match."'";
}
}
$expression = call_user_func_array(array($DB, 'Concat'), $expression);
$sql_fields[0] = $expression;
return $sql_fields;
}