Ejemplo n.º 1
0
 /**
  * 
  */
 public function getAreaIDByPostcode($postcode)
 {
     $area = Application_Core_Postcode::getAreaCode($postcode);
     $select = $this->select()->where('postcode_area = ?', $area);
     $areaRow = $this->fetchRow($select);
     if (count($areaRow) > 0) {
         return (int) $areaRow['dsi_area_id'];
     }
 }
Ejemplo n.º 2
0
 /**
  * Finds a specific riskarea by postcode outcode
  *
  * @param string $postcode The full UK postcode for the property
  * @param int $productID A valid homelet product ID
  * @return array
  */
 function findByPostcode($postcode, $productID)
 {
     // First we need to check that the postcode is valid, but only run this
     // check if the global.ini parameter test.filterPostcode is set to true
     $params = Zend_Registry::get('params');
     if (is_object($params->test) && $params->test->filterPostcode) {
         $postcodeUtil = new Application_Core_Postcode();
         $postcode = $postcodeUtil->validate($postcode);
         if ($postcode == '') {
             return false;
         }
     }
     $postcodeArray = explode(' ', $postcode);
     $outcode = $postcodeArray[0];
     // This should give us the outcode
     $select = $this->select()->from($this->_name, array('risk_area'))->where('product_id=?', $productID)->where('postcode = ?', $outcode)->where('start_date <= ?', date("Y-m-d"))->where('end_date >= ? OR end_date IS NULL', date("Y-m-d"));
     $row = $this->fetchRow($select);
     if (!empty($row)) {
         $returnVal = $row->risk_area;
     } else {
         $returnVal = null;
     }
     return $returnVal;
 }
Ejemplo n.º 3
0
 /**
  * Fetch a list of addresses by the postcode
  *
  * @param postcode Postcode for the search
  * @param houseNumber Optional house number for the search
  * @return array
  */
 public function getPropertiesByPostcode($postcode, $houseNumber = null)
 {
     // First we need to check that the postcode is valid, but only run this
     // check if the global.ini parameter test.filterPostcode is set to true
     $params = Zend_Registry::get('params');
     if (is_object($params->test) && $params->test->filterPostcode) {
         $postcodeUtils = new Application_Core_Postcode();
         $postcode = $postcodeUtils->validate($postcode);
     }
     if ($postcode != '') {
         $postcodesDataSource = new Datasource_Core_Postcodes();
         $addresses = $postcodesDataSource->getPropertiesByPostcode($postcode, $houseNumber);
         $returnArray = array();
         foreach ($addresses as $address) {
             array_push($returnArray, array('id' => $address->id, 'houseNumber' => $address->NUM, 'buildingName' => $address->SBN != '' ? $address->SBN . ' ' . $address->BNA : $address->BNA, 'address1' => $address->address1, 'address2' => $address->address2, 'address3' => $address->address3, 'address4' => $address->address4, 'address5' => $address->address5, 'postcode' => $address->postcode, 'organisation' => $address->ORG, 'department' => $address->ORD, 'county' => $address->CTP));
         }
     } else {
         // Not a valid postcode - return an error
         return array('error' => true, 'errorMessage' => 'Not a valid postcode');
     }
     // Before we return the raw data - loop through and build some nice single line addresses for form selection
     // WARNING: This may have duplicates due to dropping departments etc.. do an array cleanup before using!
     foreach ($returnArray as &$address) {
         $singleLine = '';
         if ($address['organisation']) {
             $singleLine .= ucwords(strtolower($address['organisation'])) . ', ';
         }
         if ($address['buildingName']) {
             $singleLine .= ucwords(strtolower($address['buildingName'])) . ', ';
         }
         if ($address['houseNumber']) {
             $singleLine .= ucwords(strtolower($address['houseNumber'])) . ', ';
         }
         if ($address['address1']) {
             $singleLine .= ucwords(strtolower($address['address1'])) . ', ';
         }
         if ($address['address2']) {
             $singleLine .= ucwords(strtolower($address['address2'])) . ', ';
         }
         if ($address['address3']) {
             $singleLine .= ucwords(strtolower($address['address3'])) . ', ';
         }
         if ($address['address4']) {
             $singleLine .= ucwords(strtolower($address['address4'])) . ', ';
         }
         if ($address['address5']) {
             $singleLine .= ucwords(strtolower($address['address5'])) . ', ';
         }
         if ($address['county']) {
             $singleLine .= ucwords(strtolower($address['county'])) . ', ';
         }
         $singleLineWithoutPostcode = $singleLine;
         if ($address['postcode']) {
             $singleLine .= strtoupper($address['postcode']) . ', ';
         }
         $singleLine = trim($singleLine, ', ');
         $singleLineWithoutPostcode = trim($singleLineWithoutPostcode, ', ');
         $address['singleLine'] = $singleLine;
         $address['singleLineWithoutPostcode'] = $singleLineWithoutPostcode;
     }
     return $returnArray;
 }