- Модуль: timeman
- Путь к файлу: ~/bitrix/modules/timeman/lib/absence.php
- Класс: BitrixTimemanAbsence
- Вызов: Absence::setDesktopOnline
static function setDesktopOnline($userId, $currentDate, $lastDate = null)
{
$userId = intval($userId);
if ($userId <= 0 || !self::isActive() || !self::isRegisterDesktop())
return false;
if (
$currentDate && $lastDate
&& $currentDate->getTimestamp() - $lastDate->getTimestamp() < BitrixMainUserTable::getSecondsForLimitOnline()
)
{
return false;
}
$dateStart = (new BitrixMainTypeDateTime())->format('Y-m-d').' 00:00:00';
$orm = BitrixTimemanModelEntriesTable::getList(Array(
'select' => Array(
'ID',
'USER_ID'
),
'filter' => Array(
'=USER_ID' => $userId,
'>=DATE_START' => new BitrixMainDBSqlExpression('?', $dateStart),
'=DATE_FINISH' => null,
),
));
$todayStart = new BitrixMainTypeDateTime((new BitrixMainTypeDateTime())->format('Y-m-d').' 00:00:00', 'Y-m-d H:i:s');
$entryId = 0;
if ($entry = $orm->fetch())
{
$entryId = $entry['ID'];
}
if (!$entryId)
{
return false;
}
$currentDateTime = $currentDate->getTimestamp() - $todayStart->getTimestamp();
if ($lastDate)
{
$systemText = Loc::getMessage('TIMEMAN_ABSENCE_TEXT_DESKTOP_ONLINE_REPORT', [
'#OFFLINE_DATE#' => $lastDate->format(DateTime::getFormat()),
'#ONLINE_DATE#' => $currentDate->format(DateTime::getFormat()),
'#DURATION#' => self::formatDuration($currentDate->getTimestamp() - $lastDate->getTimestamp()),
'#BR#' => "nr"
]);
}
else
{
$systemText = Loc::getMessage('TIMEMAN_ABSENCE_TEXT_DESKTOP_ONLINE_FIRST_TIME');
}
BitrixTimemanModelAbsenceTable::add(Array(
'ENTRY_ID' => $entry['ID'],
'USER_ID' => $entry['USER_ID'],
'DATE_START' => $currentDate,
'TIME_START' => $currentDateTime,
'DATE_FINISH' => $currentDate,
'TIME_FINISH' => $currentDateTime,
'DURATION' => 0,
'ACTIVE' => 'N',
'SYSTEM_TEXT' => $systemText,
'TYPE' => self::TYPE_DESKTOP_ONLINE,
'SOURCE_START' => self::SOURCE_DESKTOP_ONLINE_EVENT,
'IP_START' => $_SERVER['REMOTE_ADDR'],
'IP_FINISH' => $_SERVER['REMOTE_ADDR'],
));
return true;
}