/** * Generates a unique external Enquiry identifer. * * @return string * Returns a unique external Enquiry identifier. */ protected function _buildUniqueIdentifier() { $select = $this->select(); $utils = new Application_Core_Utilities(); while (true) { $legacyIdentifier = $utils->_generateRefno(); $select->where('RefNo = ? ', (string) $legacyIdentifier); $row = $this->fetchRow($select); if (empty($row)) { //A unique identifier has been found. break; } } return $legacyIdentifier; }
/** * Creates a new customer in both the DataStore and the LegacyDataStore, * and returns an object representation of this. The object will encapsulate both * the customer identifier, and the legacy customer identifier. * * @param string $emailAddress * The customer's email address. No validation checking is performed on this, * other than to check for a non-empty string. * * @param integer $customerType * Indicates the customer type, typically a tenant, landlord or agent. Must * correspond to a relevant const exposed by the Model_Core_Customer * class: AGENT, LANDLORD or TENANT. * * @param boolean $legacyOnly * If this is set to true then the customer record is only created in the legacy system! * * @return Model_Core_Customer * Returns a Customer object encapsulating the customer details. * * @throws Zend_Exception * Throws a Zend_Exception if parameters are missing, or if the $customerType * is invalid. * * @todo * Email the customer to let them know an account has been created and tell * them there randomly generated password. Not sure if we need to get email * content written by compliance or marketing? */ public function createNewCustomer($emailAddress, $customerType, $legacyOnly = false) { //Validate the data passed in. if (empty($emailAddress) || empty($customerType)) { throw new Zend_Exception('Required parameters missing'); } switch ($customerType) { case Model_Core_Customer::AGENT: case Model_Core_Customer::CUSTOMER: //All is well. break; default: throw new Zend_Exception('Invalid customer type specified.'); } //Save the customer into the DataStore and LegacyDataStore. To do this //first obtain the email address, password, customer type (tenant, landlord, //agent) and an unused legacy identifier (customerRefno). $passwordUtil = new Application_Core_Password(); $password = $passwordUtil->generate(); $utils = new Application_Core_Utilities(); while (true) { $legacyIdentifier = $utils->_generateRefno(); if ($this->_legacyCustomerModel->getConfirmCustomerExists($legacyIdentifier)) { continue; } //A unique identifier has been found. break; } //And create: $this->_legacyCustomerModel->insertCustomer($emailAddress, $password, $legacyIdentifier); if (!$legacyOnly) { $identifier = $this->_customerModel->insertCustomer($emailAddress, $password, $customerType); //Next link the LegacyDataStore and the DataStore. $customerMap = new Datasource_Core_CustomerMaps(); $customerMap->insertMap($legacyIdentifier, $identifier); } //Finally, encapsulate the customer details in a Model_Insurance_Common_Customer_DomainObjects_Customer //object and return. $customer = new Model_Core_Customer(); if (!$legacyOnly) { $customer->setIdentifier(Model_Core_Customer::IDENTIFIER, $identifier); } $customer->setIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER, $legacyIdentifier); $customer->setEmailAddress($emailAddress); $customer->setPassword($password); return $customer; }