2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class Address extends AppModel {
|
|
|
|
|
|
2011-08-29 03:07:32 -07:00
|
|
|
var $name = 'Address';
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-08-29 03:07:32 -07:00
|
|
|
var $validate = array(
|
|
|
|
|
'address' => array(
|
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
|
'message' => 'Please Enter the Addess',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'allowEmpty' => false
|
|
|
|
|
),
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-08-29 03:07:32 -07:00
|
|
|
'city' => array(
|
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
|
'message' => 'Please Enter the City',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'allowEmpty' => false
|
|
|
|
|
),
|
|
|
|
|
'state_id' => array(
|
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
|
'message' => 'Please select the State',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'allowEmpty' => false
|
|
|
|
|
),
|
|
|
|
|
'postcode' => array(
|
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
|
'message' => 'Please enter the Post Code',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'allowEmpty' => false
|
|
|
|
|
),
|
|
|
|
|
'country_id' => array(
|
2011-10-23 20:20:07 -07:00
|
|
|
'numeric' => array(
|
|
|
|
|
'rule' => 'numeric',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'message' => 'Please choose a Country for this Address',
|
|
|
|
|
'on' => 'create'
|
|
|
|
|
),
|
|
|
|
|
'checkStates' => array(
|
|
|
|
|
'rule' => array('checkStates'),
|
|
|
|
|
'message' => ' Australian States can only be chosen if Australia is selected. Otherwise choose "Overseas" for other Countries ',
|
|
|
|
|
'on' => 'create')),
|
|
|
|
|
|
|
|
|
|
|
2011-08-29 03:07:32 -07:00
|
|
|
'type' => array(
|
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
|
'message' => 'Please select the Type of Address',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'allowEmpty' => false
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
|
|
|
var $belongsTo = array(
|
|
|
|
|
'Customer' => array('className' => 'Customer',
|
|
|
|
|
'foreignKey' => 'customer_id',
|
|
|
|
|
'conditions' => '',
|
|
|
|
|
'fields' => '',
|
|
|
|
|
'order' => ''
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
'State' => array('className' => 'State',
|
|
|
|
|
'foreignKey' => 'state_id',
|
|
|
|
|
'conditions' => '',
|
|
|
|
|
'fields' => '',
|
|
|
|
|
'order' => ''),
|
|
|
|
|
|
|
|
|
|
'Country' => array('className' => 'Country',
|
|
|
|
|
'foreignKey' => 'country_id',
|
|
|
|
|
'conditions' => '',
|
|
|
|
|
'fields' => '',
|
|
|
|
|
'order' => ''
|
|
|
|
|
|
2011-10-23 20:20:07 -07:00
|
|
|
|
2011-08-29 03:07:32 -07:00
|
|
|
));
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-10-23 20:20:07 -07:00
|
|
|
|
|
|
|
|
/*Custom Validation Rule to Check that Address with Australian States are assigned to Australia.
|
|
|
|
|
* and that Overseas enquiries are NOT assigned to Australia.
|
|
|
|
|
* Not Portable at all. This code is only for CMC usage
|
|
|
|
|
* Should probably change this to use RegExes.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function checkStates($data) {
|
|
|
|
|
if($this->data['Address']['country_id'] != 1) { //This Enquiry is not for Australia. State must be set to overseas.
|
|
|
|
|
if($this->data['Address']['state_id'] != 9) { //The State isn't set to Overseas. Return false
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($this->data['Address']['country_id'] == 1) { //This enquiry is for Australia. State must be for an Australian State
|
|
|
|
|
if($this->data['Address']['state_id'] == 9) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
?>
|