Example #1
0
 protected static function mergeMultiFields(array &$seed, array &$targ)
 {
     if (empty($seed)) {
         return;
     }
     $targMap = array();
     foreach ($targ as $typeID => &$fields) {
         $typeMap = array();
         foreach ($fields as &$field) {
             $value = isset($field['VALUE']) ? trim($field['VALUE']) : '';
             if ($value === '') {
                 continue;
             }
             $key = $typeID === \CCrmFieldMulti::PHONE ? Crm\Integrity\DuplicateCommunicationCriterion::normalizePhone($value) : strtolower($value);
             if ($key !== '' && !isset($typeMap[$key])) {
                 $typeMap[$key] = true;
             }
         }
         unset($field);
         if (!empty($typeMap)) {
             $targMap[$typeID] =& $typeMap;
         }
         unset($typeMap);
     }
     unset($fields);
     foreach ($seed as $typeID => &$fields) {
         $fieldNum = 1;
         foreach ($fields as $field) {
             $value = isset($field['VALUE']) ? trim($field['VALUE']) : '';
             if ($value === '') {
                 continue;
             }
             $key = $typeID === \CCrmFieldMulti::PHONE ? Crm\Integrity\DuplicateCommunicationCriterion::normalizePhone($value) : strtolower($value);
             if ($key !== '' && (!isset($targMap[$typeID]) || !isset($targMap[$typeID][$key]))) {
                 if (!isset($targ[$typeID])) {
                     $targ[$typeID] = array();
                 }
                 while (isset($targ[$typeID]["n{$fieldNum}"])) {
                     $fieldNum++;
                 }
                 $targ[$typeID]["n{$fieldNum}"] = $field;
             }
         }
     }
     unset($fields);
 }