public function isOutOfDate() { if ($this->isOutOfDate === null) { $srcLastChanged = UserFieldHistory::getLastChangeTime($this->srcEntityTypeID); $dstLastChanged = UserFieldHistory::getLastChangeTime($this->dstEntityTypeID); $lastChanged = null; if ($srcLastChanged !== null && $dstLastChanged !== null) { $lastChanged = $srcLastChanged->getTimestamp() > $dstLastChanged->getTimestamp() ? $srcLastChanged : $dstLastChanged; } elseif ($srcLastChanged !== null || $dstLastChanged !== null) { $lastChanged = $srcLastChanged !== null ? $srcLastChanged : $dstLastChanged; } $this->isOutOfDate = $lastChanged !== null && $lastChanged->getTimestamp() > $this->time->getTimestamp(); } return $this->isOutOfDate; }
public function UpdateField($ID, $arField) { $obUserField = new CUserTypeEntity(); $res = $obUserField->Update($ID, $arField); if ($res) { UserFieldHistory::processModification(CCrmOwnerType::ResolveIDByUFEntityID($this->sUFEntityID), $ID); } if ($res && $arField['USER_TYPE_ID'] == 'enumeration' && is_array($arField['LIST'])) { $obEnum = new CUserFieldEnum(); $res = $obEnum->SetEnumValues($ID, $arField['LIST']); } $this->arUFList = $this->GetUserFields($this->sUFEntityID, 0, LANGUAGE_ID); return $res; }
/** * Prepare synchronization field list. * @static * @param int $srcEntityTypeID Source Entity Type ID * @param int $dstEntityTypeID Destination Entity Type ID * @param string $languageID Language * @return array */ public static function getSynchronizationFields($srcEntityTypeID, $dstEntityTypeID, $languageID = '', $forced = false) { $historyItem = self::getHistoryItem($srcEntityTypeID, $dstEntityTypeID); if ($historyItem !== null && !$forced) { $srcLastChanged = UserFieldHistory::getLastChangeTime($srcEntityTypeID); $dstLastChanged = UserFieldHistory::getLastChangeTime($dstEntityTypeID); $lastChanged = null; if ($srcLastChanged !== null && $dstLastChanged !== null) { $lastChanged = $srcLastChanged->getTimestamp() > $dstLastChanged->getTimestamp() ? $srcLastChanged : $dstLastChanged; } elseif ($srcLastChanged !== null || $dstLastChanged !== null) { $lastChanged = $srcLastChanged !== null ? $srcLastChanged : $dstLastChanged; } $lastChangeTimestamp = $lastChanged !== null ? $lastChanged->getTimestamp() : 0; /** @var DateTime $sync */ $sync = isset($historyItem['sync']) ? $historyItem['sync'] : null; if ($sync !== null && $sync->getTimestamp() > $lastChangeTimestamp) { return array(); } /** @var DateTime $check */ $check = isset($historyItem['check']) ? $historyItem['check'] : null; $required = isset($historyItem['required']) ? $historyItem['required'] : null; if ($check !== null && $check->getTimestamp() > $lastChangeTimestamp && $required === false) { return array(); } } if (!is_string($languageID) || $languageID === '') { $languageID = LANGUAGE_ID; } $srcUfEntityID = \CCrmOwnerType::ResolveUserFieldEntityID($srcEntityTypeID); $dstUfEntityID = \CCrmOwnerType::ResolveUserFieldEntityID($dstEntityTypeID); /** @var \CAllUserTypeManager $USER_FIELD_MANAGER */ global $USER_FIELD_MANAGER; $srcFields = $USER_FIELD_MANAGER->GetUserFields($srcUfEntityID, 0, $languageID); $dstFields = $USER_FIELD_MANAGER->GetUserFields($dstUfEntityID, 0, $languageID); $map = array(); foreach ($dstFields as $field) { $label = self::getFieldComplianceCode($field); if ($label === '') { continue; } $typeID = $field['USER_TYPE_ID']; if (!isset($map[$typeID])) { $map[$typeID] = array(); } if (!isset($map[$typeID][$label])) { $map[$typeID][$label] = true; } } $results = array(); foreach ($srcFields as $field) { $label = self::getFieldComplianceCode($field); if ($label === '') { continue; } $typeID = $field['USER_TYPE_ID']; if (!(isset($map[$typeID]) && isset($map[$typeID][$label]))) { $results[] = $field; } } if ($historyItem === null) { $historyItem = array('sync' => null); } $historyItem['check'] = new DateTime(); $historyItem['required'] = !empty($results); self::setHistoryItem($srcEntityTypeID, $dstEntityTypeID, $historyItem); return $results; }