Ejemplo n.º 1
0
 public static function updateMap(EntityConversionMap $map)
 {
     //Synchonize dynamic bindings only
     $srcEntitTypeID = $map->getSourceEntityTypeID();
     $dstEntitTypeID = $map->getDestinationEntityTypeID();
     $outdatedItems = array();
     foreach ($map->getItems() as $item) {
         $srcFieldID = $item->getSourceField();
         $dstFieldID = $item->getDestinationField();
         if ($dstFieldID === '') {
             $dstFieldID = $srcFieldID;
         }
         $isDynamicSrc = EntityConversionMapItem::isDynamicField($srcFieldID);
         $isDynamicDst = EntityConversionMapItem::isDynamicField($dstFieldID);
         $srcField = $isDynamicSrc ? self::getUserField($srcEntitTypeID, $srcFieldID) : null;
         $dstField = $isDynamicDst ? self::getUserField($dstEntitTypeID, $dstFieldID) : null;
         if ($isDynamicSrc && $srcField === null || $isDynamicDst && $dstField === null) {
             $outdatedItems[] = $item;
             continue;
         } elseif ($isDynamicSrc && $srcField !== null && $isDynamicDst && $dstField !== null && !$item->isLocked()) {
             $srcCode = UserFieldSynchronizer::getFieldComplianceCode($srcField);
             $dstCode = UserFieldSynchronizer::getFieldComplianceCode($dstField);
             if ($srcCode !== $dstCode) {
                 $outdatedItems[] = $item;
                 continue;
             }
         }
     }
     if (!empty($outdatedItems)) {
         foreach ($outdatedItems as $item) {
             $map->removeItem($item);
         }
     }
     $intersections = UserFieldSynchronizer::getIntersection($srcEntitTypeID, $dstEntitTypeID);
     foreach ($intersections as $intersection) {
         $srcFieldID = $intersection['SRC_FIELD_NAME'];
         $dstFieldID = $intersection['DST_FIELD_NAME'];
         if ($map->findItemBySourceID($srcFieldID) === null) {
             $map->createItem($srcFieldID, $dstFieldID);
         }
     }
 }
Ejemplo n.º 2
0
 public function map(EntityConversionMap $map, array $options = null)
 {
     $srcFields = $this->getSourceFields();
     if (empty($srcFields)) {
         return array();
     }
     $dstFields = array();
     $dstEntityTypeID = $map->getDestinationEntityTypeID();
     foreach ($map->getItems() as $item) {
         $dstFieldID = $item->getDestinationField();
         //Skip empty binding
         if ($dstFieldID === '-') {
             continue;
         }
         $srcFieldID = $item->getSourceField();
         if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && $srcFieldID !== 'PRODUCT_ROWS') {
             $altSrcFieldID = '';
             foreach ($item->getAlternativeSourceFields() as $fieldID) {
                 if (isset($srcFields[$fieldID])) {
                     $altSrcFieldID = $fieldID;
                     break;
                 }
             }
             if ($altSrcFieldID !== '') {
                 $srcFieldID = $altSrcFieldID;
             }
         }
         if ($dstFieldID === '') {
             $dstFieldID = $srcFieldID;
         }
         if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) {
             self::mapUserField(\CCrmOwnerType::Deal, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options);
         } elseif ($srcFieldID === 'PRODUCT_ROWS') {
             $productRows = \CCrmDeal::LoadProductRows($this->srcEntityID);
             if (count($productRows) > 0) {
                 if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
                     $currencyID = isset($srcFields['CURRENCY_ID']) ? $srcFields['CURRENCY_ID'] : '';
                     if ($currencyID === '' || !\CCrmCurrency::IsExists($currencyID)) {
                         $currencyID = \CCrmCurrency::GetBaseCurrencyID();
                     }
                     $actualRows = \CCrmInvoice::ProductRows2BasketItems($productRows, $currencyID, \CCrmInvoice::GetCurrencyID());
                     if (count($actualRows) > 0) {
                         foreach ($actualRows as &$productRow) {
                             unset($productRow['ID']);
                         }
                         unset($productRow);
                         $dstFields[$dstFieldID] = $actualRows;
                     }
                 } else {
                     foreach ($productRows as &$productRow) {
                         unset($productRow['ID']);
                     }
                     unset($productRow);
                     $dstFields[$dstFieldID] = $productRows;
                 }
             }
         } elseif (isset($srcFields[$srcFieldID])) {
             $dstFields[$dstFieldID] = $srcFields[$srcFieldID];
         }
     }
     if (!empty($dstFields)) {
         if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
             $dstFields['UF_DEAL_ID'] = $this->srcEntityID;
             //region Prepare Invoice Properties
             $dstFields['INVOICE_PROPERTIES'] = array();
             $invoiceEntity = new \CCrmInvoice(false);
             $companyID = isset($dstFields['UF_COMPANY_ID']) ? (int) $dstFields['UF_COMPANY_ID'] : 0;
             $contactID = isset($dstFields['UF_CONTACT_ID']) ? (int) $dstFields['UF_CONTACT_ID'] : 0;
             $personTypeID = 0;
             $personTypes = \CCrmPaySystem::getPersonTypeIDs();
             if ($companyID > 0 && isset($personTypes['COMPANY'])) {
                 $personTypeID = $personTypes['COMPANY'];
             } elseif (isset($personTypes['CONTACT'])) {
                 $personTypeID = $personTypes['CONTACT'];
             }
             $properties = $invoiceEntity->GetProperties(0, $personTypeID);
             if (is_array($properties)) {
                 \CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $invoiceProperties);
                 foreach ($properties as $property) {
                     $dstFields['INVOICE_PROPERTIES'][$property['FIELDS']['ID']] = $property['VALUE'];
                 }
             }
             //endregion
         } elseif ($dstEntityTypeID === \CCrmOwnerType::Quote) {
             $dstFields['DEAL_ID'] = $this->srcEntityID;
         }
     }
     return $dstFields;
 }
Ejemplo n.º 3
0
 public function map(EntityConversionMap $map, array $options = null)
 {
     $srcFields = $this->getSourceFields();
     if (empty($srcFields)) {
         return array();
     }
     $multiFieldKeys = array('PHONE' => true, 'EMAIL' => true, 'WEB' => true, 'IM' => true);
     $dstFields = array();
     $dstEntityTypeID = $map->getDestinationEntityTypeID();
     foreach ($map->getItems() as $item) {
         $dstFieldID = $item->getDestinationField();
         //Skip empty binding
         if ($dstFieldID === '-') {
             continue;
         }
         $srcFieldID = $item->getSourceField();
         if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && !isset($multiFieldKeys[$srcFieldID]) && $srcFieldID !== 'PRODUCT_ROWS') {
             $altSrcFieldID = '';
             foreach ($item->getAlternativeSourceFields() as $fieldID) {
                 if (isset($srcFields[$fieldID])) {
                     $altSrcFieldID = $fieldID;
                     break;
                 }
             }
             if ($altSrcFieldID !== '') {
                 $srcFieldID = $altSrcFieldID;
             }
         }
         if ($dstFieldID === '') {
             $dstFieldID = $srcFieldID;
         }
         if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) {
             self::mapUserField(\CCrmOwnerType::Lead, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options);
         } elseif (isset($multiFieldKeys[$srcFieldID])) {
             $multifields = $this->getSourceMultiFields();
             if (isset($multifields[$dstFieldID])) {
                 if (!isset($dstFields['FM'])) {
                     $dstFields['FM'] = array();
                 }
                 $dstFields['FM'][$dstFieldID] = $multifields[$dstFieldID];
             }
         } elseif ($srcFieldID === 'PRODUCT_ROWS') {
             $productRows = \CCrmLead::LoadProductRows($this->srcEntityID);
             if (count($productRows) > 0) {
                 foreach ($productRows as &$productRow) {
                     unset($productRow['ID']);
                 }
                 unset($productRow);
                 $dstFields[$dstFieldID] = $productRows;
             }
         } elseif (isset($srcFields[$srcFieldID])) {
             $dstFields[$dstFieldID] = $srcFields[$srcFieldID];
         }
     }
     if (!empty($dstFields)) {
         $dstFields['LEAD_ID'] = $this->srcEntityID;
     }
     return $dstFields;
 }
Ejemplo n.º 4
0
 public function map(EntityConversionMap $map, array $options = null)
 {
     $srcFields = $this->getSourceFields();
     if (empty($srcFields)) {
         return array();
     }
     $dstFields = array();
     $dstEntityTypeID = $map->getDestinationEntityTypeID();
     foreach ($map->getItems() as $item) {
         $dstFieldID = $item->getDestinationField();
         //Skip empty binding
         if ($dstFieldID === '-') {
             continue;
         }
         $srcFieldID = $item->getSourceField();
         if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && $srcFieldID !== 'PRODUCT_ROWS') {
             $altSrcFieldID = '';
             foreach ($item->getAlternativeSourceFields() as $fieldID) {
                 if (isset($srcFields[$fieldID])) {
                     $altSrcFieldID = $fieldID;
                     break;
                 }
             }
             if ($altSrcFieldID !== '') {
                 $srcFieldID = $altSrcFieldID;
             }
         }
         if ($dstFieldID === '') {
             $dstFieldID = $srcFieldID;
         }
         if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) {
             self::mapUserField(\CCrmOwnerType::Quote, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options);
         } elseif ($srcFieldID === 'PRODUCT_ROWS') {
             $productRows = \CCrmQuote::LoadProductRows($this->srcEntityID);
             if (count($productRows) > 0) {
                 if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
                     $currencyID = isset($srcFields['CURRENCY_ID']) ? $srcFields['CURRENCY_ID'] : '';
                     if ($currencyID === '' || !\CCrmCurrency::IsExists($currencyID)) {
                         $currencyID = \CCrmCurrency::GetBaseCurrencyID();
                     }
                     $actualRows = \CCrmInvoice::ProductRows2BasketItems($productRows, $currencyID, \CCrmInvoice::GetCurrencyID());
                     if (count($actualRows) > 0) {
                         foreach ($actualRows as &$productRow) {
                             unset($productRow['ID']);
                         }
                         unset($productRow);
                         $dstFields[$dstFieldID] = $actualRows;
                     }
                 } else {
                     foreach ($productRows as &$productRow) {
                         unset($productRow['ID']);
                     }
                     unset($productRow);
                     $dstFields[$dstFieldID] = $productRows;
                 }
             }
         } elseif (isset($srcFields[$srcFieldID])) {
             $dstFields[$dstFieldID] = $srcFields[$srcFieldID];
         }
     }
     if (!empty($dstFields) && $dstEntityTypeID === \CCrmOwnerType::Invoice) {
         $dstFields['UF_QUOTE_ID'] = $this->srcEntityID;
     }
     return $dstFields;
 }