['title' => 'First Name', 'type' => self::TYPE_STRING], 'lastName' => ['title' => 'Last Name', 'type' => self::TYPE_STRING], 'email' => ['title' => 'Email', 'type' => self::TYPE_STRING], 'directPhone' => ['title' => 'Direct Phone', 'type' => self::TYPE_STRING], 'cellPhone' => ['title' => 'Cell Phone', 'type' => self::TYPE_STRING], 'photo' => ['title' => 'Photo', 'type' => self::TYPE_STRING], 'bio' => ['title' => 'Bio', 'type' => self::TYPE_STRING], 'linkedInUrl' => ['title' => 'LinkedIn Url', 'type' => self::TYPE_STRING], 'home' => [ 'type' => self::TYPE_ARRAY, 'fields' => [ 'address' => ['title' => 'Home Address', 'type' => self::TYPE_STRING], 'address2' => ['title' => 'Home Address 2', 'type' => self::TYPE_STRING], 'city' => ['title' => 'Home City', 'type' => self::TYPE_STRING], 'state' => ['title' => 'Home State', 'type' => self::TYPE_STRING], 'zip' => ['title' => 'Home Zip', 'type' => self::TYPE_STRING], ], ], 'billing' => [ 'type' => self::TYPE_ARRAY, 'fields' => [ 'firstName' => ['title' => 'Billing Fist Name', 'type' => self::TYPE_STRING], 'lastName' => ['title' => 'Billing Last Name', 'type' => self::TYPE_STRING], 'address' => ['title' => 'Billing Address', 'type' => self::TYPE_STRING], 'address2' => ['title' => 'Billing Address 2', 'type' => self::TYPE_STRING], 'city' => ['title' => 'Billing City', 'type' => self::TYPE_STRING], 'state' => ['title' => 'Billing State', 'type' => self::TYPE_STRING], 'zip' => ['title' => 'Billing Zip', 'type' => self::TYPE_STRING], ], ], 'shipping' => [ 'type' => self::TYPE_ARRAY, 'fields' => [ 'firstName' => ['title' => 'Shipping Fist Name', 'type' => self::TYPE_STRING], 'lastName' => ['title' => 'Shipping Last Name', 'type' => self::TYPE_STRING], 'address' => ['title' => 'Shipping Address', 'type' => self::TYPE_STRING], 'address2' => ['title' => 'Shipping Address 2', 'type' => self::TYPE_STRING], 'city' => ['title' => 'Shipping City', 'type' => self::TYPE_STRING], 'state' => ['title' => 'Shipping State', 'type' => self::TYPE_STRING], 'zip' => ['title' => 'Shipping Zip', 'type' => self::TYPE_STRING], ], ], ]; protected $_data1 = []; protected $_data2 = []; protected $_bioChangedMessage = 'HTML Content Changed'; public function __construct(array $data1, array $data2) { $this->_data1 = $data1; $this->_data2 = $data2; } public function getDiff() { $updatedValues = []; if ($this->_data1 && $this->_data2) { $data1 = $this->_getData4Compare($this->_data1, $this->_fields); $data2 = $this->_getData4Compare($this->_data2, $this->_fields); $data1Diff = Qs_Array::diffRecursive($data1, $data2); $data2Diff = Qs_Array::diffRecursive($data2, $data1); $updatedValues = $this->_getUpdatedValues($data1Diff, $data2Diff, $this->_fields); if (array_key_exists('bio', $updatedValues)) { $updatedValues['bio']['previousValue'] = $this->_bioChangedMessage; $updatedValues['bio']['currentValue'] = $this->_bioChangedMessage; } } return $updatedValues; } protected function _getUpdatedValues(array $prevValues, array $currValues, array $fields, $keyPrefix = null) { $values = []; foreach ($fields as $field => $info) { if (self::TYPE_ARRAY == $info['type']) { $subValues = $this->_getUpdatedValues( Qs_Array::get($prevValues, $field, []), Qs_Array::get($currValues, $field, []), $info['fields'], $field ); if ($subValues) { $values += $subValues; } } else { if (array_key_exists($field, $prevValues)) { $key = (null === $keyPrefix) ? $field : ($keyPrefix . ucfirst($field)); $values[$key] = [ 'title' => $info['title'], 'previousValue' => $prevValues[$field], 'currentValue' => $currValues[$field], ]; } } } return $values; } protected function _getData4Compare(array $data, array $fields) { $prepared = []; if ('y' == Qs_Array::get($data, 'shipping[asBilling]')) { $data[Entity::ADDRESS_SHIPPING] = Qs_Array::get($data, Entity::ADDRESS_BILLING, []); } foreach ($fields as $field => $info) { if (self::TYPE_ARRAY == $info['type']) { $prepared[$field] = $this->_getData4Compare(Qs_Array::get($data, $field, []), $info['fields']); } else { $prepared[$field] = Qs_Array::get($data, $field, ''); } } return $prepared; } }