From 31c893713981d3083cc4171945b4e36f90ccba2e Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 6 Apr 2009 20:39:03 +0200 Subject: [PATCH] Started fixing the object classes. --- .../Horde/Kolab/Server/Object/Inetorgperson.php | 76 +++++++++------------- .../lib/Horde/Kolab/Server/Object/Kolab/User.php | 5 +- .../Kolab/Server/Object/Kolabinetorgperson.php | 62 ------------------ .../Kolab/Server/Object/Organizationalperson.php | 46 ++----------- 4 files changed, 37 insertions(+), 152 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php index 5392b1889..24de21b0d 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php @@ -51,65 +51,54 @@ class Horde_Kolab_Server_Object_Inetorgperson extends Horde_Kolab_Server_Object_ self::ATTRIBUTE_GIVENNAME, self::ATTRIBUTE_MAIL, ), - /** - * Derived attributes are calculated based on other attribute values. - */ 'derived' => array( self::ATTRIBUTE_GIVENNAME => array( + 'base' => self::ATTRIBUTE_GIVENNAME, + 'order' => 0, 'desc' => 'Given name.', ), self::ATTRIBUTE_MIDDLENAMES => array( + 'base' => self::ATTRIBUTE_GIVENNAME, + 'order' => 1, 'desc' => 'Additional names separated from the given name by whitespace.', ), ), - /** - * Default values for attributes without a value. - */ 'defaults' => array( ), - /** - * Locked attributes. These are fixed after the object has been stored - * once. They may not be modified again. - */ 'locked' => array( + self::ATTRIBUTE_MAIL, ), - /** - * The object classes representing this object. - */ 'object_classes' => array( self::OBJECTCLASS_INETORGPERSON, ), ); /** + * Return the filter string to retrieve this object type. + * + * @static + * + * @return string The filter to retrieve this object type from the server + * database. + */ + public static function getFilter() + { + return '(&(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_INETORGPERSON . '))'; + } + + /** * Derive an attribute value. * * @param string $attr The attribute to derive. * * @return mixed The value of the attribute. */ - protected function derive($attr) + protected function derive($attr, $separator = '$') { switch ($attr) { - case self::ATTRIBUTE_ID: - $result = split(',', $this->uid); - if (substr($result[0], 0, 3) == 'cn=') { - return substr($result[0], 3); - } else { - return $result[0]; - } case self::ATTRIBUTE_GIVENNAME: case self::ATTRIBUTE_MIDDLENAMES: - $gn = $this->_get(self::ATTRIBUTE_GIVENNAME); - if (empty($gn)) { - return; - } - list($a[self::ATTRIBUTE_GIVENNAME], - $a[self::ATTRIBUTE_MIDDLENAMES]) = explode(' ', $gn, 2); - if (empty($a[$attr])) { - return; - } - return $a[$attr]; + return $this->getField($attr, ' ', 2); default: return parent::derive($attr); } @@ -123,23 +112,15 @@ class Horde_Kolab_Server_Object_Inetorgperson extends Horde_Kolab_Server_Object_ * * @return mixed The value of the attribute. */ - protected function collapse($attr, &$info) + protected function collapse($key, $attributes, &$info, $separator = '$') { - switch ($attr) { + switch ($key) { case self::ATTRIBUTE_GIVENNAME: - case self::ATTRIBUTE_MIDDLENAMES: - if (!isset($info[self::ATTRIBUTE_MIDDLENAMES]) - && !isset($info[self::ATTRIBUTE_GIVENNAME])) { - return; - } - - if (isset($info[self::ATTRIBUTE_MIDDLENAMES])) { - $givenname = isset($info[self::ATTRIBUTE_GIVENNAME]) ? $info[self::ATTRIBUTE_GIVENNAME] : ''; - $info[self::ATTRIBUTE_GIVENNAME] = $givenname . isset($info[self::ATTRIBUTE_MIDDLENAMES]) ? ' ' . $info[self::ATTRIBUTE_MIDDLENAMES] : ''; - unset($info[self::ATTRIBUTE_MIDDLENAMES]); - } + parent::collapse($key, $attributes, $info, ' '); + break; default: - return parent::derive($attr); + parent::collapse($key, $attributes, $info, $separator); + break; } } @@ -155,8 +136,9 @@ class Horde_Kolab_Server_Object_Inetorgperson extends Horde_Kolab_Server_Object_ */ public static function generateId($info) { - $id_mapfields = array('givenName', 'sn'); - $id_format = '%s %s'; + $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, + self::ATTRIBUTE_SN); + $id_format = self::ATTRIBUTE_CN . '=' . '%s %s'; $fieldarray = array(); foreach ($id_mapfields as $mapfield) { diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php index 293f2b4bb..45751fee7 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php @@ -257,14 +257,15 @@ class Horde_Kolab_Server_Object_Kolab_User extends Horde_Kolab_Server_Object_Kol if (isset($conf['kolab']['server']['user_id_mapfields'])) { $id_mapfields = $conf['kolab']['server']['user_id_mapfields']; } else { - $id_mapfields = array('givenName', 'sn'); + $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, + self::ATTRIBUTE_SN); } /** The user ID format. */ if (isset($conf['kolab']['server']['user_id_format'])) { $id_format = $conf['kolab']['server']['user_id_format']; } else { - $id_format = '%s %s'; + $id_format = self::ATTRIBUTE_CN . '=' . '%s %s'; } $fieldarray = array(); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php index 3fb3821a0..817ae7d22 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php @@ -46,81 +46,19 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob * @var array */ static public $init_attributes = array( - /** - * Derived attributes are calculated based on other attribute values. - */ 'derived' => array( ), - /** - * Default values for attributes without a value. - */ 'defaults' => array( ), - /** - * Locked attributes. These are fixed after the object has been stored - * once. They may not be modified again. - */ 'locked' => array( self::ATTRIBUTE_MAIL, ), - /** - * The object classes representing this object. - */ 'object_classes' => array( self::OBJECTCLASS_KOLABINETORGPERSON, ), ); /** - * 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_ID: - $result = split(',', $this->uid); - if (substr($result[0], 0, 3) == self::ATTRIBUTE_CN . '=') { - return substr($result[0], 3); - } else { - return $result[0]; - } - default: - return parent::derive($attr); - } - } - - /** - * Generates an ID for the given information. - * - * @param array $info The data of the object. - * - * @static - * - * @return string|PEAR_Error The ID. - */ - public static function generateId($info) - { - $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, - self::ATTRIBUTE_SN); - $id_format = '%s %s'; - - $fieldarray = array(); - foreach ($id_mapfields as $mapfield) { - if (isset($info[$mapfield])) { - $fieldarray[] = $info[$mapfield]; - } else { - $fieldarray[] = ''; - } - } - - return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,"); - } - - /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. 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 1c3c4239c..a0c0af19c 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php @@ -63,51 +63,15 @@ class Horde_Kolab_Server_Object_Organizationalperson extends Horde_Kolab_Server_ ); /** - * 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_ID: - $result = split(',', $this->uid); - if (substr($result[0], 0, 3) == 'cn=') { - return substr($result[0], 3); - } else { - return $result[0]; - } - default: - return parent::derive($attr); - } - } - - /** - * Generates an ID for the given information. - * - * @param array $info The data of the object. + * Return the filter string to retrieve this object type. * * @static * - * @return string|PEAR_Error The ID. + * @return string The filter to retrieve this object type from the server + * database. */ - public static function generateId($info) + public static function getFilter() { - $id_mapfields = array('givenName', 'sn'); - $id_format = '%s %s'; - - $fieldarray = array(); - foreach ($id_mapfields as $mapfield) { - if (isset($info[$mapfield])) { - $fieldarray[] = $info[$mapfield]; - } else { - $fieldarray[] = ''; - } - } - - return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,"); + return '(&(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_ORGANIZATIONALPERSON . '))'; } - } \ No newline at end of file -- 2.11.0