[Svn] r2353 - branches/devel-api/program/include

trac at roundcube.net trac at roundcube.net
Fri Mar 13 12:29:21 CET 2009


Author: thomasb
Date: 2009-03-13 06:29:21 -0500 (Fri, 13 Mar 2009)
New Revision: 2353

Added:
   branches/devel-api/program/include/rcube_addressbook.php
Modified:
   branches/devel-api/program/include/rcube_contacts.php
   branches/devel-api/program/include/rcube_ldap.php
Log:
Create abstract addressbook class to define the interface of future address book extensions

Added: branches/devel-api/program/include/rcube_addressbook.php
===================================================================
--- branches/devel-api/program/include/rcube_addressbook.php	                        (rev 0)
+++ branches/devel-api/program/include/rcube_addressbook.php	2009-03-13 11:29:21 UTC (rev 2353)
@@ -0,0 +1,169 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/include/rcube_addressbook.php                                 |
+ |                                                                       |
+ | This file is part of the RoundCube Webmail client                     |
+ | Copyright (C) 2006-2009, RoundCube Dev. - Switzerland                 |
+ | Licensed under the GNU GPL                                            |
+ |                                                                       |
+ | PURPOSE:                                                              |
+ |   Interface to the local address book database                        |
+ |                                                                       |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube at gmail.com>                        |
+ +-----------------------------------------------------------------------+
+
+ $Id:  $
+
+*/
+
+
+/**
+ * Abstract skeleton of an address book/repository
+ *
+ * @package Addressbook
+ */
+abstract class rcube_addressbook
+{
+    /** public properties */
+    var $primary_key;
+    var $readonly = true;
+    var $ready = false;
+    var $list_page = 1;
+    var $page_size = 10;
+
+    /**
+     * Save a search string for future listings
+     *
+     * @param mixed Search params to use in listing method, obtained by get_search_set()
+     */
+    abstract function set_search_set($filter);
+
+    /**
+     * Getter for saved search properties
+     *
+     * @return mixed Search properties used by this class
+     */
+    abstract function get_search_set();
+
+    /**
+     * Reset saved results and search parameters
+     */
+    abstract function reset();
+
+    /**
+     * List the current set of contact records
+     *
+     * @param  array  List of cols to show
+     * @param  int    Only return this number of records, use negative values for tail
+     * @return array  Indexed list of contact records, each a hash array
+     */
+    abstract function list_records($cols=null, $subset=0);
+
+    /**
+     * Search records
+     *
+     * @param array   List of fields to search in
+     * @param string  Search value
+     * @param boolean True if results are requested, False if count only
+     * @return Indexed list of contact records and 'count' value
+     */
+    abstract function search($fields, $value, $strict=false, $select=true);
+
+    /**
+     * Count number of available contacts in database
+     *
+     * @return object rcube_result_set Result set with values for 'count' and 'first'
+     */
+    abstract function count();
+
+    /**
+     * Return the last result set
+     *
+     * @return object rcube_result_set Current result set or NULL if nothing selected yet
+     */
+    abstract function get_result();
+
+    /**
+     * Get a specific contact record
+     *
+     * @param mixed record identifier(s)
+     * @param boolean True to return record as associative array, otherwise a result set is returned
+     * @return mixed Result object with all record fields or False if not found
+     */
+    abstract function get_record($id, $assoc=false);
+
+    /**
+     * Close connection to source
+     * Called on script shutdown
+     */
+    function close() { }
+
+    /**
+     * Set internal list page
+     *
+     * @param  number  Page number to list
+     * @access public
+     */
+    function set_page($page)
+    {
+      $this->list_page = (int)$page;
+    }
+
+    /**
+     * Set internal page size
+     *
+     * @param  number  Number of messages to display on one page
+     * @access public
+     */
+    function set_pagesize($size)
+    {
+      $this->page_size = (int)$size;
+    }
+
+    /**
+     * Create a new contact record
+     *
+     * @param array Assoziative array with save data
+     * @param boolean True to check for duplicates first
+     * @return The created record ID on success, False on error
+     */
+    function insert($save_data, $check=false)
+    {
+      /* empty for read-only address books */
+    }
+
+    /**
+     * Update a specific contact record
+     *
+     * @param mixed Record identifier
+     * @param array Assoziative array with save data
+     * @return True on success, False on error
+     */
+    function update($id, $save_cols)
+    {
+      /* empty for read-only address books */
+    }
+
+    /**
+     * Mark one or more contact records as deleted
+     *
+     * @param array  Record identifiers
+     */
+    function delete($ids)
+    {
+      /* empty for read-only address books */
+    }
+
+    /**
+     * Remove all records from the database
+     */
+    function delete_all()
+    {
+      /* empty for read-only address books */
+    }
+
+}
+ 
\ No newline at end of file

Modified: branches/devel-api/program/include/rcube_contacts.php
===================================================================
--- branches/devel-api/program/include/rcube_contacts.php	2009-03-11 21:43:18 UTC (rev 2352)
+++ branches/devel-api/program/include/rcube_contacts.php	2009-03-13 11:29:21 UTC (rev 2353)
@@ -25,7 +25,7 @@
  *
  * @package Addressbook
  */
-class rcube_contacts
+class rcube_contacts extends rcube_addressbook
 {
   var $db = null;
   var $db_name = '';
@@ -60,30 +60,6 @@
 
 
   /**
-   * Set internal list page
-   *
-   * @param  number  Page number to list
-   * @access public
-   */
-  function set_page($page)
-  {
-    $this->list_page = (int)$page;
-  }
-
-
-  /**
-   * Set internal page size
-   *
-   * @param  number  Number of messages to display on one page
-   * @access public
-   */
-  function set_pagesize($size)
-  {
-    $this->page_size = (int)$size;
-  }
-
-
-  /**
    * Save a search string for future listings
    *
    * @param  string SQL params to use in listing method
@@ -118,13 +94,6 @@
   
   
   /**
-   * Close connection to source
-   * Called on script shutdown
-   */
-  function close(){}
-  
-  
-  /**
    * List the current set of contact records
    *
    * @param  array  List of cols to show
@@ -233,7 +202,7 @@
    *
    * @return Result array or NULL if nothing selected yet
    */
-  function get_result($as_res=true)
+  function get_result()
   {
     return $this->result;
   }

Modified: branches/devel-api/program/include/rcube_ldap.php
===================================================================
--- branches/devel-api/program/include/rcube_ldap.php	2009-03-11 21:43:18 UTC (rev 2352)
+++ branches/devel-api/program/include/rcube_ldap.php	2009-03-13 11:29:21 UTC (rev 2353)
@@ -24,7 +24,7 @@
  *
  * @package Addressbook
  */
-class rcube_ldap
+class rcube_ldap extends rcube_addressbook
 {
   var $conn;
   var $prop = array();

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list