Started cleaning up the object class hierarchy. The object classes should not have...
authorGunnar Wrobel <p@rdus.de>
Mon, 23 Mar 2009 10:27:58 +0000 (10:27 +0000)
committerGunnar Wrobel <p@rdus.de>
Mon, 23 Mar 2009 10:38:09 +0000 (11:38 +0100)
framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/address.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/adminrole.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/base.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/distlist.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/domainmaintainer.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/group.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/server.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/sharedfolder.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/user.php

index 500f3bc..71eef4e 100644 (file)
@@ -31,36 +31,18 @@ class Horde_Kolab_Server_Object
 {
 
     /** Define attributes specific to this object type */
+
+    /** The global ID of this object on the server */
     const ATTRIBUTE_UID          = 'dn';
+
+    /** The ID part of the UID */
     const ATTRIBUTE_ID           = 'id';
-    const ATTRIBUTE_SID          = 'uid';
-    const ATTRIBUTE_CN           = 'cn';
-    const ATTRIBUTE_SN           = 'sn';
-    const ATTRIBUTE_GIVENNAME    = 'givenName';
-    const ATTRIBUTE_FN           = 'fn';
-    const ATTRIBUTE_MAIL         = 'mail';
-    const ATTRIBUTE_DELEGATE     = 'kolabDelegate';
-    const ATTRIBUTE_MEMBER       = 'member';
-    const ATTRIBUTE_VISIBILITY   = 'visible';
-    const ATTRIBUTE_LNFN         = 'lnfn';
-    const ATTRIBUTE_FNLN         = 'fnln';
-    const ATTRIBUTE_DOMAIN       = 'domain';
-    const ATTRIBUTE_DELETED      = 'kolabDeleteFlag';
-    const ATTRIBUTE_FBPAST       = 'kolabFreeBusyPast';
-    const ATTRIBUTE_FBFUTURE     = 'kolabFreeBusyFuture';
-    const ATTRIBUTE_FOLDERTYPE   = 'kolabFolderType';
-    const ATTRIBUTE_HOMESERVER   = 'kolabHomeServer';
-    const ATTRIBUTE_FREEBUSYHOST = 'kolabFreeBusyServer';
-    const ATTRIBUTE_IMAPHOST     = 'kolabImapServer';
-    const ATTRIBUTE_IPOLICY      = 'kolabInvitationPolicy';
+
+    /** The attribute holding the object classes */
+    const ATTRIBUTE_OC           = 'objectClass';
 
     /** Define the possible Kolab object classes */
-    const OBJECTCLASS_TOP                = 'top';
-    const OBJECTCLASS_INETORGPERSON      = 'inetOrgPerson';
-    const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson';
-    const OBJECTCLASS_HORDEPERSON        = 'hordePerson';
-    const OBJECTCLASS_KOLABGROUPOFNAMES  = 'kolabGroupOfNames';
-    const OBJECTCLASS_KOLABSHAREDFOLDER  = 'kolabSharedFolder';
+    const OBJECTCLASS_TOP        = 'top';
 
     /**
      * Link into the Kolab server.
@@ -88,21 +70,6 @@ class Horde_Kolab_Server_Object
     /** FIXME: Add an attribute cache for the get() function */
 
     /**
-     * The LDAP filter to retrieve this object type.
-     *
-     * @var string
-     */
-    public static $filter = '';
-
-    /**
-     * The group the UID must be member of so that this object really
-     * matches this class type. This may not include the root UID.
-     *
-     * @var string
-     */
-    protected $required_group;
-
-    /**
      * The LDAP attributes supported by this class.
      *
      * @var array
@@ -110,7 +77,7 @@ class Horde_Kolab_Server_Object
     public $supported_attributes = false;
 
     /**
-     * Attributes derived from the LDAP values.
+     * Attributes derived from other object attributes.
      *
      * @var array
      */
@@ -130,14 +97,16 @@ class Horde_Kolab_Server_Object
      *
      * @var array
      */
-    protected $object_classes = array();
+    protected $object_classes = array(
+        self::OBJECTCLASS_TOP
+    );
 
     /**
      * Sort by this attributes (must be a LDAP attribute).
      *
      * @var string
      */
-    var $sort_by = self::ATTRIBUTE_SN;
+    var $sort_by = self::ATTRIBUTE_UID;
 
     /**
      * Initialize the Kolab Object. Provide either the UID or a
@@ -209,6 +178,19 @@ class Horde_Kolab_Server_Object
     }
 
     /**
+     * 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_TOP . '))';
+    }
+
+    /**
      * Does the object exist?
      *
      * @return NULL
@@ -231,7 +213,7 @@ class Horde_Kolab_Server_Object
     protected function read()
     {
         $this->_cache = $this->db->read($this->uid,
-                                       $this->supported_attributes);
+                                        $this->supported_attributes);
     }
 
     /**
@@ -247,6 +229,7 @@ class Horde_Kolab_Server_Object
     public function get($attr, $single = true)
     {
         if ($attr != self::ATTRIBUTE_UID) {
+            // FIXME: This wont work this way.
             if ($this->supported_attributes !== false
                 && !in_array($attr, $this->supported_attributes)
                 && !in_array($attr, $this->derived_attributes)) {
@@ -265,8 +248,6 @@ class Horde_Kolab_Server_Object
         switch ($attr) {
         case self::ATTRIBUTE_UID:
             return $this->uid;
-        case self::ATTRIBUTE_FN:
-            return $this->getFn();
         default:
             return $this->_get($attr, $single);
         }
@@ -304,22 +285,8 @@ class Horde_Kolab_Server_Object
     {
         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_LNFN:
-            $gn = $this->_get(self::ATTRIBUTE_GIVENNAME, true);
-            $sn = $this->_get(self::ATTRIBUTE_SN, true);
-            return sprintf('%s, %s', $sn, $gn);
-        case self::ATTRIBUTE_FNLN:
-            $gn = $this->_get(self::ATTRIBUTE_GIVENNAME, true);
-            $sn = $this->_get(self::ATTRIBUTE_SN, true);
-            return sprintf('%s %s', $gn, $sn);
-        default:
-            return false;
+            return substr($this->uid, 0,
+                          strlen($this->uid) - strlen($this->db->getBaseUid()) - 1);
         }
     }
 
@@ -355,68 +322,17 @@ class Horde_Kolab_Server_Object
     }
 
     /**
-     * Get the "first name" attribute of this object
-     *
-     * FIXME: This should get refactored to be combined with the Id value.
-     *
-     * @return string the "first name" of this object
-     */
-    protected function getFn()
-    {
-        $sn = $this->_get(self::ATTRIBUTE_SN, true);
-        $cn = $this->_get(self::ATTRIBUTE_CN, true);
-        return trim(substr($cn, 0, strlen($cn) - strlen($sn)));
-    }
-
-    /**
-     * Get the groups for this object
-     *
-     * @return mixed An array of group ids or a PEAR Error in case of
-     *               an error.
-     */
-    public function getGroups()
-    {
-        return array();
-    }
-
-    /**
-     * Returns the server url of the given type for this user.
-     *
-     * This method can be used to encapsulate multidomain support.
-     *
-     * @param string $server_type The type of server URL that should be returned.
-     *
-     * @return string|PEAR_Error The server url or empty.
-     */
-    public function getServer($server_type)
-    {
-        throw new Horde_Kolab_Server_Exception('Not implemented!');
-    }
-
-    /**
      * Generates an ID for the given information.
      *
      * @param array $info The data of the object.
      *
      * @static
      *
-     * @return string|PEAR_Error The ID.
+     * @return string The ID.
      */
     public static function generateId($info)
     {
-        $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 hash('sha256', uniqid(mt_rand(), true));
     }
 
     /**
@@ -437,7 +353,7 @@ class Horde_Kolab_Server_Object
             }
         }
 
-        $info['objectClass'] = $this->object_classes;
+        $info[self::ATTRIBUTE_OC] = $this->object_classes;
 
         $result = $this->db->save($this->uid, $info);
         if ($result === false || is_a($result, 'PEAR_Error')) {
index e4d8ec6..99fb851 100644 (file)
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object_base
 {
 
     /**
-     * The LDAP filter to retrieve this object type
-     *
-     * @var string
-     */
-    public static $filter = '(&(objectclass=inetOrgPerson)(!(uid=*))(sn=*))';
-
-    /**
      * Attributes derived from the LDAP values.
      *
      * @var array
      */
     public $derived_attributes = array(
-        Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
-        Horde_Kolab_Server_Object::ATTRIBUTE_FNLN,
+        self::ATTRIBUTE_LNFN,
+        self::ATTRIBUTE_FNLN,
     );
 
     /**
@@ -52,12 +45,25 @@ class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object
      * @var array
      */
     protected $object_classes = array(
-        Horde_Kolab_Server_Object::OBJECTCLASS_TOP,
-        Horde_Kolab_Server_Object::OBJECTCLASS_INETORGPERSON,
-        Horde_Kolab_Server_Object::OBJECTCLASS_KOLABINETORGPERSON,
+        self::OBJECTCLASS_TOP,
+        self::OBJECTCLASS_INETORGPERSON,
+        self::OBJECTCLASS_KOLABINETORGPERSON,
     );
 
     /**
+     * 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 '(&(objectclass=inetOrgPerson)(!(uid=*))(sn=*))';
+    }
+
+    /**
      * Convert the object attributes to a hash.
      *
      * @param string $attrs The attributes to return.
@@ -68,7 +74,7 @@ class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object
     {
         if (!isset($attrs)) {
             $attrs = array(
-                Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
+                self::ATTRIBUTE_LNFN,
             );
         }
         return parent::toHash($attrs);
index 5230e91..ade18c1 100644 (file)
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object_base
 {
 
     /**
-     * The LDAP filter to retrieve this object type
-     *
-     * @var string
-     */
-    public static $filter = '(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))';
-
-    /**
      * Attributes derived from the LDAP values.
      *
      * @var array
      */
     public $derived_attributes = array(
-        Horde_Kolab_Server_Object::ATTRIBUTE_ID,
-        Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
+        self::ATTRIBUTE_ID,
+        self::ATTRIBUTE_LNFN,
     );
 
     /**
@@ -51,9 +44,9 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
      * @var array
      */
     protected $object_classes = array(
-        Horde_Kolab_Server_Object::OBJECTCLASS_TOP,
-        Horde_Kolab_Server_Object::OBJECTCLASS_INETORGPERSON,
-        Horde_Kolab_Server_Object::OBJECTCLASS_KOLABINETORGPERSON,
+        self::OBJECTCLASS_TOP,
+        self::OBJECTCLASS_INETORGPERSON,
+        self::OBJECTCLASS_KOLABINETORGPERSON,
     );
 
     /**
@@ -65,6 +58,19 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
     protected $required_group;
 
     /**
+     * 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 '(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))';
+    }
+
+    /**
      * Convert the object attributes to a hash.
      *
      * @param string $attrs The attributes to return.
@@ -75,8 +81,8 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
     {
         if (!isset($attrs)) {
             $attrs = array(
-                Horde_Kolab_Server_Object::ATTRIBUTE_SID,
-                Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
+                self::ATTRIBUTE_SID,
+                self::ATTRIBUTE_LNFN,
             );
         }
         return parent::toHash($attrs);
@@ -111,10 +117,10 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
             $parts           = split(',', $this->required_group);
             list($groupname) = sscanf($parts[0], 'cn=%s');
 
-            $result = $this->db->add(array(Horde_Kolab_Server_Object::ATTRIBUTE_CN => $groupname,
+            $result = $this->db->add(array(self::ATTRIBUTE_CN => $groupname,
                                            'type' => 'Horde_Kolab_Server_Object_group',
-                                           Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER => $members,
-                                           Horde_Kolab_Server_Object::ATTRIBUTE_VISIBILITY => false));
+                                           self::ATTRIBUTE_MEMBER => $members,
+                                           self::ATTRIBUTE_VISIBILITY => false));
             if (is_a($result, 'PEAR_Error')) {
                 return $result;
             }
@@ -126,7 +132,7 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
             if ($result === false) {
                 $members   = $admin_group->getMembers();
                 $members[] = $this->uid;
-                $admin_group->save(array(Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER => $members));
+                $admin_group->save(array(self::ATTRIBUTE_MEMBER => $members));
             }
         }
         return parent::save($info);
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/base.php
new file mode 100644 (file)
index 0000000..9b59e59
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+/**
+ * A bsaic object representation.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * This class provides basic methods common to all Kolab server objects.
+ *
+ * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Kolab_Server_Object_base extends Horde_Kolab_Server_Object
+{
+
+    const ATTRIBUTE_SID          = 'uid';
+    const ATTRIBUTE_CN           = 'cn';
+    const ATTRIBUTE_SN           = 'sn';
+    const ATTRIBUTE_GIVENNAME    = 'givenName';
+    const ATTRIBUTE_FN           = 'fn';
+    const ATTRIBUTE_MAIL         = 'mail';
+    const ATTRIBUTE_DELEGATE     = 'kolabDelegate';
+    const ATTRIBUTE_MEMBER       = 'member';
+    const ATTRIBUTE_VISIBILITY   = 'visible';
+    const ATTRIBUTE_LNFN         = 'lnfn';
+    const ATTRIBUTE_FNLN         = 'fnln';
+    const ATTRIBUTE_DOMAIN       = 'domain';
+    const ATTRIBUTE_DELETED      = 'kolabDeleteFlag';
+    const ATTRIBUTE_FBPAST       = 'kolabFreeBusyPast';
+    const ATTRIBUTE_FBFUTURE     = 'kolabFreeBusyFuture';
+    const ATTRIBUTE_FOLDERTYPE   = 'kolabFolderType';
+    const ATTRIBUTE_HOMESERVER   = 'kolabHomeServer';
+    const ATTRIBUTE_FREEBUSYHOST = 'kolabFreeBusyServer';
+    const ATTRIBUTE_IMAPHOST     = 'kolabImapServer';
+    const ATTRIBUTE_IPOLICY      = 'kolabInvitationPolicy';
+
+    const OBJECTCLASS_INETORGPERSON      = 'inetOrgPerson';
+    const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson';
+    const OBJECTCLASS_HORDEPERSON        = 'hordePerson';
+    const OBJECTCLASS_KOLABGROUPOFNAMES  = 'kolabGroupOfNames';
+    const OBJECTCLASS_KOLABSHAREDFOLDER  = 'kolabSharedFolder';
+
+    /**
+     * The group the UID must be member of so that this object really
+     * matches this class type. This may not include the root UID.
+     *
+     * @var string
+     */
+    protected $required_group;
+
+    /**
+     * The attributes supported by this class
+     *
+     * @var array
+     */
+/*     public $supported_attributes = array( */
+/*         self::ATTRIBUTE_FBPAST, */
+/*     ); */
+
+
+    /**
+     * 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.
+     *
+     * @static
+     *
+     * @return string|PEAR_Error The ID.
+     */
+    public static function generateId($info)
+    {
+        $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,");
+    }
+
+}
\ No newline at end of file
index f27985c..a03d43d 100644 (file)
  */
 class Horde_Kolab_Server_Object_distlist extends Horde_Kolab_Server_Object_group
 {
-
     /**
-     * The LDAP filter to retrieve this object type
+     * Return the filter string to retrieve this object type.
+     *
+     * @static
      *
-     * @var string
+     * @return string The filter to retrieve this object type from the server
+     *                database.
      */
-    public static $filter = '(&(objectClass=kolabGroupOfNames)(mail=*))';
+    public static function getFilter()
+    {
+        return '(&(objectClass=kolabGroupOfNames)(mail=*))';
+    }
 };
index c04fa67..1549abc 100644 (file)
@@ -34,9 +34,9 @@ class Horde_Kolab_Server_Object_domainmaintainer extends Horde_Kolab_Server_Obje
      * @var array
      */
     public $derived_attributes = array(
-        Horde_Kolab_Server_Object::ATTRIBUTE_ID,
-        Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
-        Horde_Kolab_Server_Object::ATTRIBUTE_DOMAIN,
+        self::ATTRIBUTE_ID,
+        self::ATTRIBUTE_LNFN,
+        self::ATTRIBUTE_DOMAIN,
     );
 
     /**
@@ -58,9 +58,9 @@ class Horde_Kolab_Server_Object_domainmaintainer extends Horde_Kolab_Server_Obje
     {
         if (!isset($attrs)) {
             $attrs = array(
-                Horde_Kolab_Server_Object::ATTRIBUTE_SID,
-                Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
-                Horde_Kolab_Server_Object::ATTRIBUTE_DOMAIN,
+                self::ATTRIBUTE_SID,
+                self::ATTRIBUTE_LNFN,
+                self::ATTRIBUTE_DOMAIN,
             );
         }
         return parent::toHash($attrs);
@@ -75,7 +75,7 @@ class Horde_Kolab_Server_Object_domainmaintainer extends Horde_Kolab_Server_Obje
      */
     public function save($info)
     {
-        foreach ($info[Horde_Kolab_Server_Object::ATTRIBUTE_DOMAIN] as $domain) {
+        foreach ($info[self::ATTRIBUTE_DOMAIN] as $domain) {
             $domain_uid = sprintf('cn=%s,cn=domain,cn=internal,%s',
                                   $domain, $this->db->getBaseUid());
 
@@ -87,8 +87,8 @@ class Horde_Kolab_Server_Object_domainmaintainer extends Horde_Kolab_Server_Obje
             }
             if (!$domain_group->exists()) {
                 $members = array($this->uid);
-                $domain_group->save(array(Horde_Kolab_Server_Object::ATTRIBUTE_CN => $domain,
-                                          Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER => $members));
+                $domain_group->save(array(self::ATTRIBUTE_CN => $domain,
+                                          self::ATTRIBUTE_MEMBER => $members));
             } else {
                 $result = $domain_group->isMember($this->uid);
                 if (is_a($result, 'PEAR_Error')) {
@@ -97,7 +97,7 @@ class Horde_Kolab_Server_Object_domainmaintainer extends Horde_Kolab_Server_Obje
                 if ($result === false) {
                     $members   = $domain_group->getMembers();
                     $members[] = $this->uid;
-                    $domain_group->save(array(Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER => $members));
+                    $domain_group->save(array(self::ATTRIBUTE_MEMBER => $members));
                 }
             }
         }
index 3578c55..17d35a6 100644 (file)
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object_base
 {
 
     /**
-     * The LDAP filter to retrieve this object type
-     *
-     * @var string
-     */
-    public static $filter = '(objectClass=kolabGroupOfNames)';
-
-    /**
      * Attributes derived from the LDAP values.
      *
      * @var array
      */
     public $derived_attributes = array(
-        Horde_Kolab_Server_Object::ATTRIBUTE_ID,
-        Horde_Kolab_Server_Object::ATTRIBUTE_VISIBILITY,
+        self::ATTRIBUTE_ID,
+        self::ATTRIBUTE_VISIBILITY,
     );
 
     /**
@@ -51,9 +44,9 @@ class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
      * @var array
      */
     protected $object_classes = array(
-        Horde_Kolab_Server_Object::OBJECTCLASS_TOP,
-        Horde_Kolab_Server_Object::OBJECTCLASS_INETORGPERSON,
-        Horde_Kolab_Server_Object::OBJECTCLASS_KOLABGROUPOFNAMES,
+        self::OBJECTCLASS_TOP,
+        self::OBJECTCLASS_INETORGPERSON,
+        self::OBJECTCLASS_KOLABGROUPOFNAMES,
     );
 
     /**
@@ -61,7 +54,20 @@ class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
      *
      * @var string
      */
-    public $sort_by = Horde_Kolab_Server_Object::ATTRIBUTE_MAIL;
+    public $sort_by = self::ATTRIBUTE_MAIL;
+
+    /**
+     * 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 '(objectClass=kolabGroupOfNames)';
+    }
 
     /**
      * Derive an attribute value.
@@ -91,9 +97,9 @@ class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
     {
         if (!isset($attrs)) {
             $attrs = array(
-                Horde_Kolab_Server_Object::ATTRIBUTE_ID,
-                Horde_Kolab_Server_Object::ATTRIBUTE_MAIL,
-                Horde_Kolab_Server_Object::ATTRIBUTE_VISIBILITY,
+                self::ATTRIBUTE_ID,
+                self::ATTRIBUTE_MAIL,
+                self::ATTRIBUTE_VISIBILITY,
             );
         }
         return parent::toHash($attrs);
@@ -143,7 +149,7 @@ class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
      */
     public function getMembers()
     {
-        return $this->_get(Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER, false);
+        return $this->_get(self::ATTRIBUTE_MEMBER, false);
     }
 
     /**
@@ -160,7 +166,7 @@ class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
             return $members;
         }
         if (!in_array($member, $members)) {
-            $this->_cache[Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER][] = $member;
+            $this->_cache[self::ATTRIBUTE_MEMBER][] = $member;
         } else {
             return PEAR::raiseError(_("The UID %s is already a member of the group %s!"),
                                     $member, $this->_uid);
@@ -182,8 +188,8 @@ class Horde_Kolab_Server_Object_group extends Horde_Kolab_Server_Object
             return $members;
         }
         if (in_array($member, $members)) {
-            $this->_cache[Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER] =
-                array_diff($this->_cache[Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER],
+            $this->_cache[self::ATTRIBUTE_MEMBER] =
+                array_diff($this->_cache[self::ATTRIBUTE_MEMBER],
                            array($member));
         } else {
             return PEAR::raiseError(_("The UID %s is no member of the group %s!"),
index 42a7f12..8c8702c 100644 (file)
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Object_server extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_server extends Horde_Kolab_Server_Object_base
 {
 
     /**
-     * The LDAP filter to retrieve this object type
-     *
-     * @var string
-     */
-    public static $filter = '(&((k=kolab))(objectclass=kolab))';
-
-    /**
      * The attributes supported by this class
      *
      * @var array
      */
     public $supported_attributes = array(
-        Horde_Kolab_Server_Object::ATTRIBUTE_FBPAST,
+        self::ATTRIBUTE_FBPAST,
     );
 
+    /**
+     * 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 '(&((k=kolab))(objectclass=kolab))';
+    }
 }
\ No newline at end of file
index e904ebd..74195b5 100644 (file)
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Object_sharedfolder extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_sharedfolder extends Horde_Kolab_Server_Object_base
 {
 
     /**
-     * The LDAP filter to retrieve this object type
-     *
-     * @var string
-     */
-    public static $filter = '(objectClass=kolabSharedFolder)';
-
-    /**
      * The ldap classes for this type of object.
      *
      * @var array
      */
     protected $object_classes = array(
-        Horde_Kolab_Server_Object::OBJECTCLASS_TOP,
-        Horde_Kolab_Server_Object::OBJECTCLASS_KOLABSHAREDFOLDER,
+        self::OBJECTCLASS_TOP,
+        self::OBJECTCLASS_KOLABSHAREDFOLDER,
     );
 
     /**
+     * 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 '(objectClass=kolabSharedFolder)';
+    }
+
+    /**
      * Generates an ID for the given information.
      *
      * @param array $info The data of the object.
@@ -71,9 +77,9 @@ class Horde_Kolab_Server_Object_sharedfolder extends Horde_Kolab_Server_Object
     {
         if (!isset($attrs)) {
             $attrs = array(
-                Horde_Kolab_Server_Object::ATTRIBUTE_CN,
-                Horde_Kolab_Server_Object::ATTRIBUTE_HOMESERVER,
-                Horde_Kolab_Server_Object::ATTRIBUTE_FOLDERTYPE,
+                self::ATTRIBUTE_CN,
+                self::ATTRIBUTE_HOMESERVER,
+                self::ATTRIBUTE_FOLDERTYPE,
             );
         }
         return parent::toHash($attrs);
index 85beac2..cefbf73 100644 (file)
@@ -26,7 +26,7 @@
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object_base
 {
 
     /** Define attributes specific to this object type */
@@ -39,13 +39,6 @@ class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object
     const USERTYPE_RESOURCE = 3;
 
     /**
-     * The LDAP filter to retrieve this object type
-     *
-     * @var string
-     */
-    public static $filter = '(&(objectClass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))';
-
-    /**
      * The attributes supported by this class
      *
      * @var array
@@ -58,6 +51,7 @@ class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object
      * @var array
      */
     public $derived_attributes = array(
+        self::ATTRIBUTE_FN,
         'id',
         'usertype',
         //FIXME: Do we really want to have this type of functionality within this library?
@@ -115,6 +109,19 @@ class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object
     }
 
     /**
+     * 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  '(&(objectClass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))';
+    }
+
+    /**
      * Derive an attribute value.
      *
      * @param string $attr The attribute to derive.
@@ -134,6 +141,16 @@ class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object
             } else {
                 return self::USERTYPE_STANDARD;
             }
+        case self::ATTRIBUTE_LNFN:
+            $gn = $this->_get(self::ATTRIBUTE_GIVENNAME, true);
+            $sn = $this->_get(self::ATTRIBUTE_SN, true);
+            return sprintf('%s, %s', $sn, $gn);
+        case self::ATTRIBUTE_FNLN:
+            $gn = $this->_get(self::ATTRIBUTE_GIVENNAME, true);
+            $sn = $this->_get(self::ATTRIBUTE_SN, true);
+            return sprintf('%s %s', $gn, $sn);
+        case self::ATTRIBUTE_FN:
+            return $this->getFn();
         default:
             return parent::derive($attr);
         }
@@ -160,6 +177,20 @@ class Horde_Kolab_Server_Object_user extends Horde_Kolab_Server_Object
     }
 
     /**
+     * Get the "first name" attribute of this object
+     *
+     * FIXME: This should get refactored to be combined with the Id value.
+     *
+     * @return string the "first name" of this object
+     */
+    protected function getFn()
+    {
+        $sn = $this->_get(self::ATTRIBUTE_SN, true);
+        $cn = $this->_get(self::ATTRIBUTE_CN, true);
+        return trim(substr($cn, 0, strlen($cn) - strlen($sn)));
+    }
+
+    /**
      * Get the groups for this object
      *
      * @return mixed|PEAR_Error An array of group ids, false if no groups were