tableName = 'Electorate'; $this->keyField = 'ID'; /* A listing of legal fields */ $this->fields = array( 'ID' => 'NUMERIC', 'PollNumber' => 'NUMERIC', 'FirstName' => 'STRING', 'MiddleName' => 'STRING', 'LastName' => 'STRING', 'Salutation' => 'STRING', 'StreetNumber' => 'NUMERIC', 'StreetNumberSuffix' => 'ENUM', 'Street' => 'STRING', 'StreetType' => 'STRING', 'StreetDirection' => 'STRING', 'Unit' => 'STRING', 'City' => 'STRING', 'Province' => 'PROVINCE', 'PostalCode' => 'POSTAL', 'PhoneNumber' => 'PHONE', 'VotingAttention' => 'ENUM', 'Canvassed' => 'BOOL', 'Phoned' => 'BOOL', 'PhoneLookedUp' => 'BOOL', 'Voted' => 'BOOL' ); /* A listing of fields that may be null */ $this->legallyNull = array( 'StreetNumberSuffix' => 1, 'Unit' => 1, 'Canvassed' => 1, 'Phoned' => 1, 'PhoneLookup' => 1, 'Voted' => 1, 'MiddleName' => 1, 'StreetDirection' => 1 ); $this->DatabaseTableRow($id); } /* Get and set the ID value */ function id($id = null) { if ($id != null && $this->data['ID'] == null) { $this->data['ID'] = $id; } /* Return the current ID value. */ return($this->data['ID']); } /* Get and set the pollNumber */ function pollNumber($poll = null) { /* See if we are setting a value. */ if ($poll != null) { $this->data['PollNumber'] = $poll; } /* Return the currently value of the Poll Number */ return($this->data['PollNumber']); } /* Get and set the first name */ function name($salutation = null, $first = null, $last = null, $middle = null) { /* See if we are setting a value */ if ($salutation != null) { $this->data['Salutation'] = $salutation; } if ($first != null) { $this->data['FirstName'] = $first; } if ($last != null) { $this->data['LastName'] = $last; } if ($middle != null) { $this->data['MiddleName'] = $middle; } /* Return the current value of the firstName */ return(array($this->data['Salutation'], $this->data['FirstName'], $this->data['LastName'], $this->data['MiddleName'])); } /* Get and set the phone number */ function phoneNumber($phone = null) { /* Set the value if it exists */ if ($phone != null) { $this->data['PhoneNumber'] = $phone; } /* Return the current value of phone number */ return($this->data['PhoneNumber']); } /* Get and set the address */ function address($number=null, $suffix=null, $street = null, $streetType = null, $unit = null, $city = null, $prov = null, $postal = null) { /* Set the various values if they exists */ if ($number != null) { $this->data['StreetNumber'] = $number; } if ($suffix!= null) { $this->data['StreetNumberSuffix'] = $suffix; } if ($street != null) { $this->data['Street'] = $street; } if ($streetType != null) { $this->data['StreetType'] = $streetType; } if ($unit != null) { $this->data['Unit'] = $unit; } if ($city != null) { $this->data['City'] = $city; } if ($prov != null) { $this->data['Province'] = $prov; } if ($postal != null) { $this->data['PostalCode'] = $postal; } /* Return the address */ return(array( $this->data['StreetNumber'], $this->data['StreetNumberSuffix'], $this->data['Street'], $this->data['StreetType'], $this->data['Unit'], $this->data['City'], $this->data['Province'], $this->data['PostalCode'])); } /* Get and set the Votting Attention */ function votingAttention($attn = null) { /* Set the value if we have one to set */ if ($attn != null) { $this->data['VotingAttention'] = $attn; } /* Return the current value */ return($this->data['VotingAttention']); } /* Get intention as number instead of string enum */ function votingIntentionAsNumber() { switch ($intention) { case 'Definite': return 1; case 'Probably': return 2; case 'Possibly': return 3; case 'Not': return 4; case 'Hostile': return 5; default: return 0; } } /* Get and set the canvassed flag */ function canvassed($bool = null) { /* Set the value if it's not null */ if ($bool != null) { $this->data['Canvassed'] = $bool; } /* Return the current value */ return($this->data['Canvassed']); } /* Get and set the Phoned flag */ function phoned($bool = null) { /* Set the value if it's not null */ if ($bool != null) { $this->data['Phoned'] = $bool; } /* Return the current value */ return($this->data['Phoned']); } /* Get and set the PhonedLookUp flag */ function phonedLookUp($bool = null) { /* Set the value if it's not null */ if ($bool != null) { $this->data['PhoneLookedUp'] = $bool; } /* Return the current value */ return($this->data['PhoneLookedUp']); } /* Get and set the Voted flag */ function voted($bool = null) { /* Set the value if it's not null */ if ($bool != null) { $this->data['Voted'] = $bool; } /* Return the current value */ return($this->data['Voted']); } /** Really just for testing, but you never know */ function insert() { $sql = "INSERT INTO " . $this->table . " SET "; $sets = array(); foreach ($this->fields as $field) { if (null !== $this->data[$field]) { $sets[] = $field . "='" . mysql_real_escape_string($this->data[$field]) . "'"; } else { if ($this->legallyNull[$field] != 1) { $this->errorMessage = "Field '$field' is null"; $this->errorLine = __LINE__; return(false); } } } $sql .= join(', ', $sets); $sql .= ";"; /* Execute the query */ if (!mysql_query($sql, $this->link)) { $this->errorMessage = "DB Error(" . mysql_errno() . ") - " . mysql_error() . " - $sql"; $this->errorLine = __LINE__; return(false); } return(true); } /** Builds a string representation of the address. */ function getTextualAddress() { extract($this->data); $unit = ''; if ('' != $Unit) { $unit = $Unit . '-'; } $suffix = ''; if ($StreetNumberSuffix != '') { $suffix = ' ' . $StreetNumberSuffix; } $type = $StreetType; if (($p = strpos($type, '/')) !== FALSE) { $type = substr($type, 0, $p); # Snip off french. } $dir = ''; if ($StreetDirection != '') { $dir = ' ' . $StreetDirection; } return $unit . $StreetNumber . $suffix . ' ' . $Street . ' ' . $type . $dir; } } ?>