* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBDatasource'); /** * String Salutation * * Simple string functions * * @todo merge with WBGeo_Address * @todo resolve persongenderid * @todo salutation stuff * @version 0.1.0 * @package WB * @subpackage base */ class WBString_Salutation extends WBStdClass { private $data = array( 'persongender' => WBDatasource::PERSONGENDER_NEUTRAL, 'title' => '', 'name' => '', 'salutation' => '', 'greeting' => '' ); /** * Default Constructor * * @param array */ public function __construct($parameter = array()) { } /** * Get Name Data * * @param string named address part or empty for all * @return string|array */ public function get($column = '') { if (empty($column)) { return $this->data; } // avoid notice if (!isset($this->data[$column])) { return ''; } return $this->data[$column]; } /** * Gender Code * * Use PERSONGENDER_NEUTRAL to reset to default * * @param string id of gender */ public function setGender($id = WBDatasource::PERSONGENDER_NEUTRAL) { $this->data['persongender'] = $id; } /** * Set Name * * Use name and parse it to figure out * * @param string name */ public function setName($name = '') { $this->data['name'] = ''; $this->data['title'] = ''; $this->parseNameLine($name); } /** * Get Salutation * * @return string */ public function getSalutation() { $this->buildGreetingAndSalutation(); return $this->data['salutation']; } /** * Get Greeting * * @return string */ public function getGreeting() { $this->buildGreetingAndSalutation(); return $this->data['greetiing']; } /** * Build Greeting and Salutation * * Use gender, title and name to create proper salutation as well as greetings */ private function buildGreetingAndSalutation() { $name = $this->data['name']; if (!empty($this->data['title'])) { $name = sprintf('%s %s', $this->data['title'], $name); } switch ($this->data['persongender']) { case WBDatasource::PERSONGENDER_FEMALE: $gre = sprintf('Sehr geehrte Frau %s', $name); $sal = 'Frau'; break; case WBDatasource::PERSONGENDER_MALE: $gre = sprintf('Sehr geehrter Herr %s', $name); $sal = 'Herr'; break; default: $gre = 'Sehr geehrte Damen und Herren'; $sal = ''; break; } $this->data['salutation'] = $sal; $this->data['greetiing'] = $gre; } /** * Parse Name * * Extract gender, * * @todo @implement for different languages */ private function parseNameLine($line) { // Frau / Herr if (preg_match('/^Frau\s+/i', $line)) { $this->data['title'] = 'Frau'; $line = preg_replace('/^Frau\s+/', '', $line); $this->data['persongender'] = WBDatasource::PERSONGENDER_FEMALE; } else if (preg_match('/^Herr\s+/', $line)) { $this->data['title'] = 'Herr'; $line = preg_replace('/^Herr\s+/', '', $line); $this->data['persongender'] = WBDatasource::PERSONGENDER_MALE; } if (empty($this->data['name'])) { $this->data['name'] = $line; return; } $this->data['name'] .= "\n" . $line; } }