- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/lib/absence/agent.php
- Класс: BitrixIntranetAbsenceAgent
- Вызов: Agent::general
static function general($iblockElementId, $type)
{
if(Loader::includeModule('iblock') && is_numeric($iblockElementId) && $iblockElementId>0)
{
$iblockId = UserAbsence::getIblockId();
if($iblockId > 0)
{
$userId = CIBlockElement::GetProperty($iblockId, $iblockElementId, ["sort" => "asc"], ["CODE"=>"USER"])->Fetch()['VALUE'];
$absenceType = CIBlockElement::GetProperty($iblockId, $iblockElementId, ["sort" => "asc"], ["CODE"=>"ABSENCE_TYPE"])->Fetch()['VALUE_XML_ID'];
$absence = IblockElementTable::getList(
[
'select' => [
'ACTIVE_FROM',
'ACTIVE_TO'
],
'filter' => [
'ID' => $iblockElementId
]
]
)->Fetch();
if(!empty($userId) && !empty($absenceType) && !empty($absence))
{
$duration = 0;
if($absence['ACTIVE_TO'] instanceof DateTime && $absence['ACTIVE_FROM'] instanceof DateTime)
{
$duration = $absence['ACTIVE_TO']->getTimestamp() - $absence['ACTIVE_FROM']->getTimestamp();
}
$data = [
'USER_ID' => $userId,
'ABSENCE_TYPE' => $absenceType,
'START' => $absence['ACTIVE_FROM'],
'END' => $absence['ACTIVE_TO'],
'DURATION' => $duration,
];
$event = new Event('intranet', $type, $data);
$event->send();
}
}
}
return '';
}