Implement missing methods, abstraction.
authorJan Schneider <jan@horde.org>
Wed, 8 Dec 2010 18:16:49 +0000 (19:16 +0100)
committerJan Schneider <jan@horde.org>
Wed, 8 Dec 2010 18:16:49 +0000 (19:16 +0100)
vilma/lib/Driver.php
vilma/lib/Driver/qmailldap.php
vilma/lib/Driver/sql.php

index c0b54bd..7923c8e 100644 (file)
@@ -9,8 +9,8 @@
  * @author Daniel Collins <horde_dev@argentproductions.com>
  * @package Vilma
  */
-class Vilma_Driver {
-
+abstract class Vilma_Driver
+{
     /**
      * A hash containing any parameters for the current driver.
      *
@@ -29,6 +29,40 @@ class Vilma_Driver {
     }
 
     /**
+     * Returns a list of all users, aliases, or groups and forwards for a
+     * domain.
+     *
+     * @param string $domain      Domain on which to search.
+     * @param string $type        Only return a specific type. One of 'all',
+     *                            'user', 'alias','forward', or 'group'.
+     * @param string $key         Sort list by this key.
+     * @param integer $direction  Sort direction.
+     *
+     * @return array Account information for this domain
+     */
+    public function getAddresses($domain, $type = 'all', $key = 'user_name',
+                                 $direction = 0)
+    {
+        $addresses = $this->_getAddresses($domain, $type);
+        Horde_Array::arraySort($addresses, $key, $direction, true);
+        return $addresses;
+    }
+
+    /**
+     * Returns a list of all users, aliases, or groups and forwards for a
+     * domain.
+     *
+     * @param string $domain      Domain on which to search.
+     * @param string $type        Only return a specific type. One of 'all',
+     *                            'user', 'alias','forward', or 'group'.
+     * @param string $key         Sort list by this key.
+     * @param integer $direction  Sort direction.
+     *
+     * @return array Account information for this domain
+     */
+    abstract protected function _getAddresses($domain, $type = 'all');
+
+    /**
      * Returns all the users sorted by domain and as arrays of each domain.
      *
      * @return array  An array of domains then users for each domain.
@@ -420,6 +454,10 @@ class Vilma_Driver {
         return $domain['max_users'];
     }
 
+    public function getUserFormAttributes()
+    {
+    }
+
     /**
      * Attempts to return a concrete Vilma_Driver instance based on $driver.
      *
index f9a3ab6..43a811b 100644 (file)
@@ -108,30 +108,22 @@ class Vilma_Driver_qmailldap extends Vilma_Driver {
      *
      * @return array Account information for this domain
      */
-    function getAddresses($domain, $type = 'all', $key = 'user_name',
-                          $direction = 0)
+    protected function _getAddresses($domain, $type = 'all')
     {
         Horde::logMessage("Get Addresses Called for $domain with type $type and key $key", 'DEBUG');
         $addresses = array();
         if ($type == 'all' || $type == 'user') {
-            $users = $this->_getUsers($domain);
-            $addresses = array_merge($addresses, $users);
+            $addresses += $this->_getUsers($domain);
         }
         if ($type == 'all' || $type == 'alias') {
-            $aliases = $this->_getAliases($domain);
-            $addresses = array_merge($addresses, $aliases);
+            $addresses += $this->_getAliases($domain);
         }
-        if (($type == 'all') || ($type == 'forward')) {
-            $forwards = $this->_getGroupsAndForwards('forward',$domain);
-            $addresses = array_merge($addresses, $forwards);
+        if ($type == 'all' || $type == 'forward') {
+            $addresses += $this->_getGroupsAndForwards('forward', $domain);
         }
-        if (($type == 'all') || ($type == 'group')) {
-            $groups = $this->_getGroupsAndForwards('group',$domain);
-            $addresses = array_merge($addresses, $groups);
+        if ($type == 'all' || $type == 'group') {
+            $addresses += $this->_getGroupsAndForwards('group', $domain));
         }
-        // Sort the results
-        require_once 'Horde/Array.php';
-        Horde_Array::arraySort($addresses, $key, $direction, true);
         return $addresses;
     }
 
@@ -1197,10 +1189,9 @@ class Vilma_Driver_qmailldap extends Vilma_Driver {
         die("deleteVirtual()");
     }
 
-    function getUserFormAttributes()
+    public function getUserFormAttributes()
     {
-        $attrs = array();
-        $attrs[] = array(
+        return array(array(
             'label' => _("Account Status"),
             'name' => 'user_enabled',
             'type' => 'enum',
@@ -1216,9 +1207,7 @@ class Vilma_Driver_qmailldap extends Vilma_Driver {
                 ),
              ),
              'default' => 'active',
-        );
-
-        return $attrs;
+        ));
     }
 
     function _connect()
index 5d3f3df..2aafc8b 100644 (file)
@@ -197,6 +197,30 @@ class Vilma_Driver_sql extends Vilma_Driver {
     }
 
     /**
+     * Returns a list of all users, aliases, or groups and forwards for a
+     * domain.
+     *
+     * @param string $domain      Domain on which to search.
+     * @param string $type        Only return a specific type. One of 'all',
+     *                            'user', 'alias','forward', or 'group'.
+     * @param string $key         Sort list by this key.
+     * @param integer $direction  Sort direction.
+     *
+     * @return array Account information for this domain
+     */
+    protected function _getAddresses($domain, $type = 'all')
+    {
+        $addresses = array();
+        if ($type == 'all' || $type == 'user') {
+            $addresses += $this->getUsers($domain);
+        }
+        if ($type == 'all' || $type == 'alias') {
+            $addresses += $this->getVirtuals($domain);
+        }
+        return $addresses;
+    }
+
+    /**
      * Returns all available users, if a domain name is passed then limit the
      * list of users only to those users.
      *