/** * Set model address, Check whether its an array or object of model address. * * @access public * @param array $address [Models_Address] * @return Void */ public function setAddress($address) { if (is_array($address)) { $address = new Models_Address(); $address->setAddress1($address['address1']); $address->setAddress2($address['address2']); $address->setZipCode($address['zipCode']); $address->setCountry($address['country']); $address->setMobileNumber($address['mobileNumber']); $address->setHomeNumber($address['homeNumber']); $this->_address = $address; } elseif (is_a($address, 'Models_Address')) { $this->_address = $address; } else { $this->_errorStack->push(self::VALIDATION_TYPE, 910, $this->_errorList[910]); } }
/** * Update user address using user id. * * @access public * @param int $id [address id] * @param array $data [user address information] * @return bool */ public function updateAddress($id, $data) { $this->_errorStack = Noobh_ErrorStackSingleton::getInstance(); try { if (is_array($data)) { $address1 = htmlspecialchars(htmlspecialchars($data['address1'])); $address2 = htmlspecialchars($data['address2']); $zip = htmlspecialchars($data['zip']); $country = htmlspecialchars($data['country']); $mobileNumber = htmlspecialchars($data['mobileNumber']); $homeNumber = htmlspecialchars($data['homeNumber']); //$addressModel = new Models_Address($userId = null, $id); $addressModel = new Models_Address(); $result = $addressModel->getAddressBy($userId = null, $id); if (!$result) { throw new Exception($this->_errorList[602], 602); } else { echo $addressModel->getAddress1(); $addressModel->setAddress1($address1); $addressModel->setAddress2($address2); $addressModel->setZipCode($zip); $addressModel->setCountry($country); $addressModel->setMobileNumber($mobileNumber); $addressModel->setHomeNumber($homeNumber); if (empty($this->_errorStack->getErrorList())) { $addressModel->save(); } } } else { throw new Exception($this->_errorList[600], 600); } } catch (Exception $ex) { $code = $ex->getCode(); $message = $ex->getMessage(); $this->_errorStack->push(self::VALIDATION_TYPE, $code, $message); Noobh_Log::error($message); throw new Exception($message); } }