- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/classes/general/hrxml.php
- Класс: CUserHRXMLImport
- Вызов: CUserHRXMLImport::ImportSyncTimeCard
private function ImportSyncTimeCard($xml)
{
$absenceTypePropertyId = 0;
$rsProperty = CIBlockProperty::GetList(
array(),
array('IBLOCK_ID' => $this->ABSENCE_IBLOCK_ID, 'CODE' => 'ABSENCE_TYPE')
);
if ($arProperty = $rsProperty->Fetch())
$absenceTypePropertyId = $arProperty['ID'];
if ($absenceTypePropertyId > 0)
{
$db_enum_list = CIBlockProperty::GetPropertyEnum(
$absenceTypePropertyId,
array(),
array('IBLOCK_ID' => $this->ABSENCE_IBLOCK_ID)
);
$arStates = array();
while ($ar_enum_list = $db_enum_list->GetNext())
{
$arStates[$ar_enum_list['XML_ID']] = array(
'ID' => $ar_enum_list['ID'],
'NAME' => $ar_enum_list['VALUE']
);
}
}
$obElement = &$this->__element;
foreach ($xml->TimeCard as $timeCard)
{
if (isset($timeCard->ReportedResource))
{
$personID = $this->GetPersonGUID($timeCard->ReportedResource->SpecifiedPerson->PersonID);
$arUserFields = array(
'XML_ID' => $this->FindUserByPersonID($personID),
'ACTIVE' => 'Y',
);
if (empty($arUserFields['XML_ID']))
{
$this->warnings[] = str_replace('#ID#', $personID, GetMessage('IBLOCK_HR_USER_NOT_FOUND'));
continue;
}
$arTimePROP = array();
$rsUser = CUser::GetList(
"ID",
"desc",
$arUserFields,
array('FIELDS' => array('ID'))
);
if ($arUser = $rsUser->fetch())
$arTimePROP['USER'] = $arUser['ID'];
else
continue;
foreach ($timeCard->TimeCardReportedItem as $timeItem)
{
if ($absenceTypePropertyId > 0 && isset($timeItem->TimeInterval->TimeIntervalTypeCode))
{
$timeIntervalTypeCode = (string) $timeItem->TimeInterval->TimeIntervalTypeCode;
if (array_key_exists($timeIntervalTypeCode, $arStates))
{
$arTimePROP['ABSENCE_TYPE'] = $arStates[$timeIntervalTypeCode]['ID'];
}
else
{
$ibpenum = new CIBlockPropertyEnum;
$attr = $timeItem->TimeInterval->TimeIntervalTypeCode->attributes();
$attr = (array) $attr;
$attr = array_shift($attr);
$arFields = array(
'PROPERTY_ID' => $absenceTypePropertyId,
'VALUE' => $attr['name'],
'XML_ID' => $timeIntervalTypeCode,
);
$arFields = $this->ConvertCharset($arFields);
if ($PropID = $ibpenum->Add($arFields))
{
$arTimePROP['ABSENCE_TYPE'] = $PropID;
$arStates[$timeIntervalTypeCode] = array(
'ID' => $PropID,
'NAME' => $arFields['VALUE'],
);
}
}
}
$arTimeRecord = array(
'ACTIVE' => 'Y',
'IBLOCK_ID' => $this->ABSENCE_IBLOCK_ID,
'PROPERTY_VALUES' => $arTimePROP,
'ACTIVE_FROM' => explode('-', (string) $timeItem->TimeInterval->FreeFormEffectivePeriod->StartDate->FormattedDateTime),
'ACTIVE_TO' => explode('-', (string) $timeItem->TimeInterval->FreeFormEffectivePeriod->EndDate->FormattedDateTime),
);
$arTimeRecord['ACTIVE_FROM'] = $arTimeRecord['ACTIVE_FROM'][2].'.'
.$arTimeRecord['ACTIVE_FROM'][1].'.'
.$arTimeRecord['ACTIVE_FROM'][0];
$arTimeRecord['ACTIVE_TO'] = $arTimeRecord['ACTIVE_TO'][2].'.'
.$arTimeRecord['ACTIVE_TO'][1].'.'
.$arTimeRecord['ACTIVE_TO'][0];
$arTimeRecord = $this->ConvertCharset($arTimeRecord);
$arTimeRecord['NAME'] = $arStates[$timeIntervalTypeCode]['NAME'];
$result = $obElement->Add($arTimeRecord);
}
}
}
return true;
}