Started fixing the object classes.
authorGunnar Wrobel <p@rdus.de>
Mon, 6 Apr 2009 18:39:03 +0000 (20:39 +0200)
committerGunnar Wrobel <p@rdus.de>
Mon, 6 Apr 2009 18:39:03 +0000 (20:39 +0200)
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Organizationalperson.php

index 5392b18..24de21b 100644 (file)
@@ -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) {
index 293f2b4..45751fe 100644 (file)
@@ -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();
index 3fb3821..817ae7d 100644 (file)
@@ -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.
index 1c3c423..a0c0af1 100644 (file)
@@ -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