<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

use Bitrix\Main\Loader,
    Bitrix\Main\UserTable;

Loader::includeModule('statistic');




// Данные о пользователе
$arResult['ADD_OWNER'] = UserTable::getList([
    'filter' => [
        'ID' => $arResult['CREATED_BY']
    ],
    'select' => [
        'ID',
        'NAME',
        'LAST_NAME',
        'DATE_REGISTER',
        'PERSONAL_PHOTO'
    ]
])->fetch();


// Аватар
$arResult['ADD_OWNER']['USER_PIC'] = CFile::ResizeImageGet(
    $arResult['ADD_OWNER']['PERSONAL_PHOTO'],
    array(
        "width" => 100,
        "height" => 100
    ),
    BX_RESIZE_IMAGE_PROPORTIONAL_ALT,
    false
);

// Дата регистрации пользователя
$arResult['ADD_OWNER']['DATE_REGISTER'] = CIBlockFormatProperties::DateFormat(
    'j F Y',
    MakeTimeStamp(
        $arResult['ADD_OWNER']['DATE_REGISTER'],
        CSite::GetDateFormat()
    )
);


// Онлайн ли автор
$rsData = CUserOnline::GetList(
    $guest_count,
    $session_count,
    false,
    array(
        'USER_AUTH' => 'Y'
    ),
);
while ($ar = $rsData->Fetch()) {
    if ($ar['LAST_USER_ID'] === $arResult['CREATED_BY']) {
        $arResult['ADD_OWNER']['ONLINE'] = 'Y';
        break;
    }
}

// Дата создания в красивом формате
$arResult['DATE_CREATE'] = CIBlockFormatProperties::DateFormat(
    'j F Y в H:i',
    MakeTimeStamp(
        $arResult['DATE_CREATE'],
        CSite::GetDateFormat()
    )
);

// Счетчик объяв пользователя todo можно оптимизировать через $res->getCount()
$k = 0;
$elements = \Bitrix\Iblock\ElementTable::getList([
    'select' => [
        'ID'
    ],
    'filter' => [
        '=ACTIVE' => 'Y',
        'CREATED_BY' => $arResult['CREATED_BY']
    ],
])->fetchAll();
foreach ($elements as $element) {
    $arResult['ADD_OWNER']['COUNT_ADDS'] = $k++;
}


$cp = $this->__component; // объект компонента
if (is_object($cp)) {
    $cp->SetResultCacheKeys(array(
            'ADD_OWNER',
            'OPEN_IN_FRAME'
        )
    );
}

