Проблемы с кодировкой при группировке по алфавиту

Доброго дня, нашел для себя решение по группировке ресурсов по буквам алфавита на modx.ru, работает все, кроме вывода самих букв, они почему-то выводятся в неправильной кодировке.
Вот как делаю:

Сначала получаем идентификаторы всех ресурсов с помощью pdoResources и передаём этот список идентификаторов в свой сниппет.

[[pdoResources?
	&parents=`5,4,2,22,6`
	&depth=`3`
	&hideContainers=`1`
	&includeTVs=`image`
	&sortby=`pagetitle`
	&sortdir=`ASC`
	&showHidden=`1`
	&returnIds=`1`
	&limit=`0`
	&toPlaceholder=`brands`
]]
[[!getBrands?
	&resources=`[[+brands]]`
	&tpl=`brandRow`
	&tplLetter=`brandLetter`
	&tplRowWrapper=`brandRowWrapper`
	&tplWrapper=`brandWrapper`
]]
Сниппет getBrands

Данный сниппет принимает на вход список идентификаторов записей и выводит их, группируя по первой букве.

$output = '';
/* Идентификаторы ресурсов через запятую */
$resources = $modx->getOption('resources', $scriptProperties, false);
/* Шаблон одного бренда */
$tpl = $modx->getOption('tpl', $scriptProperties, false);
/* Шаблон буквы */
$tplLetter = $modx->getOption('tplLetter', $scriptProperties, false);
/* Шаблон обёртки для брендов ($tpl) */
$tplRowWrapper = $modx->getOption('tplRowWrapper', $scriptProperties, false);
/* Шаблон обёртки группы брендов */
$tplWrapper = $modx->getOption('tplWrapper', $scriptProperties, false);
if (!$resources || !$tpl || !$tplLetter || !$tplRowWrapper || !$tplWrapper) {
	return $output;
}
$c = $modx->newQuery('modResource');
$c->where(array(
	'id:IN' => explode(',', $resources),
));
$c->sortby('pagetitle', 'ASC');
$brands = $modx->getCollection('modResource', $c);
if (!is_array($brands)) {
	return $output;
}
$lastLetter = false;
$outputRow = '';
$tree = array();
$prevPagetitle = false; // Предыдущий заголовок страницы для пропуска повторных
foreach ($brands as &$brand) {
	$pagetitle = $brand->get('pagetitle');
	if (!strlen($pagetitle)) {
		continue;
	}
	// Если предыдущий заголовок не первый и равен текущему
	if ($prevPagetitle !== false && $prevPagetitle == $pagetitle) {
		continue;
	}
	$currentLetter = $pagetitle[0];
  	if (!isset($tree[$currentLetter])) {
		$tree[$currentLetter] = array();
	}
	$tree[$currentLetter][] = $modx->getChunk($tpl, $brand->toArray());
	$lastLetter = $currentLetter;
	$prevPagetitle = $pagetitle;
}
foreach ($tree as $letter => &$brands) {
	$outputLetter = $modx->parseChunk($tplLetter, array('letter' => $letter));
	$outputRows = implode('', $brands);
	$outputRows = $modx->parseChunk($tplRowWrapper, array('output' => $outputRows));
	$output .= $modx->parseChunk($tplWrapper, array('output' => $outputLetter.$outputRows));
}
return $output;
В итоге выводится вот так:


В общем проблема только с буквой, помогите.
Антон
22 августа 2016, 15:37
modx.pro
1
1 154
0

Комментарии: 2

Илья Уткин
22 августа 2016, 19:02
+1
$currentLetter = mb_substr($pagetitle, 0,1);
    Антон
    22 августа 2016, 19:22
    0
    Спасибо большое!
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    2