From 21d29a89cd82bb0f611b37d941d72977aec83dbd Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 6 Apr 2009 20:38:26 +0200 Subject: [PATCH] Improved deriving attributes. --- .../Kolab_Server/lib/Horde/Kolab/Server/Object.php | 33 +++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php index 3bef6390a..5c71aaaaf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php @@ -343,26 +343,39 @@ class Horde_Kolab_Server_Object * * @return mixed The value of the attribute. */ - protected function derive($attr, $separator = '$') + protected function derive($attr) { switch ($attr) { case self::ATTRIBUTE_ID: return substr($this->uid, 0, strlen($this->uid) - strlen($this->server->getBaseUid()) - 1); default: - $basekey = $this->attributes[$attr]['base']; - $base = $this->_get($basekey); - if (empty($base)) { - return; - } - $fields = explode($separator, $base); //FIXME: Fill the cache here - return isset($fields[$this->attributes[$attr]['order']]) ? $fields[$this->attributes[$attr]['order']] : null; - + return $this->getField($attr); } } /** + * Get a derived attribute value. + * + * @param string $attr The attribute to derive. + * @param string $separator The field separator. + * @param int $max_count The maximal number of fields. + * + * @return mixed The value of the attribute. + */ + protected function getField($attr, $separator = '$', $max_count = null) + { + $basekey = $this->attributes[$attr]['base']; + $base = $this->_get($basekey); + if (empty($base)) { + return; + } + $fields = explode($separator, $base, $max_count); + return isset($fields[$this->attributes[$attr]['order']]) ? $fields[$this->attributes[$attr]['order']] : null; + } + + /** * Collapse derived values back into the main attributes. * * @param string $key The attribute to collapse into. @@ -374,7 +387,7 @@ class Horde_Kolab_Server_Object */ protected function collapse($key, $attributes, &$info, $separator = '$') { - switch ($attr) { + switch ($key) { default: /** * Check how many empty entries we have at the end of the array. We -- 2.11.0