From b712da496cf4194356a3fd4ebf9c73ff7d535e17 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Sat, 11 Apr 2009 09:24:51 +0200 Subject: [PATCH] Final touch to the organizational person class. Added collapsed postal address. --- .../Kolab/Server/Object/Organizationalperson.php | 131 ++++++++++++++++++++- 1 file changed, 127 insertions(+), 4 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php index a51f0b29f..fb7ac3a0a 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php @@ -27,9 +27,30 @@ */ class Horde_Kolab_Server_Object_Organizationalperson extends Horde_Kolab_Server_Object_Person { + /** Define attributes specific to this object type */ - const ATTRIBUTE_POSTALADDRESS = 'postalAddress'; + /** The postal address */ + const ATTRIBUTE_POSTALADDRESS = 'postalAddress'; + /** The job title */ + const ATTRIBUTE_JOBTITLE = 'title'; + + /** The street address */ + const ATTRIBUTE_STREET = 'street'; + + /** The post office box */ + const ATTRIBUTE_POSTOFFICEBOX = 'postOfficeBox'; + + /** The postal code */ + const ATTRIBUTE_POSTALCODE = 'postalCode'; + + /** The city */ + const ATTRIBUTE_CITY = 'l'; + + /** The fax number */ + const ATTRIBUTE_FAX = 'facsimileTelephoneNumber'; + + /** The specific object class of this object type */ const OBJECTCLASS_ORGANIZATIONALPERSON = 'organizationalPerson'; /** @@ -38,9 +59,37 @@ class Horde_Kolab_Server_Object_Organizationalperson extends Horde_Kolab_Server_ * @var array */ static public $init_attributes = array( - /** - * The object classes representing this object. - */ + 'defined' => array( + self::ATTRIBUTE_JOBTITLE, + self::ATTRIBUTE_STREET, + self::ATTRIBUTE_POSTOFFICEBOX, + self::ATTRIBUTE_POSTALCODE, + self::ATTRIBUTE_CITY, + self::ATTRIBUTE_FAX, + self::ATTRIBUTE_POSTALADDRESS, + ), + 'derived' => array( + self::ATTRIBUTE_SN => array( + 'base' => self::ATTRIBUTE_POSTALADDRESS, + 'order' => 0, + ), + self::ATTRIBUTE_STREET => array( + 'base' => self::ATTRIBUTE_POSTALADDRESS, + 'order' => 1, + ), + self::ATTRIBUTE_POSTOFFICEBOX => array( + 'base' => self::ATTRIBUTE_POSTALADDRESS, + 'order' => 2, + ), + self::ATTRIBUTE_POSTALCODE => array( + 'base' => self::ATTRIBUTE_POSTALADDRESS, + 'order' => 3, + ), + self::ATTRIBUTE_CITY => array( + 'base' => self::ATTRIBUTE_POSTALADDRESS, + 'order' => 4, + ), + ), 'object_classes' => array( self::OBJECTCLASS_ORGANIZATIONALPERSON, ), @@ -58,4 +107,78 @@ class Horde_Kolab_Server_Object_Organizationalperson extends Horde_Kolab_Server_ { return '(&(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_ORGANIZATIONALPERSON . '))'; } + + /** + * Derive an attribute value. + * + * @param string $attr The attribute to derive. + * + * @return mixed The value of the attribute. + */ + protected function derive($attr) + { + switch ($attr) { + case self::ATTRIBUTE_POSTALADDRESS: + return $this->_get(self::ATTRIBUTE_POSTALADDRESS, true); + default: + return parent::derive($attr); + } + } + + /** + * Collapse derived values back into the main attributes. + * + * @param string $key The attribute to collapse into. + * @param array $attributes The attribute to collapse. + * @param array &$info The information currently working on. + * @param string $separator Separate the fields using this character. + * + * @return NULL. + */ + protected function collapse($key, $attributes, &$info, $separator = '$') + { + switch ($key) { + case self::ATTRIBUTE_POSTALADDRESS: + $empty = true; + $postalData = array(); + foreach ($attributes as $attribute) { + if (!empty($info[$attribute])) { + if (is_array($info[$attribute])) { + $new = $info[$attribute][0]; + } else { + $new = $info[$attribute]; + } + $postalData[$attribute] = $this->quote($new); + $empty = false; + } else { + $old = $this->_get($attribute, true); + if (!empty($old)) { + $postalData[$attribute] = $this->quote($old); + $empty = false; + } else { + $postalData[$attribute] = ''; + } + } + } + + if ($empty === true) { + return; + } + + if (!empty($postalData[self::ATTRIBUTE_STREET])) { + $postalData['street_segment'] = $postalData[self::ATTRIBUTE_STREET]; + } else { + $postalData['street_segment'] = $postalData[self::ATTRIBUTE_POSTOFFICEBOX]; + } + + $info[self::ATTRIBUTE_POSTALADDRESS] = sprintf('%s$%s$%s %s', + $this->quote($postalData[self::ATTRIBUTE_SN]), + $this->quote($postalData['street_segment']), + $this->quote($postalData[self::ATTRIBUTE_POSTALCODE]), + $this->quote($postalData[self::ATTRIBUTE_CITY])); + return; + default: + return parent::collapse($key, $attributes, &$info, $separator); + } + } } \ No newline at end of file -- 2.11.0