| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Integration\Hubspot; |
| 4 |
|
| 5 |
class Common |
| 6 |
{ |
| 7 |
public static function formFldMapping($dataFinal, $fieldMap, $data, $type = '') |
| 8 |
{ |
| 9 |
foreach ($fieldMap as $value) { |
| 10 |
$triggerValue = $value->formField; |
| 11 |
$actionValue = $value->hubspotField; |
| 12 |
if ('custom' === $triggerValue) { |
| 13 |
$dataFinal[$actionValue] = $value->customValue; |
| 14 |
} elseif (!is_null($data[$triggerValue])) { |
| 15 |
if ('deal' === $type) { |
| 16 |
if (strtotime($data[$triggerValue])) { |
| 17 |
$formated = strtotime($data[$triggerValue]); |
| 18 |
$dataFinal[$actionValue] = $formated; |
| 19 |
} else { |
| 20 |
$dataFinal[$actionValue] = $data[$triggerValue]; |
| 21 |
} |
| 22 |
} else { |
| 23 |
$dataFinal[$actionValue] = $data[$triggerValue]; |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
return $dataFinal; |
| 28 |
} |
| 29 |
|
| 30 |
public static function customFldMapping($type, $action, $integrationDetails, $data) |
| 31 |
{ |
| 32 |
$customFields = self::customFields(); |
| 33 |
foreach ($customFields[$type] as $key => $name) { |
| 34 |
if (property_exists($action, $name)) { |
| 35 |
$data[$key] = $integrationDetails->{$name}; |
| 36 |
} |
| 37 |
} |
| 38 |
return $data; |
| 39 |
} |
| 40 |
|
| 41 |
public static function customFields() |
| 42 |
{ |
| 43 |
return [ |
| 44 |
'lead' => [ |
| 45 |
'hs_lead_status' => 'lead_status', |
| 46 |
'lifecyclestage' => 'lifecycle_stage', |
| 47 |
'hubspot_owner_id' => 'contact_owner', |
| 48 |
], |
| 49 |
'deal' => [ |
| 50 |
'hubspot_owner_id' => 'contact_owner', |
| 51 |
'deal_type' => 'dealtype', |
| 52 |
'hs_priority' => 'priority', |
| 53 |
], |
| 54 |
'company' => [ |
| 55 |
'associatedCompanyIds' => 'company', |
| 56 |
'associatedVids' => 'contact', |
| 57 |
], |
| 58 |
]; |
| 59 |
} |
| 60 |
} |
| 61 |
|