/** The postal address */
const ATTRIBUTE_POSTALADDRESS = 'postalAddress';
+ /** The raw postal address as stored in the database */
+ const ATTRIBUTE_POSTALADDRESSRAW = 'postalAddressRaw';
+
/** The job title */
const ATTRIBUTE_JOBTITLE = 'title';
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_POSTALADDRESS => array(
+ 'base' => array(
+ self::ATTRIBUTE_POSTALADDRESS,
+ ),
+ 'method' => 'getPostalAddress',
),
- self::ATTRIBUTE_POSTALCODE => array(
- 'base' => self::ATTRIBUTE_POSTALADDRESS,
- 'order' => 3,
+ self::ATTRIBUTE_POSTALADDRESSRAW => array(
+ 'base' => array(
+ self::ATTRIBUTE_POSTALADDRESS,
+ ),
+ 'method' => '_get',
+ 'args' => array(
+ self::ATTRIBUTE_POSTALADDRESS,
+ ),
),
- self::ATTRIBUTE_CITY => array(
- 'base' => self::ATTRIBUTE_POSTALADDRESS,
- 'order' => 4,
+ ),
+ 'collapsed' => array(
+ self::ATTRIBUTE_POSTALADDRESS => array(
+ 'base' => array(
+ self::ATTRIBUTE_SN,
+ self::ATTRIBUTE_STREET,
+ self::ATTRIBUTE_POSTOFFICEBOX,
+ self::ATTRIBUTE_POSTALCODE,
+ self::ATTRIBUTE_CITY,
+ ),
),
+ 'method' => 'setPostalAddress',
),
'object_classes' => array(
self::OBJECTCLASS_ORGANIZATIONALPERSON,
}
/**
- * Derive an attribute value.
- *
- * @param string $attr The attribute to derive.
+ * Get the value for the postal address. This is not the complete postal
+ * address but just an additional section you may set to complete the postal
+ * address (things like "c/o John Doe").
*
- * @return mixed The value of the attribute.
+ * @return string The postal address.
*/
- protected function derive($attr)
+ protected function getPostalAddress()
{
- switch ($attr) {
- case self::ATTRIBUTE_POSTALADDRESS:
- return $this->_get(self::ATTRIBUTE_POSTALADDRESS, true);
- default:
- return parent::derive($attr);
+ $postal = $this->_get(self::ATTRIBUTE_POSTALADDRESS, true);
+ if (empty($postal)) {
+ return $postal;
+ }
+ $postal_parts = explode('$', $postal);
+ if (isset($postal_parts[2])) {
+ return $this->unquote($postal_parts[2]);
+ } else {
+ return '';
}
}
/**
- * Collapse derived values back into the main attributes.
+ * Set the complete postal address.
*
* @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.
+ * @param array $attributes The attributes to collapse.
+ * @param array $info The information currently working on.
*
* @return NULL.
*/
- protected function collapse($key, $attributes, &$info, $separator = '$')
+ protected function setPostalAddress($key, $attributes, &$info)
{
- 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;
+ $empty = true;
+ $postalData = array();
+ foreach ($attributes as $attribute) {
+ if (!empty($info[$attribute])) {
+ if (is_array($info[$attribute])) {
+ $new = $info[$attribute][0];
} else {
- $old = $this->_get($attribute, true);
- if (!empty($old)) {
- $postalData[$attribute] = $this->quote($old);
- $empty = false;
- } else {
- $postalData[$attribute] = '';
- }
+ $new = $info[$attribute];
}
- }
-
- if ($empty === true) {
- return;
- }
-
- if (!empty($postalData[self::ATTRIBUTE_STREET])) {
- $postalData['street_segment'] = $postalData[self::ATTRIBUTE_STREET];
+ $postalData[$attribute] = $this->quote($new);
+ $empty = false;
} else {
- $postalData['street_segment'] = $postalData[self::ATTRIBUTE_POSTOFFICEBOX];
+ $old = $this->_get($attribute, true);
+ if (!empty($old)) {
+ $postalData[$attribute] = $this->quote($old);
+ $empty = false;
+ } else {
+ $postalData[$attribute] = '';
+ }
}
+ }
- $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]));
+ if ($empty === true) {
return;
- default:
- return parent::collapse($key, $attributes, &$info, $separator);
}
+
+ if (!empty($postalData[self::ATTRIBUTE_STREET])) {
+ $postalData['street_segment'] = $postalData[self::ATTRIBUTE_STREET];
+ } else {
+ $postalData['street_segment'] = $postalData[self::ATTRIBUTE_POSTOFFICEBOX];
+ }
+
+ $info[$key] = sprintf('%s$%s$%s$%s %s',
+ $postalData[self::ATTRIBUTE_SN],
+ $postalData[self::ATTRIBUTE_POSTALADDRESS],
+ $postalData['street_segment'],
+ $postalData[self::ATTRIBUTE_POSTALCODE],
+ $postalData[self::ATTRIBUTE_CITY]);
}
+
}
\ No newline at end of file