- Модуль: timeman
- Путь к файлу: ~/bitrix/modules/timeman/lib/absence.php
- Класс: BitrixTimemanAbsence
- Вызов: Absence::setDesktopStart
static function setDesktopStart($userId)
{
$userId = intval($userId);
if ($userId <= 0 || !self::isActive() || !self::isRegisterDesktop())
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;
}
$currentDate = new BitrixMainTypeDateTime();
$currentDateTime = $currentDate->getTimestamp() - $todayStart->getTimestamp();
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',
'TYPE' => self::TYPE_DESKTOP_START,
'SOURCE_START' => self::SOURCE_DESKTOP_START_EVENT,
'IP_START' => $_SERVER['REMOTE_ADDR'],
'IP_FINISH' => $_SERVER['REMOTE_ADDR'],
));
return true;
}