. */ /** * An interface to the contact table in the database */ class Contact extends Model { /** {@inheritDoc} */ public $table = 'contact', $fillable_columns = ['clientId', 'name', 'email', 'address', 'address_2', 'postal_code', 'city', 'country', 'language']; /** * {@inheritDoc} * @param $key {@inheritDoc} * @param $value {@inheritDoc} */ protected function mutator($key, $value) { switch ($key) { case 'language': if (!in_array($value, Correspondence::LANGUAGES)) { throw new Exception("Language $value not available."); } default: return parent::mutator($key, $value); } } /** * Get the client that this contact is linked to * * @return client The client */ public function getClient() { return new Client($this->pdo, $this->clientId); } /** * Make a new offer for this contact * * @throws PDOException If something went wrong with the database * @throws Exception If there was a problem with the input * * @return offer A new instance of the offer class containing the new offer */ public function createOffer() { $stmt = $this->pdo->prepare("INSERT INTO `".Constants::db_prefix."offer` (`contactId`) VALUES (?)"); $stmt->execute(array($this->id)); if ($stmt->rowCount() == 1) { return new Offer($this->pdo, $this->pdo->lastInsertId()); } else { $error = $stmt->errorInfo(); throw new Exception($error[2]); } } /** * Make a mailer to send to this contact * * @return Mailer The mailer */ public function mailer() { $mailer = new Mailer($this->pdo); $mailer->addAddress($this->email, $this->name); return $mailer; } }